share-buy-detail.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="share-buy-detail">
  3. <tui-skeleton v-if="isRequest" :loadingType="3" :isLoading="true"></tui-skeleton>
  4. <!-- 拼单信息 && 立即拼单 -->
  5. <view class="group-message">
  6. <share-buy-group-message :countDownTime="countDownTime" :hasEndTip="true">
  7. <template v-slot:head>
  8. <view class="message">
  9. 还差
  10. <text v-text="collageData.needNum"></text>
  11. 人参团,赶快邀请好友来拼单吧!
  12. </view>
  13. </template>
  14. <template v-slot:foot>
  15. <tui-button type="base" width="600rpx" height="90rpx" shape="circle" :size="30" @click="onShare">
  16. <text>邀请好友拼单</text>
  17. </tui-button>
  18. <view class="line"></view>
  19. <tui-button
  20. type="base"
  21. width="600rpx"
  22. height="90rpx"
  23. shape="circle"
  24. :plain="true"
  25. :size="30"
  26. @click="handleToHome"
  27. >
  28. <text>去首页逛逛</text>
  29. </tui-button>
  30. </template>
  31. </share-buy-group-message>
  32. </view>
  33. <!-- 商品基本信息 参与拼单用户信息-->
  34. <view class="member-info">
  35. <share-buy-member-info
  36. :memberNum="collageData.memberNum"
  37. :existNum="collageData.existNum"
  38. :shopInfo="collageData"
  39. ></share-buy-member-info>
  40. </view>
  41. <!-- 分享 -->
  42. <cm-share-popup ref="sharePopup" :data="posterData" type="product"></cm-share-popup>
  43. </view>
  44. </template>
  45. <script>
  46. import { fetchCollageOrderDetail } from '@/services/api/order.js'
  47. import { countDown } from '@/common/utils.js'
  48. import { mapGetters } from 'vuex'
  49. export default {
  50. data() {
  51. return {
  52. isRequest: true,
  53. collageId: '',
  54. collageData: {},
  55. // 海报生成数据
  56. posterData: {
  57. porductName: '',
  58. productPrice: '',
  59. productOriginPrice: '',
  60. productImage: '',
  61. qrCodeImage: '' // 商品详情二维码
  62. },
  63. timer: null,
  64. countDownTime: {}
  65. }
  66. },
  67. computed: {
  68. ...mapGetters(['userId'])
  69. },
  70. // 分享到微信用户
  71. onShareAppMessage() {
  72. const shareData = {
  73. type: 4,
  74. collageId: this.collageData.collageId,
  75. initiatorId: this.userId
  76. }
  77. const state_str = encodeURIComponent(this.$crypto.encrypt(shareData))
  78. console.log(state_str)
  79. return {
  80. title: '哈喽,赶快来参团吧!这件商品拼团买更便宜~',
  81. path: `/pages/index/index?state_str=${state_str}`,
  82. imageUrl: this.collageData.productImage
  83. }
  84. },
  85. onLoad(options) {
  86. this.collageId = options.collageId
  87. },
  88. onShow() {
  89. this.fetchOrderDetails()
  90. },
  91. methods: {
  92. // 获取拼单详情
  93. async fetchOrderDetails() {
  94. try {
  95. const res = await fetchCollageOrderDetail({
  96. collageId: this.collageId,
  97. userId: this.userId
  98. })
  99. this.collageData = res.data
  100. const { memberNum, existNum, productName, productImage, price } = this.collageData
  101. // 验证拼单是否成功
  102. if (memberNum === existNum) {
  103. uni.setStorageSync('SHARE_BUY_COLLAGE_DATA', this.collageData)
  104. setTimeout(() => {
  105. this.$router.redirectTo('share-buy/share-buy-success')
  106. }, 500)
  107. return
  108. }
  109. // 设置分享海报商品信息
  110. this.posterData.porductName = productName
  111. this.posterData.productImage = productImage
  112. this.posterData.productPrice = price
  113. this.countDown()
  114. this.isRequest = false
  115. } catch (e) {
  116. console.log(e)
  117. }
  118. },
  119. // 去首页
  120. handleToHome() {
  121. this.$router.switchTab('home')
  122. },
  123. // 分享
  124. async onShare() {
  125. this.$refs.sharePopup.open()
  126. },
  127. // 倒计时
  128. countDown() {
  129. const startTime = Date.now()
  130. const endTime = new Date(this.collageData.endTime).getTime()
  131. this.timer && clearTimeout(this.timer)
  132. countDown(endTime, startTime, {}, item => {
  133. this.countDownTime = item.conttainer
  134. this.timer = item.t
  135. })
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .share-buy-detail {
  142. .line {
  143. height: 24rpx;
  144. }
  145. .member-info {
  146. margin-top: 24rpx;
  147. }
  148. .message {
  149. font-size: 30rpx;
  150. color: #333333;
  151. text {
  152. color: #ff457b;
  153. }
  154. }
  155. }
  156. </style>