coupons.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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">{{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" 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">查看订单</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.get_TobeclaimedCoupons()
  87. },
  88. get_TobeclaimedCoupons() {
  89. if (this.currentIndex == 0) {
  90. this.$api.base("post", "/couponApi/list-pending", {}, {}).then(res => {
  91. this.toBeclaimedCoupons = res.list
  92. })
  93. } else {
  94. this.$api.base("post",`/couponApi/list-user?pageNum=${this.form_submit.pageNum}&pageSize=${this.form_submit.pageSize}&status=${this.form_submit.status}`,{}, {}).then(res => {
  95. this.totalNumber=res.total
  96. if(this.form_submit.pageNum==1){
  97. this.toBeclaimedCoupons = res.rows
  98. }else{
  99. this.toBeclaimedCoupons=[...this.toBeclaimedCoupons,...res.rows]
  100. }
  101. })
  102. }
  103. },
  104. get_statistical(){
  105. // 数据映射
  106. const idToKeyMap = {
  107. 0: 'list-pending',
  108. 1: 'list-unused',
  109. 2: 'list-used',
  110. 3: 'list-overdue'
  111. };
  112. this.$api.base("post", "/couponApi/statistical", {}, {}).then(res => {
  113. this.tabsList.forEach(tab => {
  114. const key = idToKeyMap[tab.id];
  115. tab.count = res.data[key] || 0;
  116. });
  117. })
  118. },
  119. get_coupons(e){
  120. this.$api.base("post", "/couponApi/receive", {templateId:e.id}, {}).then(res => {
  121. if(res.code==0){
  122. this.get_statistical()
  123. this.get_TobeclaimedCoupons()
  124. this.$app.popup.toast('领取成功')
  125. }
  126. })
  127. }
  128. }
  129. };
  130. </script>
  131. <style>
  132. @import url("coupons");
  133. </style>