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

218 lines
4.3 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months 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.detail.id ? this.refreshLockStatus() : 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. 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-popup {
  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-popup {
  174. width: 100vw;
  175. bottom: 269rpx;
  176. .tips {
  177. color: #1B1B1B;
  178. font-size: 32rpx;
  179. }
  180. }
  181. .qr {
  182. margin-top: 40rpx;
  183. width: 350rpx;
  184. height: 350rpx;
  185. }
  186. </style>