index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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
  12. asyncChange
  13. :loading="blackLoading"
  14. size="20"
  15. :value="isBlacked"
  16. @change="change"
  17. ></u-switch>
  18. </user-info-row-item>
  19. </view>
  20. <view v-if="isFriend" class="info_row">
  21. <u-button
  22. @click="() => (showConfirm = true)"
  23. type="error"
  24. plain
  25. text="解除好友关系"
  26. ></u-button>
  27. </view>
  28. <u-toast ref="uToast"></u-toast>
  29. <u-modal
  30. :content="`确定要解除与${sourceInfo.nickname}的好友关系吗?`"
  31. asyncClose
  32. :show="showConfirm"
  33. showCancelButton
  34. @confirm="confirmRemove"
  35. @cancel="() => (showConfirm = false)"
  36. ></u-modal>
  37. </view>
  38. </template>
  39. <script>
  40. import IMSDK from "openim-uniapp-polyfill";
  41. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  42. import UserInfoRowItem from "../userCard/components/UserInfoRowItem.vue";
  43. import { ContactChooseTypes } from "../../../constant";
  44. export default {
  45. components: {
  46. CustomNavBar,
  47. UserInfoRowItem,
  48. },
  49. data() {
  50. return {
  51. blackLoading: false,
  52. sourceInfo: {},
  53. showConfirm: false,
  54. };
  55. },
  56. computed: {
  57. isFriend() {
  58. return (
  59. this.$store.getters.storeFriendList.findIndex(
  60. (friend) => friend.userID === this.sourceInfo.userID,
  61. ) !== -1
  62. );
  63. },
  64. isBlacked() {
  65. return (
  66. this.$store.getters.storeBlackList.findIndex(
  67. (black) => black.userID === this.sourceInfo.userID,
  68. ) !== -1
  69. );
  70. },
  71. },
  72. onLoad(options) {
  73. const { sourceInfo } = options;
  74. this.sourceInfo = JSON.parse(sourceInfo);
  75. },
  76. methods: {
  77. change(isBlack) {
  78. this.blackLoading = true;
  79. if (isBlack) {
  80. IMSDK.asyncApi(IMSDK.IMMethods.AddBlack, IMSDK.uuid(), {
  81. toUserID: this.sourceInfo.userID,
  82. ex: "",
  83. })
  84. .catch(() => this.showToast("操作失败"))
  85. .finally(() => (this.blackLoading = false));
  86. return;
  87. }
  88. IMSDK.asyncApi(
  89. IMSDK.IMMethods.RemoveBlack,
  90. IMSDK.uuid(),
  91. this.sourceInfo.userID
  92. )
  93. .catch(() => this.showToast("操作失败"))
  94. .finally(() => (this.blackLoading = false));
  95. },
  96. confirmRemove() {
  97. IMSDK.asyncApi(
  98. IMSDK.IMMethods.DeleteFriend,
  99. IMSDK.uuid(),
  100. this.sourceInfo.userID,
  101. )
  102. .then(() => this.showToast("操作成功"))
  103. .catch(() => this.showToast("操作失败"))
  104. .finally(() => (this.showConfirm = false));
  105. },
  106. toMore() {
  107. uni.navigateTo({
  108. url: `/pages_im/pages/common/detailsFileds/index?sourceInfo=${JSON.stringify(
  109. this.sourceInfo,
  110. )}`,
  111. });
  112. },
  113. toMark() {
  114. const friendInfo = this.$store.getters.storeFriendList.find(
  115. (friend) => friend.userID === this.sourceInfo.userID,
  116. )
  117. uni.navigateTo({
  118. url: `/pages_im/pages/common/markOrIDPage/index?isRemark=true&sourceInfo=${JSON.stringify(
  119. friendInfo,
  120. )}`,
  121. });
  122. },
  123. toShare() {
  124. uni.navigateTo({
  125. url: `/pages_im/pages/common/contactChoose/index?type=${
  126. ContactChooseTypes.ShareCard
  127. }&cardInfo=${JSON.stringify(this.sourceInfo)}`,
  128. });
  129. },
  130. showToast(message) {
  131. this.$refs.uToast.show({
  132. message,
  133. });
  134. },
  135. },
  136. };
  137. </script>
  138. <style lang="scss">
  139. .user_more_container {
  140. @include colBox(false);
  141. height: 100vh;
  142. background-color: #f6f6f6;
  143. .info_row {
  144. background-color: #fff;
  145. margin: 24rpx;
  146. border-radius: 6px;
  147. overflow: hidden;
  148. .u-button {
  149. border: none;
  150. }
  151. }
  152. }
  153. </style>