裂变星小程序-25.03.04
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
3.8 KiB

  1. <template>
  2. <view class="page">
  3. <navbar leftClick @leftClick="$utils.navigateBack" />
  4. <view class="content">
  5. <image class="avatar" :src="detail.headImage"></image>
  6. <text class="nick-name">{{ detail.headTitle || '' }}</text>
  7. <template v-if="isLocked">
  8. <button class="btn" type="success" @click="onAdd">添加</button>
  9. </template>
  10. <template v-else>
  11. <image class="qr" :src="detail.wxCodeImage" :show-menu-by-longpress="true"></image>
  12. </template>
  13. </view>
  14. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-user.png"></popupUnlock>
  15. </view>
  16. </template>
  17. <script>
  18. import { mapState } from 'vuex'
  19. import popupUnlock from '../components/popupUnlock.vue'
  20. export default {
  21. components: {
  22. popupUnlock,
  23. },
  24. data() {
  25. return {
  26. id: null,
  27. detail: {
  28. id: null,
  29. userId: null,
  30. headImage: null,
  31. headTitle: null,
  32. indexImage: null,
  33. num: 0,
  34. wxCodeImage: null,
  35. textDetails: null,
  36. },
  37. isLocked: true,
  38. }
  39. },
  40. computed: {
  41. ...mapState(['userInfo']),
  42. },
  43. onShow() {
  44. if (this.id && uni.getStorageSync('token')) {
  45. this.fetchDetails()
  46. }
  47. },
  48. onLoad(option) {
  49. const { id, state, shareId } = option
  50. if (shareId) {
  51. uni.setStorageSync('shareId', shareId)
  52. }
  53. if (state) {
  54. uni.setStorageSync('state', state)
  55. }
  56. if (id) {
  57. uni.setStorageSync('id', id)
  58. }
  59. this.id = id
  60. if (uni.getStorageSync('token')) {
  61. this.fetchDetails()
  62. } else {
  63. uni.navigateTo({
  64. url: '/pages_order/auth/wxLogin'
  65. })
  66. }
  67. },
  68. onShareAppMessage(res) {
  69. const {
  70. headTitle,
  71. indexImage,
  72. } = this.detail
  73. let o = {
  74. title : headTitle,
  75. imageUrl: indexImage,
  76. query: `id=${this.id}&state=0&shareId=${this.userInfo.id}`,
  77. }
  78. this.refreshLockStatus()
  79. return o
  80. },
  81. methods: {
  82. async fetchDetails() {
  83. try {
  84. this.detail = await this.$fetch('getShareInfo', { id: this.id })
  85. } catch (err) {
  86. }
  87. },
  88. async fetchCheckShare() {
  89. try {
  90. return await this.$fetch('checkShare', { id: this.id })
  91. } catch (err) {
  92. return {}
  93. }
  94. },
  95. async refreshLockStatus() {
  96. const result = await this.fetchCheckShare()
  97. const { title, open } = result
  98. this.$refs.popupUnlock.close();
  99. if (open) {
  100. this.isLocked = false
  101. return
  102. }
  103. title && uni.showToast({
  104. title,
  105. icon: 'none',
  106. duration: 3000
  107. })
  108. },
  109. openPopup() {
  110. this.$refs.popupUnlock.open();
  111. },
  112. async onAdd() {
  113. const result = await this.fetchCheckShare()
  114. const { open, need_num, num } = result
  115. if (open) { // 转发已达标
  116. this.isLocked = false
  117. return
  118. }
  119. uni.showToast({
  120. title: `还需转发${need_num - num}`,
  121. icon: 'none',
  122. })
  123. this.openPopup()
  124. }
  125. },
  126. }
  127. </script>
  128. <style scoped lang="scss">
  129. .page {
  130. position: relative;
  131. height: 100vh;
  132. }
  133. .content {
  134. display: flex;
  135. flex-direction: column;
  136. align-items: center;
  137. }
  138. .avatar {
  139. width: 180rpx;
  140. height: 180rpx;
  141. margin-top: 127rpx;
  142. }
  143. .nick-name {
  144. color: #1B1B1B;
  145. font-size: 32rpx;
  146. margin-top: 30rpx;
  147. }
  148. .btn, .qr {
  149. position: absolute;
  150. }
  151. .btn {
  152. width: calc(100% - 60rpx*2);
  153. height: auto;
  154. left: 60rpx;
  155. bottom: 292rpx;
  156. background-color: #07C160;
  157. border: none;
  158. color: #FFFFFF;
  159. font-size: 28rpx;
  160. line-height: 1;
  161. border-radius: 45rpx;
  162. padding: 25rpx 0;
  163. box-sizing: border-box;
  164. }
  165. .qr {
  166. width: 350rpx;
  167. height: 350rpx;
  168. bottom: 269rpx;
  169. }
  170. </style>