index.js
2.88 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import {
couponsApi
} from "../../api/api"
const baseImgUrl = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/cgacar/'
import {componentsMixin } from '../../mixins/index'
Component({
behaviors:[componentsMixin],
properties: {
requestFlag: {
type: Boolean,
observer(n) {
if (n) {
this.getCoupons()
}
}
}
},
data: {
list: [],
IMGURLTemp:baseImgUrl
},
pageLifetimes: {
show: function () {},
hide: function () {}
},
methods: {
closeModal() {
this.setData({
show: false
})
},
submit() {
let {
list
} = this.data;
let ids = []
list.forEach(item => {
ids.push(item.id)
})
this.closeModal()
// this.triggerEvent('onConfirm', ids)
this.toReceive(ids)
},
toUse(e) {
this.closeModal()
let {
item
} = e.currentTarget.dataset
// this.triggerEvent('click', target)
this.toUserCard(item)
},
//一键领取优惠券
toReceive(ids) {
let para = {
couponIdList: ids,
}
couponsApi.toReciveCard(para).then(res => {
if (res) {
// wx.navigateTo({
// url: '/packageMine/pages/coupon/success/success'
// })
wx.$router.go('packageMine.success')
}
})
},
// 去使用
toUserCard(item) {
let para = {
couponIdList: [item.id],
}
couponsApi.toReciveCard(para).then(res => {
if (res) {
let {
discountType,
useChannel,
id
} = item
if (discountType == 2 || discountType == 4) {
wx.$router.go('packageMall.coupon', {
userCouponId: id,
useMemberType: 0
})
return
}
/**线上商品代金券 */
if (discountType == 3 && useChannel == 1) {
wx.$router.go('packageMine.coupon.recommend', {
couponInfo: item
})
return
}
let temp = JSON.stringify(item)
wx.navigateTo({
url: '/packageMine/pages/coupon/detail/detail?item=' + temp
})
// wx.$router.go('packageMine.detail', { item: temp })
}
})
},
/**获取礼券 */
getCoupons() {
let couponIds = wx.getStorageSync('lastCouponIds')
let para = {
discountTypes: [3],
lastCouponIds: couponIds,
directionalFlag:1
}
couponsApi.getHomeCardData(para).then(res => {
let flag = res.list.length ? true : false
let ids = couponIds || []
res.list.forEach(item => {
ids.push(item.id)
})
this.setData({
list: res.list,
show: flag,
})
if (ids.length > 0) {
wx.setStorageSync('lastCouponIds', ids)
}
})
},
}
})