coupons.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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" :key="item.id"
  10. @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}}</view>
  30. <view class="coupons-getbtn" v-if="currentIndex===0" @click="get_coupons(item)">立即领取</view>
  31. <view class="coupons-getbtn" v-if="currentIndex===2" @click="goto_orderDetail(item)">查看订单</view>
  32. </view>
  33. </view>
  34. <view class="ribbon"
  35. :style="{backgroundColor:`${currentIndex===3?'#e8e8e8':''}`,color:`${currentIndex===3?'#8c8c8c':''}`}">
  36. {{tabsList[currentIndex].text}}
  37. </view>
  38. </view>
  39. <view style="height: 30rpx;"></view>
  40. <view v-if="toBeclaimedCoupons.length<1" class="not-data">
  41. <image src="@/static/img/empty.svg" mode="widthFix" class="icon"></image>
  42. <view>暂无数据</view>
  43. </view>
  44. </view>
  45. </view>
  46. </ax-body>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. coupons_card: 'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/bNfT8BQFvtcead404bdf22856fe1306af8fbb672a74c.png/1.png',
  53. couponsBg:'https://charge.hub.zswlgz.com/apifile//2025/12/09/YXVyOk6RqkKi2a5b93800594ecafd15e6599498e7e90_20251209095058A002.png',
  54. currentIndex: 0, // 默认选中第一个选项卡
  55. tabsList: [{
  56. text: '待领取',
  57. id: 0
  58. }, {
  59. text: '待使用',
  60. id: 1
  61. }, {
  62. text: '已使用',
  63. id: 2
  64. }, {
  65. text: '已过期',
  66. id: 3
  67. }],
  68. toBeclaimedCoupons: [],
  69. totalNumber: 0,
  70. form_submit: {
  71. pageNum: 1,
  72. pageSize: 10,
  73. status: 1,
  74. }
  75. };
  76. },
  77. onLoad() {
  78. this.get_statistical()
  79. },
  80. onReachBottom(e) {
  81. this.form_submit.pageNum++
  82. if (this.totalNumber > this.toBeclaimedCoupons.length) {
  83. this.get_TobeclaimedCoupons()
  84. }
  85. },
  86. mounted() {
  87. this.get_TobeclaimedCoupons()
  88. },
  89. methods: {
  90. handleTabClick(e) {
  91. this.currentIndex = e.id;
  92. this.form_submit.status = e.id
  93. this.toBeclaimedCoupons = []
  94. this.get_TobeclaimedCoupons()
  95. this.get_statistical()
  96. },
  97. get_TobeclaimedCoupons() {
  98. if (this.currentIndex == 0) {
  99. this.$api.base("post", "/couponApi/list-pending", {}, {}).then(res => {
  100. this.toBeclaimedCoupons = res.list
  101. })
  102. } else {
  103. this.$api.base("post",
  104. `/couponApi/list-user?pageNum=${this.form_submit.pageNum}&pageSize=${this.form_submit.pageSize}&status=${this.form_submit.status}`, {}, {}
  105. ).then(res => {
  106. this.totalNumber = res.total
  107. if (this.form_submit.pageNum == 1) {
  108. this.toBeclaimedCoupons = res.rows
  109. } else {
  110. this.toBeclaimedCoupons = [...this.toBeclaimedCoupons, ...res.rows]
  111. }
  112. })
  113. }
  114. },
  115. get_statistical() {
  116. // 数据映射
  117. const idToKeyMap = {
  118. 0: 'list-pending',
  119. 1: 'list-unused',
  120. 2: 'list-used',
  121. 3: 'list-overdue'
  122. };
  123. this.$api.base("post", "/couponApi/statistical", {}, {}).then(res => {
  124. this.tabsList.forEach(tab => {
  125. const key = idToKeyMap[tab.id];
  126. tab.count = res.data[key] || 0;
  127. });
  128. })
  129. },
  130. goto_orderDetail(e) {
  131. uni.navigateTo({
  132. url: `/pages/order-detail/order-detail?orderId=${e.useOrderId}`
  133. })
  134. },
  135. get_coupons(e) {
  136. if (e.dayReceiveCount > e.totalCount) return this.$app.popup.toast('您来慢了~该优惠券已被领完')
  137. uni.showLoading({
  138. mask:true
  139. });
  140. let timer = setInterval(() => {
  141. clearInterval(timer)
  142. this.$api.base("post", "/couponApi/receive", {
  143. templateId: e.id
  144. }, {}).then(res => {
  145. uni.hideLoading()
  146. if (res.code == 0) {
  147. this.get_statistical()
  148. this.get_TobeclaimedCoupons()
  149. this.$app.popup.toast('领取成功')
  150. }
  151. })
  152. }, 100);
  153. }
  154. }
  155. };
  156. </script>
  157. <style>
  158. @import url("coupons");
  159. </style>