index.vue 3.5 KB

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