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

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