confirmWorkOrder.js
18.7 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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
// tabRepairOrder/pages/confirmWorkOrder/index.js
const IMG_URL =
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import api from '../../api'
import commonApi from '~/api/api'
import { getPositionList, setConfigInfo } from '~/store/index'
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
showInventory:false,
inventoryData: {
upgradeGoodsCommodityCode: '',
upgradeGoodsCustomCode: '',
specification: '',
stock: ''
},
IMG_URL,
confirmInfo: {
customer: {},
subOrderList: [],
serviceItemsList: []
},
currentTab: 'goods',
serviceCount: 0,
canEditTechnician: false,
baseInfoObj: [
{
label: '施工单号',
key: 'constructionCode',
copy: true
},
{
label: '关联主订单',
key: 'orderCode',
copy: true
},
{
label: '客户姓名',
key: 'customerName',
subObj: 'customer',
copy: true
},
{
label: '客户车型',
key: 'customerCarName',
subObj: 'customer'
},
{
label: '车架号',
key: 'standNo',
copy: true
},
{
label: '驻店',
key: 'sellerName'
},
{
label: '派单时间',
key: 'createdDate'
}
],
positionTypeList: [],
goodsList: [], // 所有可关联商品 包含当前施工单商品
mainSelected: [], // 主技师已选
deputySelected: [], // 副手技师已选
servicesList: [], // 所有服务项目列表
editServicesList: [], // 编辑时显示的服务项目数据
userPermissions: [] // 权限数组
},
onRoute(options) {
let userInfo = wx.$util.getUserInfo()
this.setData(
{
userInfo
},
async () => {
// 获取配置服务数据
let baseConfigData = await setConfigInfo(app.globalData)
this.getDetail(options)
this.getTechnicianList()
this.getGoodsList(options)
this.setData({
baseConfigData
})
this.getStaffPermissions()
}
)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {},
/**
* 生命周期函数--监听页面显示
*/
onShow() {},
// 打开弹窗
openInventoryPopup(e) {
console.log(e.target.dataset)
let {inventory:{
upgradeGoodsCommodityCode,
upgradeGoodsCustomCode,
specification,
stock
}} = e.target.dataset
const inventoryData ={
upgradeGoodsCommodityCode,
upgradeGoodsCustomCode,
specification,
stock
}
this.setData({
showInventory: true,
inventoryData
});
},
// 打开物料弹窗
openInventory(e){
const inventoryData=e.detail
this.setData({
showInventory: true,
inventoryData
});
},
// 关闭弹窗
closeInventoryPopup() {
this.setData({
showInventory: false
});
},
// 监听弹窗关闭事件
onInventoryClose() {
this.setData({
showInventory: false
});
},
// 获取人员权限
getStaffPermissions() {
let { userInfo } = this.data
commonApi.staffPermissions({ phone: userInfo?.phone }).then(res => {
console.log(res)
let { code, data, message } = res
if (code == 0) {
this.setData({ userPermissions: data || [] }, () => {
this.updateTechnicianEditable()
})
} else {
wx.$util.showToast(message)
}
})
},
// 获取详情数据
getDetail(data) {
wx.showLoading({
title: '加载中'
})
api
.getConstructionDetail({
id: data?.id,
constructionCode: data?.constructionCode
})
.then(res => {
wx.hideLoading()
let { code, data, message } = res
data = data || {}
data.customer = data.customer || {}
data.subOrderList = Array.isArray(data.subOrderList) ? data.subOrderList : []
data.serviceItemsList = Array.isArray(data.serviceItemsList) ? data.serviceItemsList : []
const mainSelected = data?.mainTechnicianList
?.filter(val => val.technicianType == 0)
?.map(it => {
return {
staffName: it.technicianName,
id: it.id,
uuid: it.technicianUuid,
staffPhone: it.staffPhone,
shareRatio:
it.shareRatio === null ||
it.shareRatio === undefined ||
isNaN(Number(it.shareRatio))
? ''
: Math.round(Number(it.shareRatio) * 100)
}
})
const deputySelected = data?.mainTechnicianList
?.filter(val => val.technicianType == 1)
?.map(it => {
return {
staffName: it.technicianName,
id: it.id,
uuid: it.technicianUuid,
staffPhone: it.staffPhone,
shareRatio:
it.shareRatio === null ||
it.shareRatio === undefined ||
isNaN(Number(it.shareRatio))
? ''
: Math.round(Number(it.shareRatio) * 100)
}
})
data.customer.customerCarName = data.customer.carSeriesName
? `${data.customer.carBrand}-${data.customer.carChildsBrandName}-${data.customer.carSeriesName}`
: ''
data.customer.vinStr =
data.customer.vin ||
data.customer.frameNo ||
data.customer.carVin ||
data.customer.vinCode ||
''
data.storeName =
data.merchantName ||
data.shopMerchantName ||
data.customer.merchantName ||
data.customer.shopMerchantName ||
''
const serviceCount = this._calcServiceCount(data.serviceItemsList || [])
if (data.createdDate) {
data.createdDate = new Date(data.createdDate).format('yyyy-MM-dd hh:mm:ss')
}
data?.subOrderList?.forEach(val => {
})
if (code == 0) {
this.setData({
mainSelected,
deputySelected,
confirmInfo: data || {},
serviceCount
}, () => {
this.updateTechnicianEditable()
})
} else {
wx.$util.showToast(message)
}
})
},
hasPermission(key) {
const list = this.data.userPermissions || []
return Array.isArray(list) && list.some(v => v && v.code == key)
},
updateTechnicianEditable() {
const status = this.data.confirmInfo?.constructionStatus
const statusOk = status === 0 || status === '0' || status === null || status === undefined
const can = statusOk && this.hasPermission('SHIGONGQUEREN')
if (can === this.data.canEditTechnician) return
this.setData({ canEditTechnician: can })
},
_calcServiceCount(serviceItemsList) {
return (serviceItemsList || []).reduce((acc, group) => {
const count = Array.isArray(group?.detailList) ? group.detailList.length : 0
return acc + count
}, 0)
},
switchTab(e) {
const { tab } = e.currentTarget.dataset
if (!tab) return
this.setData({
currentTab: tab
})
},
setCopyData(e) {
const { content } = e.currentTarget.dataset
if (!content) return
wx.setClipboardData({
data: String(content),
success: () => {
wx.$util.showToast('已复制')
}
})
},
handleCancel() {
wx.switchTab({
url: '/pages/tabRepairOrder/pages/index/index'
})
},
// 获取技师数据
getTechnicianList() {
let { userInfo } = this.data
// 获取技师数据
api
.getTechnicianList({
yqMerchantId: !wx.$hasPermission?.isSuper?.(userInfo)
? wx.$util.getStorageSync('dj_boutique_user_info')?.merchantId
: ''
})
.then(respone => {
wx.hideLoading()
if (respone?.code == 0) {
this.setData({
artificerList: respone.data || []
})
}
})
},
// 获取可关联的商品数据
getGoodsList(data) {
api
.getCanRelateGoodsList({
orderCode: data?.orderCode,
constructionCode: data?.constructionCode
})
.then(async res => {
let { code, data, message } = res
if (code == 0) {
const positionTypeList = (await getPositionList()) || []
if (positionTypeList) {
data?.forEach(val => {
val.positionStr = positionTypeList.filter(
v => v.positionValue == val.position
)[0]?.positionName
})
}
this.setData({
goodsList: data || []
})
} else {
wx.$util.showToast(message)
}
})
},
// 关联商品
handleEditGoods() {
let { confirmInfo } = this.data
// 编辑时的商品数据
const editGoodsList = wx.$util.deepClone(confirmInfo.subOrderList)
this.setData({ editGoodsFlag: true, editGoodsList })
},
// 删除商品
handleDelgoods(e) {
let { editGoodsList } = this.data
let { index } = e.currentTarget.dataset
editGoodsList?.splice(index, 1)
this.setData({ editGoodsList })
},
// 关联商品取消
handelGoodsCancel() {
this.setData({
editGoodsFlag: false
})
},
// 关联商品完成
handelGoodsConfirm() {
let { editGoodsList } = this.data
// 将修改后的商品数据赋值给confirmInfo
this.setData({
['confirmInfo.subOrderList']: editGoodsList,
editGoodsFlag: false
})
},
relateGoods() {
this.setData({ relateGoodsVisable: true })
},
// 关联商品弹窗取消
handelRelateGoodsCancel() {
this.setData({ relateGoodsVisable: false })
},
// 关联商品弹窗确认
handelRelateGoodsConfirm(e) {
this.setData({
editGoodsList: e.detail
})
this.handelRelateGoodsCancel()
},
showPopup(e) {
if (!this.data.canEditTechnician) return
let { type } = e.currentTarget.dataset
this.setData({
technicianMultiple: type == 'deputy',
artificerSelectPopup: true
})
},
// 技师选择确认
// changeArtificer(e) {
// let { technicianMultiple } = this.data
// if (technicianMultiple) {
// if (e.detail?.selectedTechnicians?.length > 2) {
// return wx.$util.showToast('副手技师最多选择两个')
// }
// this.setData({
// deputySelected: e.detail?.selectedTechnicians
// })
// } else {
// this.setData({
// mainSelected: e.detail?.selectedTechnicians
// })
// }
// this.setData({
// artificerSelectPopup: false
// })
// },
// 技师选择确认
changeArtificer(e) {
console.log(e, 'changeArtificer')
let { technicianMultiple, mainSelected, deputySelected } = this.data
if (technicianMultiple) {
if (e.detail?.selectedTechnicians?.length > 2) {
return wx.$util.showToast('副手技师最多选择两个')
}
const deputySelected = e.detail?.selectedTechnicians || []
const sumDeputy = deputySelected
.map(i => parseInt(i.shareRatio || 0))
.reduce((a, b) => a + (isNaN(b) ? 0 : b), 0)
let residual = 100 - sumDeputy
if (residual < 0) residual = 0
if (residual > 100) residual = 100
const newMainSelected = Array.isArray(mainSelected)
? wx.$util.deepClone(mainSelected)
: []
if (newMainSelected.length) newMainSelected[0].shareRatio = residual
this.setData({
deputySelected,
mainSelected: newMainSelected
})
} else {
const newMainSelected = e.detail?.selectedTechnicians || []
const hasDeputy = (deputySelected || []).length > 0
if (newMainSelected.length) {
if (hasDeputy) {
const sumDeputy = (deputySelected || [])
.map(i => parseInt(i.shareRatio || 0))
.reduce((a, b) => a + (isNaN(b) ? 0 : b), 0)
let residual = 100 - sumDeputy
if (residual < 0) residual = 0
if (residual > 100) residual = 100
newMainSelected[0].shareRatio = residual
} else {
newMainSelected[0].shareRatio = ''
}
}
this.setData({
mainSelected: newMainSelected
})
}
this.setData({
artificerSelectPopup: false
})
},
// 编辑服务项目
handleEditService() {
let { confirmInfo } = this.data
const editServicesList = wx.$util.deepClone(confirmInfo.serviceItemsList)
this.setData({
editServiceFlag: true,
editServicesList
})
},
// 删除服务项目
handleDelServices(e) {
let { index, sindex } = e.currentTarget.dataset
let { editServicesList } = this.data
editServicesList[index]?.detailList?.splice(sindex, 1)
if (!editServicesList[index]?.detailList?.length) {
editServicesList?.splice(index, 1)
}
this.setData({
editServicesList
})
},
// 编辑服务项目取消
handelServicesCancel() {
this.setData({
editServiceFlag: false
})
},
// 编辑服务项目完成
handelServicesConfirm() {
let { editServicesList } = this.data
// 将修改后的商品数据赋值给confirmInfo
this.setData({
['confirmInfo.serviceItemsList']: editServicesList,
editServiceFlag: false,
serviceCount: this._calcServiceCount(editServicesList)
})
},
// 选择服务项目弹窗
selectServices() {
this.setData({ selectServiceVisable: true })
},
// 选择服务项目弹窗确定
handleSelectServiceConfirm(e) {
this.setData({
editServicesList: e.detail,
})
this.handleSelectServiceCancel()
},
// 选择服务项目弹窗取消
handleSelectServiceCancel() {
this.setData({ selectServiceVisable: false })
},
// 提交电子施工单
submit() {
const {
editGoodsFlag,
editServiceFlag,
confirmInfo,
mainSelected,
goodsList,
deputySelected,
requesting
} = this.data
const validateWithImmediateFeedback = (condition, message) => {
if (condition) {
wx.$util.showToast(message)
return true
}
return false
}
if (validateWithImmediateFeedback(editGoodsFlag, '请确认完成商品关联'))
return
if (
validateWithImmediateFeedback(editServiceFlag, '请确认完成服务项目修改')
)
return
if (
validateWithImmediateFeedback(
!confirmInfo?.subOrderList?.length,
'请关联商品'
)
)
return
if (validateWithImmediateFeedback(!mainSelected?.length, '请选择主技师'))
return
if (
validateWithImmediateFeedback(
(deputySelected?.length || 0) > 0 &&
deputySelected.some(
it => it.shareRatio === '' || it.shareRatio == null
),
'副手技师分成比例不能为空'
)
) {
return
}
// return
if (
validateWithImmediateFeedback(
!confirmInfo?.serviceItemsList?.length,
'请选择服务项目'
)
)
return
// return
// wx.showModal({
// title: '是否确认生成电子施工单',
// content:
// '请确认客户商品有无增减,服务项目是否完整。提交后不可修改客户商品、技师、服务项目',
// confirmText: '确认提交',
// confirmColor: '#347BFF',
// cancelText: '返回',
// complete: res => {
// if (res.confirm) {
const subOrderList = confirmInfo?.subOrderList?.map(val => {
return {
subOrderCode: val.subOrderCode
}
})
const allRelationList = goodsList?.map(val => {
val.constructionFlag = 2
confirmInfo?.subOrderList?.map(item => {
if (val.subOrderCode == item.subOrderCode)
val.constructionFlag = 1
})
return {
subOrderCode: val.subOrderCode,
constructionFlag: val.constructionFlag
}
})
const mainTechnicianList = [
...(mainSelected?.map(val => ({
id: val.id,
technicianName: val.staffName,
technicianUuid: val.uuid,
technicianType: 0,
staffPhone: val.staffPhone,
shareRatio:
val.shareRatio === '' ||
val.shareRatio === undefined ||
val.shareRatio === null ||
isNaN(Number(val.shareRatio))
? 1
: Number(val.shareRatio) / 100
})) || []),
...(deputySelected?.map(val => ({
id: val.id,
technicianName: val.staffName,
technicianUuid: val.uuid,
technicianType: 1,
staffPhone: val.staffPhone,
shareRatio:
val.shareRatio === '' ||
val.shareRatio === undefined ||
val.shareRatio === null ||
isNaN(Number(val.shareRatio))
? 0
: Number(val.shareRatio) / 100
})) || [])
]
const serviceItemsList = (confirmInfo?.serviceItemsList || []).reduce(
(acc, val) => {
const details = (val?.detailList || []).map(it => ({
serviceItemsId: it.serviceItemsId,
serviceItemsName: it.serviceItemsName,
categoryId: it.categoryId,
itemsConfigName: it.itemsConfigName,
materialStandard: it.materialStandard,
timeStandard: it.timeStandard,
serviceCost: it.serviceCost,
useNum: it.useNum
}))
return acc.concat(details)
},
[]
)
let params = {
id: confirmInfo.id,
constructionCode: confirmInfo.constructionCode,
orderCode: confirmInfo.orderCode,
reworkFlag: confirmInfo?.reworkFlag, // 是否返工
subOrderList,
mainTechnicianList,
serviceItemsList,
allRelationList // 传全部可选商品,区分是否需要施工
}
if (requesting) return false
this.setData({
requesting: true
})
wx.$util.showLoading()
api.confirmConstruction(params).then(res => {
wx.$util.hideLoading()
let { code, message } = res
if (code == 0) {
wx.$router.redirectTo('repairOrderDetail', {
id: confirmInfo.id,
constructionCode: confirmInfo.constructionCode,
orderCode: confirmInfo.orderCode
})
} else {
wx.$util.showToast(message)
}
setTimeout(() => {
this.setData({
requesting: false
})
}, 1000)
})
// }
// }
// })
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {}
})