index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="user_more_container">
  3. <custom-nav-bar title="好友设置" />
  4. <view class="row_wrap">
  5. <view class="info_row">
  6. <user-info-row-item v-if="isFriend" @click="toMark" lable="设置备注" arrow />
  7. <user-info-row-item @click="toMore" lable="个人资料" arrow />
  8. <user-info-row-item @click="toShare" lable="推荐给朋友" arrow />
  9. </view>
  10. <view class="info_row">
  11. <user-info-row-item lable="加入黑名单" arrow>
  12. <u-switch asyncChange :loading="blackLoading" size="20" :value="isBlacked" @change="change"></u-switch>
  13. </user-info-row-item>
  14. </view>
  15. <view v-if="isFriend" class="info_row">
  16. <u-button @click="() => (showConfirm = true)" type="error" plain text="解除好友关系"></u-button>
  17. </view>
  18. <u-toast ref="uToast"></u-toast>
  19. <u-modal
  20. :content="`确定要解除与${sourceInfo.nickname}的好友关系吗?`"
  21. asyncClose
  22. :show="showConfirm"
  23. showCancelButton
  24. @confirm="confirmRemove"
  25. @cancel="() => (showConfirm = false)"
  26. ></u-modal>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import IMSDK from 'openim-uniapp-polyfill';
  32. import CustomNavBar from '../../../components/CustomNavBar/index.vue';
  33. import UserInfoRowItem from '../userCard/components/UserInfoRowItem.vue';
  34. import { ContactChooseTypes } from '../../../constant';
  35. export default {
  36. components: {
  37. CustomNavBar,
  38. UserInfoRowItem
  39. },
  40. data() {
  41. return {
  42. blackLoading: false,
  43. sourceInfo: {},
  44. showConfirm: false
  45. };
  46. },
  47. computed: {
  48. isFriend() {
  49. return this.$store.getters.storeFriendList.findIndex((friend) => friend.userID === this.sourceInfo.userID) !== -1;
  50. },
  51. isBlacked() {
  52. return this.$store.getters.storeBlackList.findIndex((black) => black.userID === this.sourceInfo.userID) !== -1;
  53. }
  54. },
  55. onLoad(options) {
  56. const { sourceInfo } = options;
  57. this.sourceInfo = JSON.parse(sourceInfo);
  58. },
  59. methods: {
  60. change(isBlack) {
  61. this.blackLoading = true;
  62. if (isBlack) {
  63. IMSDK.asyncApi(IMSDK.IMMethods.AddBlack, IMSDK.uuid(), {
  64. toUserID: this.sourceInfo.userID,
  65. ex: ''
  66. }).catch(() => this.showToast('操作失败'))
  67. .finally(() => (this.blackLoading = false));
  68. return;
  69. }
  70. IMSDK.asyncApi(IMSDK.IMMethods.RemoveBlack, IMSDK.uuid(), this.sourceInfo.userID)
  71. .catch(() => this.showToast('操作失败'))
  72. .finally(() => (this.blackLoading = false));
  73. },
  74. confirmRemove() {
  75. IMSDK.asyncApi(IMSDK.IMMethods.DeleteFriend, IMSDK.uuid(), this.sourceInfo.userID)
  76. .then(() => this.showToast('操作成功'))
  77. .catch(() => this.showToast('操作失败'))
  78. .finally(() => (this.showConfirm = false));
  79. },
  80. toMore() {
  81. let sourceInfo=JSON.stringify(this.sourceInfo);
  82. uni.navigateTo({
  83. url: `/pages_im/pages/common/detailsFileds/index?sourceInfo=${sourceInfo}`
  84. });
  85. },
  86. toMark() {
  87. const friendInfo = this.$store.getters.storeFriendList.find((friend) => friend.userID === this.sourceInfo.userID);
  88. uni.navigateTo({
  89. url: `/pages_im/pages/common/markOrIDPage/index?isRemark=true&sourceInfo=${JSON.stringify(friendInfo)}`
  90. });
  91. },
  92. toShare() {
  93. uni.navigateTo({
  94. url: `/pages_im/pages/common/contactChoose/index?type=${ContactChooseTypes.ShareCard}&cardInfo=${JSON.stringify(this.sourceInfo)}`
  95. });
  96. },
  97. showToast(message) {
  98. this.$refs.uToast.show({
  99. message
  100. });
  101. }
  102. }
  103. };
  104. </script>
  105. <style lang="scss">
  106. .user_more_container {
  107. @include colBox(false);
  108. height: 100vh;
  109. background-color: #f6f6f6;
  110. .row_wrap {
  111. flex: 1;
  112. overflow-y: auto;
  113. }
  114. .info_row {
  115. background-color: #fff;
  116. margin: 24rpx;
  117. border-radius: 6px;
  118. overflow: hidden;
  119. .u-button {
  120. border: none;
  121. }
  122. }
  123. }
  124. </style>