deming/pageC/groupBuy/index.vue

113 lines
3.5 KiB
Vue
Raw Normal View History

2020-07-16 17:39:06 +08:00
<template>
<view class="group">
<view>
2020-08-08 18:15:07 +08:00
<!-- <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> -->
<u-tabs :list="tabList" name="gc_name" :is-scroll="true" :current="current" @change="tabsChange" active-color="#FF780F" :show-bar="false" height="88" font-size="24" inactive-color="#333333"></u-tabs>
2020-07-16 17:39:06 +08:00
</view>
2020-08-08 18:15:07 +08:00
<swiper :current="swiperCurrent" @animationfinish="animationfinish" :style="{height: swiperHeight}">
2020-07-16 17:39:06 +08:00
<swiper-item class="swiper-item" v-for="(_, index) in tabList" :key="index">
2020-07-30 20:33:16 +08:00
<scroll-view scroll-y style="width: 100%;" @scrolltolower="onreachBottom">
2020-08-08 18:15:07 +08:00
<view v-if="pinTuanList[index]">
<SpecialGoods v-for="(item, index) in pinTuanList[index]" :key="index" :item="item" type='group'></SpecialGoods>
</view>
<u-loadmore :status="loadStatus" bgColor="#FFF" margin-top="20" margin-bottom="20" v-if="!pinTuanList[index] || pinTuanList[index].length>=pageSize" @loadmore="onreachBottom"></u-loadmore>
<u-empty text="暂无商品" mode="list" color="#000" v-if="!pinTuanList[index] || !pinTuanList[index].length"></u-empty>
2020-07-16 17:39:06 +08:00
</scroll-view>
</swiper-item>
</swiper>
</view>
</template>
<script>
2020-07-23 20:58:56 +08:00
import SpecialGoods from "../../components/shop/special-shop/index";
2020-07-16 17:39:06 +08:00
export default {
data() {
return {
2020-07-30 20:33:16 +08:00
pageSize: 12,
2020-07-21 21:02:28 +08:00
tabList: [],
2020-07-23 20:58:56 +08:00
current: -1,
2020-07-16 17:39:06 +08:00
swiperCurrent: 0,
2020-07-21 21:02:28 +08:00
page: 0,
pinTuanList: [],
2020-07-23 20:58:56 +08:00
swiperHeight: '',
2020-07-30 20:33:16 +08:00
timer: true, // 限制下拉刷新
loadStatus: 'loadmore',
2020-07-16 17:39:06 +08:00
}
},
components: {
2020-07-23 20:58:56 +08:00
SpecialGoods,
2020-07-16 17:39:06 +08:00
},
2020-07-21 21:02:28 +08:00
onLoad() {
this.getGoodsClass();
2020-07-23 20:58:56 +08:00
this.setViewHeight();
2020-07-21 21:02:28 +08:00
},
watch: {
current(index) {
2020-07-30 20:33:16 +08:00
this.getPinTuanList({ id: this.tabList[index].gc_id, load: 'reload' });
2020-07-21 21:02:28 +08:00
}
2020-07-16 17:39:06 +08:00
},
methods: {
2020-07-21 21:02:28 +08:00
// 获取优惠券拼团分类
async getGoodsClass() {
return await this.$u.api.getGoodsClass().then(res => {
if(res.errCode == 0) {
this.current = 0;
2020-08-08 18:15:07 +08:00
this.tabList = res.data;
2020-07-21 21:02:28 +08:00
}
})
},
// 拼团列表
2020-07-30 20:33:16 +08:00
async getPinTuanList({ id, page, load }) {
2020-07-23 20:58:56 +08:00
const res = await this.$u.api.getPinTuanList({
2020-07-21 21:02:28 +08:00
page: this.page,
gc_id: id,
2020-07-16 17:39:06 +08:00
})
2020-07-30 20:33:16 +08:00
this.timer = true;
if (res.errCode == 0) {
2020-08-08 18:15:07 +08:00
if(load == 'reload') this.pinTuanList[this.current] = res.data;
else if(load == 'loadmore') this.pinTuanList[this.current].push(...res.data);
2020-07-30 20:33:16 +08:00
}
2020-08-08 18:15:07 +08:00
this.$forceUpdate();
2020-07-23 20:58:56 +08:00
return res.data.length;
2020-07-16 17:39:06 +08:00
},
2020-07-30 20:33:16 +08:00
// 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--;
})
},
2020-07-16 17:39:06 +08:00
// tabs通知swiper切换
tabsChange(index) {
2020-08-08 18:15:07 +08:00
this.current = index;
2020-07-16 17:39:06 +08:00
this.swiperCurrent = index;
},
// 由于swiper的内部机制问题快速切换swiper不会触发dx的连续变化需要在结束时重置状态
// swiper滑动结束分别设置tabs和swiper的状态
animationfinish(e) {
let current = e.detail.current;
this.swiperCurrent = current;
this.current = current;
},
2020-07-23 20:58:56 +08:00
setViewHeight() {
const res = uni.getSystemInfoSync();
this.swiperHeight = res.windowHeight - (88 / 2) + 'px';
},
2020-07-16 17:39:06 +08:00
}
};
</script>
<style lang="scss" scoped>
</style>