goods-coupon-list.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="good-coupon-list" :class="{ top: isSticky }">
  3. <!-- 骨架 -->
  4. <tui-skeleton v-if="isRequest" :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. class="sui-search"
  19. :class="{ fixed: isSticky }"
  20. disabled
  21. @gosearch="goSearch"
  22. ></sui-search>
  23. <!-- 商品列表 -->
  24. <view class="product-list">
  25. <template v-for="(product, index) in productList">
  26. <cm-product class="product" :key="index" :data="product"></cm-product>
  27. </template>
  28. </view>
  29. <!-- 加载更多 -->
  30. <template v-if="productList.length > 6">
  31. <tui-loadmore :index="2" :visible="isRequest"></tui-loadmore>
  32. <tui-nomore :text="loadingText" :visible="!isRequest" backgroundColor="#f7f7f7"></tui-nomore>
  33. </template>
  34. </template>
  35. </template>
  36. <!-- 侧边 -->
  37. <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
  38. <!-- 可拖动悬浮按钮 -->
  39. <cm-drag :cartNum="kindCount" :isDock="true" :existTabBar="true" @btnClick="btnClick"> </cm-drag>
  40. </view>
  41. </template>
  42. <script>
  43. import CmProduct from '@/components/cm-module/cm-product/cm-product.vue'
  44. import SuiSearch from '@/components/sui-search/sui-search.vue'
  45. import CmEmpty from '@/components/cm-module/cm-empty/cm-empty.vue'
  46. import CmDrag from '@/components/cm-module/cm-drag/cm-drag'
  47. import { mapGetters, mapActions } from 'vuex'
  48. export default {
  49. components: {
  50. CmEmpty,
  51. SuiSearch,
  52. CmProduct,
  53. CmDrag
  54. },
  55. data() {
  56. return {
  57. baseUrl: this.$Static,
  58. productList: [], //商品列表
  59. listQuery: {
  60. userId: '',
  61. couponId: '',
  62. pageNum: 1,
  63. pageSize: 10,
  64. productName: ''
  65. },
  66. hasNextPage: false,
  67. isScrollTop: false,
  68. isRequest: true,
  69. isRefresh: false,
  70. timer: null,
  71. isSticky: false
  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', 'kindCount']),
  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. goSearch() {
  115. uni.navigateTo({ url: '/pages/goods/goods-coupon-list-search' })
  116. },
  117. btnClick() {
  118. this.$api.navigateTo('/pages/goods/cart')
  119. }
  120. },
  121. // 监听页面滚动事件
  122. onPageScroll(e) {
  123. this.isSticky = e.scrollTop > 0
  124. this.isScrollTop = e.scrollTop > 400
  125. },
  126. onPullDownRefresh() {
  127. //下拉刷新
  128. this.listQuery.pageNum = 1
  129. this.isRefresh = true
  130. this.fetchProductList()
  131. },
  132. onReachBottom() {
  133. if (!this.hasNextPage) return
  134. clearTimeout(this.timer)
  135. this.timer = setTimeout(() => {
  136. console.log('触底了')
  137. this.fetchProductList()
  138. }, 200)
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .sui-search {
  144. width: 100%;
  145. top: 0;
  146. left: 0;
  147. z-index: 999;
  148. &.fixed {
  149. position: fixed;
  150. }
  151. }
  152. .good-coupon-list {
  153. min-height: 100%;
  154. background: #f7f7f7;
  155. box-sizing: border-box;
  156. overflow: hidden;
  157. &.top {
  158. padding-top: 124rpx;
  159. }
  160. .product-list {
  161. display: flex;
  162. justify-content: space-between;
  163. flex-wrap: wrap;
  164. padding: 12rpx 24rpx 12rpx;
  165. background-color: #f7f7f7;
  166. box-sizing: border-box;
  167. .product {
  168. margin: 12rpx 0;
  169. }
  170. }
  171. }
  172. </style>