coupon-list.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <!-- TODO -->
  3. <view class="coupon-find-list">
  4. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  5. <!-- tabs -->
  6. <template v-else>
  7. <tui-tabs
  8. :tabs="tabs"
  9. :currentTab="currentTab"
  10. @change="tabChange"
  11. :sliderWidth="118"
  12. color="#333333"
  13. selectedColor="#FF457B"
  14. sliderBgColor="#FF457B"
  15. ></tui-tabs>
  16. <!-- 优惠券列表 -->
  17. <swiper
  18. :indicator-dots="false"
  19. :autoplay="false"
  20. class="swiper"
  21. :style="{ height: swiperHeight + 'px' }"
  22. :current="currentTab"
  23. @change="swiperChange"
  24. >
  25. <swiper-item class="coupon-list" v-for="(item, type) of couponData" :key="type">
  26. <cm-empty
  27. v-if="item.couponList.length <= 0"
  28. message="暂无任何优惠券~"
  29. :image="baseUrl + 'icon-coupon-empty.png'"
  30. :offset="-12"
  31. ></cm-empty>
  32. <scroll-view scroll-y="true" class="coupon-scorll" @scrolltolower="scorllBottom" v-else>
  33. <template v-for="(coupon, index) in item.couponList">
  34. <cm-coupon
  35. :key="index"
  36. :couponData="coupon"
  37. @btnClick="couponClick"
  38. :showStatus="item.showStatus"
  39. ></cm-coupon>
  40. </template>
  41. <template v-if="item.couponList.length >= 6">
  42. <tui-loadmore :index="3" :visible="loadmore"></tui-loadmore>
  43. <tui-nomore :text="loadingText" :visible="!loadmore" backgroundColor="#f7f7f7"></tui-nomore>
  44. </template>
  45. </scroll-view>
  46. </swiper-item>
  47. </swiper>
  48. <!-- 跳转领券中心 -->
  49. <view class="footer">
  50. <view class="btn" @click="$api.navigateTo('/pages/user/activity/coupon-find-list')">领券中心</view>
  51. </view>
  52. </template>
  53. </view>
  54. </template>
  55. <script>
  56. import CmCoupon from '@/components/cm-module/cm-coupon/cm-coupon.vue'
  57. import CmEmpty from '@/components/cm-module/cm-empty/cm-empty.vue'
  58. import { mapGetters, mapActions } from 'vuex'
  59. export default {
  60. components: {
  61. CmCoupon,
  62. CmEmpty
  63. },
  64. data() {
  65. return {
  66. windowHeight: 0,
  67. baseUrl: this.$Static,
  68. isRequest: true,
  69. loadmore: false, // 正在加载更多
  70. currentTab: 0,
  71. pageSize: 6,
  72. timer: null,
  73. couponData: {
  74. // 已领取/未使用
  75. 0: {
  76. type: 'received',
  77. pageNum: 1,
  78. status: 1,
  79. hasNextPage: false,
  80. couponList: [],
  81. showStatus: false,
  82. total: 0
  83. },
  84. // 已使用
  85. 1: {
  86. type: 'used',
  87. pageNum: 1,
  88. status: 2,
  89. hasNextPage: false,
  90. couponList: [],
  91. showStatus: true,
  92. total: 0
  93. },
  94. // 已过期
  95. 2: {
  96. type: 'expired',
  97. pageNum: 1,
  98. status: 3,
  99. hasNextPage: false,
  100. couponList: [],
  101. showStatus: true,
  102. total: 0
  103. }
  104. }
  105. }
  106. },
  107. computed: {
  108. ...mapGetters(['isIphoneX', 'userId', 'unusedNum', 'expiredNum', 'usedNum']),
  109. swiperHeight() {
  110. if (this.isIphoneX) {
  111. return this.windowHeight - 120
  112. }
  113. return this.windowHeight - 80
  114. // return this.swiperHeight
  115. },
  116. // 当前选中tab对应的优惠券列表信息
  117. queryInfo() {
  118. return this.couponData[this.currentTab]
  119. },
  120. loadingText() {
  121. return this.queryInfo.hasNextPage ? '上拉加载更多' : '没有更多了'
  122. },
  123. // tabs列表
  124. tabs() {
  125. return [
  126. {
  127. name: this.makeTabText(this.unusedNum, '未使用')
  128. },
  129. {
  130. name: this.makeTabText(this.usedNum, '已使用')
  131. },
  132. {
  133. name: this.makeTabText(this.expiredNum, '已失效')
  134. }
  135. ]
  136. }
  137. },
  138. onLoad() {
  139. this.getWindowHeight()
  140. this.initCouponList()
  141. },
  142. methods: {
  143. // tab文字提示
  144. makeTabText(number, text) {
  145. if (number <= 0) return text
  146. return number > 99 ? `${text} 99+` : `${text} ${number}`
  147. },
  148. // 初始化列表
  149. async initCouponList() {
  150. try {
  151. await this.fetchCouponList(1)
  152. await this.fetchCouponList(2)
  153. await this.fetchCouponList(3)
  154. this.isRequest = false
  155. } catch (e) {
  156. //TODO handle the exception
  157. console.log(e)
  158. }
  159. },
  160. // 获取优惠券
  161. fetchCouponList(status) {
  162. let query = null
  163. if (status) {
  164. query = this.couponData[status - 1]
  165. } else {
  166. query = this.couponData[this.currentTab]
  167. }
  168. // 查询参数
  169. const listQuery = {
  170. userId: this.userId,
  171. pageSize: this.pageSize,
  172. pageNum: query.pageNum,
  173. status: status || query.status
  174. }
  175. this.loadmore = true
  176. return this.CouponService.CouponReceiveList(listQuery).then(res => {
  177. query.hasNextPage = res.data.hasNextPage
  178. query.total = res.data.total
  179. query.couponList = [...query.couponList, ...res.data.list]
  180. query.pageNum++
  181. this.loadmore = false
  182. })
  183. },
  184. // tab切换
  185. tabChange(e) {
  186. this.currentTab = e.index
  187. if (this.queryInfo.pageNum === 1) this.fetchCouponList()
  188. },
  189. // 轮播图切换
  190. swiperChange(e) {
  191. this.currentTab = e.detail.current
  192. if (this.queryInfo.pageNum === 1) this.fetchCouponList()
  193. },
  194. // 获取可用屏幕高度
  195. getWindowHeight() {
  196. this.windowHeight = uni.getSystemInfoSync().windowHeight
  197. console.log(this.windowHeight)
  198. },
  199. // 加载更多
  200. scorllBottom() {
  201. if (!this.queryInfo.hasNextPage) return
  202. clearTimeout(this.timer)
  203. this.timer = setTimeout(() => {
  204. console.log('触底了')
  205. this.fetchCouponList()
  206. }, 200)
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. page {
  213. width: 100%;
  214. height: 100%;
  215. background: #f7f7f7;
  216. }
  217. .swiper {
  218. height: 800rpx;
  219. background: #f7f7f7;
  220. .coupon-list {
  221. height: 100%;
  222. overflow-y: scroll;
  223. .coupon-scorll {
  224. height: 100%;
  225. }
  226. }
  227. }
  228. .footer {
  229. display: flex;
  230. justify-content: center;
  231. align-items: center;
  232. background: #f7f7f7;
  233. padding-top: 20rpx;
  234. .btn {
  235. display: flex;
  236. justify-content: center;
  237. align-items: center;
  238. width: 600rpx;
  239. height: 90rpx;
  240. background: linear-gradient(90deg, #fc32b4 0%, #f83c6c 100%);
  241. border-radius: 45rpx;
  242. font-size: 30rpx;
  243. color: #ffffff;
  244. }
  245. }
  246. </style>