deming/pageE/mine/MemberServeCoupon.vue

167 lines
4.3 KiB
Vue
Raw Normal View History

2020-07-08 18:14:41 +08:00
<template>
<view class="coupon-swiper">
2020-07-17 17:34:42 +08:00
<u-tabs-swiper ref="coupon" :list="couponGroupList" name="gc_name" :is-scroll="true" active-color="#FF780F" :current="couponCurrent" font-size="24" :show-bar="false" @change="couponTabsChange" height="88" ></u-tabs-swiper>
2020-07-08 18:14:41 +08:00
<swiper :current="swiperCouponCurrent" @animationfinish="couponAnimationFinish" :style="{ height: swiperHeight }">
<swiper-item class="swiper-coupon-item" v-for="(_, i) in couponGroupList" :key="i">
2020-07-30 20:33:16 +08:00
<scroll-view scroll-y style="height: 100%;" @scrolltolower="onreachBottom">
2020-07-08 18:14:41 +08:00
<view v-for="(coupon, index) in couponList" :key="index" class="coupon-item">
<Coupon :couponInfo="coupon" :status='0' :type="0" @exchange="exchangeCoupon($event)"></Coupon>
</view>
2020-07-30 20:33:16 +08:00
<u-loadmore :status="loadStatus" bgColor="#FFF" margin-top="20" margin-bottom="20" v-if="couponList.length>=pageSize" @loadmore="onreachBottom"></u-loadmore>
2020-07-08 18:14:41 +08:00
<u-empty text="暂无优惠券" mode="coupon" color="#000" v-if="!couponList.length"></u-empty>
</scroll-view>
</swiper-item>
</swiper>
</view>
</template>
<script>
import Coupon from "@/components/mine/coupon/index";
export default {
data() {
return {
2020-07-30 20:33:16 +08:00
pageSize: 1,
2020-07-08 18:14:41 +08:00
swiperHeight: '',
couponCurrent: 0,
swiperCouponCurrent: 0,
2020-07-17 17:34:42 +08:00
couponGroupList: [],
couponList: [],
page: 0,
2020-07-27 17:59:47 +08:00
loadStatus: 'loadmore',
timer: true,
2020-07-08 18:14:41 +08:00
}
},
components: {
Coupon
},
created() {
this.setViewHeight();
2020-07-17 17:34:42 +08:00
this.getGoodsClass();
},
watch: {
couponCurrent(index) {
const id = this.couponGroupList[index].gc_id;
2020-07-30 20:33:16 +08:00
this.getCouponList({ gc_id: id, load: 'reload' });
2020-07-17 17:34:42 +08:00
}
2020-07-08 18:14:41 +08:00
},
methods: {
2020-07-30 20:33:16 +08:00
onreachBottom() {
2020-07-27 17:59:47 +08:00
if(!this.timer) return false;
this.loadStatus = "loading";
this.page++;
2020-07-30 20:33:16 +08:00
this.getCouponList({
gc_id: this.couponGroupList[this.couponCurrent].gc_id,
load: 'loadmore',
2020-07-27 17:59:47 +08:00
}).then(length => {
if(length == 0) {
this.page--;
this.loadStatus = 'nomore';
} else {
this.loadStatus = 'loading';
}
}).catch(() => {
this.loadStatus = "nomore";
this.page--;
})
},
2020-07-17 17:34:42 +08:00
getGoodsClass() {
this.$u.api.getGoodsClass().then(res => {
if(res.errCode == 0) {
this.couponGroupList = res.data;
2020-07-30 20:33:16 +08:00
this.getCouponList({ gc_id: this.couponGroupList[0].gc_id, load: 'reload' });
2020-07-17 17:34:42 +08:00
}
})
},
2020-07-30 20:33:16 +08:00
async getCouponList({ gc_id, load }) {
const res = await this.$u.api.getCouponList({
2020-07-17 17:34:42 +08:00
page: this.page,
gc_id: gc_id,
})
2020-07-30 20:33:16 +08:00
this.timer = true;
if(res.errCode == 0) {
if(load == 'reload') this.couponList = res.data;
else if(load == 'loadmore') this.couponList.push(...res.data);
}
return res.data.length;
2020-07-17 17:34:42 +08:00
},
2020-07-08 18:14:41 +08:00
exchangeCoupon(id) {
2020-07-30 20:33:16 +08:00
// console.log(id);
2020-07-08 18:14:41 +08:00
},
couponTabsChange(index) {
this.couponCurrent = index;
},
couponAnimationFinish(e) {
const current = e.detail.current;
this.swiperCouponCurrent = current;
this.couponCurrent = current;
},
setViewHeight() {
const res = uni.getSystemInfoSync();
this.swiperHeight = res.windowHeight - ((88 + 10 + 88) / 2) + 'px';
},
},
};
</script>
<style lang="scss" scoped>
.coupon-swiper {
.swiper-coupon-item {
box-sizing: border-box;
background-color: #ffffff;
padding: 30rpx {
top: 0;
};
.coupon-item {
margin-bottom: 20rpx;
}
// .coupon-item {
// padding: 30rpx;
// background-color: #ffffff;
// display: flex;
// align-items: flex-end;
// // margin-bottom: 2rpx;
// > img {
// width: 180rpx;
// height: 160rpx;
// border-radius: 10rpx;
// margin-right: 30rpx;
// }
// .coupon-main {
// .coupon-title {
// font-size: 30rpx;
// color: rgba(51,51,51,1);
// }
// .coupon-date {
// display: flex;
// align-items: center;
// margin: 29rpx 0 20rpx;
// > img {
// width: 24rpx;
// height: 24rpx;
// margin-right: 15rpx;
// }
// > view {
// font-size: 24rpx;
// color: rgba(153,153,153,1);
// }
// }
// .coupon-integral {
// font-size: 30rpx;
// font-weight: 500;
// color: rgba(255,120,15,1);
// }
// }
// .coupon-btn {
// margin-left: auto;
// width: 85rpx;
// // height: 42rpx;
// border: 2rpx solid rgba(255,120,15,1);
// border-radius: 10rpx;
// font-size: 26rpx;
// color: rgba(255,120,15,1);
// line-height: 42rpx;
// text-align: center;
// }
// }
}
}
</style>