index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <!-- 我的好友 -->
  3. <a-spin :spinning="loading">
  4. <div class="my-friend">
  5. <a-input-search placeholder="输入好友代码进行搜索"
  6. enter-button="搜索"
  7. class="searchFriendInput"
  8. @search="handleSearch">
  9. <template #prefix>
  10. <SearchOutlined />
  11. </template>
  12. </a-input-search>
  13. <div class="mt10">
  14. <div class="item"
  15. v-for="(item, index) in searchFriend"
  16. :key="index + '11'">
  17. <div class="left">
  18. <span>{{item.frienduserid}} {{ item.friendname }}</span>
  19. </div>
  20. <div class="right"
  21. @click="operate(item)">
  22. <span v-if="item.isfriend">
  23. <svg class="icon svg-icon"
  24. aria-hidden="true">
  25. <use xlink:href="#icon-shanchu" />
  26. </svg>
  27. </span>
  28. <span v-else
  29. class="addFriBtn">加为好友</span>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </a-spin>
  35. </template>
  36. <script lang="ts">
  37. import { SearchOutlined } from '@ant-design/icons-vue';
  38. import { defineComponent, ref } from 'vue';
  39. import { initData } from '@/common/methods';
  40. import { QueryWrFriendApplyRsp } from '@/services/go/wrtrade/interface';
  41. import { queryQueryWrFriend } from '@/services/go/wrtrade';
  42. import { friendOperate } from '@/services/proto/accountinfo';
  43. import { getUsrId } from '@/services/bus/user';
  44. import { queryResultLoadingAndInfo, requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
  45. import { message } from 'ant-design-vue';
  46. import { Modal } from 'ant-design-vue';
  47. import { geLoginID_number } from '@/services/bus/login';
  48. export default defineComponent({
  49. name: 'friend',
  50. components: { SearchOutlined },
  51. setup() {
  52. const myFriends = ref<QueryWrFriendApplyRsp[]>([]);
  53. const searchFriend = ref<QueryWrFriendApplyRsp[]>([]);
  54. const loading = ref<boolean>(false);
  55. // 设置 新增和删除好友 公共请求参数
  56. // operatetype: number; // 操作类型-1:申请 2:审核通过 3:审核拒绝 4: 删除
  57. function getParam(operatetype: 1 | 2 | 3 | 4, frienduserid: string) {
  58. return {
  59. operatetype,
  60. userid: getUsrId(),
  61. frienduserid,
  62. applysrc: 2,
  63. applicantid: geLoginID_number(),
  64. };
  65. }
  66. // 删除好友
  67. function deleteFriend(frienduserid: string) {
  68. Modal.confirm({
  69. title: '删除好友',
  70. content: '确定删除好友?',
  71. onOk() {
  72. const param = getParam(4, frienduserid);
  73. requestResultLoadingAndInfo(friendOperate, param, loading, ['删除好友成功', '删除好友失败:']).then(() => {
  74. queryMyFriend();
  75. });
  76. },
  77. });
  78. }
  79. // 添加好友
  80. function addFriend(frienduserid: string) {
  81. const param = getParam(1, frienduserid);
  82. requestResultLoadingAndInfo(friendOperate, param, loading, ['添加好友成功', '添加好友失败:']).then(() => {
  83. queryMyFriend();
  84. });
  85. }
  86. function operate({ frienduserid, isfriend }: QueryWrFriendApplyRsp) {
  87. const id = frienduserid.toString();
  88. if (isfriend) {
  89. deleteFriend(id);
  90. } else {
  91. addFriend(id);
  92. }
  93. }
  94. // 查询好友列表
  95. function queryMyFriend(value?: string) {
  96. loading.value = true;
  97. queryQueryWrFriend(value)
  98. .then((res) => {
  99. if (!value) {
  100. myFriends.value = res; // 我的朋友
  101. }
  102. searchFriend.value = res;
  103. })
  104. .catch((err: string) => message.error(err))
  105. .finally(() => {
  106. loading.value = false;
  107. });
  108. }
  109. function handleSearch(value: string) {
  110. if (value) {
  111. const findResult = myFriends.value.filter((e) => String(e.frienduserid).includes(value));
  112. if (findResult.length) {
  113. searchFriend.value = findResult;
  114. } else {
  115. queryMyFriend(value);
  116. }
  117. } else {
  118. searchFriend.value = myFriends.value;
  119. }
  120. }
  121. initData(() => {
  122. queryMyFriend();
  123. });
  124. return { operate, myFriends, loading, handleSearch, searchFriend };
  125. },
  126. });
  127. </script>
  128. <style lang="less">
  129. .my-friend {
  130. height: 340px;
  131. width: 260px;
  132. padding: 10px 9px 0 11px;
  133. background: @m-grey22;
  134. border: 1px solid @m-grey23;
  135. box-shadow: 0px 10px 10px 0px @m-black18;
  136. .rounded-corners(5px);
  137. .item {
  138. width: 100%;
  139. height: 40px;
  140. line-height: 40px;
  141. color: @m-grey57;
  142. font-size: 14px;
  143. border-bottom: 1px solid @m-grey58;
  144. .flex;
  145. justify-content: space-between;
  146. .left {
  147. span:last-child {
  148. margin-left: 10px;
  149. }
  150. }
  151. .right {
  152. padding-right: 10px;
  153. .icon {
  154. color: @m-yellow7;
  155. font-size: 16px;
  156. height: 40px;
  157. line-height: 40px;
  158. display: none;
  159. }
  160. .addFriBtn {
  161. display: inline-block;
  162. cursor: pointer;
  163. width: 80px;
  164. height: 26px;
  165. border: 1px solid @m-blue0;
  166. .rounded-corners(13px);
  167. color: @m-blue0;
  168. font-size: 14px;
  169. line-height: 24px;
  170. text-align: center;
  171. }
  172. }
  173. }
  174. .item:hover {
  175. background: @m-grey56;
  176. .rounded-corners(5px);
  177. color: @m-white0;
  178. .addFriBtn {
  179. border: 1px solid @m-blue33;
  180. color: @m-blue33;
  181. }
  182. .right {
  183. .icon {
  184. display: block;
  185. }
  186. }
  187. }
  188. .searchFriendInput {
  189. border: 1px solid @m-grey59;
  190. .ant-input-wrapper .searchFriendInput {
  191. border: none;
  192. height: 28px;
  193. box-shadow: none !important;
  194. }
  195. }
  196. }
  197. </style
  198. >;