coupon-receive.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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"></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">
  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 } 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. }
  56. },
  57. computed: {
  58. ...mapGetters(['userId']),
  59. visiable() {
  60. return this.list.length > this.listQuery.pageSize
  61. }
  62. },
  63. onReachBottom() {
  64. this.fetchCouponList()
  65. },
  66. onLoad() {
  67. this.initCouponList()
  68. },
  69. methods: {
  70. // 优惠券操作事件
  71. handleClick(coupon) {
  72. console.log(coupon)
  73. this.initCouponList()
  74. this.$router.addRefreshType('receiveCouponBack')
  75. },
  76. // 初始化优惠券列表
  77. initCouponList() {
  78. this.listQuery.pageNum = 1
  79. this.listQuery.userId = this.userId
  80. this.list = []
  81. this.hasNextPage = true
  82. this.fetchCouponList()
  83. },
  84. // 获取优惠券列表
  85. fetchCouponList: debounce(async function() {
  86. if (!this.hasNextPage) return
  87. this.isLoading = true
  88. try {
  89. const res = await fetchCouponCenterInfo(this.listQuery)
  90. this.list = [...this.list, ...res.data.list]
  91. this.total = res.data.total
  92. this.hasNextPage = res.data.hasNextPage
  93. this.listQuery.pageNum++
  94. } catch (e) {
  95. console.log(e)
  96. } finally {
  97. this.isRequest = false
  98. this.isLoading = false
  99. }
  100. }, 200),
  101. // 查看描述详情
  102. toDescDetail(entry) {
  103. this.$router.navigateTo('coupon/coupon-description?entryType=' + entry.id)
  104. },
  105. // 我的优惠券
  106. userCouponCenter(){
  107. this.$router.redirectTo('coupon/coupon-user')
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .coupon-list {
  114. padding-top: 24rpx;
  115. .coupon-section {
  116. margin: 0 24rpx 24rpx;
  117. }
  118. }
  119. .control {
  120. @extend .cm-flex-center;
  121. @extend .fixed-bottom;
  122. align-items: flex-start;
  123. height: 140rpx;
  124. }
  125. </style>