supplementaryOrderPay.js
6.73 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
// subvehicleConversion/pages/supplementaryOrderPay/supplementaryOrderPay.js
import { getOrderDetail, createPayOrder, updateOrderRemark } from '~/subvehicleConversion/api'
import { createQrcodeImage } from '~/api/api'
import qrcode from '~/utils/lib/wxqrcode'
import pageApi from '~/api/api'
const navStyle = 'background:transparent;box-shadow:none;'
let time = null
Page({
/**
* 页面的初始数据
*/
data: {
orderInfo: {},
wxqrcode: '',
posqrcode: '',
selectPayType: 1, // 支付方式(1:线上微信支付,2:线下收款,3:POS机收款, 4:支付宝支付)
payItems: [
{ id: 1, name: '微信支付', icon: 'wxPay' },
{ id: 3, name: 'POS机', icon: 'posPay' },
],
timer: null,
orderList: [
{
name: '客户姓名',
value: 'customerName'
},
{
name: '客户手机号',
value: 'customerPhone'
},
{
name: '商品名称',
value: 'goodsName'
},
{
name: '订金金额',
value: 'depositPrice',
handle: 'money'
},
{
name: '订金支付时间',
value: 'payDate'
},
{
name: '订单编号',
value: 'subOrderCode'
},
{
name: '备注',
value: 'remark',
handle: 'input'
}
],
showRemark: false,
textAreaValue: '', // 备注回显
navStyle
},
// 生成小程序码
createWxQrcode() {
let { wxqrcode } = this.data
if (wxqrcode) return
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 => {
_this.setData({
wxqrcode: res.data
})
})
},
async posPay(outTradeNo) {
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(outTradeNo, {
size: parseInt(size)
})
this.setData({
posqrcode: _img
})
},
// 添加备注
showMask() {
let { orderDetail } = this.data
this.setData({
showRemark: true,
textAreaValue: orderDetail?.remark || ''
})
},
remarkCancel() {
this.setData({
showRemark: false
})
},
// 备注确认
remarkConfirm(e) {
let remark = e.detail
let { orderCode } = this.data
if (remark) {
wx.showLoading()
updateOrderRemark({
orderCode: orderCode,
remark: remark
}).then(res => {
wx.hideLoading()
let { code } = res
if (code == 0) {
this.getDetail()
}
})
}
},
// getYqMerchantSettingDetail() {
// const userInfo = wx.$util.getUserInfo()
// pageApi.getYqStoreConfig({yqMerchantId: userInfo?.merchantId}).then(res => {
// console.log(res)
// })
// },
getDetail() {
let { orderCode, orderInfo } = this.data
let _this = this
getOrderDetail({
orderCode
})
.then(res => {
let { code, message, data } = res
if (code != 0) return
data.orderTime = data.orderTime ? wx.$util.tsFormatTime(data.orderTime, 'Y年M月D日 h:m:s') : ''
if (code == 0) {
let copyData = {
...data.customer,
...data,
...data.shopmallSubOrder.shopmallOrder,
...data.shopmallSubOrder,
...data.payOrder
}
let payDate = copyData?.payDate
copyData.payDate = payDate ? wx.$util.tsFormatTime(payDate, 'Y年M月D日 h:m:s') : ''
this.setData({
orderDetail: copyData,
orderInfo
})
wx.$util.hideLoading()
let { payOrder, status } = data
if (payOrder?.payStatus == 2 || status == 4) {
wx.$util.showToast('支付成功')
if (time) clearInterval(time)
// 通知并跳转成功页面
wx.$router.redirectTo('paySuccess', { orderCode })
}
} 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 ('subvehicleConversion/pages/supplementaryOrderPay/supplementaryOrderPay' == url) {
time = setInterval(() => {
_this.getDetail(orderCode)
}, 5 * 1000)
}
})
},
async handleTab(e) {
const { id: selectPayType } = e.target.dataset.item
let { orderCode } = this.data
this.setData({
selectPayType
})
if (selectPayType == 3) {
// pos机支付
let result = await createPayOrder({
orderCode,
payType: selectPayType
})
let { code, data } = result
if (code != 0) return
this.posPay(data.outTradeNo)
} else {
this.createWxQrcode()
}
},
back() {
wx.$router.back()
},
onRoute(options) {
let { orderCode } = options
this.setData({
orderCode
})
// 获取园区店支付配置
// this.getYqMerchantSettingDetail()
// 获取支付订单详情
this.getDetail()
// 获取微信付款二维码
this.createWxQrcode()
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {},
onPageScroll({scrollTop}){
this.setData({
navStyle:scrollTop > 20 ? '' : navStyle
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// const timer = setInterval(this.getQrCode, 3000)
// this.setData({
// timer
// })
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
const { timer } = this.data
clearInterval(timer)
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
if (time) clearInterval(time)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {}
})