2020-06-11 16:12:04 +08:00
|
|
|
<template>
|
2020-07-17 17:34:42 +08:00
|
|
|
<view class="coupon-swiper">
|
|
|
|
<view class="top">
|
|
|
|
<view class="title">全部优惠券</view>
|
|
|
|
<view class="view-more" @click="toCouponPage">查看更多></view>
|
|
|
|
</view>
|
2020-08-08 12:07:50 +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="60" ></u-tabs-swiper> -->
|
|
|
|
<u-tabs :list="couponGroupList" name="gc_name" :is-scroll="true" :current="couponCurrent" @change="couponTabsChange" active-color="#FF780F" :show-bar="false" height="60" font-size="24" inactive-color="#333333"></u-tabs>
|
2020-07-17 17:34:42 +08:00
|
|
|
<!-- :style="{ height: swiperHeight }" -->
|
2020-08-07 19:56:47 +08:00
|
|
|
<swiper class="box" :current="swiperCouponCurrent" @animationfinish="couponAnimationFinish" :style="{height: swiperHeight}">
|
2020-07-17 17:34:42 +08:00
|
|
|
<swiper-item class="swiper-coupon-item" v-for="(_, i) in couponGroupList" :key="i">
|
2020-07-18 17:43:37 +08:00
|
|
|
<!-- 最多显示四个 -->
|
2020-08-08 12:07:50 +08:00
|
|
|
<view v-if="couponList[i]">
|
|
|
|
<view v-for="(coupon, index) in couponList[i].slice(0, 4)" :key="index" class="coupon-item">
|
|
|
|
<Coupon :couponInfo="coupon" :status='0' :type="0"></Coupon>
|
|
|
|
</view>
|
2020-07-18 17:43:37 +08:00
|
|
|
</view>
|
2020-08-08 12:07:50 +08:00
|
|
|
<u-empty text="暂无优惠券" mode="coupon" color="#000" v-if="!couponList[i] || !couponList[i].length"></u-empty>
|
2020-07-17 17:34:42 +08:00
|
|
|
</swiper-item>
|
|
|
|
</swiper>
|
|
|
|
</view>
|
2020-06-11 16:12:04 +08:00
|
|
|
</template>
|
|
|
|
<script>
|
2020-07-17 17:34:42 +08:00
|
|
|
import Coupon from "@/components/mine/coupon/index";
|
2020-06-11 16:12:04 +08:00
|
|
|
export default {
|
2020-07-17 17:34:42 +08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
swiperHeight: '',
|
|
|
|
couponCurrent: 0,
|
|
|
|
swiperCouponCurrent: 0,
|
|
|
|
couponGroupList: [],
|
|
|
|
couponList: [],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
Coupon
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
couponCurrent(index) {
|
|
|
|
const id = this.couponGroupList[index].gc_id;
|
|
|
|
this.getCouponList(id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.getGoodsClass();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getGoodsClass() {
|
|
|
|
this.$u.api.getGoodsClass().then(res => {
|
|
|
|
if(res.errCode == 0) {
|
|
|
|
this.couponGroupList = res.data;
|
|
|
|
this.getCouponList(this.couponGroupList[0].gc_id);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getCouponList(gc_id) {
|
|
|
|
this.$u.api.getCouponList({
|
|
|
|
page: 0,
|
|
|
|
gc_id: gc_id,
|
|
|
|
}).then(res => {
|
|
|
|
if(res.errCode == 0) {
|
2020-08-08 12:07:50 +08:00
|
|
|
this.couponList[this.couponCurrent] = res.data;
|
2020-07-17 17:34:42 +08:00
|
|
|
} else {
|
2020-08-08 12:07:50 +08:00
|
|
|
this.couponList[this.couponCurrent] = [];
|
2020-07-17 17:34:42 +08:00
|
|
|
}
|
2020-07-18 17:43:37 +08:00
|
|
|
// 设置 swiper 高度
|
|
|
|
this.setViewHeight();
|
2020-08-08 12:07:50 +08:00
|
|
|
this.$forceUpdate();
|
2020-07-17 17:34:42 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
couponTabsChange(index) {
|
|
|
|
this.couponCurrent = index;
|
2020-08-08 12:07:50 +08:00
|
|
|
this.swiperCouponCurrent = this.couponCurrent;
|
2020-07-17 17:34:42 +08:00
|
|
|
},
|
|
|
|
couponAnimationFinish(e) {
|
|
|
|
const current = e.detail.current;
|
|
|
|
this.swiperCouponCurrent = current;
|
|
|
|
this.couponCurrent = current;
|
|
|
|
},
|
|
|
|
setViewHeight() {
|
2020-07-18 17:43:37 +08:00
|
|
|
// 一个优惠券的高度 97px, 下距离 10px
|
2020-07-20 17:28:37 +08:00
|
|
|
let num = 0;
|
2020-08-08 12:07:50 +08:00
|
|
|
num = this.couponList[this.couponCurrent].length
|
|
|
|
? this.couponList[this.couponCurrent].length > 4 ? 4 : this.couponList[this.couponCurrent].length
|
2020-07-20 17:28:37 +08:00
|
|
|
: 1
|
2020-08-04 21:46:52 +08:00
|
|
|
this.swiperHeight = (200 + 20) * num + 'rpx';
|
2020-07-17 17:34:42 +08:00
|
|
|
},
|
|
|
|
toCouponPage() {
|
|
|
|
this.$u.route({
|
|
|
|
url: '/pageE/mine/MemberServe',
|
|
|
|
params: {
|
|
|
|
current: 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-06-11 16:12:04 +08:00
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
2020-07-17 17:34:42 +08:00
|
|
|
.coupon-swiper {
|
2020-07-24 19:48:57 +08:00
|
|
|
background-color: #ffffff;
|
|
|
|
margin-bottom: 40rpx;
|
2020-07-17 17:34:42 +08:00
|
|
|
.top {
|
2020-07-24 19:48:57 +08:00
|
|
|
padding: 0 30rpx;
|
2020-08-05 21:39:02 +08:00
|
|
|
height: 80rpx;
|
2020-07-17 17:34:42 +08:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
.title {
|
|
|
|
font-size: 30rpx;
|
|
|
|
font-weight: 500;
|
|
|
|
color: rgba(51,51,51,1);
|
|
|
|
}
|
|
|
|
.view-more {
|
2020-08-07 19:56:47 +08:00
|
|
|
font-size: 20rpx;
|
2020-07-17 17:34:42 +08:00
|
|
|
color: rgba(153,153,153,1);
|
|
|
|
}
|
|
|
|
}
|
2020-08-07 19:56:47 +08:00
|
|
|
.box {
|
|
|
|
padding-top: 20rpx;
|
|
|
|
.swiper-coupon-item {
|
|
|
|
padding: 0 30rpx;
|
|
|
|
box-sizing: border-box;
|
|
|
|
background-color: #ffffff;
|
|
|
|
.coupon-item {
|
|
|
|
height: 200rpx;
|
|
|
|
margin-bottom: 20rpx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-11 16:12:04 +08:00
|
|
|
}
|
|
|
|
</style>
|