coupon-user.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="coupon-user">
  3. <!-- tabs选项卡 -->
  4. <tui-tabs
  5. :tabs="tabs"
  6. selectedColor="#f83c6c"
  7. sliderBgColor="#f83c6c"
  8. badgeBgColor="#f83c6c"
  9. itemWidth="33.333%"
  10. :isFixed="true"
  11. :currentTab="currentTab"
  12. @change="tabChange"
  13. ></tui-tabs>
  14. <!-- 轮播区域 -->
  15. <swiper
  16. :indicator-dots="false"
  17. :autoplay="false"
  18. :duration="400"
  19. :current="currentTab"
  20. @change="swiperChange"
  21. class="swiper"
  22. >
  23. <swiper-item v-for="(tab, index) in tabs" :key="index">
  24. <!-- 优惠券列表为空 -->
  25. <template v-if="list.length <= 0">
  26. <tui-no-data :imgUrl="staticUrl + 'icon-coupon-empty.png'" :imgHeight="230" :imgWidth="290">
  27. <view class="empty-tip">暂无任何优惠券~~</view>
  28. </tui-no-data>
  29. </template>
  30. <scroll-view scroll-y="true" class="scroll-box" v-else @scrolltolower="onScrollToLower">
  31. <tui-skeleton v-if="isRequest" :loadingType="3" :isLoading="true"></tui-skeleton>
  32. <view style="height: 24rpx;"></view>
  33. <view class="coupon-section" v-for="item in list" :key="item.couponId">
  34. <template v-if="currentTab === 0">
  35. <cm-coupon controlType="use" :couponData="item"></cm-coupon>
  36. </template>
  37. <template v-if="currentTab === 1">
  38. <cm-coupon bgType="off" status="used" :couponData="item"></cm-coupon>
  39. </template>
  40. <template v-if="currentTab === 2">
  41. <cm-coupon bgType="off" status="expired" :couponData="item"></cm-coupon>
  42. </template>
  43. </view>
  44. <!-- 优惠券说明 -->
  45. <!-- <coupon-desc-entry @click="toDescDetail"></coupon-desc-entry> -->
  46. <cm-loadmore :hasMore="hasNextPage" :isLoading="isLoading" :visiable="visiable"></cm-loadmore>
  47. <view style="height: 140rpx;"></view>
  48. </scroll-view>
  49. </swiper-item>
  50. </swiper>
  51. <!-- 领取优惠券 -->
  52. <view class="control">
  53. <tui-button
  54. class="create"
  55. type="base"
  56. :size="28"
  57. width="650rpx"
  58. height="88rpx"
  59. shape="circle"
  60. @click="receiveCouponCenter"
  61. >
  62. 领券中心
  63. </tui-button>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import { fetchReceivedCouponList } from '@/services/api/coupon.js'
  69. import { debounce } from '@/common/utils.js'
  70. import { mapGetters,mapActions } from 'vuex'
  71. export default {
  72. data() {
  73. return {
  74. tabs: [
  75. {
  76. name: '未使用',
  77. num: 10,
  78. isDot: false,
  79. disabled: false
  80. },
  81. {
  82. name: '已使用',
  83. num: 10,
  84. isDot: false,
  85. disabled: false
  86. },
  87. {
  88. name: '已失效',
  89. num: '',
  90. isDot: false,
  91. disabled: false
  92. }
  93. ],
  94. isLoading: false,
  95. isRequest: true,
  96. currentTab: 0,
  97. listQuery: {
  98. status: 0,
  99. userId: 0,
  100. pageNum: 1,
  101. pageSize: 10
  102. },
  103. list: [],
  104. total: 0,
  105. hasNextPage: true
  106. }
  107. },
  108. computed: {
  109. ...mapGetters(['userId', 'unusedNum', 'expiredNum', 'usedNum']),
  110. visiable() {
  111. return this.list.length > this.listQuery.pageSize
  112. }
  113. },
  114. onLoad() {
  115. this.initCount()
  116. this.initCouponList()
  117. },
  118. onShow() {
  119. if(this.$router.checkRefreshType('receiveCouponBack')){
  120. this.initCount()
  121. this.initCouponList()
  122. }
  123. },
  124. methods: {
  125. ...mapActions('coupon',['initCouponCount']),
  126. // 初始化优惠券数量统计
  127. async initCount() {
  128. await this.initCouponCount()
  129. this.tabs[0].num = this.unusedNum
  130. this.tabs[1].num = this.usedNum
  131. this.tabs[2].num = this.expiredNum
  132. },
  133. // 初始化优惠券列表
  134. initCouponList() {
  135. this.isRequest = true
  136. this.listQuery.pageNum = 1
  137. this.listQuery.status = this.currentTab + 1
  138. this.listQuery.userId = this.userId
  139. this.list = []
  140. this.hasNextPage = true
  141. this.fetchCouponList()
  142. },
  143. // 获取优惠券列表
  144. fetchCouponList: debounce(async function() {
  145. if (!this.hasNextPage) return
  146. this.isLoading = true
  147. try {
  148. const res = await fetchReceivedCouponList(this.listQuery)
  149. this.list = [...this.list, ...res.data.list]
  150. this.total = res.data.total
  151. this.hasNextPage = res.data.hasNextPage
  152. this.listQuery.pageNum++
  153. } catch (e) {
  154. console.log(e)
  155. } finally {
  156. this.isRequest = false
  157. this.isLoading = false
  158. }
  159. }, 200),
  160. // tab切换
  161. tabChange(e) {
  162. this.currentTab = e.index
  163. this.initCouponList()
  164. },
  165. // 轮播切换
  166. swiperChange(e) {
  167. this.currentTab = e.detail.current
  168. this.initCouponList()
  169. },
  170. // 滚动到底部
  171. onScrollToLower() {
  172. this.fetchCouponList()
  173. },
  174. // 跳转领券中心
  175. receiveCouponCenter() {
  176. this.$router.redirectTo('coupon/coupon-receive')
  177. },
  178. // 查看描述详情
  179. toDescDetail(entry){
  180. this.$router.navigateTo('coupon/coupon-description?entryType=' + entry.id)
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .swiper {
  187. height: 100vh;
  188. .scroll-box {
  189. height: 100vh;
  190. padding-top: 80rpx;
  191. box-sizing: border-box;
  192. .coupon-section {
  193. margin: 24rpx;
  194. margin-top: 0;
  195. }
  196. }
  197. }
  198. .control {
  199. @extend .cm-flex-center;
  200. @extend .fixed-bottom;
  201. align-items: flex-start;
  202. height: 140rpx;
  203. }
  204. </style>