pay.js
8.19 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
// packageStoreAssistant/packageActivity/pages/pay/pay.js
import ActivityApi from '~/api/activityApi/index'
import wxqrcode from '~/utils/lib/wxqrcode'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
import {
centsToyuan,
accAdd
} from '~/utils/format'
Page({
/**
* 页面的初始数据
*/
data: {
qrcode: '',
showStatus: false,
payStyle: 1,
payItems: [{
id: 1,
name: '微信支付',
icon: 'pay-wechat'
},
{
id: 3,
name: 'POS机',
icon: 'pay-pos'
}
],
timer: null,
orderList: [{
name: '客户姓名',
value: 'customerNickName',
}, {
name: '活动名称',
value: 'activityName',
}, {
name: '商品名称',
value: 'goodsName',
isMark: true
}, {
name: '定金金额',
value: 'activityPrice'
}, {
name: '定金支付时间',
value: 'time',
}, {
name: '订单编号',
value: 'subOrderCode',
}],
orderDetail: {
goodsName: ''
}
},
/**
* 生命周期函数--监听页面加载
*/
// onLoad(options) {
// console.log(options)
// const [price, decimal] = centsToyuan(88.8,2)
// .toString()
// .split(".");
// console.log(centsToyuan(88.8))
// },
onRoute(options) {
//supplementOrderFlag =1 补录订单 需要付全款
const {
subOrderCode,
id,
goodsId,
goodsName,
finalPaymentAmount,
activityName,
time,
customerNickName,
supplementOrderFlag
} = options
const [price, decimal] = finalPaymentAmount
.toString()
.split(".");
const {
orderDetail
} = this.data
this.setData({
supplementOrderFlag,
goodsId,
price,
decimal,
orderDetail: {
...orderDetail,
...{
goodsName,
activityName,
time,
finalPaymentAmount,
customerNickName,
subOrderCode
}
},
})
console.log(this.data.orderDetail)
this.subOrderCode = subOrderCode
this.actId = id
this.selectSamePriceGoods()
},
/*获取商品*/
async selectSamePriceGoods() {
const selectSamePriceGoodsAll = await ActivityApi.selectSamePriceGoods({
actId: this.actId
})
const {
goodsId,
supplementOrderFlag,
orderDetail
} = this.data;
const activityInfo = selectSamePriceGoodsAll.find(item => item.goodsId == goodsId)
const activityPrice = activityInfo.activityPrice
const selectSamePriceGoods = supplementOrderFlag == 1?selectSamePriceGoodsAll:selectSamePriceGoodsAll.filter(i=>i.activityPrice == activityPrice)
const selectValue = selectSamePriceGoods.findIndex(item => item.goodsId == goodsId)
this.setData({
selectValue,
goodsList: selectSamePriceGoods,
orderDetail: {
...orderDetail,
...{
activityPrice:centsToyuan(activityPrice)
}
},
})
this.createPayOrder()
},
/*获取订单编号*/
createPayOrder() {
this.clearInter()
const {
payStyle,
goodsId
} = this.data
const {
accountName
} = wx.$storage.get('userInfo')
ActivityApi.createPayOrder({
updatedBy: accountName,
subOrderCode: this.subOrderCode,
shopmallGoodsId: goodsId,
orderPaySource: 1,
selectPayType: payStyle
}).then(res => {
console.log(res)
const {
orderCode
} = res.goodsOrder
const outTradeNo = res?.payOrder?.outTradeNo
this.setData({
orderCode,
outTradeNo
})
if(payStyle == 1) {
this.getQrCode()
}
if(payStyle == 3) {
this.posPay()
}
})
},
/*获取订单支付状态*/
async getOrderStatus() {
const orderStatus = await ActivityApi.orderDetail({
orderCode: this.subOrderCode
})
if (orderStatus.payOrder?.payStatus == 2) {
wx.redirectTo({
url: `/packageStoreAssistant/packageActivity/pages/success/success?id=${this.actId}&subOrderCode=${this.subOrderCode}`
})
}
},
showPopup() {
this.setData({
showStatus: true
})
},
/*选择后的商品*/
setGoods(val) {
const {
goodsId,
goodsName,
activityPrice,
crowdFundingPrice
} = val.detail
const {
orderDetail,
supplementOrderFlag
} = this.data
const wkPrice = supplementOrderFlag == 1? crowdFundingPrice : accAdd(crowdFundingPrice, -activityPrice)
const [price, decimal] = centsToyuan(wkPrice)
.toString()
.split(".");
this.setData({
goodsId,
price,
decimal,
orderDetail: {
...orderDetail,
...{
goodsName,
activityPrice: centsToyuan(activityPrice)
}
},
})
this.createPayOrder()
},
async handleTab(e) {
this.clearInter()
const {
id
} = e.target.dataset.item
this.setData({
payStyle: id
})
// if(id == 3) {
// const result = await ActivityApi.createPayOrderPOS({ orderCode:this.subOrderCode,payType: id})
// let { code, data } = result
// if (code != 0) return
// this.posPay(data.outTradeNo)
// }else {
// this.createPayOrder()
// }
this.createPayOrder()
},
/** pso生成二维码*/
async posPay() {
// console.log(text)
let size = 0
try {
const info = getSystemInfoSync()
let scale = info.windowWidth / 750 //不同屏幕下QRcode的适配比例;设计稿是750宽
let width = 300 * scale
size = width
} catch (e) {
size = 150
}
const {outTradeNo} = this.data
let qrcode = wxqrcode.createQrCodeImg(outTradeNo, {
size: parseInt(size)
})
this.setData({
qrcode
})
this.timer = setInterval(this.getOrderStatus, 4e3)
},
/** 微信生成二维码*/
async getQrCode() {
const {
orderCode
} = this.data;
const sessionId = 123;
const params = {
appId: 'wx06d1198e751435d1',
qrcodeType: 'QR_WXA_UNLIMIT',
path: 'packagesPayment/pages/payment/index',
scene: `orderCode=${orderCode}&workWxSessionId=${sessionId}`,
channelType: 1
}
const qrcode = await ActivityApi.createWeappQrcode(params)
this.setData({
qrcode
})
this.timer = setInterval(this.getOrderStatus, 4e3)
},
/** 清除定时器*/
clearInter() {
clearInterval(this.timer)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
this.clearInter()
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
this.clearInter()
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})