defeatOrder.js
33.5 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
// tabWorkOrder/pages/defeatOrder/defeatOrder.js
import api from '../../api'
import api2 from '~/api/api.js'
import { getYQorderInfo, getPositionList, setConfigInfo } from '~/store/index'
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: [
{
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: [],
tipsProps: {
tipsText: '本表单用于快速生成战败客户订单',
showTips: false,
type: 1
},
selectCustomIndex: 0, // 选择产品对应客户
copyGoodsData: [],
frontGearArr: [], // 前挡
sideRearGearArr: [], // 侧后挡
skylightArr: [], // 天窗
sideBeforeRearGearArr: [], // 前侧窗玻璃
sideAfterRearGearArr: [], // 后档
customerInfoBox: false,
baseConfigData: {}
},
routerBack() {
wx.$router.back()
},
reWrite(type, data) {
let { notUpgradeOrderList, typeIndx } = this.data
notUpgradeOrderList[typeIndx][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}]`
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
})
},
showCustomPop(e) {
let { index } = e.currentTarget.dataset
this.setData({
customerInfoBox: true,
selectCustomIndex: index
})
},
addUserItem() {
let { notUpgradeOrderList, copyGoodsData, shortcutList } = this.data
if (notUpgradeOrderList.length >= 10) return
notUpgradeOrderList.push({
customer: {
customerName: '',
customerPhone: '',
standNo: '',
customerSex: 1,
plateNumber: '',
experienceFlag: 'Y'
},
shortcutList: wx.$util.deepClone(shortcutList)
})
this.setData({
notUpgradeOrderList
})
// if (copyGoodsData.length == 1 && copyGoodsData[0].upgradeGoodsList.length == 1) {
this.defaultChoose(notUpgradeOrderList.length - 1)
// }
setTimeout(() => {
this.setData({
toView: 'addBtn'
})
}, 0)
},
/**设置日期 */
setTimeList(dateNum) {
let maxDate = new Date().format('yyyy-MM-dd')
let today = dateNum || new Date().format('yyyy-MM-dd')
/**
* 根据日期字符串获取星期几
* @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
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)
},
showPopup(e) {
let { copyGoodsData, baseConfigData } = this.data
let { showName, index, type, positionnnum: positionNum } = e.currentTarget.dataset
let arr = []
if (showName == 'goodsBox') {
// type 产品类型 1前挡 2侧后挡 3天窗 根据类型过滤显示商品弹窗数据
copyGoodsData?.forEach((val, index) => {
if (
val.goodsType == 1 ||
val.goodsType == baseConfigData?.selfBuildFilmType
) {
arr.push({
goodsType: val.goodsType,
goodsTypeName: val.goodsTypeName,
upgradeGoodsList: []
})
for (var i = 0; i < arr?.length; i++) {
let arr2 = [];
val?.upgradeGoodsList?.forEach((subVal, subInd) => {
if (type == 1 && [1].includes(subVal.merchantGoodsPosition)) {
arr2.push(subVal);
if (
subVal?.goodsInfo?.goodsType == arr[i]?.goodsType ||
subVal?.upgradeGoodsType == arr[i]?.goodsType
)
arr[i].upgradeGoodsList = arr2;
}
console.log([positionNum], [positionNum].includes(subVal.merchantGoodsPosition));
if (
type == 2 &&
[Number(positionNum)].includes(subVal.merchantGoodsPosition)
) {
arr2.push(subVal);
if (
subVal?.goodsInfo?.goodsType == arr[i]?.goodsType ||
subVal?.upgradeGoodsType == arr[i]?.goodsType
)
arr[i].upgradeGoodsList = arr2;
}
if (
type == 3 &&
[5, 6, 7].includes(subVal.merchantGoodsPosition)
) {
arr2.push(subVal);
if (
subVal?.goodsInfo?.goodsType == arr[i]?.goodsType ||
subVal?.upgradeGoodsType == arr[i]?.goodsType
)
arr[i].upgradeGoodsList = arr2;
}
});
if (!arr[i]?.upgradeGoodsList?.length) arr.splice(i, 1);
}
// for (var i = 0; i < arr?.length; i++) {
// let arr2 = []
// val?.upgradeGoodsList?.forEach((subVal, subInd) => {
// if (type == 1 && [1].includes(subVal.merchantGoodsPosition)) {
// arr2.push(subVal)
// if (
// subVal?.goodsInfo?.goodsType == arr[i]?.goodsType ||
// subVal?.upgradeGoodsType == arr[i]?.goodsType
// )
// arr[i].upgradeGoodsList = arr2
// }
// if (
// type == 2 &&
// [2, 3, 4].includes(subVal.merchantGoodsPosition)
// ) {
// arr2.push(subVal)
// if (
// subVal?.goodsInfo?.goodsType == arr[i]?.goodsType ||
// subVal?.upgradeGoodsType == arr[i]?.goodsType
// )
// arr[i].upgradeGoodsList = arr2
// }
// if (
// type == 3 &&
// [5, 6, 7].includes(subVal.merchantGoodsPosition)
// ) {
// arr2.push(subVal)
// if (
// subVal?.goodsInfo?.goodsType == arr[i]?.goodsType ||
// subVal?.upgradeGoodsType == arr[i]?.goodsType
// )
// arr[i].upgradeGoodsList = arr2
// }
// })
// if (!arr[i]?.upgradeGoodsList?.length) arr.splice(i, 1)
// }
}
})
}
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}`
this.setData({
[prop]: value
})
},
changeGender(e) {
let { gender, index } = e.currentTarget.dataset
wx.vibrateShort()
let prop = `notUpgradeOrderList[${index}].customer.customerSex`
this.setData({
[prop]: gender
})
},
// 获取商品
async getOrderBaseGoodsList(merchantId) {
const positionTypeList = (await getPositionList()) || []
// 获取配置服务数据
let baseConfigData = await setConfigInfo(app.globalData)
let {
frontGearArr, // 前挡
sideBeforeRearGearArr, // 前侧窗玻璃
sideRearGearArr, // 侧后挡
sideAfterRearGearArr, // 后档
skylightArr // 天窗
} = this.data
this.setData({
positionTypeList,
baseConfigData
})
api
.getOrderBaseGoodsList({
merchantId,
upradeFlag: 'N'
})
.then(res => {
let { code, data, message } = res
if (code == 0) {
wx.hideLoading()
// 筛选出太阳膜商品 goodsType 1太阳膜 自建商品-太阳膜
let arrData = []
data?.forEach(val => {
if ([1, baseConfigData?.selfBuildFilmType].includes(val.goodsType))
arrData.push(val)
val?.upgradeGoodsList?.forEach(subVal => {
subVal.merchantGoodsId = subVal.id
if ([1].includes(subVal.merchantGoodsPosition)) {
frontGearArr.push(subVal)
}
if ([2].includes(subVal.merchantGoodsPosition)) {
sideBeforeRearGearArr.push(subVal)
}
if ([3].includes(subVal.merchantGoodsPosition)) {
sideRearGearArr.push(subVal)
}
if ([4].includes(subVal.merchantGoodsPosition)) {
sideAfterRearGearArr.push(subVal)
}
if ([5, 6, 7].includes(subVal.merchantGoodsPosition)) {
skylightArr.push(subVal)
}
})
})
let goodsData = arrData
const filterList = 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,
copyGoodsData: goodsData
})
// 仅有一件商品 默认选中
// if (goodsData.length == 1 && goodsData[0].upgradeGoodsList.length == 1) {
this.defaultChoose(0)
// }
} else {
wx.$util.showToast(message)
}
})
},
defaultChoose(index) {
let { frontGearArr, sideRearGearArr, skylightArr } = this.data
// 仅有一个商品直接选中
let arr = [].concat(
sideRearGearArr.length == 1 ? sideRearGearArr : [],
frontGearArr.length == 1 ? frontGearArr : [],
skylightArr.length == 1 ? skylightArr : []
)
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) {
wx.$router.go('tabWorkOrder.upgradeStaffDaily', {
// reportDate: hasNeedReport.date
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
this.checkPhoneUseConfig()
let {
orderObj,
notUpgradeOrderList,
dateObj,
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 (!phoneRex.test(notUpgradeOrderList[index].customer.customerPhone)) {
this.showToast(`请输入第${index + 1}位客户正确的手机号`)
return
}
if (isCarBrand && !notUpgradeOrderList[index].customer.carSeriesName) {
return this.showToast(`请输入第${index + 1}位客户车型`)
}
if (isStandNo && !notUpgradeOrderList[index].customer.standNo) {
return this.showToast(`请输入第${index + 1}位客户车架号`)
}
if (isPlateNumber && !notUpgradeOrderList[index].customer.plateNumber) {
return this.showToast(`请输入第${index + 1}位客户车牌号`)
}
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
}
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('加载中...')
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)
// 去除优惠券 参数
delete orderObj.customerCouponId;
delete orderObj.couponName;
// 使用优惠券的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
})
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: function (res) {
this.setTimeList()
res && this.initOPtions(res)
if (res.scene) {
this.setData(res)
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function (res) { },
/**
* 生命周期函数--监听页面显示
*/
onShow: function (res) { },
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 () { }
})