index.js
2.7 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
import { couponsApi } from '~/api/api'
import { componentsMixin } from '../../mixins/index'
Component({
behaviors: [componentsMixin],
properties: {
requestFlag: {
type: Boolean,
observer(n) {
this.getCoupons()
}
}
},
data: {
list: [],
IMGURL: wx.$imgUrl
},
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,
receiveWay: 1,
}
couponsApi.toReciveCard(para).then(res => {
if (res) {
wx.$router.go('/packageShopmall/packageMine/pages/coupon/success/success')
}
})
},
// 去使用
toUserCard(item) {
console.log(item)
let para = {
couponIdList: [item.id],
receiveWay: 1,
}
couponsApi.toReciveCard(para).then(res => {
if (res) {
let { discountType, useChannel, id } = item
if (discountType == 2 || discountType == 4) {
wx.$router.go('/packageShopmall/packageMall/pages/coupon/coupon', {
userCouponId: id,
useMemberType: 0
})
return
}
/**线上商品代金券 */
if (discountType == 3 && useChannel == 1) {
wx.$router.go('/packageShopmall/packageMine/pages/coupon/recommend/recommend', {
couponInfo: item
})
return
}
let temp = JSON.stringify(item)
wx.navigateTo({
url: '/packageShopmall/packageMine/pages/coupon/detail/detail?item=' + temp
})
}
})
},
/**获取礼券 */
getCoupons() {
let couponIds = wx.$storage.get('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.$storage.set('lastCouponIds', ids)
}
})
}
}
})