good-coupon-list.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="good-coupon-list">
  3. <!-- 骨架 -->
  4. <tui-skeleton v-if="skeletonShow" :isLoading="true" loadingType="2"></tui-skeleton>
  5. <template v-else>
  6. <!-- 列表为空 -->
  7. <cm-empty
  8. v-if="productList.length <= 0"
  9. message="暂无任何商品~"
  10. :image="baseUrl + 'icon-empty-search.png'"
  11. :offset="90"
  12. ></cm-empty>
  13. <template v-else>
  14. <!-- 搜索 -->
  15. <sui-search
  16. placeholder="请输入商品关键词"
  17. :radius="30"
  18. @search="searchBlur"
  19. @clear="searchClear"
  20. class="sui-search"
  21. ></sui-search>
  22. <!-- 商品列表 -->
  23. <view class="product-list">
  24. <template v-for="(product, index) in productList">
  25. <cm-product class="product" :key="index" :data="product"></cm-product>
  26. </template>
  27. </view>
  28. <!-- 加载更多 -->
  29. <template v-if="productList.length > 6">
  30. <tui-loadmore :index="2" :visible="isRequest"></tui-loadmore>
  31. <tui-nomore :text="loadingText" :visible="!isRequest" backgroundColor="#fff"></tui-nomore>
  32. </template>
  33. </template>
  34. </template>
  35. <!-- 侧边 -->
  36. <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
  37. </view>
  38. </template>
  39. <script>
  40. import CmProduct from '@/components/cm-module/cm-product/cm-product.vue'
  41. import SuiSearch from '@/components/sui-search/sui-search.vue'
  42. import CmEmpty from '@/components/cm-module/cm-empty/cm-empty.vue'
  43. import { mapGetters, mapActions } from 'vuex'
  44. export default {
  45. components: {
  46. CmEmpty,
  47. SuiSearch,
  48. CmProduct
  49. },
  50. data() {
  51. return {
  52. baseUrl: this.$Static,
  53. productList: [], //商品列表
  54. listQuery: {
  55. userId: '',
  56. couponId: '',
  57. pageNum: 1,
  58. pageSize: 10,
  59. productName: ''
  60. },
  61. hasNextPage: false,
  62. isScrollTop: false,
  63. isRequest: true,
  64. isRefresh: false,
  65. timer: null
  66. }
  67. },
  68. filters: {
  69. //处理金额
  70. PriceFormat: function(text) {
  71. return Number(text).toFixed(2)
  72. }
  73. },
  74. onLoad(options) {
  75. this.listQuery.couponId = options.couponId
  76. this.listQuery.userId = this.userId
  77. this.fetchProductList()
  78. },
  79. computed: {
  80. ...mapGetters(['hasLogin', 'userInfo', 'userId']),
  81. loadingText() {
  82. return this.hasNextPage ? '上拉加载' : '没有更多了'
  83. }
  84. },
  85. methods: {
  86. ...mapActions('cart', ['addToCart']),
  87. //初始化商品数据列表
  88. fetchProductList() {
  89. this.CouponService.ProductInfoByCoupon(this.listQuery)
  90. .then(response => {
  91. let data = response.data
  92. if (this.isRefresh) {
  93. this.productList = data.list
  94. } else {
  95. this.productList = [...this.productList, ...data.list]
  96. }
  97. this.hasNextPage = data.hasNextPage
  98. this.listQuery.pageNum++
  99. })
  100. .catch(error => {
  101. this.$util.msg(error.msg, 2000)
  102. })
  103. .finally(() => {
  104. this.isRequest = false
  105. if (this.isRefresh) {
  106. setTimeout(() => {
  107. uni.stopPullDownRefresh()
  108. this.isRefresh = false
  109. }, 500)
  110. }
  111. })
  112. },
  113. // 搜索框失去焦点
  114. searchBlur(val) {
  115. this.listQuery.productName = val
  116. this.listQuery.pageNum = 1
  117. this.fetchProductList()
  118. },
  119. // 搜索框清空
  120. searchClear() {
  121. this.listQuery.productName = ''
  122. }
  123. },
  124. // 监听页面滚动事件
  125. onPageScroll(e) {
  126. this.isScrollTop = e.scrollTop > 400
  127. },
  128. onPullDownRefresh() {
  129. //下拉刷新
  130. this.pageNum = 1
  131. this.isRefresh = true
  132. this.fetchProductList()
  133. },
  134. onReachBottom() {
  135. if (!this.hasNextPage) return
  136. clearTimeout(this.timer)
  137. this.timer = setTimeout(() => {
  138. console.log('触底了')
  139. this.fetchProductList()
  140. }, 200)
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .good-coupon-list {
  146. padding-top: 124rpx;
  147. min-height: 100%;
  148. background: #f7f7f7;
  149. box-sizing: border-box;
  150. .sui-search {
  151. position: fixed;
  152. width: 100%;
  153. top: 0;
  154. left: 0;
  155. z-index: 999;
  156. }
  157. .product-list {
  158. display: flex;
  159. justify-content: space-between;
  160. flex-wrap: wrap;
  161. padding: 0 24rpx 12rpx;
  162. background-color: #f7f7f7;
  163. box-sizing: border-box;
  164. .product {
  165. margin: 12rpx 0;
  166. }
  167. }
  168. }
  169. </style>