confirmOrder.js
16.9 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
import api from '../../api.js'
import order_mixins from '../order_mixins.js'
import { setWebSocket, getPositionList } from '~/store/index'
import { normalizeMarketingFlagOnItem } from '~/utils/marketingFlag'
import {
formatOrderGoodsUnitPrice,
formatOrderMoney,
resolveOrderPackageFinalPrice,
sumOrderMoney
} from '../../services/orderPricePresentation.helpers.js'
import {
buildBoutiqueCustomerDailyDisplay,
resolveBoutiqueDetailCustomerPhone
} from '../createOrder/services/customerDailyFields.helpers.js'
import {
LOW_PRICE_ORDER_EDIT_MESSAGE,
isLowPriceOrder
} from '~/utils/workOrderLowPrice.helpers.js'
const IMG_URL =
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
let time = null
let app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
...order_mixins.data,
orderInfo: {},
showTips: true,
artificerSelectObj: {},
successDate: '',
showDateSelect: false,
isErrorOrder: false,
customerTagLabels: []
},
getSelectDate(e) {
this.setData({
successDate: e.detail,
showDateSelect: false
})
},
toshowDateModal() {
this.setData({
showDateSelect: true
})
},
closeTips() {
this.setData({
showTips: false
})
},
setCopyData(e) {
// console.log(e)
let { content } = e.currentTarget.dataset
wx.$util.setCopyData(`${content}`)
},
// 修改订单时间
rangeSelect(e) {
let { date } = e.detail
let { orderInfo } = this.data
let params = {
orderCode: orderInfo.orderCode,
orderTime: date + ' 00:00:00'
}
api
.updateOrderTime(params)
.then(result => {
// console.log(result)
let { code } = result
if (code == '0') {
this.showToast('修改日期成功')
orderInfo.time = params.orderTime
this.setData({
orderInfo
})
} else {
this.showToast('修改日期失败')
}
})
.catch(err => {
console.log(err)
})
},
next() {
let _this = this
_this.checkPayType()
},
checkPayType() {
let {
orderInfo: { selectPayType, status, orderCode },
successDate,
isErrorOrder
} = this.data
let _this = this
// 微信支付
if (selectPayType == 1) {
_this.setData({
showPopup: true
})
_this.getDetail(orderCode)
if (!time) {
time = setInterval(() => {
_this.getDetail(orderCode)
}, 5 * 1000)
}
return false
}
// pos机支付
if (selectPayType == 3) {
if (status == 1) {
wx.showModal({
title: '重要提示',
content:
'请检查店内是否配备POS机,确认信息该工单将无法撤销或修改!\n若4S店已向车主收款,请返回修改支付方式为“门店收款”。',
confirmText: '确认信息',
confirmColor: '#ff0000',
cancelText: '返回',
success(res) {
if (res.confirm) {
_this.createPayOrder()
}
}
})
} else {
_this.createPayOrder()
}
} else {
if (!successDate && !isErrorOrder && selectPayType != 0)
return wx.$util.showToast(
selectPayType == 2 ? '请选择4S店收款时间' : '请选择嘀加收款时间'
)
this.setData({
showPopup: true
})
}
},
createPayOrder() {
let {
orderInfo: { selectPayType, orderCode, payeeType },
outTradeNo,
payVoucherList,
successDate,
isErrorOrder
} = this.data
let obj = {
orderCode,
payType: selectPayType,
payeeType: payeeType
}
// 支付方式 2:门店收款 5:嘀加收款 6:对公转账 7:其它收款
if ([2, 5, 6, 7].includes(Number(selectPayType)) && !isErrorOrder) {
obj.successDate = new Date(successDate).format('yyyy-MM-dd hh:mm:ss')
}
if (payVoucherList?.length && outTradeNo) {
obj.payVoucherList = payVoucherList.map(v => {
return v?.url
})
obj.outTradeNo = outTradeNo
}
console.log(obj)
wx.$util.showLoading()
// 状态更新 需刷新工单列表和预约管理列表
wx.$util.refreshPageData()
api.createPayOrder(obj).then(res => {
console.log(res)
let { code, data, message } = res
if (code == 0) {
wx.hideLoading()
console.log(`类型为:${selectPayType}`)
if (selectPayType == 3 || selectPayType == 1) {
this.setData({
['orderInfo.payOrder.outTradeNo']: data.outTradeNo,
showPopup: true
})
this.getDetail(orderCode)
if (!time) {
time = setInterval(() => {
// console.log('6666666666')
this.getDetail(orderCode)
}, 5 * 1000)
}
} else {
wx.$router.redirectTo('orderDetail', data)
}
} else {
wx.$util.showToast(message)
}
})
},
installOnly(refusalReason) {
let {
orderInfo: { orderCode }
} = this.data
api
.installOnly({
orderCode,
refusalReason
})
.then(res => {
console.log(res)
// 状态更新 需刷新工单列表和预约管理列表
wx.$util.refreshPageData()
let { code, message } = res
if (code == 0) {
wx.$router.redirectTo('orderDetail', {
orderCode
})
} else {
this.showToast(message)
}
})
},
makePhoneCall(e) {
console.log(e)
let { data } = e.currentTarget.dataset
wx.makePhoneCall({
phoneNumber: data
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
maxDate: new Date().format('yyyy-MM-dd')
// startDate,
// endDate
})
// if (options.orderCode) {
// wx.$util.showLoading('加载中...')
// this.getDetail(options.orderCode)
// }
if (time) clearInterval(time)
this.checkPhoneShow(app.globalData.YQorderSetting?.yqPhoneConfig)
// wx.$util.setWebSocket()
setWebSocket()
if (options.orderCode) {
wx.$util.showLoading('加载中...')
this.getDetail(options.orderCode)
}
},
onRoute(options) {
if (options.orderCode) {
wx.$util.showLoading('加载中...')
if (options.isErrorOrder) {
this.setData({
isErrorOrder: true
})
}
// options.orderCode = '250908213534979'
this.getDetail(options.orderCode)
}
},
async getDetail(orderCode) {
// console.log(orderCode)
let _this = this
let { isErrorOrder } = this.data
const positionTypeList = (await getPositionList()) || []
api
.getPackageGoodsDetail({
orderCode
})
.then(res => {
let { code, message, data } = res
if (code == 0) {
wx.$util.hideLoading()
if (data.payOrder && data.payOrder.payStatus == 2) {
if (time) clearInterval(time)
wx.$router.redirectTo('orderDetail', {
orderCode
})
return
}
let couponName = data.customerCoupon
? data.customerCoupon.couponName
: ''
let total_price = 0
let warrantyCardList = []
for (var i = 0; i < data?.subOrderList?.length; i++) {
let e = data?.subOrderList[i]
normalizeMarketingFlagOnItem(e)
total_price = sumOrderMoney([total_price, e.finalPrice])
e.displayPrice = formatOrderGoodsUnitPrice(e)
e.positionStr =
positionTypeList.filter(
v => v.positionValue == e.upgradeGoodsPosition
)[0]?.positionName || ''
if (e.upgradeWarrantyPeriod || e.upgradeWarrantyPeriod > 0) {
warrantyCardList.push({
warrantyPeriod: e.upgradeWarrantyPeriod,
goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName
})
}
}
data.packageGoodsList?.forEach(item => {
item.packageGoodsOrderList.forEach(g => {
g.displayPrice = formatOrderGoodsUnitPrice(g)
})
item.goodsList = item.packageGoodsOrderList
item.count = item.goodsList.length ? item.goodsList[0].number : 1
// 套餐总价直接累加所有商品的总价
item.finalPrice = resolveOrderPackageFinalPrice(item.goodsList)
item.packageGoodsOrderList.forEach(g => {
g.positionStr =
positionTypeList.filter(
v => v.positionValue == g.upgradeGoodsPosition
)[0]?.positionName || ''
})
total_price = sumOrderMoney([total_price, item.finalPrice])
normalizeMarketingFlagOnItem(item)
})
data = {
...data.customer,
...data.payOrder,
...data,
packageGoodsList: data.packageGoodsList,
couponName,
total_price: formatOrderMoney(total_price, '0.00')
}
data.customerPhone = resolveBoutiqueDetailCustomerPhone(data)
if (data.orderTime)
data.time = new Date(data.orderTime).format('yyyy-MM-dd hh:mm:ss')
if (data.customerCoupon) {
data.customerCoupon.customerCouponCode =
data.customerCoupon.customerCouponCode.split('-')[0]
}
if (data.customer.carSeriesName) {
data.carType = `${data.customer.carBrand || ''}-${
data.customer.carChildsBrandName || ''
}-${data.customer.carSeriesName || ''}`
}
const customerDailyDisplay = buildBoutiqueCustomerDailyDisplay(
data.customer
)
data.customerTagLabels = customerDailyDisplay.customerTagLabels
data.actualDeliveryDateDisplay = customerDailyDisplay.actualDeliveryDate
data.showCustomerTags = customerDailyDisplay.showCustomerTags
data.showActualDeliveryDate = customerDailyDisplay.showActualDeliveryDate
this.setData({
orderInfo: data,
customerTagLabels: data.customerTagLabels,
flag: true,
warrantyCardList
})
// 校验是否显示二级流量方
if (data.subShopMerchantName) {
let { customerObj } = this.data
if (
customerObj.findIndex(
val => val?.key && val.key == 'subShopMerchantName'
) < 0
) {
customerObj[customerObj.length - 2] = {
label: '二级流量方',
key: 'subShopMerchantName'
}
}
this.setData({
customerObj
})
}
// 是2:门店收款 5:嘀加收款 6:对公转账 7:其它收款并且不是错误订单 自动打开门店收款弹窗
if (
!isErrorOrder &&
[2, 5, 6, 7].includes(Number(data.selectPayType))
) {
this.toshowDateModal()
}
// 获取园区店技师配置信息
api
.getQYTechnicianList({
yqMerchantId: wx.$util.getStorageSync('dj_boutique_user_info')
?.merchantId
})
.then(respone => {
if (respone?.code == 0) {
if (respone?.data.length > 0) this.isArtificer(respone.data)
}
})
} else {
wx.showModal({
title: '温馨提示',
content: message,
showCancel: false,
confirmText: '刷新',
confirmColor: '#347BFF',
success(res) {
if (res.confirm) {
_this.getDetail(orderCode)
}
}
})
}
})
},
async getPackageGoodsDetail(orderCode) {
try {
let params = {
orderCode
}
const positionTypeList = (await getPositionList()) || []
api.getPackageGoodsDetail(params).then(res => {
res.data?.packageGoodsList.forEach(item => {
item.packageGoodsOrderList.forEach(g => {
g.displayPrice = formatOrderGoodsUnitPrice(g)
})
item.goodsList = item.packageGoodsOrderList
item.count = item.goodsList.length ? item.goodsList[0].number : 1
// 套餐总价直接累加所有商品的总价
item.finalPrice = resolveOrderPackageFinalPrice(item.goodsList)
item.packageGoodsOrderList.forEach(g => {
g.positionStr =
positionTypeList.filter(
v => v.positionValue == g.upgradeGoodsPosition
)[0]?.positionName || ''
})
normalizeMarketingFlagOnItem(item)
})
if (res.code == 0) {
const ordinaryTotal = sumOrderMoney(
(res.data?.subOrderList || this.data.orderInfo.subOrderList || []).map(
item => item.finalPrice
)
)
const packageTotal = sumOrderMoney(
(res.data?.packageGoodsList || []).map(item => item.finalPrice)
)
this.setData({
packageGoodsList: res.data.packageGoodsList,
'orderInfo.total_price': formatOrderMoney(
sumOrderMoney([ordinaryTotal, packageTotal]),
'0.00'
)
})
}
})
} catch (err) {}
},
isArtificer(data) {
let { customerObj, orderInfo } = this.data
orderInfo.isOpenArtificer = true
// if(customerObj.findIndex(val =>val?.key && val.key == 'technicianName') < 0) {
// customerObj[customerObj.length] = {
// label: '选择技师:',
// key: 'technicianName',
// type: 'select',
// callBack: 'selectArtificer'
// }
// }
this.setData({
// customerObj,
artificerList: data, // 园区店配置的技师数据
// artificerList: orderInfo?.technicianConfigDTOList,
orderInfo
})
},
// 选择技师确认
changeArtificer(e) {
console.log(e)
let value = e?.detail || {}
let { orderInfo } = this.data
orderInfo?.subOrderList?.forEach(val => {
if (val.subOrderCode == value?.subOrderCode) {
val.technicianName = value.technicianName
val.technicianUuid = value.technicianUuid
val.technicianId = value.technicianId
}
})
orderInfo?.packageGoodsList?.forEach(child => {
console.log(child, 'child')
child?.goodsList.forEach(val => {
if (val.subOrderCode == value?.subOrderCode) {
val.technicianName = value.technicianName
val.technicianUuid = value.technicianUuid
val.technicianId = value.technicianId
}
})
})
let params = {
orderCode: orderInfo?.orderCode,
subOrderCode: value?.subOrderCode,
technicianName: value?.technicianName,
technicianUuid: value?.technicianUuid,
technicianId: value?.technicianId
}
api.updateTechnicianInfo(params).then(res => {
let { code, message } = res
if (code == 0) {
this.setData({
artificerSelectPopup: false,
artificerSelectObj: value,
orderInfo
})
} else {
wx.$util.showToast(message)
}
})
},
// 选择技师
selectArtificer(e) {
let { item } = e.currentTarget.dataset
console.log(item)
this.setData({
artificerSelectPopup: true,
artificerSelectObj: item
})
},
checkPhoneShow(config) {
// 有就屏蔽手机号的显示
if (config) {
let { customerObj } = this.data
delete customerObj[2]
this.setData({
customerObj
})
}
},
/**
* 从工单确认详情进入编辑;低价单只允许查看和确认,不允许回到创建页修改。
*
* @returns {void|false} 低价单拦截时返回 false
*/
edit() {
let { orderInfo } = this.data
if (isLowPriceOrder(orderInfo)) {
wx.$util.showToast(LOW_PRICE_ORDER_EDIT_MESSAGE)
return false
}
// filmOrder 0车膜升级 1精品升级
// let routeName = orderInfo?.filmOrder ? 'premiumUpgrade' : 'createOrder'
let routeName = 'createOrder'
wx.$router.redirectTo(routeName, orderInfo)
// wx.$router.redirectTo('createOrder', orderInfo)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
if (time) clearInterval(time)
time = null
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {},
// 返回
goBack: function () {
this.edit()
// wx.$router.back()
}
})