coupons.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. 暂无数据
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. coupons_card: 'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/bNfT8BQFvtcead404bdf22856fe1306af8fbb672a74c.png/1.png',
  46. currentIndex: 0, // 默认选中第一个选项卡
  47. tabsList: [{
  48. text: '待领取',
  49. id: 0
  50. }, {
  51. text: '待使用',
  52. id: 1
  53. }, {
  54. text: '已使用',
  55. id: 2
  56. }, {
  57. text: '已过期',
  58. id: 3
  59. }],
  60. toBeclaimedCoupons: [],
  61. totalStatistics:{},
  62. form_submit: {
  63. pageNum: 1,
  64. pageSize: 10,
  65. status:1,
  66. }
  67. };
  68. },
  69. onLoad() {
  70. this.get_statistical()
  71. },
  72. onReachBottom(e) {
  73. this.form_submit.pageNum++
  74. this.get_TobeclaimedCoupons()
  75. },
  76. mounted() {
  77. this.get_TobeclaimedCoupons()
  78. },
  79. methods: {
  80. //选项卡点击
  81. handleTabClick(e) {
  82. this.currentIndex = e.id;
  83. this.form_submit.status=e.id
  84. this.get_TobeclaimedCoupons()
  85. },
  86. get_TobeclaimedCoupons() {
  87. if (this.currentIndex == 0) {
  88. this.$api.base("post", "/couponApi/list-pending", {}, {}).then(res => {
  89. this.toBeclaimedCoupons = res.list
  90. })
  91. } else {
  92. this.$api.base("post", "/couponApi/list-user",this.form_submit, {}).then(res => {
  93. if(this.form_submit.pageNum==1){
  94. this.toBeclaimedCoupons = res.rows
  95. }else{
  96. this.toBeclaimedCoupons=[...this.toBeclaimedCoupons,...res.rows]
  97. }
  98. })
  99. }
  100. },
  101. get_statistical(){
  102. // 数据映射
  103. const idToKeyMap = {
  104. 0: 'list-pending',
  105. 1: 'list-unused',
  106. 2: 'list-used',
  107. 3: 'list-overdue'
  108. };
  109. this.$api.base("post", "/couponApi/statistical", {}, {}).then(res => {
  110. this.tabsList.forEach(tab => {
  111. const key = idToKeyMap[tab.id];
  112. tab.count = res.data[key] || 0;
  113. });
  114. })
  115. },
  116. get_coupons(e){
  117. this.$api.base("post", "/couponApi/receive", {templateId:e.id}, {}).then(res => {
  118. if(res.code==0){
  119. this.get_statistical()
  120. this.get_TobeclaimedCoupons()
  121. this.$app.popup.toast('领取成功')
  122. }
  123. })
  124. }
  125. }
  126. };
  127. </script>
  128. <style>
  129. @import url("coupons");
  130. </style>