goods-column.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <!-- 当mescroll-body写在子组件时,父页面需引入mescroll-comp.js的mixins -->
  3. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
  4. :up="upOption" :down="downOption" v-if="hasData">
  5. <!-- 数据列表 -->
  6. <view class="goods-column">
  7. <scroll-view scroll-x="true">
  8. <view class="column-wrap">
  9. <view class="item flex-col m-r-50 muted" v-for="(item, index) in columnList" :key="index" @tap="changeActive(index)">
  10. <view class="xxl normal title" :class="{bold: active == index}">{{item.name}}</view>
  11. <view class="m-t-8 xs text-center" :class="active == index ?'active' :''">{{item.remark}}</view>
  12. <!-- <view class="m-t-8 xs text-center" :class="{normal : active == index}">{{item.remark}}</view> -->
  13. <!-- <view v-if="active == index" class="line br60"></view> -->
  14. </view>
  15. </view>
  16. </scroll-view>
  17. </view>
  18. <view class="goods">
  19. <u-waterfall ref="uWaterfall" v-model="goodsList" :add-time="20">
  20. <template v-slot:left="{leftList}">
  21. <view style="padding:0 9rpx 0 30rpx">
  22. <goods-list width="336rpx" type="waterfall" :list="leftList"></goods-list>
  23. </view>
  24. </template>
  25. <template v-slot:right="{rightList}">
  26. <view style="padding:0 30rpx 0 9rpx;">
  27. <goods-list width="336rpx" type="waterfall" :list="rightList"></goods-list>
  28. </view>
  29. </template>
  30. </u-waterfall>
  31. </view>
  32. </mescroll-body>
  33. </template>
  34. <script>
  35. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  36. import {
  37. getGoodsListColumn,
  38. getGoodsColumn
  39. } from "@/api/store"
  40. export default {
  41. mixins: [MescrollMixin], // 使用mixin
  42. props:{
  43. autoGetData: {
  44. type: Boolean,
  45. default:true
  46. }
  47. },
  48. data() {
  49. return {
  50. goodsList: [],
  51. active: 0,
  52. columnList: [],
  53. upOption: {
  54. auto: false,
  55. empty: {
  56. icon: '/static/images/goods_null.png',
  57. tip: "暂无商品",
  58. }
  59. },
  60. downOption:{use: false, isLock: true},
  61. hasData: true
  62. }
  63. },
  64. mounted() {
  65. if(this.autoGetData) {
  66. this.getData()
  67. }
  68. },
  69. methods: {
  70. async getData() {
  71. await this.getGoodsColumnFun()
  72. this.$refs.uWaterfall && this.$refs.uWaterfall.clear();
  73. this.mescroll.resetUpScroll();
  74. },
  75. changeActive(index) {
  76. this.active = index
  77. this.$refs.uWaterfall.clear();
  78. this.mescroll.resetUpScroll();
  79. },
  80. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  81. upCallback(page) {
  82. //联网加载数据
  83. const {columnList, active} = this
  84. const pageNum = page.num; // 页码, 默认从1开始
  85. const pageSize = page.size; // 页长, 默认每页10条
  86. if(!columnList.length) return
  87. const columnId = columnList[active].id
  88. getGoodsListColumn({
  89. page_size: pageSize,
  90. page_no: pageNum,
  91. column_id: columnId
  92. }).then(({
  93. data
  94. }) => {
  95. let curPageData = data.lists;
  96. let curPageLen = curPageData.length;
  97. let hasNext = !!data.more;
  98. if (page.num == 1) this.goodsList = [];
  99. this.goodsList = this.goodsList.concat(curPageData);
  100. this.mescroll.endSuccess(curPageLen, hasNext);
  101. })
  102. },
  103. async getGoodsColumnFun() {
  104. const {
  105. data,
  106. code
  107. } = await getGoodsColumn()
  108. if (code == 1) {
  109. this.columnList = data
  110. this.hasData = data.length ? true : false
  111. }
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .goods-column {
  118. .column-wrap {
  119. display: inline-block;
  120. white-space: nowrap;
  121. padding: 30rpx;
  122. .item {
  123. display: inline-block;
  124. position: relative;
  125. overflow: hidden;
  126. .title {
  127. position: relative;
  128. z-index: 1;
  129. }
  130. .xs{
  131. &.active{
  132. color: #fff;
  133. border-radius: 20rpx;
  134. background: linear-gradient(142deg, #F16D60 0%, #F8352B 100%);
  135. }
  136. }
  137. .line {
  138. position: absolute;
  139. top: 32rpx;
  140. left: 0;
  141. width: 144rpx;
  142. height: 12rpx;
  143. background: linear-gradient(90deg, #FF2C3C 0%, rgba(255, 44, 60, 0) 100%);
  144. }
  145. }
  146. }
  147. }
  148. </style>