chargeDetail.js
10.3 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
import { IMG_URL } from '~/config';
import USERAPI from "~/api/usersApi/index";
Page({
data: {
IMGURL: IMG_URL,
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 = wx.p.format.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 = wx.p.format.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.cache.storageApi.getSessionId()
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, isGH } = this.data
if (!res) {
// wx.redirectTo({
// url: '/packageShopmall/packageEquity/pages/allEquity/allEquity?showToast=1'
// })
setTimeout(() => {
wx.p.router.back(e => {
e.onLoad({ showToast: 1 })
})
}, 500)
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 = wx.p.format.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,
isGH,
showComponent: true
}, () => {
if (options.source == 'GH') {
this.handleEquityOfGH(options.couponsItem)
}
})
})
},
toCoupons() {
wx.navigateTo({
url: '/packageMine/pages/order/index/index'
})
},
toOpenPage() {
this.modalOnCancel()
wx.navigateTo({
url: '/packageSaveMoney/pages/open/open?page=business'
})
},
toMemberPage() {
this.toOpenPage()
},
toRecharge() {
const isLogin = this.checkLogin()
if (!isLogin) {
return
}
if (!this.data.rechageNum) {
wx.p.wxApi.showToast('请输入充值账号')
return
}
if (this.data.isGameUse) return this.comfirmBuyItem()
// if(this.data.isGH)return this.toRechargeFill(this.data.rechageNum)
const { noMemberPrice, salesPrice } = this.data.selectedItem
let diffPrice = 0
if (noMemberPrice) {
diffPrice = wx.p.format.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
}
this.orderCode = orderCode
const {
merchantId
} = wx.p.storage.get('merchant_info')
const { selectedItem, rechageNum, isGameUse, coupons } = this.data
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,curIndex,listData } = self.data
// 设置埋点参数
const tracker = {
item_type: 7,
view: 3,
id: selectedItem.id
}
const firstLevel = listData[curIndex]
self.orderTime = Number(timeStamp)
self.order_total_price = selectedItem.salesPrice
self.pay_time = new Date().getTime()
self.trade_name = `${firstLevel.productName}${selectedItem.denomination}`
self.trade_classification = firstLevel.goodsCategory
self.addTrack(tracker)
//跳转商品详情
let obj = {
...query,
...selectedItem,
rechageNum,
isGH: self.data.isGH
}
const temp = JSON.stringify(obj)
wx.navigateTo({
url: '/packageSaveMoney/pages/chargeWait/chargeWait?query=' + temp
})
},
fail() { }
})
},
// 设置标题名称
setNaviTitle(title) {
wx.setNavigationBarTitle({
title
})
},
onLoad(options) {
this.data.isGameUse = options.inType == 'game'
this.data.isGH = options.source == 'GH'
const query = options ? options.param : this.data.query
this.getChargeDetail(query, options)
this.setNaviTitle(query.brandName)
if (options.inType == 'game') return
wx.p.eventbus.on('EQUITYGOODS', data => {
this.toCheckMember()
})
},
onShow() {
this.toCheckMember()
},
// 处理广汇权益明细进入的卡券
handleEquityOfGH(couponsItem) {
let { selectedItem } = this.data
selectedItem.payCouponsPrice = wx.p.format.decimal(selectedItem.lineationPrice - (Number(couponsItem.denomination)), 2)
this.setData({
selectedItem,
coupons: couponsItem
})
},
// 检测是否已经登录
checkLogin() {
const sessionId = wx.p.cache.storageApi.getSessionId()
let flag = true
if (!sessionId) {
flag = false
this.setData({
showLogin: true,
showComponent: false
})
}
return flag
},
loginCallBack(data) {
if (data) {
this.toCheckMember()
}
},
// 广汇赠送权益直充
// toRechargeFill(phone) {
// wx.p.wxApi.showLoading()
// const { productId, orderCode, productName, discount } = this.data.ghOption
// wx.p.api.equityApi.toRechargeByPhone({ orderCode, phone, productId }).then(res => {
// if (res) {
// const obj = {
// brandName: productName,
// rechageNum: phone,
// denomination: discount,
// isGH: true
// }
// const temp = JSON.stringify(obj)
// wx.navigateTo({
// url: '/packageSaveMoney/pages/chargeWait/chargeWait?query=' + temp
// })
// }
// })
// },
// 2023-12版本 添加权益下单支付成功埋点
/**添加埋点开始 */
/**
* 商品-活动id,
* 物品类型item_type 1 商品 3活动,
* view 动作类型 3下单
* */
async addTrack(query) {
const {
id,
item_type,
view
} = query
const userInfo = wx.p.cache.userInfo.getUserInfo() || {},
{
openId
} = await USERAPI.getWXUserInfo()
const {
merchantId
} = wx.p.storage.get('merchant_info')
let data = {
open_id: openId || null,
item_type,
customer_phone: userInfo.phone || null,
action_type: view,
item_id: id,
business_type: 1,
add_way: 103,
merchant_id: merchantId,
customer_name: userInfo.nickName || null,
master_order_no: this.orderCode,
sub_order_no: this.orderCode,
order_time: new Date(this.orderTime).format('yyyy-MM-dd hh:mm:ss'),
order_total_price: this.order_total_price || 0,
pay_method: "微信支付",
pay_time: new Date(this.pay_time).format('yyyy-MM-dd hh:mm:ss') || '',
status: '已支付',
trade_pay_price: this.order_total_price || 0,
trade_name: this.trade_name || '',
trade_classification: this.trade_classification || '',
association_classify_first_name:this.trade_classification || ''
}
this.firstEnter = false
const jsonList = [JSON.stringify(data)]
const res = await wx.p.api.shopmallApi.trackHttp({
jsonList
})
},
})