coupon-receive.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="coupon-receive">
  3. <tui-skeleton v-if="isRequest" :loadingType="3" :isLoading="true"></tui-skeleton>
  4. <!-- 优惠券列表 -->
  5. <view class="coupon-list">
  6. <!-- 优惠券列表为空 -->
  7. <template v-if="list.length <= 0 && !isLoading">
  8. <cm-empty :imageUrl="staticUrl + 'icon-coupon-empty.png'" :imgHeight="230" :imgWidth="290">
  9. <view class="empty-tip">暂无任何优惠券~~</view>
  10. </cm-empty>
  11. </template>
  12. <view class="coupon-section" v-for="item in list" :key="item.couponId">
  13. <cm-coupon controlType="receive" :couponData="item" @click="handleClick"></cm-coupon>
  14. </view>
  15. </view>
  16. <!-- 优惠券说明 -->
  17. <coupon-desc-entry @click="toDescDetail" v-if="userId" :couponTipStr="couponTipStr"></coupon-desc-entry>
  18. <!-- 加载更多 -->
  19. <cm-loadmore :hasMore="hasNextPage" :isLoading="isLoading" :visiable="visiable"></cm-loadmore>
  20. <!-- 占位 -->
  21. <view style="height: 140rpx;"></view>
  22. <!-- 我的优惠券 -->
  23. <view class="control" v-if="userId > 0">
  24. <tui-button
  25. class="create"
  26. type="base"
  27. :size="28"
  28. width="650rpx"
  29. height="88rpx"
  30. shape="circle"
  31. @click="userCouponCenter"
  32. >
  33. 我的优惠券
  34. </tui-button>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { fetchCouponCenterInfo, fetchCouponDisplay } from '@/services/api/coupon.js'
  40. import { debounce } from '@/common/utils.js'
  41. import { mapGetters } from 'vuex'
  42. export default {
  43. data() {
  44. return {
  45. listQuery: {
  46. userId: 0,
  47. pageNum: 1,
  48. pageSize: 10
  49. },
  50. list: [],
  51. total: 0,
  52. hasNextPage: true,
  53. isLoading: false,
  54. isRequest: true,
  55. couponTipStr: ''
  56. }
  57. },
  58. computed: {
  59. ...mapGetters(['userId']),
  60. visiable() {
  61. return this.list.length > this.listQuery.pageSize
  62. }
  63. },
  64. onReachBottom() {
  65. this.fetchCouponList()
  66. },
  67. onLoad() {
  68. this.initCouponList()
  69. this.fetchCouponDisplay() // 获取可领取优惠券类型
  70. },
  71. methods: {
  72. // 优惠券操作事件
  73. handleClick(coupon) {
  74. console.log(coupon)
  75. this.initCouponList()
  76. this.$router.addRefreshType('receiveCouponBack')
  77. },
  78. // 初始化优惠券列表
  79. initCouponList() {
  80. this.listQuery.pageNum = 1
  81. this.listQuery.userId = this.userId
  82. this.list = []
  83. this.hasNextPage = true
  84. this.fetchCouponList()
  85. },
  86. // 获取优惠券列表
  87. fetchCouponList: debounce(async function() {
  88. if (!this.hasNextPage) return
  89. this.isLoading = true
  90. try {
  91. const res = await fetchCouponCenterInfo(this.listQuery)
  92. this.list = [...this.list, ...res.data.list]
  93. this.total = res.data.total
  94. this.hasNextPage = res.data.hasNextPage
  95. this.listQuery.pageNum++
  96. } catch (e) {
  97. console.log(e)
  98. } finally {
  99. this.isRequest = false
  100. this.isLoading = false
  101. }
  102. }, 200),
  103. // 获取可领取优惠券类型
  104. async fetchCouponDisplay() {
  105. try {
  106. const res = await fetchCouponDisplay({ userId: this.userId })
  107. this.couponTipStr = res.data
  108. } catch (e) {
  109. console.log('获取优惠券类型失败')
  110. }
  111. },
  112. // 查看描述详情
  113. toDescDetail(entry) {
  114. this.$router.navigateTo(`coupon/coupon-description?entryType=${entry.id}&title=${entry.name}`)
  115. },
  116. // 我的优惠券
  117. userCouponCenter() {
  118. this.$router.redirectTo('coupon/coupon-user')
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .coupon-list {
  125. padding-top: 24rpx;
  126. .coupon-section {
  127. margin: 0 24rpx 24rpx;
  128. }
  129. }
  130. .control {
  131. @extend .cm-flex-center;
  132. @extend .fixed-bottom;
  133. align-items: flex-start;
  134. height: 140rpx;
  135. }
  136. </style>