good-floorMore.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="good-floor-more">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <template v-if="!isRequest">
  5. <!-- 商品列表 -->
  6. <view class="product-list">
  7. <template v-for="(product, index) in productList">
  8. <cm-product class="product" :key="index" :data="product"></cm-product>
  9. </template>
  10. </view>
  11. <template v-if="productList.length >= 6">
  12. <tui-loadmore :index="3" :visible="loadmore"></tui-loadmore>
  13. <tui-nomore :text="loadingText" :visible="!loadmore" backgroundColor="#f7f7f7"></tui-nomore>
  14. </template>
  15. <!-- 侧边 -->
  16. <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
  17. </template>
  18. </view>
  19. </template>
  20. <script>
  21. import CmProduct from '@/components/cm-module/cm-product/cm-product.vue'
  22. import { mapGetters } from 'vuex'
  23. export default {
  24. components: {
  25. CmProduct
  26. },
  27. data() {
  28. return {
  29. productList: [], //商品列表
  30. pageNum: 1,
  31. pageSize: 6,
  32. floorId: undefined,
  33. title: '',
  34. hasNextPage: false,
  35. isScrollTop: false,
  36. isRequest: true,
  37. loadmore: false, // 正在加载更多
  38. timer: null
  39. }
  40. },
  41. onLoad(option) {
  42. this.floorId = option.floorId
  43. this.title = option.title
  44. this.init()
  45. },
  46. computed: {
  47. ...mapGetters(['userId']),
  48. loadingText() {
  49. return this.hasNextPage ? '上拉加载更多' : '没有更多了'
  50. }
  51. },
  52. methods: {
  53. // 首页初始化
  54. async init() {
  55. uni.setNavigationBarTitle({
  56. title: this.title
  57. })
  58. try {
  59. await this.fetchProductList()
  60. this.isRequest = false
  61. } catch (e) {
  62. this.$util.msg(e.msg, 2000)
  63. }
  64. },
  65. //初始化商品数据列表
  66. fetchProductList() {
  67. this.loadmore = true
  68. return this.ProductService.QueryProductList({
  69. pageNum: this.pageNum,
  70. pageSize: this.pageSize,
  71. floorId: this.floorId,
  72. userId: this.userId
  73. })
  74. .then(response => {
  75. let data = response.data
  76. this.productList = [...this.productList, ...data.list]
  77. this.hasNextPage = data.hasNextPage
  78. this.title = data.title
  79. this.pageNum++
  80. this.loadmore = false
  81. })
  82. .catch(error => {
  83. this.$util.msg(error.msg, 2000)
  84. })
  85. }
  86. },
  87. onPageScroll(e) {
  88. this.isScrollTop = e.scrollTop > 400
  89. },
  90. onReachBottom() {
  91. if (!this.hasNextPage) return
  92. clearTimeout(this.timer)
  93. this.timer = setTimeout(() => {
  94. console.log('触底了')
  95. this.fetchProductList()
  96. }, 200)
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. .good-floor-more {
  102. background: $uni-floor-bg-color;
  103. }
  104. .product-list {
  105. display: flex;
  106. justify-content: space-between;
  107. flex-wrap: wrap;
  108. padding: 0 24rpx;
  109. box-sizing: border-box;
  110. .product {
  111. margin-top: 24rpx;
  112. }
  113. }
  114. </style>