share-buy-entry.vue 4.6 KB

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