2020-06-11 08:12:04 +00:00
|
|
|
|
<template>
|
|
|
|
|
<view class="list">
|
2020-07-24 11:48:57 +00:00
|
|
|
|
<view class="top">商品推荐</view>
|
2020-07-17 09:34:42 +00:00
|
|
|
|
<view>
|
2020-08-08 04:07:50 +00:00
|
|
|
|
<u-tabs :list="classifyList" name="gc_name" :is-scroll="true" :current="current" @change="tabsChange" active-color="#FF780F" :show-bar="false" height="60" font-size="24" inactive-color="#333333"></u-tabs>
|
2020-07-16 09:39:06 +00:00
|
|
|
|
</view>
|
2020-08-08 04:07:50 +00:00
|
|
|
|
<swiper class="swiper-box" :current="swiperCurrent" @animationfinish="animationfinish" :style="{height: swiperHeight}">
|
2020-07-17 09:34:42 +00:00
|
|
|
|
<swiper-item class="swiper-item" v-for="(_, index) in classifyList" :key="index">
|
2020-08-08 04:07:50 +00:00
|
|
|
|
<view class="goods-item">
|
|
|
|
|
<item v-for="item in goodsList[index]" :key="item.goods_id" :info="item"></item>
|
2020-07-24 11:48:57 +00:00
|
|
|
|
</view>
|
2020-08-08 04:07:50 +00:00
|
|
|
|
<u-empty text="暂无商品" mode="list" color="#000" margin-top="20" v-if="!goodsList[index] || !goodsList[index].length"></u-empty>
|
2020-07-16 09:39:06 +00:00
|
|
|
|
</swiper-item>
|
2020-07-17 09:34:42 +00:00
|
|
|
|
</swiper>
|
2020-07-23 12:58:56 +00:00
|
|
|
|
<!-- 加载更多 -->
|
2020-08-11 14:15:58 +00:00
|
|
|
|
<u-loadmore class="load-size" :status="loadStatus" bgColor="#FFF" margin-top="20" margin-bottom="20" @loadmore="loadMore"></u-loadmore>
|
2020-07-24 11:48:57 +00:00
|
|
|
|
</view>
|
2020-06-11 08:12:04 +00:00
|
|
|
|
</template>
|
|
|
|
|
<script>
|
2020-07-23 12:58:56 +00:00
|
|
|
|
import item from "./item";
|
2020-06-11 08:12:04 +00:00
|
|
|
|
export default {
|
2020-07-16 09:39:06 +00:00
|
|
|
|
name:"list",
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2020-08-07 03:59:08 +00:00
|
|
|
|
// pageSize: 12,
|
2020-07-23 06:56:20 +00:00
|
|
|
|
current: -1,
|
2020-07-16 09:39:06 +00:00
|
|
|
|
swiperCurrent: 0,
|
2020-07-17 09:34:42 +00:00
|
|
|
|
goodsList: [],
|
2020-07-23 06:56:20 +00:00
|
|
|
|
classifyList: [],
|
|
|
|
|
swiperHeight: '',
|
2020-07-23 12:58:56 +00:00
|
|
|
|
page: 1, // 从 1 开始
|
|
|
|
|
loadStatus: 'loadmore',
|
|
|
|
|
timer: true,
|
2020-07-16 09:39:06 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2020-07-23 12:58:56 +00:00
|
|
|
|
components: {
|
|
|
|
|
item,
|
2020-06-18 06:57:26 +00:00
|
|
|
|
},
|
2020-07-17 09:34:42 +00:00
|
|
|
|
watch: {
|
|
|
|
|
current(index) {
|
2020-07-27 09:59:47 +00:00
|
|
|
|
this.page = 1;
|
2020-08-08 04:07:50 +00:00
|
|
|
|
// this.goodsList = [];
|
2020-07-17 09:34:42 +00:00
|
|
|
|
const id = this.classifyList[index].gc_id;
|
2020-07-23 12:58:56 +00:00
|
|
|
|
this.getGoodsRecommend({gc_id: id});
|
2020-07-17 09:34:42 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
2020-07-23 06:56:20 +00:00
|
|
|
|
this.getGoodsClassRecommend();
|
2020-07-16 09:39:06 +00:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
2020-08-18 04:12:01 +00:00
|
|
|
|
loadMore() {
|
2020-07-23 12:58:56 +00:00
|
|
|
|
if(!this.timer) return false;
|
|
|
|
|
this.loadStatus = "loading";
|
|
|
|
|
this.page++;
|
|
|
|
|
this.getGoodsRecommend({
|
|
|
|
|
gc_id: this.classifyList[this.current].gc_id,
|
|
|
|
|
page: this.page,
|
|
|
|
|
reload: false,
|
|
|
|
|
}).then(length => {
|
2020-07-24 12:35:28 +00:00
|
|
|
|
// console.log(length);
|
2020-07-23 12:58:56 +00:00
|
|
|
|
if(length == 0) {
|
|
|
|
|
this.page--;
|
|
|
|
|
this.loadStatus = 'nomore';
|
|
|
|
|
} else {
|
2020-07-30 12:33:16 +00:00
|
|
|
|
this.loadStatus = 'loadmore';
|
2020-07-23 12:58:56 +00:00
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
this.loadStatus = "nomore";
|
|
|
|
|
this.page--;
|
|
|
|
|
})
|
|
|
|
|
},
|
2020-08-05 09:38:11 +00:00
|
|
|
|
getGoodsClassRecommend() {
|
2020-07-23 06:56:20 +00:00
|
|
|
|
this.$u.api.getGoodsClassRecommend().then(res => {
|
2020-08-17 10:09:19 +00:00
|
|
|
|
console.log(res)
|
2020-07-23 06:56:20 +00:00
|
|
|
|
if (res.errCode == 0) {
|
|
|
|
|
// 初始化 current
|
|
|
|
|
this.current = 0;
|
|
|
|
|
this.classifyList = res.data.gc_recommend;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2020-07-23 12:58:56 +00:00
|
|
|
|
async getGoodsRecommend({ page = this.page, gc_id, reload = true } = {}) {
|
|
|
|
|
const res = await this.$u.api.getGoodsRecommend({
|
|
|
|
|
page: page,
|
2020-07-17 09:34:42 +00:00
|
|
|
|
gc_id: gc_id,
|
|
|
|
|
})
|
2020-08-05 09:38:11 +00:00
|
|
|
|
// this.swiperCurrent = this.current;
|
2020-07-23 12:58:56 +00:00
|
|
|
|
if (res.errCode == 0) {
|
2020-07-30 12:33:16 +00:00
|
|
|
|
this.timer = true;
|
2020-08-08 04:07:50 +00:00
|
|
|
|
if(reload) this.goodsList[this.current] = res.data.goodsList;
|
|
|
|
|
else this.goodsList[this.current].push(...res.data.goodsList);
|
2020-07-23 12:58:56 +00:00
|
|
|
|
// console.log(this.goodsList);
|
|
|
|
|
this.setSwiperHeight();
|
|
|
|
|
}
|
2020-08-08 04:07:50 +00:00
|
|
|
|
this.$forceUpdate();
|
2020-07-23 12:58:56 +00:00
|
|
|
|
return res.data.goodsList.length;
|
2020-07-17 09:34:42 +00:00
|
|
|
|
},
|
2020-07-23 06:56:20 +00:00
|
|
|
|
setSwiperHeight() {
|
2020-08-08 04:07:50 +00:00
|
|
|
|
// height: 480rpx, margin-bottom: 26rpx
|
2020-08-18 02:38:35 +00:00
|
|
|
|
const height = Math.ceil(this.goodsList[this.current].length / 2) * (450 + 26);
|
2020-08-05 09:38:11 +00:00
|
|
|
|
this.swiperHeight = height == 0 ? '230rpx' : height + 'rpx';
|
2020-08-08 04:07:50 +00:00
|
|
|
|
// console.log(this.swiperHeight);
|
2020-07-23 06:56:20 +00:00
|
|
|
|
},
|
2020-07-16 09:39:06 +00:00
|
|
|
|
// tabs通知swiper切换
|
|
|
|
|
tabsChange(index) {
|
2020-08-05 09:38:11 +00:00
|
|
|
|
this.current = index;
|
2020-08-08 04:07:50 +00:00
|
|
|
|
this.swiperCurrent = this.current;
|
2020-08-05 09:38:11 +00:00
|
|
|
|
// this.getGoodsRecommend({ gc_id: this.classifyList[this.current].gc_id });
|
2020-07-16 09:39:06 +00:00
|
|
|
|
},
|
|
|
|
|
// 由于swiper的内部机制问题,快速切换swiper不会触发dx的连续变化,需要在结束时重置状态
|
|
|
|
|
// swiper滑动结束,分别设置tabs和swiper的状态
|
|
|
|
|
animationfinish(e) {
|
|
|
|
|
let current = e.detail.current;
|
|
|
|
|
this.current = current;
|
2020-08-05 09:38:11 +00:00
|
|
|
|
this.swiperCurrent = current;
|
|
|
|
|
// this.getGoodsRecommend({ gc_id: this.classifyList[this.current].gc_id });
|
2020-07-16 09:39:06 +00:00
|
|
|
|
},
|
2020-06-18 06:57:26 +00:00
|
|
|
|
}
|
2020-06-11 08:12:04 +00:00
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.list{
|
2020-07-24 11:48:57 +00:00
|
|
|
|
background-color: #ffffff;
|
|
|
|
|
padding: 30rpx {
|
|
|
|
|
top: 0;
|
|
|
|
|
};
|
|
|
|
|
.top {
|
2020-06-11 08:37:52 +00:00
|
|
|
|
font-size: 30rpx;
|
2020-08-05 14:06:09 +00:00
|
|
|
|
height: 74rpx;
|
|
|
|
|
line-height: 88rpx;
|
2020-06-11 08:37:52 +00:00
|
|
|
|
text-align: center;
|
|
|
|
|
color: #333;
|
|
|
|
|
}
|
2020-08-04 13:46:52 +00:00
|
|
|
|
.swiper-box {
|
|
|
|
|
height: 100%;
|
2020-08-08 04:07:50 +00:00
|
|
|
|
padding-top: 20rpx;
|
2020-08-04 13:46:52 +00:00
|
|
|
|
.swiper-item {
|
2020-08-06 02:48:21 +00:00
|
|
|
|
// height: 100%;
|
2020-08-04 13:46:52 +00:00
|
|
|
|
.goods-item {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
width: 100%;
|
2020-08-06 02:48:21 +00:00
|
|
|
|
// height: 100%;
|
2020-08-04 13:46:52 +00:00
|
|
|
|
overflow-y: scroll;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-11 08:12:04 +00:00
|
|
|
|
}
|
|
|
|
|
</style>
|