coupon-receive.vue 4.6 KB

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