chargeDetail.js
7.25 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import {
decimal
} from '~/utils/format'
Page({
data: {
curIndex: 0,
checkedItem: 0,
isOpen: false,
selectedItem: null,
listData: [],
isGameUse: false,
coupons: null,
showCoupons: false,
},
// 获取当前商品绑定的优惠券并且处理价格
getCouponsItem(e) {
const couponsItem = e.detail
let {
selectedItem
} = this.data
selectedItem.payCouponsPrice = decimal(selectedItem.lineationPrice - (Number(couponsItem.denomination)), 2)
this.setData({
selectedItem,
coupons: couponsItem
})
},
toSelectCoupons() {
const isLogin = this.checkLogin()
if (!isLogin) {
return
}
if (this.data.isGH) return
this.setData({
showCoupons: true
})
},
bindInput(e) {
this.setData({
rechageNum: e.detail.value
})
},
changeMumberType(e) {
let {
selectedItem,
listData,
coupons
} = this.data
const {
index
} = e.currentTarget.dataset
selectedItem = listData[index].denominationList[0]
if (coupons) {
selectedItem.payCouponsPrice = decimal(selectedItem.lineationPrice - (Number(coupons.denomination)), 2)
}
this.setData({
curIndex: index,
selectedItem,
checkedItem: 0
})
},
checkedMumberType(e) {
const {
item,
index
} = e.currentTarget.dataset
let richText = decodeURIComponent(item.buysNotes)
richText = richText.replace(/\<span/g, '<span class="rich_text"')
this.setData({
checkedItem: index,
selectedItem: item,
richText
})
},
toCheckMember() {
if (this.data.isGameUse) return
const SID = wx.p.storage.get('sessionId')
if (!SID) {
return
}
wx.p.api.equityApi.checkOpenMember().then(res => {
let flag = false
if (res.code == 0 && res.data) {
flag = true
}
this.setData({
isOpen: flag
})
wx.p.eventbus.off('EQUITYGOODS')
})
},
getChargeDetail(query, options) {
let para = {
brandName: query.brandName,
supplier: query.supplier
}
if (this.data.isGameUse) {
para.id = query.id
}
wx.p.api.equityApi.chargeData(para).then(res => {
let {
selectedItem,
curIndex,
checkedItem,
richText,
isGameUse,
coupons
} = this.data
if (!res) {
setTimeout(() => {
wx.p.router.back()
}, 1500)
return
}
if (res.length) {
let brandLogo = res[0].brandLogo
query.icon = query.icon ? query.icon : brandLogo
res.forEach(item => {
item.denominationList.map(el => {
if (el.noMemberPrice) {
el.diffPraice = decimal(el.noMemberPrice - el.salesPrice, 2)
} else {
el.diffPraice = 0
}
return el
})
})
}
if (!query.id) {
selectedItem = res[0].denominationList[0]
} else {
for (let i = 0; i < res.length; i++) {
if (res[i].productName == query.productName) {
curIndex = i
}
for (let j = 0; j < res[i].denominationList.length; j++) {
if (res[i].denominationList[j].id == query.id) {
checkedItem = j
selectedItem = res[i].denominationList[j]
}
}
}
}
richText = decodeURIComponent(selectedItem.buysNotes)
richText = richText.replace(/\<span/g, '<span class="rich_text"')
if (isGameUse) {
selectedItem.payCouponsPrice = selectedItem.lineationPrice
}
this.setData({
listData: res,
query,
selectedItem,
checkedItem,
curIndex,
richText,
showLogin: false,
isGameUse,
showComponent: true
}, () => {
if (options.source == 'GH') {
this.handleEquityOfGH(options.couponsItem)
}
})
})
},
toCoupons() {
wx.p.router.go('/packageMine/pages/order/index/index')
},
toOpenPage() {
this.modalOnCancel()
wx.p.router.go('/packageEquity/pages/open/open?page=business')
},
toMemberPage() {
this.toOpenPage()
},
async toRecharge() {
const loginStatus = await wx.p.router.intercept()
if (loginStatus) return
if (!this.data.rechageNum) {
wx.p.wxApi.showToast('请输入充值账号')
return
}
if (this.data.isGameUse) return this.comfirmBuyItem()
const {
noMemberPrice,
salesPrice
} = this.data.selectedItem
let diffPrice = 0
if (noMemberPrice) {
diffPrice = decimal(noMemberPrice - salesPrice, 2)
}
this.setData({
showModal: true,
diffPrice
})
},
modalOnCancel() {
this.setData({
showModal: false
})
},
comfirmBuyItem() {
wx.p.wxApi.showLoading()
let para = {
supplier: this.data.query.supplier
}
wx.p.api.equityApi.getOrderCode(para).then(res => {
this.getPayParam(res)
this.modalOnCancel()
})
},
// 获取支付参数
getPayParam(orderCode) {
if (!orderCode) {
return
}
const {
selectedItem,
rechageNum,
isGameUse,
coupons
} = this.data, {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
orderCode,
goodsId: selectedItem.id,
rechargeNumber: rechageNum,
goodsQuality: 1,
// payMannerId: 19,
paySource: 3,
merchantId
}
if (isGameUse && coupons) {
para.usedCouponIds = [coupons.id]
}
wx.p.api.equityApi.payGoodsOrder(para).then(res => {
wx.hideLoading()
this.handlePay(res)
})
},
// 处理支付
handlePay(payData) {
const {
timeStamp,
nonceStr,
packages,
signType,
paySign
} = payData
let self = this
wx.requestPayment({
timeStamp: timeStamp,
nonceStr: nonceStr,
package: packages,
signType: signType,
paySign: paySign,
success() {
//跳转商品详情
let {
query,
selectedItem,
rechageNum
} = self.data
wx.p.router.go('/packageEquity/pages/chargeWait/chargeWait', {
query: {
...query,
...selectedItem,
rechageNum,
}
})
},
fail() {}
})
},
// 设置标题名称
setNaviTitle(title) {
wx.setNavigationBarTitle({
title
})
},
onLoad(options) {
const query = options.param
this.getChargeDetail(query, options)
this.setNaviTitle(query.brandName)
wx.p.eventbus.on('EQUITYGOODS', data => {
this.toCheckMember()
})
},
onShow() {
this.toCheckMember()
},
// 处理广汇权益明细进入的卡券
handleEquityOfGH(couponsItem) {
let {
selectedItem
} = this.data
selectedItem.payCouponsPrice = decimal(selectedItem.lineationPrice - (Number(couponsItem.denomination)), 2)
this.setData({
selectedItem,
coupons: couponsItem
})
},
// 检测是否已经登录
checkLogin() {
const sessionId = wx.p.storage.get('sessionId')
let flag = true
if (!sessionId) {
flag = false
this.setData({
showLogin: true,
showComponent: false
})
}
return flag
},
loginCallBack(data) {
if (data) {
this.toCheckMember()
}
}
})