share-buy-detail.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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" @share="onAfterShare">
  43. <template #title>
  44. <view class="share-title">
  45. <view class="title">
  46. 还差
  47. <text v-text="collageData.needNum"></text>
  48. 人,赶快邀请好友来拼单吧!
  49. </view>
  50. <view class="share-desc">
  51. 拼单已发起,人满后立即发货
  52. <text v-if="canShare">(首次分享可获得一张消费分享券)</text>
  53. </view>
  54. </view>
  55. </template>
  56. </cm-share-popup>
  57. </view>
  58. </template>
  59. <script>
  60. import { fetchCollageOrderDetail, orderShare } from '@/services/api/order.js'
  61. import { fetchCouponDisplay } from '@/services/api/coupon.js'
  62. import { countDown, queryStringify } from '@/common/utils.js'
  63. import { mapGetters } from 'vuex'
  64. export default {
  65. data() {
  66. return {
  67. isRequest: true,
  68. collageId: '',
  69. collageData: {},
  70. // 海报生成数据
  71. posterData: {},
  72. timer: null,
  73. countDownTime: {},
  74. couponTipStr: ''
  75. }
  76. },
  77. computed: {
  78. ...mapGetters(['userId']),
  79. canShare() {
  80. return this.collageData.shareFlag === 1 && this.couponTipStr.indexOf('3') > -1
  81. }
  82. },
  83. // 分享到微信用户
  84. onShareAppMessage() {
  85. const shareData = {
  86. type: 4,
  87. collageId: this.collageData.collageId,
  88. initiatorId: this.userId
  89. }
  90. const state_str = encodeURIComponent(this.$crypto.encrypt(shareData))
  91. console.log(state_str)
  92. return {
  93. title: '哈喽,赶快来参团吧!这件商品拼团买更便宜~',
  94. path: `/pages/index/index?state_str=${state_str}`,
  95. imageUrl: this.collageData.productImage
  96. }
  97. },
  98. onLoad(options) {
  99. this.collageId = options.collageId
  100. this.fetchCouponDisplay()
  101. },
  102. onShow() {
  103. this.fetchOrderDetails()
  104. },
  105. methods: {
  106. // 获取可领取优惠券类型
  107. async fetchCouponDisplay() {
  108. try {
  109. const res = await fetchCouponDisplay({ userId: this.userId })
  110. this.couponTipStr = res.data
  111. } catch (e) {
  112. console.log('获取优惠券类型失败')
  113. }
  114. },
  115. // 分享结束
  116. async onAfterShare() {
  117. if (!this.canShare) return
  118. try {
  119. await orderShare({ orderId: this.collageData.orderId, userId: this.userId })
  120. this.$toast('分享成功')
  121. } catch (e) {
  122. this.$toast('分享失败')
  123. }
  124. },
  125. // 分享
  126. async onShare() {
  127. const query = queryStringify({
  128. type: 4,
  129. collageId: this.collageData.collageId,
  130. initiatorId: this.userId
  131. })
  132. this.posterData = {
  133. porductName: '哈喽,赶快来参团吧!这件商品拼团买更便宜~',
  134. productPrice: this.collageData.price,
  135. productOriginPrice: this.collageData.normalPrice,
  136. productImage: this.collageData.productImage,
  137. query: query
  138. }
  139. this.$refs.sharePopup.open()
  140. },
  141. // 获取拼单详情
  142. async fetchOrderDetails() {
  143. try {
  144. const res = await fetchCollageOrderDetail({
  145. collageId: this.collageId,
  146. userId: this.userId
  147. })
  148. this.collageData = res.data
  149. const { memberNum, existNum, productName, productImage, price } = this.collageData
  150. // 验证拼单是否成功
  151. if (memberNum === existNum) {
  152. uni.setStorageSync('SHARE_BUY_COLLAGE_DATA', this.collageData)
  153. setTimeout(() => {
  154. this.$router.redirectTo('share-buy/share-buy-success')
  155. }, 500)
  156. return
  157. }
  158. // 设置分享海报商品信息
  159. this.posterData.porductName = productName
  160. this.posterData.productImage = productImage
  161. this.posterData.productPrice = price
  162. this.countDown()
  163. this.isRequest = false
  164. } catch (e) {
  165. console.log(e)
  166. }
  167. },
  168. // 去首页
  169. handleToHome() {
  170. this.$router.switchTab('home')
  171. },
  172. // 倒计时
  173. countDown() {
  174. const startTime = Date.now()
  175. const endTime = new Date(this.collageData.endTime).getTime()
  176. this.timer && clearTimeout(this.timer)
  177. countDown(endTime, startTime, {}, item => {
  178. this.countDownTime = item.conttainer
  179. this.timer = item.t
  180. })
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .share-buy-detail {
  187. .line {
  188. height: 24rpx;
  189. }
  190. .member-info {
  191. margin-top: 24rpx;
  192. }
  193. .message {
  194. font-size: 30rpx;
  195. color: #333333;
  196. text {
  197. color: #ff457b;
  198. }
  199. }
  200. .share-title {
  201. text-align: center;
  202. padding-bottom: 40rpx;
  203. .title {
  204. font-size: 34rpx;
  205. font-weight: bold;
  206. line-height: 48rpx;
  207. color: #666666;
  208. text {
  209. color: #ff457b;
  210. }
  211. }
  212. .share-desc {
  213. margin-top: 14rpx;
  214. font-size: 26rpx;
  215. color: #333;
  216. line-height: 1.6;
  217. text {
  218. color: #ff457b;
  219. }
  220. }
  221. }
  222. }
  223. </style>