share-buy-detail.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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, queryStringify } 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. timer: null,
  58. countDownTime: {}
  59. }
  60. },
  61. computed: {
  62. ...mapGetters(['userId'])
  63. },
  64. // 分享到微信用户
  65. onShareAppMessage() {
  66. const shareData = {
  67. type: 4,
  68. collageId: this.collageData.collageId,
  69. initiatorId: this.userId
  70. }
  71. const state_str = encodeURIComponent(this.$crypto.encrypt(shareData))
  72. console.log(state_str)
  73. return {
  74. title: '哈喽,赶快来参团吧!这件商品拼团买更便宜~',
  75. path: `/pages/index/index?state_str=${state_str}`,
  76. imageUrl: this.collageData.productImage
  77. }
  78. },
  79. onLoad(options) {
  80. this.collageId = options.collageId
  81. },
  82. onShow() {
  83. this.fetchOrderDetails()
  84. },
  85. methods: {
  86. // 分享
  87. async onShare() {
  88. const query = queryStringify({
  89. type: 4,
  90. collageId: this.collageData.collageId,
  91. initiatorId: this.userId
  92. })
  93. this.posterData = {
  94. porductName: '哈喽,赶快来参团吧!这件商品拼团买更便宜~',
  95. productPrice: this.collageData.price,
  96. productOriginPrice: this.collageData.normalPrice,
  97. productImage: this.collageData.productImage,
  98. query: query
  99. }
  100. this.$refs.sharePopup.open()
  101. },
  102. // 获取拼单详情
  103. async fetchOrderDetails() {
  104. try {
  105. const res = await fetchCollageOrderDetail({
  106. collageId: this.collageId,
  107. userId: this.userId
  108. })
  109. this.collageData = res.data
  110. const { memberNum, existNum, productName, productImage, price } = this.collageData
  111. // 验证拼单是否成功
  112. if (memberNum === existNum) {
  113. uni.setStorageSync('SHARE_BUY_COLLAGE_DATA', this.collageData)
  114. setTimeout(() => {
  115. this.$router.redirectTo('share-buy/share-buy-success')
  116. }, 500)
  117. return
  118. }
  119. // 设置分享海报商品信息
  120. this.posterData.porductName = productName
  121. this.posterData.productImage = productImage
  122. this.posterData.productPrice = price
  123. this.countDown()
  124. this.isRequest = false
  125. } catch (e) {
  126. console.log(e)
  127. }
  128. },
  129. // 去首页
  130. handleToHome() {
  131. this.$router.switchTab('home')
  132. },
  133. // 倒计时
  134. countDown() {
  135. const startTime = Date.now()
  136. const endTime = new Date(this.collageData.endTime).getTime()
  137. this.timer && clearTimeout(this.timer)
  138. countDown(endTime, startTime, {}, item => {
  139. this.countDownTime = item.conttainer
  140. this.timer = item.t
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .share-buy-detail {
  148. .line {
  149. height: 24rpx;
  150. }
  151. .member-info {
  152. margin-top: 24rpx;
  153. }
  154. .message {
  155. font-size: 30rpx;
  156. color: #333333;
  157. text {
  158. color: #ff457b;
  159. }
  160. }
  161. }
  162. </style>