113 lines
3.2 KiB
Vue
113 lines
3.2 KiB
Vue
<template>
|
||
<view class="group">
|
||
<view>
|
||
<u-tabs-swiper ref="uTabs" :list="tabList" name="gc_name" :current="current" @change="tabsChange" :is-scroll="true" active-color="#FF780F" swiperWidth="750" height="88" :show-bar="false"></u-tabs-swiper>
|
||
</view>
|
||
<swiper :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish" :style="{height: swiperHeight}">
|
||
<swiper-item class="swiper-item" v-for="(_, index) in tabList" :key="index">
|
||
<scroll-view scroll-y style="width: 100%;" @scrolltolower="onreachBottom">
|
||
<SpecialGoods v-for="(item, index) in pinTuanList" :key="index" :item="item" type='group'></SpecialGoods>
|
||
<u-loadmore :status="loadStatus" bgColor="#FFF" margin-top="20" margin-bottom="20" v-if="pinTuanList.length>=pageSize" @loadmore="onreachBottom"></u-loadmore>
|
||
<u-empty text="暂无商品" mode="list" color="#000" v-if="!pinTuanList.length"></u-empty>
|
||
</scroll-view>
|
||
</swiper-item>
|
||
</swiper>
|
||
</view>
|
||
</template>
|
||
<script>
|
||
import SpecialGoods from "../../components/shop/special-shop/index";
|
||
export default {
|
||
data() {
|
||
return {
|
||
pageSize: 12,
|
||
tabList: [],
|
||
current: -1,
|
||
swiperCurrent: 0,
|
||
page: 0,
|
||
pinTuanList: [],
|
||
swiperHeight: '',
|
||
timer: true, // 限制下拉刷新
|
||
loadStatus: 'loadmore',
|
||
}
|
||
},
|
||
components: {
|
||
SpecialGoods,
|
||
},
|
||
onLoad() {
|
||
this.getGoodsClass();
|
||
this.setViewHeight();
|
||
},
|
||
watch: {
|
||
current(index) {
|
||
this.getPinTuanList({ id: this.tabList[index].gc_id, load: 'reload' });
|
||
}
|
||
},
|
||
methods: {
|
||
// 获取优惠券拼团分类
|
||
async getGoodsClass() {
|
||
return await this.$u.api.getGoodsClass().then(res => {
|
||
if(res.errCode == 0) {
|
||
this.tabList = res.data;
|
||
this.current = 0;
|
||
}
|
||
})
|
||
},
|
||
// 拼团列表
|
||
async getPinTuanList({ id, page, load }) {
|
||
const res = await this.$u.api.getPinTuanList({
|
||
page: this.page,
|
||
gc_id: id,
|
||
})
|
||
this.timer = true;
|
||
if (res.errCode == 0) {
|
||
if(load == 'reload') this.pinTuanList = res.data;
|
||
else if(load == 'loadmore') this.pinTuanList.push(...res.data);
|
||
}
|
||
return res.data.length;
|
||
},
|
||
// scroll-view到底部加载更多
|
||
onreachBottom() {
|
||
if(!this.timer) return false;
|
||
this.loadStatus = "loading";
|
||
this.page++;
|
||
this.getPinTuanList({
|
||
id: this.tabList[this.current].gc_id,
|
||
load: 'loadmore',
|
||
}).then(length => {
|
||
console.log(length);
|
||
if(length == 0) {
|
||
this.page--;
|
||
this.loadStatus = 'nomore';
|
||
} else {
|
||
this.loadStatus = 'loadmore';
|
||
}
|
||
}).catch(() => {
|
||
this.loadStatus = "nomore";
|
||
this.page--;
|
||
})
|
||
},
|
||
// tabs通知swiper切换
|
||
tabsChange(index) {
|
||
this.swiperCurrent = index;
|
||
},
|
||
// 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.swiperCurrent = current;
|
||
this.current = current;
|
||
},
|
||
setViewHeight() {
|
||
const res = uni.getSystemInfoSync();
|
||
this.swiperHeight = res.windowHeight - (88 / 2) + 'px';
|
||
},
|
||
}
|
||
};
|
||
</script>
|
||
<style lang="scss" scoped>
|
||
</style> |