cate-list.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="cate-list">
  3. <mescroll-uni :ref="'mescrollRef'+i" :top="positionTop" @init="mescrollInit"
  4. @down="downCallback" @up="upCallback" :up="upOption" :down="downOption" >
  5. <view class="content">
  6. <view style="margin: 0 20rpx" v-if="appConfig.cate_style == 3">
  7. <cate-nav :list="cateTwoList"></cate-nav>
  8. </view>
  9. <ad-swipers :pid="11" height="268rpx" padding="20rpx 20rpx 0" radius="10rpx">
  10. </ad-swipers>
  11. <view class="sort-nav-wrap">
  12. <sort-nav v-model="sortConfig"></sort-nav>
  13. </view>
  14. <view class="goods">
  15. <view v-show="sortConfig.goodsType == 'double'" class="double">
  16. <goods-list type="double" :list="goodsList"></goods-list>
  17. </view>
  18. <view v-show="sortConfig.goodsType == 'one'" class="one">
  19. <goods-list :list="goodsList" type="one"></goods-list>
  20. </view>
  21. </view>
  22. </view>
  23. </mescroll-uni>
  24. </view>
  25. </template>
  26. <script>
  27. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  28. import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
  29. import {
  30. getGoodsList,
  31. getListByLevelOne
  32. } from "@/api/store"
  33. import {
  34. mapGetters,
  35. mapActions
  36. } from 'vuex'
  37. const app = getApp()
  38. export default {
  39. mixins: [MescrollMixin, MescrollMoreItemMixin],
  40. name: "cate-list",
  41. props: {
  42. top: {
  43. type: [Number, String]
  44. },
  45. cate: {
  46. type: Object,
  47. default: () => ({})
  48. }
  49. },
  50. data() {
  51. return {
  52. goodsList: [],
  53. cateTwoList: [],
  54. upOption: {
  55. auto: false, // 不自动加载
  56. noMoreSize: 1, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  57. empty: {
  58. icon: '/static/images/goods_null.png',
  59. tip: '暂无商品~', // 提示
  60. }
  61. },
  62. sortConfig: {
  63. goodsType: 'double',
  64. priceSort: '',
  65. saleSort: '',
  66. },
  67. };
  68. },
  69. computed: {
  70. ...mapGetters(['appConfig']),
  71. positionTop() {
  72. return this.top
  73. }
  74. },
  75. methods: {
  76. onRefresh() {
  77. this.mescroll.resetUpScroll(true);
  78. },
  79. async downCallback() {
  80. await this.getListByLevelOneFun()
  81. this.mescroll.resetUpScroll();
  82. },
  83. upCallback(page) {
  84. const {sortConfig: {
  85. priceSort,
  86. saleSort,
  87. }} = this
  88. getGoodsList({
  89. page_size: page.size,
  90. page_no: page.num,
  91. platform_cate_id: this.cate.id,
  92. sort_by_price: priceSort,
  93. sort_by_sales: saleSort
  94. }).then(({
  95. data
  96. }) => {
  97. const curPageData = data.lists;
  98. const curPageLen = curPageData.length;
  99. const 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 getListByLevelOneFun() {
  106. const {
  107. id
  108. } = this.cate
  109. const {
  110. code,
  111. data
  112. } = await getListByLevelOne({
  113. id
  114. })
  115. if (code == 1) {
  116. this.cateTwoList = data
  117. }
  118. }
  119. },
  120. watch: {
  121. 'sortConfig.saleSort'() {
  122. this.onRefresh()
  123. },
  124. 'sortConfig.priceSort'() {
  125. this.onRefresh()
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss">
  131. .cate-list {
  132. border-radius: 20rpx 20rpx 0 0;
  133. overflow: hidden;
  134. .contain {
  135. padding: 20rpx 30rpx 0;
  136. }
  137. .sort-nav-wrap {
  138. margin: 20rpx 20rpx 0;
  139. border-radius: 14rpx;
  140. overflow: hidden;
  141. }
  142. .title-img {
  143. width: 100%;
  144. height: 120rpx;
  145. }
  146. }
  147. </style>