CarQuotationPay.js
8.39 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
// packageEquity/pages/carQuotation/CarQuotationPay/CarQuotationPay.js
import { getOrderDetail, updateOrderStatus, getQuotationInfoById, createPayOrder } from '../../../api'
import { createQrcodeImage } from '~/api/api'
import qrcode from '~/utils/lib/wxqrcode'
// const imgUrl = {
// wechat: '/packageEquity/images/pay/wechat.png'
// }
// import { setWebSocket } from '~/store/index'
let time = null
const navStyle = 'background:transparent;box-shadow:none;'
Page({
/**
* 页面的初始数据
*/
data: {
navStyle,
payItems: [
{ id: 1, name: '微信支付', icon: 'wxPay' },
{ id: 3, name: 'POS机', icon: 'posPay' },
],
orderCode: '',
wxqrcode: '',
posqrcode: '',
orderDetail: {},
popPayShow: true,
payType: {
1: {
name: '微信支付',
imgUrl: '/packageEquity/images/wechat.png'
},
3: {
name: 'pos机支付',
imgUrl: '/packageEquity/images/posMachine.png'
}
},
selectPayType: 1
},
back() {
wx.$router.back()
},
async changePayType(e) {
console.log(e)
// pos支付
let { posqrcode } = this.data
console.log('pos支付')
let { value } = e.currentTarget.dataset
console.log(value)
// createQRCode(text) {
this.setData({
selectPayType: value
})
if (value == 3 && !posqrcode) {
let { orderCode } = this.data
let result = await createPayOrder({
orderCode,
payType: 3
})
console.log(result)
let { code, data, message } = result
if (code == 0) {
// console.log(text)
let size = 0
try {
const info = wx.getSystemInfoSync()
let scale = info.windowWidth / 750 //不同屏幕下QRcode的适配比例;设计稿是750宽
let width = 300 * scale
size = width
} catch (e) {
size = 150
}
let _img = qrcode.createQrCodeImg(data.outTradeNo, {
size: parseInt(size)
})
this.setData({
posqrcode: _img
})
}
}
},
// 生成小程序码
createWxQrcode() {
let _this = this
let oParams = {}
oParams.appId = 'wx06d1198e751435d1'
oParams.qrcodeType = 'QR_WXA_UNLIMIT'
oParams.path = 'packagesPayment/pages/payment/index'
oParams.scene = `orderCode=${_this.data.orderCode}&workWxSessionId=${wx.getStorageSync('dj_boutique_sessionId')}`
oParams.channelType = 1
// B端小程序调用接口生成领券码时,传参userId用uuid,类型由int变string
createQrcodeImage(oParams).then(res => {
console.log(res.data)
console.log(res.code)
_this.setData({
wxqrcode: res.data
})
// 轮询订单状态
})
this.getDetail()
},
createQRCode(text) {
console.log(text)
let size = 0
try {
const info = wx.getSystemInfoSync()
let scale = info.windowWidth / 750 //不同屏幕下QRcode的适配比例;设计稿是750宽
let width = 300 * scale
size = width
} catch (e) {
size = 150
}
let _img = qrcode.createQrCodeImg(text, {
size: parseInt(size)
})
this.setData({
qr: _img
})
},
// getOrderDetail() {
// // console.log(wx.$router, 'wx.$router')
// let _this = this
// let { orderCode } = this.data
// _this.getDetail(orderCode)
// },
getDetail() {
let { orderCode,orderDetail } = this.data
// console.log(orderCode)
let _this = this
getOrderDetail({
orderCode
})
.then(res => {
let { code, message, data } = res
// data.orderTime = wx.$util.tsFormatTime(data.orderTime, 'Y-M-D h:m:s')
data.orderTime = data.orderTime ? wx.$util.tsFormatTime(data.orderTime, 'Y年M月D日 h:m:s') : ''
// data.paySuccessDate = data.paySuccessDate ? wx.$util.tsFormatTime(data.paySuccessDate, 'Y-M-D h:m:s') : ''
let paySuccessDate = data?.paySuccessDate || new Date()
data.paySuccessDate = wx.$util.tsFormatTime(paySuccessDate, 'Y年M月D日 h:m:s')
if (code == 0) {
this.setData({
orderDetail: {
...orderDetail,
...data.customer,
...data
// ...data.payOrder
}
})
wx.$util.hideLoading()
// console.log(data.payOrder?.payStatus, 'payorder.paystatus')
let { payOrder, status } = data
if (payOrder?.payStatus == 2 || status == 4) {
wx.$util.showToast('支付成功')
if (time) clearInterval(time)
// 通知并跳转成功页面
_this.changeOrderStatus()
}
} else {
wx.showModal({
title: '温馨提示',
content: message,
showCancel: false,
confirmText: '刷新',
confirmColor: '#347BFF',
success(res) {
if (res.confirm) {
_this.getDetail(orderCode)
}
}
})
}
})
.finally(() => {
if (time) clearInterval(time)
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const url = `${currentPage.route}`
if ('packageEquity/pages/carQuotation/CarQuotationPay/CarQuotationPay' == url) {
time = setInterval(() => {
_this.getDetail(orderCode)
}, 5 * 1000)
}
})
},
changeOrderStatus() {
let { orderId, orderCode, orderDetail, id } = this.data
wx.$router.redirectTo('CarQuotationDetail', { orderId, orderCode, orderDetail, id })
// updateOrderStatus({ id, orderStatus: 3 })
// .then(result => {
// })
// .catch(err => {})
},
getQuotationInfoById() {
let { id } = this.data
getQuotationInfoById({ id }).then(res => {
let { code, data } = res
console.log(res)
let { orderId, payId, merchantAddress, merchantName4s, quotationGoodsInfoList } = data
// quotationGoodsInfoList
if (quotationGoodsInfoList&"ationGoodsInfoList.length) {
quotationGoodsInfoList.forEach(item=>{
if (item.position) {
const fieldMap = {
"4大件": "燃油车4大件服务",
"3电": "新能源3电服务",
"6大件": "新能源6大件服务",
// 在这里可以添加更多的替换规则
};
// 如果输入字段在字段映射中有匹配项,则进行替换,否则保持不变
fieldMap[item.position]&&( item.position = fieldMap[item.position])
}
if (item.quotationGoodsServiceItemsRelationDTOList&&item.quotationGoodsServiceItemsRelationDTOList.length) {
item.serviceItems = item.quotationGoodsServiceItemsRelationDTOList.reduce((prev,subItm,index)=>{
let unit = index == 0 ? '':'/'
prev += unit+subItm.serviceName
return prev
},'')
}
})
}
console.log(quotationGoodsInfoList,'quotationGoodsInfoList');
this.setData({
// || '230311133649896'
// orderCode: orderCode || '230310104652929',
orderCode: payId,
// orderCode: '230310104652929',
merchantAddress,
merchantName4s,
orderId,
['orderDetail.quotationGoodsInfoList']:quotationGoodsInfoList
// quotationGoodsInfoList
// id
})
this.createWxQrcode()
})
},
onRoute(options) {
// console.log(options,'options');
// console.log(options = 19)
let { data, id } = options
// id = 150
// orderCode: 230724111753590
this.setData({ id })
this.getQuotationInfoById()
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// setWebSocket()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {},
/**
* 生命周期函数--监听页面显示
*/
onShow() {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
// clearInterval(time)
// if (time) clearInterval(time)
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
if (time) clearInterval(time)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {},
onPageScroll({scrollTop}){
this.setData({
navStyle:scrollTop > 20 ? '' : navStyle
})
}
})