裂变星小程序-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.

202 lines
3.9 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. console.log('--open', open)
  99. this.$refs.popupUnlock.close();
  100. if (open) {
  101. this.isLocked = false
  102. return
  103. }
  104. title && uni.showToast({
  105. title,
  106. icon: 'none',
  107. duration: 3000
  108. })
  109. },
  110. openPopup() {
  111. this.$refs.popupUnlock.open();
  112. },
  113. async onAdd() {
  114. const result = await this.fetchCheckShare()
  115. const { open, need_num, num } = result
  116. console.log('--open', open)
  117. if (open) { // 转发已达标
  118. this.isLocked = false
  119. return
  120. }
  121. uni.showToast({
  122. title: `还需转发${need_num - num}`,
  123. icon: 'none',
  124. })
  125. this.openPopup()
  126. }
  127. },
  128. }
  129. </script>
  130. <style scoped lang="scss">
  131. .page {
  132. position: relative;
  133. height: 100vh;
  134. }
  135. .content {
  136. display: flex;
  137. flex-direction: column;
  138. align-items: center;
  139. }
  140. .avatar {
  141. width: 180rpx;
  142. height: 180rpx;
  143. margin-top: 127rpx;
  144. }
  145. .nick-name {
  146. color: #1B1B1B;
  147. font-size: 32rpx;
  148. margin-top: 30rpx;
  149. }
  150. .btn, .qr {
  151. position: absolute;
  152. }
  153. .btn {
  154. width: calc(100% - 60rpx*2);
  155. height: auto;
  156. left: 60rpx;
  157. bottom: 292rpx;
  158. background-color: #07C160;
  159. border: none;
  160. color: #FFFFFF;
  161. font-size: 28rpx;
  162. line-height: 1;
  163. border-radius: 45rpx;
  164. padding: 25rpx 0;
  165. box-sizing: border-box;
  166. }
  167. .qr {
  168. width: 350rpx;
  169. height: 350rpx;
  170. bottom: 269rpx;
  171. }
  172. </style>