cate-home.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="cate-home">
  3. <mescroll-uni :ref="'mescrollRef'+i" bg-color="#f4f4f4" :top="positionTop" @init="mescrollInit"
  4. @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  5. <view class="content">
  6. <view style="margin: 0 30rpx">
  7. <cate-nav :list="navList"></cate-nav>
  8. </view>
  9. <view class="contain" v-if="hotGoods.length">
  10. <active-area :list="hotGoods" type="hot" title="品类热销"></active-area>
  11. </view>
  12. <view class="contain" v-if="newGoods.length">
  13. <active-area :list="newGoods" type="new" title="品类推荐"></active-area>
  14. </view>
  15. <view class="goods">
  16. <image src="/static/images/category_title.png" class="title-img"></image>
  17. <u-waterfall ref="uWaterfall" v-model="goodsList" :add-time="20">
  18. <template v-slot:left="{leftList}">
  19. <view style="padding:0 9rpx 0 30rpx">
  20. <goods-list width="336rpx" type="waterfall" :list="leftList"></goods-list>
  21. </view>
  22. </template>
  23. <template v-slot:right="{rightList}">
  24. <view style="padding:0 30rpx 0 9rpx;">
  25. <goods-list width="336rpx" type="waterfall" :list="rightList"></goods-list>
  26. </view>
  27. </template>
  28. </u-waterfall>
  29. </view>
  30. </view>
  31. </mescroll-uni>
  32. </view>
  33. </template>
  34. <script>
  35. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  36. import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
  37. import {
  38. getGoodsList,
  39. getListByLevelOne,
  40. getIndexCategory
  41. } from "@/api/store"
  42. const app = getApp()
  43. export default {
  44. mixins: [MescrollMixin, MescrollMoreItemMixin],
  45. name: "cate-home",
  46. props: {
  47. top: {
  48. type: [Number, String]
  49. },
  50. cate: {
  51. type: Object,
  52. default: () => ({})
  53. }
  54. },
  55. data() {
  56. return {
  57. goodsList: [],
  58. navList: [],
  59. hotGoods: [],
  60. newGoods: [],
  61. downOption: {
  62. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  63. },
  64. upOption: {
  65. auto: false, // 不自动加载
  66. noMoreSize: 1, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  67. empty: {
  68. icon: '/static/images/goods_null.png',
  69. tip: '暂无商品~', // 提示
  70. }
  71. },
  72. };
  73. },
  74. created() {
  75. },
  76. computed: {
  77. positionTop() {
  78. return this.top
  79. }
  80. },
  81. methods: {
  82. async downCallback() {
  83. await this.getIndexCategory()
  84. this.$refs.uWaterfall.clear && this.$refs.uWaterfall.clear();
  85. this.mescroll.resetUpScroll();
  86. },
  87. upCallback(page) {
  88. let pageNum = page.num; // 页码, 默认从1开始
  89. let pageSize = page.size; // 页长, 默认每页10条
  90. getGoodsList({
  91. page_size: pageSize,
  92. page_no: pageNum,
  93. platform_cate_id: this.cate.id
  94. }).then(({
  95. data
  96. }) => {
  97. let curPageData = data.lists;
  98. let curPageLen = curPageData.length;
  99. let hasNext = !!data.more;
  100. if (page.num == 1) this.goodsList = [];
  101. this.goodsList = this.goodsList.concat(curPageData);
  102. this.mescroll.endSuccess(curPageLen, hasNext);
  103. })
  104. },
  105. async getIndexCategory() {
  106. const {
  107. id
  108. } = this.cate
  109. const {
  110. code,
  111. data
  112. } = await getIndexCategory({
  113. platform_category_id: id
  114. })
  115. if (code == 1) {
  116. const {level_two, category_hots, category_recommend} = data
  117. this.navList = level_two
  118. this.hotGoods = category_hots
  119. this.newGoods = category_recommend
  120. }
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss">
  126. .cate-home {
  127. border-radius: 20rpx 20rpx 0 0;
  128. overflow: hidden;
  129. .contain {
  130. padding: 20rpx 30rpx 0;
  131. }
  132. .title-img {
  133. width: 100%;
  134. height: 120rpx;
  135. }
  136. }
  137. </style>