AbroadCoupon.vue
1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
<div class="course_coupons" v-if="proCoupon.length>0">
<div>
<van-tag v-for="(item,index) in proCoupon" :key="index" color="#ffffff" text-color="#FF2B2B">{{proCouponHas?'已领取:':''}}{{item.title}}</van-tag>
</div>
<div @click="toCoupons" class="fontBlue">领取 ></div>
</div>
</template>
<script>
export default {
props: ['detailDataId', 'centerNo'],
data () {
return {
proCoupon: [],//优惠券
proCouponHas: false,//优惠券已领取
}
},
mounted () {
this.getOrderCoupon()
},
methods: {
//获取产品可使用优惠券
getOrderCoupon () {
this.yxAxios
.post(`${this.proxyUrl}/api/coupon/orderCoupon`, {
"proId": this.detailDataId,
"userId": this.centerNo,
})
.then((res) => {
if (res.data.data) {
if (res.data.data.has.length > 0) {
this.proCoupon = res.data.data.has
this.chooseDefaultUseCard(res.data.data.has)//设置默认选中的优惠券
this.proCouponHas = true;
} else if (res.data.data.get.length > 0) {
this.proCoupon = {
title: '您有可领优惠券'
}
}
}
});
},
// 设置默认选中的优惠券
chooseDefaultUseCard (has) {
if (has.length > 1) {
let useCard = has[0];
for (let i in has) {
console.log(Number(has[i].couponPrice) > Number(useCard.couponPrice))
if (Number(has[i].couponPrice) > Number(useCard.couponPrice)) {
useCard = has[i]
}
}
// console.log('useCard', useCard)
this.proCoupon = [useCard]
localStorage.setItem('useCard', JSON.stringify(useCard))
} else {
localStorage.setItem('useCard', JSON.stringify(this.proCoupon[0]))
}
},
//领券
toCoupons () {
this.$router.push({
name: "CardBoxSXYX",
});
},
}
}
</script>