defeatOrder.js
43.2 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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
// tabWorkOrder/pages/defeatOrder/defeatOrder.js
import api from '../../api'
import api2 from '~/api/api.js'
import { getYQorderInfo, getPositionList, setConfigInfo } from '~/store/index'
import { validateVin, formatVinInput } from '~/utils/vinVaildate'
import { checkStudyTask, checkOrderLockGate } from '~/store/ModalToQueueControl'
import { navigateToRequiredDailyReport } from '~/utils/staffDailyReportNavigation.js'
import {
normalizeSceneColumns,
resolveAutoScene,
toSceneFields
} from '../../services/sceneAutoSelection.helpers'
import {
createEmptyPositionBuckets,
pushToPositionBucket,
filterUpgradeListByPopupType
} from '../../services/goodsPositionBucket.helpers'
import {
coalesceYmd,
isDateOnOrBeforeToday
} from '../../services/calendarDateBounds.helpers.js'
const phoneRex = /^[1]([3-9])[0-9]{9}$/
const app = getApp()
let toastList = {
employeeName: '销售顾问不能为空',
subShopMerchantId: '二级流量方不能为空',
sellerUserId: '转化人员不能为空',
refusalReason: '拒升理由不能为空'
}
import { ImgUrl } from '~/config'
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL: ImgUrl,
scanIcon:
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/ocr_icon.png',
skylight:
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/miniProgram/skylight.png',
tricorn:
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/miniProgram/tricorn.png',
windshield:
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/miniProgram/windshield.png',
sideIcorn:
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/miniProgram/sideIcon.png',
afterIcorn:
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/miniProgram/afterIcon.png',
name: 'createdOrder',
shortcutList: [],
phoneShow: false,
orderObj: {},
goodsData: [],
userInfo: {},
notUpgradeOrderList: [
{
baseSceneCode: '',
baseSceneName: '',
sceneType: '',
customer: {
customerName: '',
customerPhone: '',
standNo: '',
plateNumber: '',
customerSex: 1,
experienceFlag: 'Y'
},
confirmIndex: false,
subOrderList: []
}
],
dateObj: {
beforeDay: '',
today: '',
nextDay: '',
maxDate: '',
todayShow: ''
},
toView: '',
typeIndx: 0,
isPlateNumber: false,
isStandNo: false,
experienceFlag: false,
refusalReason: false,
isShowSubShopMerchant: false,
requiredList: [],
sceneColumns: [],
tipsProps: {
tipsText: '本表单用于快速生成战败客户订单',
showTips: false,
type: 1
},
selectCustomIndex: 0, // 选择产品对应客户
copyGoodsData: [],
frontGearArr: [], // 前挡
sideRearGearArr: [], // 侧后挡
skylightArr: [], // 天窗
sideBeforeRearGearArr: [], // 前侧窗玻璃
sideAfterRearGearArr: [], // 后档
otherGoodsArr: [],
customerInfoBox: false,
baseConfigData: {},
vinValid: true
},
async prefillLastSeller() {
const { orderObj } = this.data
if (orderObj?.userId) return
const userInfo = this.data.userInfo || wx.$util.getUserInfo() || {}
const sellerUserId = userInfo?.subLoginUser?.uuid || userInfo?.uuid
if (!sellerUserId) return
try {
const res = await api.getLastUserOrderInfo({ sellerUserId })
const last = res?.data
if (!last) return
if (last.merchantId != userInfo?.shopMerchantId) return
this.setData({
'orderObj.merchantId': last.merchantId || '',
'orderObj.merchantName': last.merchantName || '',
'orderObj.userId': last.userId || '',
'orderObj.employeeName': last.employeeName || ''
})
} catch (e) {}
},
async prefillRecentScene() {
const freshUserInfo = wx.$util.getUserInfo() || {}
const userInfo =
(this.data.userInfo && Object.keys(this.data.userInfo).length
? this.data.userInfo
: freshUserInfo) || {}
try {
const res = await api.getRecentUserScene({
sceneType: String(userInfo.sceneType || ''),
phone: userInfo.phone
})
const recent = res?.code == 0 ? res?.data : null
const baseSceneCode = recent?.baseSceneCode || ''
if (!baseSceneCode) return
const list = Array.isArray(this.data.notUpgradeOrderList)
? this.data.notUpgradeOrderList
: []
const next = list.map(item =>
item?.baseSceneCode
? item
: { ...item, baseSceneCode, sceneType: recent?.sceneType }
)
this.setData({
userInfo,
notUpgradeOrderList: next,
// Merchant-Seles 组件触发拉商品依赖 orderObj.sceneType/baseSceneCode,这里同步一份
'orderObj.baseSceneCode': baseSceneCode,
'orderObj.sceneType': recent?.sceneType
})
} catch (e) {}
},
routerBack() {
wx.$router.back()
},
handleVinInput(value, autoValidate = false, type = 'standNo', index) {
let { notUpgradeOrderList, typeIndx = 0 } = this.data
const targetIndex =
typeof index === 'number' || typeof index === 'string'
? Number(index)
: typeIndx
console.log('handleVinInput', notUpgradeOrderList, targetIndex)
console.log('handleVinInputvalue', value)
const formattedValue = formatVinInput(value || '')
if (!notUpgradeOrderList?.[targetIndex]?.customer) return
notUpgradeOrderList[targetIndex].customer[type] = formattedValue
this.setData({
notUpgradeOrderList
})
// 扫描时立即校验,手动输入时需达到17位才校验
if (formattedValue && (autoValidate || formattedValue.length === 17)) {
validateVin(formattedValue)
.then(result => {
let { valid } = result.data.data
this.setData({
vinValid: valid
})
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
})
.catch(error => {
// 校验失败,所有提示已在公共方法中处理
console.log('车架号校验失败:', error)
})
}
},
reWrite(type, data) {
let { notUpgradeOrderList, typeIndx = 0 } = this.data
console.log('reWriteType', type)
console.log('handleVinInput', type, notUpgradeOrderList, typeIndx)
if (type === 'standNo') {
this.handleVinInput(data, true, type)
return
}
notUpgradeOrderList[typeIndx].customer[type] = data
this.setData({
notUpgradeOrderList
})
},
navOcr(e) {
let { type, index } = e.currentTarget.dataset
this.setData({
typeIndx: index
})
wx.$router.go(`ocr?type=${type}`)
},
changeExperience(e) {
// let { gender, index } = e.currentTarget.dataset
let { experience, index } = e.currentTarget.dataset
let prop = `notUpgradeOrderList[${index}].customer.experienceFlag`
this.setData({
[prop]: experience
})
// console.log(experience)
wx.vibrateShort()
// this.setData({
// ['orderObj.customer.experienceFlag']: experience
// })
},
// 选择产品确定
chooseGoods(e) {
let { selectCustomIndex } = this.data
let arr = e.detail || []
let subOrderListProp = `notUpgradeOrderList[${selectCustomIndex}].subOrderList`
this.setData({
[subOrderListProp]: arr
})
},
chooseCustomerInfo(e) {
let { detail } = e
console.log(detail, 'detail')
let { selectCustomIndex } = this.data
let propCustomer = `notUpgradeOrderList[${selectCustomIndex}].customer`
let prop = `notUpgradeOrderList[${selectCustomIndex}]`
const standNo = detail.customer.standNo || ''
this.setData(
{
[propCustomer]: {
customerName: detail.customer.customerName,
customerSex: detail.customer.customerSex,
customerPhone: detail.customer.customerPhone,
carBrandId: detail.customer.carBrandId,
carBrand: detail.customer.carBrand,
carChildsBrandId: detail.customer.carChildsBrandId,
carChildsBrandName: detail.customer.carChildsBrandName,
carSeriesId: detail.customer.carSeriesId,
carSeriesName: detail.customer.carSeriesName,
standNo: detail.customer.standNo,
plateNumber: detail.customer.plateNumber,
experienceFlag: detail.customer.experienceFlag || 'Y'
},
[prop + '.customerCouponCode']: detail.customerCoupon?.customerCouponCode,
[prop + '.customerCouponId']: detail?.customerCouponId, // 客户券id
customerInfoBox: false
},
() => {
// 档案带入 17 位车架号时走与 OCR 相同的校验链路,避免提交误拦
if (standNo.length === 17) {
this.handleVinInput(standNo, true, 'standNo', selectCustomIndex)
}
}
)
},
onCustomerInfoCancel() {
this.setData({ customerInfoBox: false })
},
showCustomPop(e) {
let { index } = e.currentTarget.dataset
this.setData({
customerInfoBox: true,
selectCustomIndex: index
})
},
addUserItem() {
let { notUpgradeOrderList, copyGoodsData, shortcutList, sceneColumns } =
this.data
if (notUpgradeOrderList.length >= 10) return
const newIndex = notUpgradeOrderList.length
notUpgradeOrderList.push({
baseSceneCode: '',
baseSceneName: '',
sceneType: '',
customer: {
customerName: '',
customerPhone: '',
standNo: '',
customerSex: 1,
plateNumber: '',
experienceFlag: 'Y'
},
shortcutList: wx.$util.deepClone(shortcutList)
})
if (sceneColumns?.length) {
const patch = { notUpgradeOrderList }
const inheritCode = this.data.orderObj?.baseSceneCode || ''
this.buildCustomerScenePatch(patch, newIndex, inheritCode, sceneColumns)
this.setData(patch)
} else {
this.setData({ notUpgradeOrderList })
this.getUserSceneList()
}
this.defaultChoose(newIndex)
setTimeout(() => {
this.setData({
toView: 'addBtn'
})
}, 0)
},
/**设置日期 */
setTimeList(dateNum) {
const todayYmd = new Date().format('yyyy-MM-dd')
const maxDate = coalesceYmd(todayYmd, todayYmd)
let today = dateNum || todayYmd
/**
* 根据日期字符串获取星期几
* @param dateString 日期字符串(如:2020-05-02)
* @returns {String}
*/
var dateArray = today.split('-')
let date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2])
let todayShow = ' 周' + '日一二三四五六'.charAt(date.getDay())
todayShow =
dateArray[0] +
'年' +
dateArray[1] +
'月' +
dateArray[2] +
'日 ' +
todayShow
this.setData({
dateObj: {
today,
maxDate,
todayShow
}
})
},
chooseCar(e) {
let { selectCustomIndex, notUpgradeOrderList } = this.data
notUpgradeOrderList[selectCustomIndex] = {
...notUpgradeOrderList[selectCustomIndex],
customer: {
...notUpgradeOrderList[selectCustomIndex].customer,
...e.detail
}
}
this.setData({
notUpgradeOrderList
})
},
dateChange(e) {
let { type } = e.currentTarget.dataset
let { dateObj } = this.data
this.calendar = this.selectComponent('#calender')
if (type == 'before') {
this.setTimeList(dateObj.beforeDay)
} else {
this.setTimeList(dateObj.nextDay)
}
this.calendar.resetData(
type == 'before' ? dateObj.beforeDay : dateObj.nextDay
)
},
// 获取选中天数
rangeSelect(e) {
let { date } = e.detail
const today = coalesceYmd(
this.data.dateObj?.maxDate,
new Date().format('yyyy-MM-dd')
)
if (!isDateOnOrBeforeToday(date, today)) {
return this.showToast('战败日期不能晚于今天')
}
this.setTimeList(date)
},
delBtn(e) {
let ind = e.currentTarget.dataset.ind
let { notUpgradeOrderList } = this.data
notUpgradeOrderList.splice(ind, 1)
this.setData({
notUpgradeOrderList
})
},
touchE: function (e) {
var that = this
if (e.changedTouches.length == 1) {
//手指移动结束后触摸点位置的X坐标
var endX = e.changedTouches[0].clientX
//触摸开始与结束,手指移动的距离
var disX = that.data.startX - endX
var delBtnWidth = that.data.delBtnWidth
//如果距离小于删除按钮的1/2,不显示删除按钮
var txtStyle =
disX > delBtnWidth / 2 ? 'left:-' + delBtnWidth + 'rpx' : 'left:0'
//获取手指触摸的是哪一项
var index = e.currentTarget.dataset.index
var ind = e.currentTarget.dataset.ind
var notUpgradeOrderList = that.data.notUpgradeOrderList
notUpgradeOrderList[index].txtStyle = txtStyle
//更新列表的状态
that.setData({
notUpgradeOrderList
})
}
},
//手指触摸动作开始 记录起点X坐标
touchstart: function (e) {
//开始触摸时 重置所有删除
this.data.notUpgradeOrderList.forEach(item => {
item.isTouchMove = false
item.confirmIndex = false
})
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
notUpgradeOrderList: this.data.notUpgradeOrderList
})
},
//滑动事件处理
touchmove: function (e) {
let { notUpgradeOrderList } = this.data
// 为1就不能再删除了
if (notUpgradeOrderList.length == 1) return
var that = this,
// index = e.currentTarget.dataset.index, //当前索引
ind = e.currentTarget.dataset.ind, //当前索引
startX = that.data.startX, //开始X坐标
startY = that.data.startY, //开始Y坐标
touchMoveX = e.changedTouches[0].clientX, //滑动变化坐标
touchMoveY = e.changedTouches[0].clientY, //滑动变化坐标
//获取滑动角度
angle = that.angle(
{
X: startX,
Y: startY
},
{
X: touchMoveX,
Y: touchMoveY
}
)
notUpgradeOrderList.forEach(function (v, i) {
v.isTouchMove = false
//滑动超过30度角 return
if (Math.abs(angle) > 30) return
if (i == ind) {
if (touchMoveX > startX)
//右滑
v.isTouchMove = false
//左滑
else v.isTouchMove = true
}
})
//更新数据
that.setData({
notUpgradeOrderList
})
},
/**
* 计算滑动角度
* @param {Object} start 起点坐标
* @param {Object} end 终点坐标
*/
angle: function (start, end) {
var _X = end.X - start.X,
_Y = end.Y - start.Y
//返回角度 /Math.atan()返回数字的反正切值
return (360 * Math.atan(_Y / _X)) / (2 * Math.PI)
},
/**
* 战败选品:接口仅返回 upgradeGoodsList 单品,无套餐/多规格;部位分桶规则与 createOrder 单商品一致。
*/
async showPopup(e) {
let { copyGoodsData, baseConfigData } = this.data
let payload = {
...(e.currentTarget?.dataset || {}),
...(e.detail || {})
}
let {
showName,
index,
type,
positionnnum: positionNum
} = payload
let arr = []
if (showName == 'goodsBox') {
const { orderObj, notUpgradeOrderList } = this.data
const row = notUpgradeOrderList?.[index]
const needRefetch =
orderObj?.merchantId &&
row?.baseSceneCode &&
(row.baseSceneCode !== (orderObj.baseSceneCode || '') ||
String(row.sceneType ?? '') !== String(orderObj.sceneType ?? ''))
if (needRefetch) {
wx.$util.showLoading('加载中...')
await new Promise(r =>
this.setData(
{
selectCustomIndex: index,
'orderObj.baseSceneCode': row.baseSceneCode,
'orderObj.baseSceneName': row.baseSceneName || '',
'orderObj.sceneType': row.sceneType
},
r
)
)
try {
await this.getOrderBaseGoodsList(
orderObj.merchantId,
row.sceneType,
row.baseSceneCode
)
} catch (err) {
console.log(err)
}
wx.hideLoading()
}
copyGoodsData = this.data.copyGoodsData
baseConfigData = this.data.baseConfigData
// 按部位过滤弹窗商品;其它精品为无有效部位(1-7)的商品,不限制太阳膜品类
copyGoodsData?.forEach(val => {
const matched = filterUpgradeListByPopupType(
val?.upgradeGoodsList,
type,
positionNum
)
if (!matched?.length) return
if (type == 4) {
arr.push({
goodsType: val.goodsType,
goodsTypeName: val.goodsTypeName,
upgradeGoodsList: matched.map(sub => ({
...sub,
otherFlag: true
}))
})
} else {
arr.push({
goodsType: val.goodsType,
goodsTypeName: val.goodsTypeName,
upgradeGoodsList: matched
})
}
})
}
console.log(arr, 'arr')
this.setData({
[showName]: true,
goodsData: arr,
selectCustomIndex: index
})
},
input(e) {
let { value } = e.detail
let { name, index } = e.currentTarget.dataset
let prop = `notUpgradeOrderList[${index}].${name}`
// 车架号字段特殊处理
if (name === 'customer.standNo') {
this.handleVinInput(value, false, 'standNo', index) // 手动输入时需达到17位才校验
} else {
this.setData({
[prop]: value
})
}
},
changeGender(e) {
let { gender, index } = e.currentTarget.dataset
wx.vibrateShort()
let prop = `notUpgradeOrderList[${index}].customer.customerSex`
this.setData({
[prop]: gender
})
},
/**
* 为指定客户行写入自动解析的场景字段
* @param {object} patch setData 补丁
* @param {number} index 客户在 notUpgradeOrderList 中的下标
* @param {string} currentCode 当前 baseSceneCode
* @param {Array<object>} sceneColumns 场景列表
* @returns {object|null} 解析到的场景项
*/
buildCustomerScenePatch(patch, index, currentCode, sceneColumns) {
const { scene } = resolveAutoScene(currentCode, sceneColumns)
if (!scene) return null
const fields = toSceneFields(scene)
patch[`notUpgradeOrderList[${index}].baseSceneCode`] = fields.baseSceneCode
patch[`notUpgradeOrderList[${index}].baseSceneName`] = fields.baseSceneName
patch[`notUpgradeOrderList[${index}].sceneType`] = fields.sceneType
return scene
},
/**
* 拉取场景列表并为每位客户自动选中:优先记忆值,否则取第一项
*/
async getUserSceneList() {
const freshUserInfo = wx.$util.getUserInfo() || {}
const userInfo =
(this.data.userInfo && Object.keys(this.data.userInfo).length
? this.data.userInfo
: freshUserInfo) || {}
try {
const res = await api.getUserScene({
sceneType: String(userInfo.sceneType || ''),
phone: userInfo.phone
})
const list =
res?.code == 0 && res?.data?.length ? res.data : []
const sceneColumns = normalizeSceneColumns(list)
const { notUpgradeOrderList, selectCustomIndex } = this.data
const patch = { userInfo, sceneColumns }
const customers = Array.isArray(notUpgradeOrderList)
? notUpgradeOrderList
: []
let activeScene = null
customers.forEach((customer, index) => {
const scene = this.buildCustomerScenePatch(
patch,
index,
customer?.baseSceneCode || '',
sceneColumns
)
if (index === selectCustomIndex) {
activeScene = scene
}
})
if (activeScene) {
const fields = toSceneFields(activeScene)
patch['orderObj.baseSceneCode'] = fields.baseSceneCode
patch['orderObj.baseSceneName'] = fields.baseSceneName
patch['orderObj.sceneType'] = fields.sceneType
}
this.setData(patch, () => {
const { orderObj } = this.data
const current = this.data.notUpgradeOrderList?.[selectCustomIndex] || {}
if (orderObj?.merchantId && current?.baseSceneCode && activeScene) {
this.getOrderBaseGoodsList(
orderObj.merchantId,
activeScene.sceneType,
current.baseSceneCode
)
}
})
} catch (e) {
this.setData({
userInfo,
sceneColumns: []
})
}
},
/**
* 拉取战败选品池并按部位分桶;数据源无 goodsFlag 2/3,均为可部位分桶的单品。
*/
async getOrderBaseGoodsList(
merchantId,
sceneType = this.data.orderObj.sceneType,
baseSceneCode
) {
if (!merchantId) return Promise.resolve()
const positionTypeList = (await getPositionList()) || []
// 获取配置服务数据
let baseConfigData = await setConfigInfo(app.globalData)
const orderObj = this.data.orderObj || {}
// 与新建工单一致:请求始终带 baseSceneCode,由后端按场景过滤;切换场景时须用新编码而非历史缓存
const resolvedBaseSceneCode =
baseSceneCode !== undefined && baseSceneCode !== null
? baseSceneCode
: orderObj.baseSceneCode || ''
// 每次拉取重新分桶,避免在原有数组上 push 导致切换场景后商品脏数据
const positionBuckets = createEmptyPositionBuckets()
this.setData({
positionTypeList,
baseConfigData
})
return new Promise((resolve, reject) => {
api
.getOrderBaseGoodsList({
merchantId,
sceneType,
baseSceneCode: resolvedBaseSceneCode,
upradeFlag: 'N'
})
.then(res => {
let { code, data, message } = res
if (code == 0) {
wx.hideLoading()
let arrData = []
data?.forEach(val => {
arrData.push(val)
val?.upgradeGoodsList?.forEach(subVal => {
subVal.merchantGoodsId = subVal.id
pushToPositionBucket(positionBuckets, subVal)
})
})
const {
frontGearArr,
sideBeforeRearGearArr,
sideRearGearArr,
sideAfterRearGearArr,
skylightArr,
other: otherGoodsArr
} = positionBuckets
let goodsData = arrData
goodsData.reduce((list, item) => {
item.upgradeGoodsList.forEach(val => {
val.positionStr = positionTypeList.filter(
v => v.positionValue == val.merchantGoodsPosition
)[0]?.positionName
})
item.upgradeGoodsList && list.push(...item.upgradeGoodsList)
return list
}, [])
data.forEach(item => {
item.upgradeGoodsList.forEach(v => {
v.price = 0
v.shopMinPrice = 0
v.upgradePrice = 0
v.totalPrice = 0
v.number = 1
})
})
this.setData(
{
goodsData,
frontGearArr,
sideBeforeRearGearArr,
sideAfterRearGearArr,
sideRearGearArr,
skylightArr,
otherGoodsArr,
copyGoodsData: goodsData
},
() => {
if (
goodsData.length == 1 &&
goodsData[0].upgradeGoodsList.length == 1
) {
this.defaultChoose(0)
}
resolve(data)
}
)
} else {
wx.hideLoading()
wx.$util.showToast(message)
reject(new Error(message || 'getOrderBaseGoodsList'))
}
})
.catch(err => {
wx.hideLoading()
reject(err)
})
})
},
defaultChoose(index) {
let {
frontGearArr,
sideRearGearArr,
skylightArr,
sideBeforeRearGearArr,
sideAfterRearGearArr,
otherGoodsArr
} = this.data
// 仅有一个商品直接选中
otherGoodsArr = otherGoodsArr.map(item => {
item.otherFlag = true
return item
})
let arr = [].concat(
sideRearGearArr.length == 1 ? sideRearGearArr : [],
frontGearArr.length == 1 ? frontGearArr : [],
skylightArr.length == 1 ? skylightArr : [],
sideBeforeRearGearArr.length == 1 ? sideBeforeRearGearArr : [],
sideAfterRearGearArr.length == 1 ? sideAfterRearGearArr : [],
otherGoodsArr.length == 1 ? otherGoodsArr : []
)
console.log(arr, 'defaultChoose')
arr.forEach(val => {
val.count = 1
val.active = true
})
let prop = `notUpgradeOrderList[${index}].subOrderList`
this.setData({
[prop]: arr
})
},
staffDailyReportMerchantValid(userInfo) {
// let { userInfo } = this.data
return new Promise((resolve, reject) => {
// console.log(userInfo, 'userInfo')
api
.staffDailyReportMerchantValid({
// merchantId: userInfo.shopMerchantId
merchantId: userInfo.shopMerchantId,
yqMerchantId: userInfo.merchantId,
staffUuid: userInfo.uuid,
sceneType: 1
})
.then(res => {
if (res.data) {
// 获取当前日期
let currentDate = new Date()
// 获取上一天的日期
let previousDate = new Date(currentDate)
previousDate.setDate(currentDate.getDate() - 1)
// toISOString 方法会丢失时区 导致与北京时间差八小时
let hour = previousDate.getHours() + 8
previousDate.setHours(hour)
// 格式化日期为"yyyy-mm-dd"
let formattedDate = previousDate.toISOString().split('T')[0]
if (wx.__HAS_NOREPORT_MODAL || wx.__HAS_NOTLOGIN_MODAL) return false
wx.__HAS_NOREPORT_MODAL = true
wx.showModal({
title: '日报提醒',
content: '您有未填写的日报,请点击前往。',
showCancel: false,
// cancelText: '取消', // '取消
cancelColor: '#292D33',
confirmText: '前往填写',
confirmColor: '#347BFF',
success(res) {
if (res.confirm) {
navigateToRequiredDailyReport({ reportDate: formattedDate })
}
},
complete: () => {
// 这个延迟的目的是为了避免短时间内重复弹出
// 你要是没有这个需要也可以去掉,直接把标志位改成 false 就行
setTimeout(() => {
wx.__HAS_NOREPORT_MODAL = false
}, 2000)
}
})
// return false
resolve(res.data)
} else {
resolve(res.data)
}
})
.catch(err => {
console.log(err)
})
})
},
async submit(i) {
let userInfo = wx.$util.getUserInfo()
// 校验是否填写昨日日报
let staffCheck = await this.staffDailyReportMerchantValid(userInfo)
if (staffCheck) return false
// 校验学习中心开单限制
let staffStudyTask = await checkStudyTask()
if (staffStudyTask) return false
// 校验异常订单
let lockCheck = await checkOrderLockGate()
if (lockCheck) return false
this.checkPhoneUseConfig()
let {
orderObj,
notUpgradeOrderList,
dateObj,
vinValid,
isStandNo,
isCarBrand,
isPlateNumber,
refusalReason,
isExpiredTraffic
} = this.data
let key = this.checkRequired(orderObj)
if (key) {
this.showToast(toastList[key])
wx.pageScrollTo({
selector: `.${key}`
})
return
}
for (let index = 0; index < notUpgradeOrderList.length; index++) {
if (!notUpgradeOrderList[index].customer.customerName) {
return this.showToast(`请输入第${index + 1}位客户姓名`)
}
if (!notUpgradeOrderList[index].baseSceneCode) {
return this.showToast(`请选择第${index + 1}位客户场景名称`)
}
if (!phoneRex.test(notUpgradeOrderList[index].customer.customerPhone)) {
this.showToast(`请输入第${index + 1}位客户正确的手机号`)
return
}
if (isCarBrand && !notUpgradeOrderList[index].customer.carSeriesName) {
return this.showToast(`请输入第${index + 1}位客户车型`)
}
// 非动态校验车架号-abandon
// if (isStandNo && !notUpgradeOrderList[index].customer.standNo) {
// return this.showToast(`请输入第${index + 1}位客户车架号`)
// }
// 动态校验车架号
const carVin = notUpgradeOrderList[index].customer?.standNo
if (carVin) {
// 前置判断
if (carVin.length !== 17) {
wx.$util.showToast(
'请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)'
)
return false
}
// 根据接口校验结果判断
if (carVin.length === 17 && !vinValid) {
wx.$util.showToast('车架号校验不匹配,请核对后重新输入')
return false
}
}
if (
!notUpgradeOrderList[index].subOrderList?.length &&
!isExpiredTraffic
) {
return this.showToast(`请选择第${index + 1}位客户产品`)
}
if (refusalReason && !notUpgradeOrderList[index].customer.refusalReason) {
return this.showToast(`请输入第${index + 1}位客户拒升理由`)
}
}
notUpgradeOrderList?.forEach(val => {
let arr = []
val?.subOrderList?.forEach(subVal => {
let obj = {
baseGoodsId: subVal.baseGoodsId,
totalPrice: Number(subVal.price) || 0,
number: subVal.count,
merchantGoodsId: subVal.id || subVal.merchantGoodsId
}
arr.push(obj)
})
val.subOrderList = !isExpiredTraffic ? arr : []
if (isExpiredTraffic) {
delete val.customer?.['experienceFlag'] // 删除是否体验参数
val['packageGoodsList'] = [] // 删除商品参数
}
})
orderObj = {
...orderObj,
notUpgradeOrderList,
createDate: dateObj.today
}
const today = coalesceYmd(
dateObj.maxDate,
new Date().format('yyyy-MM-dd')
)
if (!isDateOnOrBeforeToday(dateObj.today, today)) {
return this.showToast('战败日期不能晚于今天')
}
delete orderObj.customer
delete orderObj?.packageGoodsList
delete orderObj?.subOrderList
console.log(orderObj, 'orderObj')
// return;
wx.$util.showLoading('提交中...')
// this.showLoading()
api.notUpgradeOrder({ json: JSON.stringify(orderObj) }).then(res => {
wx.hideLoading()
let { code, data, message } = res
if (code == 0) {
// 状态更新 需刷新工单列表和预约管理列表
wx.$util.refreshPageData()
wx.$util.showToast({
icon: 'success',
title: '提交成功'
})
wx.$router.go('pages.index')
} else {
wx.$util.showToast(message)
}
})
},
checkRequired(obj) {
// 导入动态校验字段
let { requiredList } = this.data
let target = [...requiredList, 'employeeName']
try {
target.map(key => {
if (!obj[key]) {
throw key
}
})
} catch (error) {
return error
}
return false
},
checkPhoneUseConfig() {
let { phoneShow, orderObj, notUpgradeOrderList } = this.data
if (phoneShow && orderObj.merchantName && orderObj.employeeName) {
let phoneConfig =
phoneShow.find(item => {
item.shopMerchantId == orderObj.merchantId
}) || phoneShow.pop()
notUpgradeOrderList.forEach(item => {
item.customer.customerPhone =
item.customer.customerPhone || phoneConfig?.phoneNumber
})
this.setData({
notUpgradeOrderList
})
}
},
delGoodsList(e) {
let { index, customIndex } = e.currentTarget.dataset
let { notUpgradeOrderList } = this.data
notUpgradeOrderList[customIndex]?.subOrderList?.splice(index, 1)
this.setData({
notUpgradeOrderList
})
},
blur(e) {
let { liindex } = e.currentTarget.dataset
console.log(e, liindex)
console.log(e)
let { value } = e.detail
let { notUpgradeOrderList } = this.data
value = value.substring(0, 30)
let shortcutList = notUpgradeOrderList[liindex].shortcutList
if (!value) {
shortcutList = shortcutList.map(i => {
i.active = false
return i
})
}
let prop = `notUpgradeOrderList[${liindex}].shortcutList`
let prop2 = `notUpgradeOrderList[${liindex}].focus`
let prop3 = `notUpgradeOrderList[${liindex}].customer.refusalReason`
console.log(value, 'value')
this.setData({
[prop3]: value,
[prop]: shortcutList,
[prop2]: false
})
},
chooseShortcut(e) {
let { item, index, liindex } = e.currentTarget.dataset
console.log(item, index, liindex)
let { notUpgradeOrderList } = this.data
// console.log(object);
// debugger
// if (notUpgradeOrderList[liindex].shortcutList[index].active) return
let refusalReason =
notUpgradeOrderList[liindex].customer.refusalReason || ''
refusalReason += item.confValue
refusalReason = refusalReason.substring(0, 30)
let prop = `notUpgradeOrderList[${liindex}].shortcutList[${index}].active`
// let prop2 = `notUpgradeOrderList[${liindex}].focus`
let prop3 = `notUpgradeOrderList[${liindex}].customer.refusalReason`
this.setData({
[prop3]: refusalReason,
[prop]: true
// [prop2]: true
})
console.log(refusalReason, this.data.notUpgradeOrderList)
},
getSetting() {
// 动态获取 车型 车架 车牌 是否必填
// let { isStandNo, isCarBrand, isPlateNumber } = this.data
let {
isStandNo,
isCarBrand,
isPlateNumber,
experienceFlag,
refusalReason
} = this.data
// app .
getYQorderInfo()
.then(merchantSettingInfo => {
// let { requiredList } = this.data
if (merchantSettingInfo.carTypeRequiredFlag == 'Y') isCarBrand = true // 车型必填
if (merchantSettingInfo.standNoRequiredFlag == 'Y') isStandNo = true // 车架号必填
if (merchantSettingInfo.plateNumRequiredFlag == 'Y')
isPlateNumber = true // 车牌必填
if (merchantSettingInfo.foEfRequiredFlag == 'Y') experienceFlag = true // 战败订单是否体验
if (merchantSettingInfo.foRrRequiredFlag == 'Y') refusalReason = true // 战败订单拒升理由
this.setData({
isStandNo,
isCarBrand,
isPlateNumber,
experienceFlag,
refusalReason,
phoneShow: wx.$util.deepClone(merchantSettingInfo.yqPhoneConfig)
})
})
.catch(err => {
console.log(err)
})
api2
.getConfigList({
confGroup: 'SMARTCARLIFE_NOT_UPGRADE_LABEL'
})
.then(res => {
console.log(res)
let list = []
let { code, data } = res
if (code == 0) {
list = data
}
let prop = `notUpgradeOrderList[0].shortcutList`
this.setData({
shortcutList: list,
[prop]: list
})
})
},
init(userInfo) {
let { orderObj, scene } = this.data
orderObj.sellerMerchantName = userInfo.merchantName
orderObj.sellerMerchantId = userInfo.merchantId
orderObj.sellerName = userInfo.name
orderObj.sellerUserId = userInfo.uuid
this.setData({
orderObj
})
if (scene) {
let id = scene.split('=')[1]
api
.getCouponDeatil({
id
})
.then(info => {
let { code, data, message } = info
if (code == 0) {
if (data.usedFlag == 'Y') {
wx.showModal({
content: '该礼券已被使用',
confirmText: '知道了',
confirmColor: '#347BFF',
showCancel: false,
success(res) {
if (res.confirm) wx.$router.back()
}
})
return
}
this.setOrderObj(data)
api
.getOrderByCustomerCouponId({
customerCouponId: id
})
.then(res => {
let { code, data, message } = res
if (code == 0) {
console.log(data.orderCode, 'getOrderByCustomerCouponId')
this.setData({
['orderObj.orderCode']: data.orderCode
})
} else {
this.showToast(message)
}
})
} else {
this.showToast(message)
}
})
}
},
setOrderObj(options) {
let { scene, userInfo } = this.data
console.log('setOrderObj', options)
wx.$util.showLoading('加载中...')
const prevCustomer = this.data.notUpgradeOrderList?.[0] || {}
let orderObj = {}
Object.keys(options).map(e => {
if (options[e] != null && options[e] != undefined) {
if (typeof options[e] == 'object') {
Object.keys(options[e]).map(key => {
if (options[e][key] == null || options[e][key] == undefined)
delete options[e][key]
})
}
orderObj[e] = options[e]
}
})
console.log(orderObj)
// 保留 recent.getUserScene 预填的场景信息,避免选择门店/销售顾问后被覆盖
if (!orderObj.baseSceneCode && prevCustomer.baseSceneCode) {
orderObj.baseSceneCode = prevCustomer.baseSceneCode
}
if (!orderObj.baseSceneName && prevCustomer.baseSceneName) {
orderObj.baseSceneName = prevCustomer.baseSceneName
}
if (
(orderObj.sceneType === undefined ||
orderObj.sceneType === null ||
orderObj.sceneType === '') &&
prevCustomer.sceneType !== undefined &&
prevCustomer.sceneType !== null &&
prevCustomer.sceneType !== ''
) {
orderObj.sceneType = prevCustomer.sceneType
}
// 去除优惠券 参数
delete orderObj.customerCouponId
delete orderObj.couponName
// 去除商品选择
orderObj.subOrderList = []
// 使用优惠券的merchantId 避免优惠券和店区不一致的情况
if (!orderObj.merchantId)
orderObj.merchantId = orderObj.merchantCoupon.merchantId
if (!orderObj.customer) orderObj.customer = orderObj.customerInfo || {}
// 是扫码核销值为3 预录值为2
if (orderObj.selectPayType == null || orderObj.selectPayType == undefined)
orderObj.selectPayType = scene ? 3 : 2
// 是再次下单的 就删除优惠券字段 不是就赋值
// || orderObj.associatedOrderCode
// if (orderObj.customerCoupon && orderObj.constructionFlag != 'Y') {
// orderObj.couponName = orderObj.customerCoupon.couponName
// orderObj.customerCouponCode =
// orderObj.customerCoupon.customerCouponCode?.split('-')[0]
// if (orderObj.couponId) {
// orderObj.customerCouponId = orderObj.id
// }
// } else {
// delete orderObj.merchantCouponId
// }
if (scene) {
orderObj.customerCouponId = orderObj.id
orderObj.orderSource = 5
orderObj.sellerMerchantName = userInfo.merchantName
orderObj.sellerName = userInfo.name
orderObj.sellerMerchantId = userInfo.merchantId
orderObj.sellerUserId = userInfo.uuid
delete orderObj.remark
} else {
orderObj.orderSource = orderObj.orderSource
}
console.log(orderObj.customer, 'orderObj.customer')
if (!orderObj?.customer.customerSex) orderObj.customer.customerSex = 1
if (!orderObj?.customer.experienceFlag)
orderObj.customer.experienceFlag = 'N'
// 预约工单跳转下单(处理园区店id参数 保证可以拿到园区店的礼券yqMerchantId)
if (options.yqMerchantId && options.isAppointment) {
orderObj.sellerMerchantId = options.yqMerchantId
}
if (!orderObj.customer.salesType) orderObj.customer.salesType = 0
console.log(orderObj, 'orderObj')
if (orderObj.packageGoodsList) {
console.log(orderObj.packageGoodsList)
orderObj.packageGoodsList.forEach(item => {
item.active = true
item.isType = 'meal'
item.packageGoodsOrderList.forEach(g => {
g.sellPrice = g.upgradePrice
g.price = g.totalPrice
? Number(g.totalPrice) / Number(g.number)
: g.upgradePrice
})
item.goodsList = item.packageGoodsOrderList
item.upgradePrice = item.goodsList.reduce((prev, cur) => {
return prev + cur.sellPrice
}, 0)
item.count = item.goodsList.length ? item.goodsList[0].number : 1
item.price = item.goodsList.reduce((prev, cur) => {
return prev + Number(cur.totalPrice) / Number(cur.number)
}, 0)
let total = item.price * item.count
item.totalPrice = wx.$util.decimal(total, 2)
})
}
let f = 'notUpgradeOrderList[' + 0 + ']'
this.setData({
currentWordNumber: orderObj?.remark?.length || 0,
orderObj,
[f]: { ...orderObj },
first: true,
flag: true
})
// 门店/销售顾问确定后:如果已有场景,立即按场景拉商品(否则等用户选择场景)
if (orderObj.merchantId && orderObj.baseSceneCode) {
this.getOrderBaseGoodsList(
orderObj.merchantId,
orderObj.sceneType,
orderObj.baseSceneCode
)
} else {
this.getOrderBaseGoodsList(orderObj.merchantId)
}
},
initOPtions(res) {
if (res.customerName) {
// 解码
for (const key in res) {
res[key] = decodeURIComponent(res[key])
}
let f = 'notUpgradeOrderList[' + 0 + '].customerName'
this.setData({
[f]: res.customerName
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: async function (res) {
this.setTimeList()
const userInfo = wx.$util.getUserInfo() || {}
this.setData({
userInfo
})
res && this.initOPtions(res)
await this.prefillRecentScene()
await this.prefillLastSeller()
this.getUserSceneList()
if (res.scene) {
this.setData(res)
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function (res) {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.setTimeList()
},
onRoute(res) {
console.log(res, 'onroute')
this.setData({ isExpiredTraffic: res?.isExpiredTraffic })
if (res.scene) {
let { isAlreadyExistOrder } = this.data
res.returnFun = true
// 扫描核销进入战败工单 不可建档
isAlreadyExistOrder = true
// 修复 res 为...res 解决对象没有拓展的问题
this.setData({
...res,
isAlreadyExistOrder
})
}
// res && this.initOPtions(res);
this.getSetting()
if (res.merchantId) {
this.setData({
returnFun: true
})
this.setOrderObj(res)
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
onUnload: () => {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {}
})