goods-coupon-list.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. filters: {
  75. //处理金额
  76. PriceFormat: function(text) {
  77. return Number(text).toFixed(2)
  78. }
  79. },
  80. onLoad(options) {
  81. this.listQuery.couponId = options.couponId
  82. this.listQuery.userId = this.userId
  83. this.fetchProductList()
  84. },
  85. computed: {
  86. ...mapGetters(['hasLogin', 'userInfo', 'userId', 'kindCount']),
  87. loadingText() {
  88. return this.hasNextPage ? '上拉加载' : '没有更多了'
  89. }
  90. },
  91. methods: {
  92. ...mapActions('cart', ['addToCart']),
  93. //初始化商品数据列表
  94. fetchProductList() {
  95. this.CouponService.ProductInfoByCoupon(this.listQuery)
  96. .then(response => {
  97. let data = response.data
  98. if (this.isRefresh) {
  99. this.productList = data.list
  100. } else {
  101. this.productList = [...this.productList, ...data.list]
  102. }
  103. this.hasNextPage = data.hasNextPage
  104. this.listQuery.pageNum++
  105. })
  106. .catch(error => {
  107. this.$util.msg(error.msg, 2000)
  108. })
  109. .finally(() => {
  110. this.isRequest = false
  111. if (this.isRefresh) {
  112. setTimeout(() => {
  113. uni.stopPullDownRefresh()
  114. this.isRefresh = false
  115. }, 500)
  116. }
  117. })
  118. },
  119. // 跳转到搜索页面
  120. goSearch() {
  121. uni.navigateTo({ url: '/pages/goods/goods-coupon-list-search' })
  122. },
  123. btnClick() {
  124. this.$api.navigateTo('/pages/goods/cart')
  125. }
  126. },
  127. // 监听页面滚动事件
  128. onPageScroll(e) {
  129. this.isSticky = e.scrollTop > 0
  130. this.isScrollTop = e.scrollTop > 400
  131. },
  132. onPullDownRefresh() {
  133. //下拉刷新
  134. this.listQuery.pageNum = 1
  135. this.isRefresh = true
  136. this.fetchProductList()
  137. },
  138. onReachBottom() {
  139. if (!this.hasNextPage) return
  140. clearTimeout(this.timer)
  141. this.timer = setTimeout(() => {
  142. console.log('触底了')
  143. this.fetchProductList()
  144. }, 200)
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .sui-search {
  150. width: 100%;
  151. top: 0;
  152. left: 0;
  153. z-index: 999;
  154. &.fixed {
  155. position: fixed;
  156. }
  157. }
  158. .good-coupon-list {
  159. min-height: 100%;
  160. background: #f7f7f7;
  161. box-sizing: border-box;
  162. overflow: hidden;
  163. &.top {
  164. padding-top: 124rpx;
  165. }
  166. .product-list {
  167. display: flex;
  168. justify-content: space-between;
  169. flex-wrap: wrap;
  170. padding: 12rpx 24rpx 12rpx;
  171. background-color: #f7f7f7;
  172. box-sizing: border-box;
  173. .product {
  174. margin: 12rpx 0;
  175. }
  176. }
  177. }
  178. </style>