wxSendCoupon.vue
11.1 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<template>
<view class="warp">
<!-- #ifdef MP-WEIXIN -->
<send-coupon
v-if="cParams"
@sendcoupon="sendcoupon"
@userconfirm="userconfirm"
:send_coupon_params="cParams.send_coupon_params"
:sign="cParams.sign"
:send_coupon_merchant="cParams.send_coupon_merchant"
>
<slot></slot>
</send-coupon>
<view v-else @click.stop="receiveCoupon">
<slot></slot>
</view>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<view @click.stop="receiveCoupon">
<slot></slot>
</view>
<!-- #endif -->
<!-- 优惠券领取 -->
<tui-modal :show="confirmVisible" :custom="true" :fadein="true">
<view class="Put-box1">
<view class="text-align fs34 fs-bold">
是否领取此优惠券
</view>
<view class="flex-display flex-sp-between">
<view class="btn" @click="confirmVisible = false">
取消
</view>
<view class="btn submit" @click="receive">
确定
</view>
</view>
</view>
</tui-modal>
</view>
</template>
<script>
const NET = require('../../utils/request')
const API = require('../../config/api')
import tuiModal from "@/components/modal/modal";
export default {
name: "wxSendCoupon",
components: {
tuiModal
},
props: {
couponList: {
type: Array,
default: ()=>[]
},
isExchange: {
type: Boolean,
default: false
}
// 卡券无法加询问
// isConfirm: {
// type: Boolean,
// default: false
// }
},
data(){
return {
cParams: '',
confirmVisible: false,
successList: []
}
},
mounted(){
// console.log(this.couponList,'couponList')
let ids = []
this.couponList.forEach(item=>{
if(item.cardId){
ids.push(item.cardId)
}
// else {
// this.successList.push(item)
// }
// 解除app h5不能领券问题
this.successList.push(item)
})
// console.log(this.successList,'successList')
// #ifdef MP-WEIXIN
if(ids && ids.length > 0){
this.buildParam4Plug(ids)
}
// #endif
},
methods:{
// 获取微信卡券参数
buildParam4Plug(ids){
NET.request(API.buildParam4Plug, ids, 'POST').then(res => {
this.cParams = res.data
}).catch(res => {
})
},
// 领取优惠券
receiveCoupon() {
if(this.successList.length > 0){
const res = uni.getStorageSync('storage_key'),token = res.token;
if (token) {
if(this.isExchange){
// 积分兑换
let paramsData = {
couponId: this.couponList[0].couponId,
source: 3
}
NET.request(API.exchangeCoupon, paramsData, 'POST').then(res => {
this.$emit('success')
})
} else {
if (this.couponList.length === 1 && this.couponList[0].ifCredit) {
// 单个积分兑换的卡券去积分中心兑
uni.navigateTo({
url: `../integral/exchangeDetail?data=${JSON.stringify(this.couponList[0])}`
})
} else {
let params = []
this.successList.forEach(item=>{
params.push({
couponId: item.couponId,
couponCode: item.couponCode,
source: 1
})
})
// 领取优惠卷
NET.request(API.takeBatchCoupon, params, 'POST').then(res => {
if (res.code === '200') {
uni.showToast({
title:'领取成功',
})
this.$emit('success')
if(!this.cParams){
this.$emit('closeAd')
}
}
}).catch(res => {
if(res.data.code !== '200'){
uni.showToast({
title:res.data.message,
icon:"none"
})
}
})
}
}
} else {
uni.showToast({
title:'请先登录',
icon:"none"
})
uni.navigateTo({
url:'/pages_category_page2/userModule/login'
})
}
} else {
this.$emit('closeAd')
}
},
// 领取优惠券回调
sendcoupon(e){
console.log('领取了微信卡券', e)
const errcode = e.detail.errcode,resultList = e.detail.send_coupon_result
switch (errcode) {
case 'OK':
break
case 'PARAM_ERROR':
console.log('参数错误,请开发者查看msg中具体的错误信息并进行修复处理')
break
case 'USER_NOT_EXISTS':
console.log('登录态获取失效')
break
case 'USER_GET_FAILED':
console.log('登录态获取失败')
break
case 'SIGN_ERROR':
console.log('签名错误')
break
case 'SYSTEMERROR':
console.log('发券超时')
break
case 'FREQUENCY_LIMITED':
console.log('发券频率过高')
break
}
if(errcode === 'OK'){
resultList.forEach(item=>{
let cName = ''
this.couponList.forEach(citem=>{
if(item.stock_id === citem.cardId){
cName = citem.activityName
if(item.code === 'SUCCESS'){
citem.couponCode = item.coupon_code
this.successList.push(citem)
}
}
})
switch (item.code) {
case 'FAILED':
console.log('该张券发券失败,查看message中的具体错误信息')
break
case 'NOTENOUGH':
uni.showToast({
title:cName + '优惠券已被领取完',
icon:"none"
})
console.log('总预算用完')
break
case 'DAYLIMIT':
uni.showToast({
title:cName + '优惠券领取张数已达到上限',
icon:"none"
})
console.log('用户达到单天限领')
break
case 'NATURELIMIT':
uni.showToast({
title:cName + '优惠券领取张数已达到上限',
icon:"none"
})
console.log('用户自然人限领')
break
case 'MAXQUOTA':
uni.showToast({
title:cName + '优惠券领取张数已达到上限',
icon:"none"
})
console.log('用户领取张数达到上限')
break
case 'DUPREQUEST':
uni.showToast({
title:cName + '优惠券领取张数已达到上限',
icon:"none"
})
console.log('已通过该发券凭证给用户发券')
break
case 'NOTRUNNING':
console.log('批次状态非运营中')
break
case 'EXPIRED':
uni.showToast({
title:cName + '优惠券已过期',
icon:"none"
})
console.log('该批次已过期')
break
case 'NOTMONEY':
console.log('账户余额不足')
break
case 'USERLIMIT':
console.log('用户已超限领额度')
break
case 'FREQUENCYLIMIT':
console.log('超过频率限制')
break
}
})
this.receiveCoupon()
} else {
this.$emit('closeAd')
}
},
// 用户确认领券事件
userconfirm(e){
console.log('用户确认领券', e)
this.$emit('closeAd')
}
}
}
</script>