share-buy-entry.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="share-buy-entry">
  3. <tui-skeleton v-if="isRequest" :loadingType="3" :isLoading="true"></tui-skeleton>
  4. <!-- 商品信息 -->
  5. <share-buy-product-info :goodsData="collageData"></share-buy-product-info>
  6. <!-- 拼单信息 && 立即拼单 -->
  7. <view class="group-message">
  8. <share-buy-group-message :countDownTime="countDownTime">
  9. <template v-slot:head>
  10. <view class="message">
  11. 还差
  12. <text v-text="collageData.needNum"></text>
  13. 人参团,距离结束还剩:
  14. </view>
  15. </template>
  16. <template v-slot:foot>
  17. <tui-button type="base" width="600rpx" height="90rpx" shape="circle" :size="30" @click="onSubmit">
  18. <text>立即参团</text>
  19. </tui-button>
  20. </template>
  21. </share-buy-group-message>
  22. </view>
  23. <!-- 商品基本信息 参团用户信息-->
  24. <view class="member-info">
  25. <share-buy-member-info
  26. :memberNum="collageData.memberNum"
  27. :existNum="collageData.existNum"
  28. :shopInfo="collageData"
  29. ></share-buy-member-info>
  30. </view>
  31. <!-- 确认弹框 -->
  32. <tui-modal
  33. :show="confirmModal"
  34. content="您已经参加过该拼团活动了,请前往订单详情查看订单!"
  35. @click="onConfirm"
  36. ></tui-modal>
  37. </view>
  38. </template>
  39. <script>
  40. import { fetchCollageOrderDetail } from '@/services/api/order.js'
  41. import { countDown } from '@/common/utils.js'
  42. import { mapGetters } from 'vuex'
  43. export default {
  44. data() {
  45. return {
  46. isRequest: true,
  47. confirmModal: false,
  48. collageId: '',
  49. countDownTime: {},
  50. timer: null,
  51. collageData: {}
  52. }
  53. },
  54. computed: {
  55. ...mapGetters(['userId'])
  56. },
  57. onLoad(options) {
  58. this.collageId = options.collageId
  59. },
  60. onShow() {
  61. this.fetchOrderDetails()
  62. },
  63. methods: {
  64. // 获取拼单详情
  65. async fetchOrderDetails() {
  66. try {
  67. const res = await fetchCollageOrderDetail({
  68. collageId: this.collageId,
  69. userId: this.userId
  70. })
  71. this.collageData = res.data
  72. this.countDown()
  73. // 判断当前用户是否参与了拼团
  74. if (this.collageData.orderId > 0) {
  75. this.confirmModal = true
  76. }
  77. // 拼团已结束
  78. if (this.collageData.status === 2) {
  79. this.$toast('拼团已结束')
  80. setTimeout(() => this.$router.switchTab('home'), 1000)
  81. }
  82. this.isRequest = false
  83. } catch (e) {
  84. console.log(e)
  85. }
  86. },
  87. // 倒计时
  88. countDown() {
  89. const startTime = Date.now()
  90. const endTime = new Date(this.collageData.endTime).getTime()
  91. // 拼团已结束
  92. if (endTime < startTime) {
  93. this.$toast('拼团已结束')
  94. setTimeout(() => this.$router.switchTab('home'), 1000)
  95. return
  96. }
  97. this.timer && clearTimeout(this.timer)
  98. countDown(endTime, startTime, {}, item => {
  99. this.countDownTime = item.conttainer
  100. this.timer = item.t
  101. })
  102. },
  103. // 确认弹窗
  104. onConfirm(e) {
  105. if (e.index) {
  106. this.$router.redirectTo('order/order-detail?orderId=' + this.collageData.orderId)
  107. } else {
  108. this.$router.redirectTo('share-buy/share-buy-detail?collageId=' + this.collageId)
  109. }
  110. },
  111. // 提价购买信息
  112. onSubmit() {
  113. // 用户未登录
  114. if (!this.userId) {
  115. const pages = getCurrentPages()
  116. const page = pages[pages.length - 1]
  117. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  118. uni.redirectTo({ url: '/pages/authorize/login-custom' })
  119. return
  120. }
  121. // 提交订单信息
  122. let submitInfo = {
  123. allCount: 1,
  124. skuId: this.collageData.skuId,
  125. productCount: 1,
  126. heUserId: this.userId,
  127. collageFlag: 1,
  128. collageId: this.collageId
  129. }
  130. uni.setStorageSync('COMMIT_PRODUCT_INFO', submitInfo)
  131. this.$router.redirectTo('order/order-create?type=shareBuy')
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .share-buy-entry {
  138. .group-message,
  139. .member-info {
  140. margin-top: 24rpx;
  141. }
  142. .message {
  143. font-size: 30rpx;
  144. color: #333333;
  145. text {
  146. color: #ff457b;
  147. }
  148. }
  149. }
  150. </style>