index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <!-- 我的好友 -->
  3. <a-spin :spinning="loading">
  4. <div class="my-friend">
  5. <a-input-search
  6. placeholder="输入好友代码进行搜索"
  7. enter-button
  8. class="searchFriendInput"
  9. @search="handleSearch"
  10. />
  11. <div v-for="(item, index) in searchFriend" :key="index + '11'">
  12. <a-row type="flex">
  13. <a-col :span="12">
  14. <span>{{item.frienduserid}} {{ item.friendname }}</span>
  15. </a-col>
  16. <a-col :span="6" @click="operate(item)">
  17. <span v-if="item.isfriend">删除</span>
  18. <span v-else>添加</span>
  19. </a-col>
  20. </a-row>
  21. <a-divider />
  22. </div>
  23. </div>
  24. </a-spin>
  25. </template>
  26. <script lang="ts">
  27. import { defineComponent, ref } from 'vue';
  28. import { initData } from '@/common/methods';
  29. import { QueryWrFriendApplyRsp } from '@/services/go/wrtrade/interface';
  30. import { queryQueryWrFriend } from '@/services/go/wrtrade';
  31. import { friendOperate } from '@/services/proto/accountinfo';
  32. import { getUsrId } from '@/services/bus/user';
  33. import { queryResultLoadingAndInfo, requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
  34. import { message } from 'ant-design-vue';
  35. import { Modal } from 'ant-design-vue';
  36. import { getLongTypeLoginID } from '@/services/bus/login';
  37. export default defineComponent({
  38. name: 'friend',
  39. setup() {
  40. const myFriends = ref<QueryWrFriendApplyRsp[]>([]);
  41. const searchFriend = ref<QueryWrFriendApplyRsp[]>([]);
  42. const loading = ref<boolean>(false);
  43. // 设置 新增和删除好友 公共请求参数
  44. // operatetype: number; // 操作类型-1:申请 2:审核通过 3:审核拒绝 4: 删除
  45. function getParam(operatetype: 1 | 2 | 3 | 4, frienduserid: string) {
  46. return {
  47. operatetype,
  48. userid: getUsrId(),
  49. frienduserid,
  50. applysrc: 2,
  51. applicantid: getLongTypeLoginID(),
  52. };
  53. }
  54. // 删除好友
  55. function deleteFriend(frienduserid: string) {
  56. Modal.confirm({
  57. title: '删除好友',
  58. content: '确定删除好友?',
  59. onOk() {
  60. const param = getParam(4, frienduserid);
  61. requestResultLoadingAndInfo(friendOperate, param, loading, ['删除好友成功', '删除好友失败:']).then(() => {
  62. queryMyFriend();
  63. });
  64. },
  65. });
  66. }
  67. // 添加好友
  68. function addFriend(frienduserid: string) {
  69. const param = getParam(1, frienduserid);
  70. requestResultLoadingAndInfo(friendOperate, param, loading, ['添加好友成功', '添加好友失败:']).then(() => {
  71. queryMyFriend();
  72. });
  73. }
  74. function operate({ frienduserid, isfriend }: QueryWrFriendApplyRsp) {
  75. if (isfriend) {
  76. deleteFriend(frienduserid);
  77. } else {
  78. addFriend(frienduserid);
  79. }
  80. }
  81. // 查询好友列表
  82. function queryMyFriend(value?: string) {
  83. loading.value = true;
  84. queryQueryWrFriend(value)
  85. .then((res) => {
  86. if (!value) {
  87. myFriends.value = res; // 我的朋友
  88. }
  89. searchFriend.value = res;
  90. })
  91. .catch((err: string) => message.error(err))
  92. .finally(() => {
  93. loading.value = false;
  94. });
  95. }
  96. function handleSearch(value: string) {
  97. const findResult = myFriends.value.find((e) => String(e.frienduserid).includes(value));
  98. if (findResult) {
  99. searchFriend.value = [findResult];
  100. } else {
  101. queryMyFriend(value);
  102. }
  103. }
  104. initData(() => {
  105. queryMyFriend();
  106. });
  107. return { operate, myFriends, loading, handleSearch, searchFriend };
  108. },
  109. });
  110. </script>
  111. <style lang="less">
  112. .my-friend {
  113. height: 340px;
  114. width: 260px;
  115. }
  116. </style
  117. >;