deming/components/shop/youhq/index.vue

123 lines
3.0 KiB
Vue
Raw Normal View History

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>
<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>
<!-- :style="{ height: swiperHeight }" -->
2020-07-18 17:43:37 +08:00
<swiper :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
<!-- 最多显示四个 -->
<view v-for="(coupon, index) in couponList.slice(0, 4)" :key="index" class="coupon-item">
<Coupon :couponInfo="coupon" :status='0' :type="0"></Coupon>
</view>
<u-empty text="暂无优惠券" mode="coupon" color="#000" v-if="!couponList.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) {
this.couponList = res.data;
} else {
this.couponList = [];
}
2020-07-18 17:43:37 +08:00
// 设置 swiper 高度
this.setViewHeight();
2020-07-17 17:34:42 +08:00
})
},
couponTabsChange(index) {
this.couponCurrent = index;
},
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;
num = this.couponList.length
? this.couponList.length > 4 ? 4 : this.couponList.length
: 1
2020-07-24 19:48:57 +08:00
this.swiperHeight = (97 + 10) * num + 'px';
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;
height: 90rpx;
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 {
font-size: 18rpx;
color: rgba(153,153,153,1);
}
}
.swiper-coupon-item {
2020-07-24 19:48:57 +08:00
padding: 0 30rpx;
2020-07-17 17:34:42 +08:00
box-sizing: border-box;
background-color: #ffffff;
.coupon-item {
margin-bottom: 20rpx;
}
}
2020-06-11 16:12:04 +08:00
}
</style>