index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view class="mark_id_container">
  3. <custom-nav-bar :title="getTitle">
  4. <view class="nav_right_action" slot="more">
  5. <text v-show="!loading" @click="saveOrCopy">{{ getConfirmText }}</text>
  6. <u-loading-icon v-show="loading" />
  7. <!-- <u-button :loading="loading" @click="saveOrCopy" type="primary" :text="getConfirmText" /> -->
  8. </view>
  9. </custom-nav-bar>
  10. <view class="content_row">
  11. <u-input
  12. :disabled="!isRemark && !isSelfNickname"
  13. v-model="content"
  14. disabledColor="transparent"
  15. maxlength="16"
  16. placeholder="请输入内容"
  17. clearable
  18. >
  19. </u-input>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import IMSDK from "openim-uniapp-polyfill";
  25. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  26. import { businessInfoUpdate } from "../../../api/login";
  27. export default {
  28. components: {
  29. CustomNavBar,
  30. },
  31. props: {},
  32. data() {
  33. return {
  34. content: "",
  35. isRemark: false,
  36. isSelfNickname: false,
  37. sourceInfo: {},
  38. loading: false,
  39. };
  40. },
  41. computed: {
  42. getTitle() {
  43. if (this.isRemark) {
  44. return "设置备注";
  45. }
  46. if (this.isSelfNickname) {
  47. return "我的姓名";
  48. }
  49. return "ID号";
  50. },
  51. getConfirmText() {
  52. return this.isRemark || this.isSelfNickname ? "保存" : "复制";
  53. },
  54. },
  55. onLoad(options) {
  56. const { isRemark, isSelfNickname, sourceInfo } = options;
  57. this.sourceInfo = JSON.parse(sourceInfo);
  58. this.isRemark = !!isRemark;
  59. if (this.isRemark) {
  60. this.content = this.sourceInfo.remark;
  61. }
  62. this.isSelfNickname = !!isSelfNickname;
  63. if (this.isSelfNickname) {
  64. this.content = this.sourceInfo.nickname;
  65. }
  66. },
  67. methods: {
  68. async saveOrCopy() {
  69. if (this.isRemark) {
  70. this.loading = true;
  71. IMSDK.asyncApi(IMSDK.IMMethods.SetFriendRemark, IMSDK.uuid(), {
  72. toUserID: this.sourceInfo.userID,
  73. remark: this.content,
  74. })
  75. .then(() => {
  76. uni.$u.toast("设置成功");
  77. setTimeout(() => uni.navigateBack(), 1000);
  78. })
  79. .catch((error) => {
  80. console.log(error);
  81. uni.$u.toast("设置失败");
  82. })
  83. .finally(() => (this.loading = false));
  84. } else if (this.isSelfNickname) {
  85. this.loading = true;
  86. try {
  87. await businessInfoUpdate({
  88. userID: this.sourceInfo.userID,
  89. nickname: this.content,
  90. });
  91. await this.$store.dispatch("user/updateBusinessInfo");
  92. uni.$u.toast("修改成功");
  93. setTimeout(() => uni.navigateBack(), 1000);
  94. } catch (e) {
  95. console.log(e);
  96. uni.$u.toast("修改失败");
  97. }
  98. this.loading = false;
  99. } else {
  100. uni.setClipboardData({
  101. data: this.sourceInfo.userID,
  102. success: () => {
  103. uni.hideToast();
  104. this.$nextTick(() => {
  105. uni.$u.toast("复制成功");
  106. });
  107. },
  108. });
  109. }
  110. },
  111. },
  112. };
  113. </script>
  114. <style lang="scss" scoped>
  115. .mark_id_container {
  116. @include colBox(false);
  117. height: 100vh;
  118. .nav_right_action {
  119. margin-right: 36rpx;
  120. }
  121. .content_row {
  122. margin-top: 96rpx;
  123. margin: 72rpx 44rpx 0;
  124. .u-input {
  125. background-color: #e8eaef;
  126. }
  127. .u-button {
  128. height: 60rpx;
  129. }
  130. }
  131. }
  132. </style>