coupons.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <ax-body>
  3. <!-- <template #title></template> -->
  4. <view class="page-background">
  5. <image :src="couponsBg" mode="widthFix"></image>
  6. </view>
  7. <view class="tabs-body">
  8. <view class="tabs-box">
  9. <view class="item-tabs" :class="{ active: currentIndex === item.id }" v-for="item in tabsList"
  10. :key="item.id" @click="handleTabClick(item)">{{ item.text }}({{ item.count || 0 }})</view>
  11. </view>
  12. <view style="height: 350rpx;"></view>
  13. <view class="list-body">
  14. <view class="coupons-list-box" :style="{ opacity: `${currentIndex === 3 ? '0.5' : ''}` }"
  15. v-for="item in toBeclaimedCoupons" :key="item.id">
  16. <image class="coupons-bg-img" :src="coupons_card" mode=""></image>
  17. <view class="coupons-content-box">
  18. <view class="coupons-left">
  19. <view class="left-price">{{ item.discountPrice }}<text>元</text></view>
  20. <view class="left-rules">满{{ item.usePrice }}元可用</view>
  21. </view>
  22. <view class="coupons-center">
  23. <view class="coupons-title textHidden">{{ item.name || '' }}</view>
  24. <view class="coupons-valid" v-if="currentIndex == 0">有效期:领取后{{ item.failureTime }}天</view>
  25. <view class="coupons-valid" v-else>{{ item.validEndTime }}到期</view>
  26. <view class="coupons-range">平台所有充电桩可用</view>
  27. </view>
  28. <view class="coupons-right">
  29. <view class="coupons-dayrules textHidden" v-if="currentIndex === 0">{{ item.description }}
  30. </view>
  31. <view class="coupons-getbtn" v-if="currentIndex === 0" @click="get_coupons(item)">立即领取
  32. </view>
  33. <view class="coupons-getbtn" v-if="currentIndex === 2" @click="goto_orderDetail(item)">查看订单
  34. </view>
  35. </view>
  36. </view>
  37. <view class="ribbon"
  38. :style="{ backgroundColor: `${currentIndex === 3 ? '#e8e8e8' : ''}`, color: `${currentIndex === 3 ? '#8c8c8c' : ''}` }">
  39. {{ tabsList[currentIndex].text }}
  40. </view>
  41. </view>
  42. <view style="height: 30rpx;"></view>
  43. <view v-if="toBeclaimedCoupons.length == 0" class="not-data">
  44. <image src="@/static/img/empty.svg" mode="widthFix" class="icon"></image>
  45. <view>暂无数据</view>
  46. </view>
  47. </view>
  48. </view>
  49. </ax-body>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. coupons_card: 'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/bNfT8BQFvtcead404bdf22856fe1306af8fbb672a74c.png/1.png',
  56. couponsBg: 'https://charge.hub.zswlgz.com/apifile//2025/12/09/YXVyOk6RqkKi2a5b93800594ecafd15e6599498e7e90_20251209095058A002.png',
  57. currentIndex: 0, // 默认选中第一个选项卡
  58. tabsList: [{
  59. text: '待领取',
  60. id: 0,
  61. count: 0
  62. }, {
  63. text: '待使用',
  64. id: 1,
  65. count: 0
  66. }, {
  67. text: '已使用',
  68. id: 2,
  69. count: 0
  70. }, {
  71. text: '已过期',
  72. id: 3,
  73. count: 0
  74. }],
  75. toBeclaimedCoupons: [],
  76. totalNumber: 0,
  77. form_submit: {
  78. pageNum: 1,
  79. pageSize: 10,
  80. status: 1,
  81. }
  82. };
  83. },
  84. onLoad() {
  85. this.get_statistical()
  86. },
  87. onReachBottom(e) {
  88. this.form_submit.pageNum++
  89. if (this.totalNumber > this.toBeclaimedCoupons.length) {
  90. this.get_TobeclaimedCoupons()
  91. }
  92. },
  93. mounted() {
  94. this.get_TobeclaimedCoupons()
  95. },
  96. methods: {
  97. handleTabClick(e) {
  98. this.currentIndex = e.id;
  99. this.form_submit.status = e.id
  100. this.toBeclaimedCoupons = []
  101. this.get_TobeclaimedCoupons()
  102. },
  103. get_TobeclaimedCoupons() {
  104. if (this.currentIndex == 0) {
  105. this.$api.base("get", "/applet/v1/user/getCouponTemplatePage", {
  106. pageNum: this.form_submit.pageNum,
  107. pageSize: this.form_submit.pageSize,
  108. status: this.form_submit.status
  109. }, {}).then(res => {
  110. this.toBeclaimedCoupons = res.data.records
  111. this.tabsList[0].count = res.data.total
  112. })
  113. } else {
  114. this.$api.base("post",
  115. `/applet/v1/user/getCouponPage`, {
  116. pageNum: this.form_submit.pageNum,
  117. pageSize: this.form_submit.pageSize,
  118. status: this.form_submit.status
  119. }, {}
  120. ).then(res => {
  121. this.totalNumber = res.total
  122. if (this.form_submit.pageNum == 1) {
  123. this.toBeclaimedCoupons = res.data.records
  124. } else {
  125. this.toBeclaimedCoupons = [...this.toBeclaimedCoupons, ...res.data.records]
  126. }
  127. })
  128. }
  129. },
  130. get_statistical() {
  131. this.$api.base("get", "/applet/v1/user/getCouponStatusNum", {}, {}).then(res => {
  132. this.tabsList[1].count = res.data.unusedNum
  133. this.tabsList[2].count = res.data.usedNum
  134. this.tabsList[3].count = res.data.expiredNum
  135. })
  136. },
  137. goto_orderDetail(e) {
  138. uni.navigateTo({
  139. url: `/pages/order-detail/order-detail?orderId=${e.useOrderId}`
  140. })
  141. },
  142. get_coupons(e) {
  143. if (e.dayReceiveCount > e.totalCount) return this.$app.popup.toast('您来慢了~该优惠券已被领完')
  144. uni.showLoading({
  145. mask: true
  146. });
  147. let timer = setInterval(() => {
  148. clearInterval(timer)
  149. this.$api.base("post", "/applet/v1/user/gainCoupon", {
  150. couponCode: e.code
  151. }, {}).then(res => {
  152. uni.hideLoading()
  153. if (res.code == 0) {
  154. this.get_statistical()
  155. this.get_TobeclaimedCoupons()
  156. this.$app.popup.toast('领取成功')
  157. }
  158. })
  159. }, 100);
  160. }
  161. }
  162. };
  163. </script>
  164. <style>
  165. @import url("coupons");
  166. </style>