apply.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!-- 優惠券使用 -->
  2. <template>
  3. <view class="wanl-coupon">
  4. <view class="edgeInsetTop"></view>
  5. <!-- 优惠券卡片 -->
  6. <view class="padding-bj bg-red text-black">
  7. <view :class="coupon.type" class="item radius-bock" v-if="coupon">
  8. <image :src="couponBg" class="coupon-bg"></image>
  9. <image :src="couponReceived" class="coupon-sign" v-if="coupon_state"></image>
  10. <!-- 左侧:金额/折扣 -->
  11. <view class="item-left">
  12. <block v-if="coupon.type == 'reduction' || (coupon.type == 'vip' && coupon.usertype == 'reduction')">
  13. <view class="colour">
  14. <text class="text-price"></text>
  15. <text class="price">{{ Number(coupon.price) }}</text>
  16. </view>
  17. <view class="cu-tag wanl-gray-dark radius text-sm">
  18. {{ $t('mall.fullReduction', [Number(coupon.limit), Number(coupon.price)]) }}
  19. </view>
  20. </block>
  21. <block v-if="coupon.type == 'discount' || (coupon.type == 'vip' && coupon.usertype == 'discount')">
  22. <view class="colour">
  23. <text class="price">{{ Number(coupon.discount) }}</text>
  24. <text class="discount">{{ $t('mall.discountSuffix') }}</text>
  25. </view>
  26. <view class="cu-tag wanl-gray-dark radius text-sm">
  27. {{ $t('mall.fullDiscount', [Number(coupon.limit), Number(coupon.discount)]) }}
  28. </view>
  29. </block>
  30. <block v-if="coupon.type == 'shipping'">
  31. <view class="colour">
  32. <text class="price">{{ $t('mall.freeShipping') }}</text>
  33. </view>
  34. <view class="cu-tag wanl-gray-dark radius text-sm">
  35. {{ $t('mall.freeShippingFull', [Number(coupon.limit)]) }}
  36. </view>
  37. </block>
  38. </view>
  39. <!-- 右侧:名称+有效期+领取按钮 -->
  40. <view class="item-right padding-bj">
  41. <view class="title">
  42. <view class="cu-tag sm radius margin-right-xs tagstyle">{{ coupon.type_text }}</view>
  43. <text class="text-cut wanl-gray text-min">{{ coupon.name }}</text>
  44. </view>
  45. <view class="content text-min">
  46. <view class="wanl-gray">
  47. <view><text class="wlIcon-dot"></text>{{ $t('coupon.universal') }}</view>
  48. <block v-if="coupon.pretype == 'fixed'">
  49. <view><text class="wlIcon-dot"></text>{{ $t('coupon.start', [coupon.startdate]) }}</view>
  50. <view><text class="wlIcon-dot"></text>{{ $t('coupon.end', [coupon.enddate]) }}</view>
  51. </block>
  52. <block v-if="coupon.pretype == 'appoint'">
  53. <view v-if="coupon.validity == 0">
  54. <text class="wlIcon-dot"></text>{{ $t('coupon.permanent') }}
  55. </view>
  56. <view v-else>
  57. <text class="wlIcon-dot"></text>{{ $t('coupon.validDays', [coupon.validity]) }}
  58. </view>
  59. </block>
  60. </view>
  61. <!-- 未领取显示领取按钮 -->
  62. <view class="cu-btn sm round" @tap.stop="onReceive(coupon.id)" v-if="!coupon_state">
  63. {{ $t('mall.getNow') }}
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 可用商品列表 -->
  70. <view class="">
  71. <wanl-product :dataList="dataList" />
  72. </view>
  73. <uni-load-more :status="status" />
  74. <view class="edgeInsetBottom"></view>
  75. </view>
  76. </template>
  77. <script>
  78. import { pullCouponApply, postCouponReceive } from '@/features/mall/mall-gateway'
  79. export default {
  80. data() {
  81. return {
  82. coupon_id: 0,
  83. coupon_state: false,
  84. coupon: null,
  85. dataList: [],
  86. reload: false,
  87. total: 0,
  88. current_page: 1,
  89. last_page: 1,
  90. status: 'more',
  91. couponBg: '/static/coupon/bg_coupon_3x.png',
  92. couponReceived: '/static/coupon/img_couponcentre_received_3x.png'
  93. }
  94. },
  95. onLoad(option) {
  96. this.coupon_id = option.id
  97. this.coupon_state = option.state ? true : false
  98. this.loadData()
  99. },
  100. onPullDownRefresh() {
  101. this.current_page = 1
  102. this.reload = true
  103. this.loadData()
  104. },
  105. onReachBottom() {
  106. if (this.current_page >= this.last_page) {
  107. this.status = 'noMore'
  108. } else {
  109. this.reload = false
  110. this.current_page++
  111. this.status = 'loading'
  112. this.loadData()
  113. }
  114. },
  115. methods: {
  116. /** 加载优惠券详情及可用商品列表 */
  117. async loadData() {
  118. try {
  119. const res = await pullCouponApply({ id: this.coupon_id, page: this.current_page })
  120. uni.stopPullDownRefresh()
  121. this.coupon = res.coupon
  122. this.dataList = this.reload ? (res.goods.data || []) : this.dataList.concat(res.goods.data || [])
  123. this.total = res.goods.total
  124. this.current_page = res.goods.current_page
  125. this.last_page = res.goods.last_page
  126. this.status = res.goods.total == 0 ? 'noMore' : 'more'
  127. } catch (e) {
  128. console.error('[coupon apply] loadData', e)
  129. }
  130. },
  131. /** 领取优惠券 */
  132. async onReceive(coupon_id) {
  133. try {
  134. const res = await postCouponReceive({ id: coupon_id })
  135. this.coupon_state = true
  136. uni.showToast({ title: typeof res === 'string' ? res : this.$t('mall.receiveSuccess'), icon: 'none' })
  137. this.$store.commit('statistics/dynamic', {
  138. coupon: this.$store.state.statistics.dynamic.coupon + 1
  139. })
  140. } catch (e) {
  141. uni.showToast({ title: this.$t('coupon.receiveFailed'), icon: 'none' })
  142. }
  143. }
  144. }
  145. }
  146. </script>
  147. <style>
  148. </style>