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