coupons.vue 4.6 KB

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