You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fx-uniapp/components/shopro-coupon/shopro-coupon.vue

249 lines
6.4 KiB

2 years ago
<template>
<view class="">
<!-- 未领取已领取 -->
<view class="coupon-wrap" :style="gradientColor" :class="{ 'gray-wrap': state === 3 || state === 2 || couponData.status_code == 'cannot_get' }">
<view class="coupon-item u-flex u-row-between">
2 years ago
<!-- <view class="coupon-left u-flex-col ">
2 years ago
<view class="sum-box">
<text class="unit " :style="{ color: priceColor }"></text>
<text class="sum " :style="{ color: priceColor }">{{ couponData.amount }}</text>
<text class="sub " :style="{ color: priceColor }">{{ couponData.name }}</text>
</view>
<view class="notice " :style="{ color: color }">{{ couponData.enough }}元可用</view>
<view class="notice" :style="{ color: color }">
有效期{{ $u.timeFormat(couponData.usetime.start, 'yyyy-mm-dd') }} {{ $u.timeFormat(couponData.usetime.end, 'yyyy-mm-dd') }}
</view>
</view>
<view class="coupon-right u-flex-col">
<button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 0" @tap.stop="getCoupon">{{ stateMap[couponData.status_code] || '立即领取' }}</button>
<button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 1">去使用</button>
<button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 2">暂不可用</button>
<button class="get-btn" v-if="state === 3">{{ stateMap[couponData.status_code] }}</button>
<view class="surplus-num" :style="{ color: color }" v-if="state === 0">仅剩{{ stock }}</view>
2 years ago
</view> -->
<view class="coupon-left u-flex-col ">
<view class="sum-box">
<view class="couponInfo">
<text class="unit " :style="{ color: priceColor }"></text>
<text class="sum " :style="{ color: priceColor }">{{ couponData.amount }}</text>
</view>
<view class="notice" :style="{ color: color }">{{ couponData.enough }}元可用</view>
<!-- <text class="sub " :style="{ color: priceColor }">{{ couponData.name }}</text> -->
</view>
<image src="../../static/images/yhq.png" mode="heightFix"></image>
</view>
<view class="coupon-right u-flex-col">
<text class="sub " :style="{ color: priceColor }">{{ couponData.name }}</text>
<view class="validDate" :style="{ color: color }">
有效期{{ $u.timeFormat(couponData.usetime.start, 'yyyy-mm-dd') }} {{ $u.timeFormat(couponData.usetime.end, 'yyyy-mm-dd') }}
</view>
<view style="display: flex;align-items: center;justify-content: space-between;">
<view class="surplus-num" :style="{ color: color }" v-if="state === 0">仅剩{{ stock }}</view>
<view class="">
<button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 0" @tap.stop="getCoupon">{{ stateMap[couponData.status_code] || '立即领取' }}</button>
<button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 1">去使用</button>
<button class="get-btn" :style="{ color: btnTextColor }" v-if="state === 2">暂不可用</button>
<button class="get-btn" v-if="state === 3">{{ stateMap[couponData.status_code] }}</button>
</view>
</view>
2 years ago
</view>
</view>
</view>
</view>
</template>
<script>
/**
* shoproCoupon-优惠券
* @property {Number} state - 0:立即领取1去使用2查看详情3已失效
* @property {Object} couponData - 优惠劵数据
* @property {String} gradientColor - 渐变色
*/
export default {
components: {},
data() {
return {
stock: 0,
stateMap: {
can_use: '立即使用',
used: '已使用',
expired: '已失效',
cannot_use: '暂不可用',
can_get: '立即领取',
cannot_get: '已领取'
}
};
},
props: {
state: 0, //0:立即领取,1:去使用,2:查看详情,3:已失效。
couponData: {},
gradientColor: {
type: String,
default: ''
},
color: {
type: String,
default: ''
},
btnTextColor: {
type: String,
default: ''
},
priceColor: {
type: String,
default: ''
}
},
computed: {},
created() {
this.$nextTick(() => {
this.stock = this.couponData.stock;
});
},
methods: {
getCoupon() {
let that = this;
that.$http(
'coupons.get',
{
id: that.couponData.id
},
'领取中...'
).then(res => {
if (res.code === 1) {
that.stock -= 1;
that.$u.toast('领取成功');
}
});
}
}
};
</script>
<style lang="scss" scoped>
// 失效
.gray-wrap {
-webkit-filter: grayscale(1); /* Webkit */
filter: gray; /* IE6-9 */
filter: grayscale(1); /* W3C */
}
// 未领取,已领取
.coupon-wrap {
2 years ago
// mask: url($IMG_URL+'/imgs/coupon_bg1.png');
// -webkit-mask-box-image: url($IMG_URL+'/imgs/coupon_bg1.png');
2 years ago
mask-size: 100% 100%;
position: relative;
border-radius: 10rpx;
width: 710rpx;
2 years ago
height: 220rpx;
background: #ffffff;
// background: linear-gradient(to right, $u-type-warning-disabled, $u-type-warning);
2 years ago
.coupon-item {
width: 100%;
2 years ago
// height: 168rpx;
height:100%;
2 years ago
border-radius: 10rpx;
2 years ago
2 years ago
.coupon-left {
2 years ago
position: relative;
// height: 100%;
2 years ago
justify-content: center;
2 years ago
width:220rpx;
height:220rpx;
// padding-left: 40rpx;
.sum-box{
position: absolute;
z-index: 99;
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
image{
width:auto;
height:220rpx;
}
.couponInfo{
}
2 years ago
.unit {
font-size: 24rpx;
2 years ago
color: #222;
2 years ago
}
.sum {
2 years ago
font-size: 48rpx;
2 years ago
font-weight: bold;
2 years ago
color: #222;
// line-height: 55rpx;
// padding-right: 10rpx;
2 years ago
}
2 years ago
2 years ago
.notice {
2 years ago
margin-top: 38rpx;
font-size: 24rpx;
font-family: PingFang SC;
font-weight: 500;
color: #222222;
2 years ago
}
}
.coupon-right {
height: 100%;
2 years ago
// width: 220rpx;
flex:1;
justify-content: space-around;
padding: 0 30rpx 0 25rpx;
.sub {
font-size: 30rpx;
font-family: PingFang SC;
font-weight: bold;
color: #222222;
}
.validDate{
font-size: 24rpx;
font-family: PingFang SC;
font-weight: 500;
color: #999999;
}
2 years ago
.get-btn {
2 years ago
width: 150rpx;
height: 50rpx;
line-height: 44rpx;
background: #FFFFFF;
border: 1px solid #222222;
border-radius: 25rpx;
2 years ago
font-size: 24rpx;
2 years ago
font-family: PingFang SC;
2 years ago
font-weight: 500;
2 years ago
color: #222222;
2 years ago
}
.surplus-num {
2 years ago
font-size: 24rpx;
font-family: PingFang SC;
2 years ago
font-weight: 500;
2 years ago
color: #999999;
2 years ago
}
}
}
}
</style>