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

209 lines
4.0 KiB

1 week ago
  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. //调用增加分享次数的方法
  79. const params = {
  80. id:this.id,
  81. state:"0",
  82. }
  83. this.$fetch('addLogShareInfo', params)
  84. this.refreshLockStatus()
  85. return o
  86. },
  87. methods: {
  88. async fetchDetails() {
  89. try {
  90. this.detail = await this.$fetch('getShareInfo', { id: this.id })
  91. } catch (err) {
  92. }
  93. },
  94. async fetchCheckShare() {
  95. try {
  96. return await this.$fetch('checkShare', { id: this.id })
  97. } catch (err) {
  98. return {}
  99. }
  100. },
  101. async refreshLockStatus() {
  102. const result = await this.fetchCheckShare()
  103. const { title, open } = result
  104. console.log('--open', open)
  105. this.$refs.popupUnlock.close();
  106. if (open) {
  107. this.isLocked = false
  108. return
  109. }
  110. title && uni.showToast({
  111. title,
  112. icon: 'none',
  113. duration: 3000
  114. })
  115. },
  116. openPopup() {
  117. this.$refs.popupUnlock.open();
  118. },
  119. async onAdd() {
  120. const result = await this.fetchCheckShare()
  121. const { open, need_num, num } = result
  122. console.log('--open', open)
  123. if (open) { // 转发已达标
  124. this.isLocked = false
  125. return
  126. }
  127. uni.showToast({
  128. title: `还需转发${need_num - num}`,
  129. icon: 'none',
  130. })
  131. this.openPopup()
  132. }
  133. },
  134. }
  135. </script>
  136. <style scoped lang="scss">
  137. .page {
  138. position: relative;
  139. height: 100vh;
  140. }
  141. .content {
  142. display: flex;
  143. flex-direction: column;
  144. align-items: center;
  145. }
  146. .avatar {
  147. width: 180rpx;
  148. height: 180rpx;
  149. margin-top: 127rpx;
  150. }
  151. .nick-name {
  152. color: #1B1B1B;
  153. font-size: 32rpx;
  154. margin-top: 30rpx;
  155. }
  156. .btn, .qr {
  157. position: absolute;
  158. }
  159. .btn {
  160. width: calc(100% - 60rpx*2);
  161. height: auto;
  162. left: 60rpx;
  163. bottom: 292rpx;
  164. background-color: #07C160;
  165. border: none;
  166. color: #FFFFFF;
  167. font-size: 28rpx;
  168. line-height: 1;
  169. border-radius: 45rpx;
  170. padding: 25rpx 0;
  171. box-sizing: border-box;
  172. }
  173. .qr {
  174. width: 350rpx;
  175. height: 350rpx;
  176. bottom: 269rpx;
  177. }
  178. </style>