createArchives.js
27.6 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
// tabWorkOrder/pages/createArchives/createArchives.js
// tabWorkOrder/pages/createOrder/createOrder.js
// import deepClone from '~/utils/deepClone'
import api from '../../api'
import { getYQorderInfo } from '~/store/index'
import { checkStudyTask, checkOrderLockGate } from '~/store/ModalToQueueControl'
import { navigateToRequiredDailyReport } from '~/utils/staffDailyReportNavigation.js'
import {
coalesceYmd,
isDateOnOrBeforeToday
} from '../../services/calendarDateBounds.helpers.js'
import {
applyDeliveryDateToRow,
buildPreliminaryOrderSubmitItem,
isInviteDateAllowedForSubmit,
isInviteDateOnOrAfterToday,
resolveInviteDateMin
} from './services/createArchivesDate.helpers.js'
import {
normalizeSceneColumns,
resolveAutoScene,
toSceneFields
} from '../../services/sceneAutoSelection.helpers.js'
const app = getApp()
let toastList = {
employeeName: '销售顾问不能为空',
subShopMerchantId: '二级流量方不能为空',
customerName: '车主姓名不能为空',
customerPhone: '手机号不能为空',
sellerUserId: '转化人员不能为空',
customerCouponCode: '精品礼券不能为空',
carBrand: '车型不能为空',
standNo: '车架号( VIN码 )不能为空',
plateNumber: '车牌不能为空'
}
const phoneRex = /^[1]([3-9])[0-9]{9}$/
Page({
/**
* 页面的初始数据
*/
data: {
scanIcon:
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/ocr_icon.png',
name: 'createdOrder',
phoneShow: false,
orderObj: {
// selectPayType: 2,
// remark: ''
baseSceneCode: '',
baseSceneName: '',
sceneType: ''
},
goodsData: [],
userInfo: {},
sceneColumns: [],
notUpgradeOrderList: [
{
customerName: '',
customerPhone: '',
customerSex: 1,
baseSceneCode: '',
baseSceneName: '',
sceneType: '',
inviteDate: '',
inviteDateShow: '',
deliveryDate: '',
deliveryDateShow: '',
confirmIndex: false
}
// {
// customerName: '',
// customerPhone: '',
// standNo: '',
// customerSex: 1,
// confirmIndex: false
// }
],
dateObj: {
beforeDay: '',
today: '',
nextDay: '',
maxDate: '',
todayShow: ''
},
toView: '',
typeIndx: 0,
// isPlateNumber: false
isCarBrand: false,
isStandNo: false,
isShowSubShopMerchant: false,
requiredList: [],
tipsProps: {
tipsText: '本表单用于快速创建客户待跟进订单',
showTips: false,
type: 1
},
selectCustomIndex: 0,
inviteDateMin: '',
datePickerConfig: {
field: 'createDate',
index: 0,
minDate: '2020-10-01',
maxDate: new Date().format('yyyy-MM-dd'),
scopeKey: `createDate|2020-10-01|${new Date().format('yyyy-MM-dd')}`
}
},
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 = this.ensureNotUpgradeOrderList()
const next = list.map(item =>
item?.baseSceneCode
? item
: { ...item, baseSceneCode, sceneType: recent?.sceneType }
)
this.setData({
userInfo,
notUpgradeOrderList: next,
'orderObj.baseSceneCode': baseSceneCode,
'orderObj.sceneType': recent?.sceneType
})
} catch (e) {}
},
ensureNotUpgradeOrderList() {
const list = this.data.notUpgradeOrderList
if (Array.isArray(list)) {
this.__lastValidNotUpgradeOrderList = list
return list
}
const normalized = []
if (list && typeof list === 'object') {
Object.keys(list).forEach(k => {
const item = list[k]
if (item && typeof item === 'object') normalized.push(item)
})
}
// 如果当前值是对象(比如被错误 setData 成了 map),优先从当前值还原,避免丢失最新填写/选择的数据
if (normalized.length) {
this.setData({
notUpgradeOrderList: normalized
})
this.__lastValidNotUpgradeOrderList = normalized
return normalized
}
// 如果曾经有过有效数组,回滚到最近一次有效值,避免“突然变 1 条”
if (Array.isArray(this.__lastValidNotUpgradeOrderList)) {
this.setData({
notUpgradeOrderList: this.__lastValidNotUpgradeOrderList
})
return this.__lastValidNotUpgradeOrderList
}
if (!normalized.length) {
normalized.push({
customerName: '',
customerPhone: '',
customerSex: 1,
baseSceneCode: '',
baseSceneName: '',
sceneType: '',
inviteDate: '',
inviteDateShow: '',
deliveryDate: '',
deliveryDateShow: '',
confirmIndex: false
})
}
this.setData({
notUpgradeOrderList: normalized
})
this.__lastValidNotUpgradeOrderList = normalized
return normalized
},
routerBack() {
wx.$router.back()
},
reWrite(type, data) {
let { notUpgradeOrderList, typeIndx } = this.data
notUpgradeOrderList[typeIndx][type] = data
this.setData({
notUpgradeOrderList
})
},
navOcr(e) {
// console.log('ocr')
let { type, index } = e.currentTarget.dataset
console.log(type)
// wx.$router.go('ocr', { type: 'test' })
this.setData({
typeIndx: index
})
wx.$router.go(`ocr?type=${type}`)
},
addUserItem() {
let customer = {
customerName: '',
customerPhone: '',
customerSex: 1,
baseSceneCode: '',
baseSceneName: '',
sceneType: '',
inviteDate: '',
inviteDateShow: '',
deliveryDate: '',
deliveryDateShow: ''
}
let { notUpgradeOrderList, sceneColumns } = this.data
notUpgradeOrderList = this.ensureNotUpgradeOrderList()
const newIndex = notUpgradeOrderList.length
notUpgradeOrderList.push(customer)
if (sceneColumns?.length) {
const patch = { notUpgradeOrderList }
const inheritCode = this.data.orderObj?.baseSceneCode || ''
this.buildCustomerScenePatch(patch, newIndex, inheritCode, sceneColumns)
this.setData(patch, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
})
} else {
this.setData({ notUpgradeOrderList }, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
this.getUserSceneList()
})
}
setTimeout(() => {
this.setData({
toView: 'addBtn'
})
}, 0)
},
chooseCar(e) {
let { selectCustomIndex, notUpgradeOrderList } = this.data
notUpgradeOrderList[selectCustomIndex] = {
...notUpgradeOrderList[selectCustomIndex],
...e.detail
}
this.setData({
notUpgradeOrderList
})
},
/**
* 将 yyyy-MM-dd 格式化为页面展示文案(含星期)
* @param {string} dateStr 日期字符串
* @returns {string}
*/
formatDateShow(dateStr) {
const dateArray = dateStr.split('-')
const date = new Date(dateArray[0], parseInt(dateArray[1] - 1, 10), dateArray[2])
const weekText = ' 周' + '日一二三四五六'.charAt(date.getDay())
return (
dateArray[0] + '年' + dateArray[1] + '月' + dateArray[2] + '日 ' + weekText
)
},
/**设置日期 */
setTimeList(dateNum) {
const maxDate = new Date().format('yyyy-MM-dd')
const today = dateNum || maxDate
const todayShow = this.formatDateShow(today)
const patch = {
dateObj: {
today,
maxDate,
todayShow
},
inviteDateMin: maxDate,
'datePickerConfig.maxDate': maxDate
}
if (this.data.datePickerConfig?.field === 'createDate') {
patch['datePickerConfig.scopeKey'] = `createDate|2020-10-01|${maxDate}`
}
this.setData(patch)
},
/**
* 读取当前日期选择器上下文对应的已选值
* @param {string} field createDate | inviteDate | deliveryDate
* @param {number} index 客户行下标
* @returns {string}
*/
getDatePickerValue(field, index) {
if (field === 'createDate') {
return this.data.dateObj?.today || ''
}
const item = this.ensureNotUpgradeOrderList()[index]
return item?.[field] || ''
},
/**
* 打开共享日期选择器;按字段切换 min/max 并在范围变化时重建日历实例
* @param {WechatMiniprogram.TouchEvent} e dataset.field / dataset.index
*/
openDatePicker(e) {
const { field, index } = e.currentTarget.dataset
const { dateObj, inviteDateMin } = this.data
let minDate = ''
let maxDate = ''
const farFutureDate = new Date(
new Date().setFullYear(new Date().getFullYear() + 10)
).format('yyyy-MM-dd')
if (field === 'createDate') {
minDate = '2020-10-01'
maxDate = coalesceYmd(dateObj.maxDate, new Date().format('yyyy-MM-dd'))
} else if (field === 'inviteDate') {
minDate = resolveInviteDateMin(inviteDateMin, dateObj.maxDate)
maxDate = farFutureDate
} else if (field === 'deliveryDate') {
minDate = '2020-10-01'
maxDate = farFutureDate
}
const pickerIndex = index !== undefined && index !== '' ? Number(index) : 0
const scopeKey = `${field}|${minDate}|${maxDate}`
const currentValue = this.getDatePickerValue(field, pickerIndex)
this.setData(
{
datePickerConfig: {
field,
index: pickerIndex,
minDate,
maxDate,
scopeKey
}
},
() => {
wx.nextTick(() => {
const calendar = this.selectComponent('#sharedDateCalendar')
if (!calendar) return
calendar.showCalendar({ currentTarget: { dataset: { type: 'show' } } })
if (currentValue) {
calendar.resetData(currentValue)
}
})
}
)
},
/**
* 共享日历选中回调:建档日期或客户行到店/交付日期
* @param {WechatMiniprogram.CustomEvent} e detail.date
*/
onDatePickerSelect(e) {
const { date } = e.detail
const { field, index } = this.data.datePickerConfig || {}
if (field === 'createDate') {
const today = coalesceYmd(
this.data.dateObj?.maxDate,
new Date().format('yyyy-MM-dd')
)
if (!isDateOnOrBeforeToday(date, today)) {
this.showToast('建档日期不能晚于今天')
return
}
this.setTimeList(date)
return
}
if (
field === 'inviteDate' &&
!isInviteDateOnOrAfterToday(date, this.data.dateObj?.maxDate)
) {
this.showToast('到店日期不能早于今天')
return
}
const notUpgradeOrderList = this.ensureNotUpgradeOrderList()
if (field === 'deliveryDate') {
notUpgradeOrderList[index] = applyDeliveryDateToRow(
notUpgradeOrderList[index],
date,
this.formatDateShow(date)
)
} else {
notUpgradeOrderList[index][field] = date
notUpgradeOrderList[index][`${field}Show`] = this.formatDateShow(date)
if (field === 'inviteDate') {
notUpgradeOrderList[index].inviteDateManuallySet = true
}
}
this.setData({ notUpgradeOrderList }, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
})
},
dateChange(e) {
// console.log(e.)
// console.log(type)
let { type } = e.currentTarget.dataset
console.log(type)
let { dateObj } = this.data
this.calendar = this.selectComponent('#sharedDateCalendar')
if (type == 'before') {
this.setTimeList(dateObj.beforeDay)
} else {
this.setTimeList(dateObj.nextDay)
}
this.calendar.resetData(
type == 'before' ? dateObj.beforeDay : dateObj.nextDay
)
},
delBtn(e) {
let ind = e.currentTarget.dataset.ind
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
notUpgradeOrderList.splice(ind, 1)
this.setData({
notUpgradeOrderList
})
},
touchE: function (e) {
// return
// console.log(e)
var that = this
if (e.changedTouches.length == 1) {
//手指移动结束后触摸点位置的X坐标
var endX = e.changedTouches[0].clientX
//触摸开始与结束,手指移动的距离
var disX = that.data.startX - endX
// console.log(disX)
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
// console.log(list)
//更新列表的状态
that.setData({
notUpgradeOrderList
})
}
},
//手指触摸动作开始 记录起点X坐标
touchstart: function (e) {
// return
// console.log(e)
//开始触摸时 重置所有删除
const notUpgradeOrderList = this.ensureNotUpgradeOrderList()
notUpgradeOrderList.forEach(item => {
item.isTouchMove = false
item.confirmIndex = false
})
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
notUpgradeOrderList
})
},
//滑动事件处理
touchmove: function (e) {
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
// 为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
}
)
// console.log(that.data.list[index])
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) {
const payload = {
...(e.currentTarget?.dataset || {}),
...(e.detail || {})
}
let { showName, index } = payload
this.setData({
[showName]: true,
selectCustomIndex: index
})
},
/**
* 为指定客户行写入自动解析的场景字段
* @param {object} patch setData 补丁
* @param {number} index 客户行下标
* @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 { orderObj } = this.data
const customers = this.ensureNotUpgradeOrderList()
const inheritCode = orderObj?.baseSceneCode || ''
const patch = { userInfo, sceneColumns }
customers.forEach((customer, index) => {
const code = customer?.baseSceneCode || inheritCode
this.buildCustomerScenePatch(patch, index, code, sceneColumns)
})
const { scene: orderScene } = resolveAutoScene(inheritCode, sceneColumns)
if (orderScene) {
const fields = toSceneFields(orderScene)
patch['orderObj.baseSceneCode'] = fields.baseSceneCode
patch['orderObj.baseSceneName'] = fields.baseSceneName
patch['orderObj.sceneType'] = fields.sceneType
}
this.setData(patch, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
})
} catch (e) {
this.setData({
userInfo,
sceneColumns: []
})
}
},
input(e) {
let { notUpgradeOrderList } = this.data
let { value } = e.detail
let { name, index } = e.currentTarget.dataset
console.log(name, index)
if (!notUpgradeOrderList?.[index]?.customerSex) {
notUpgradeOrderList[index].customerSex = 1
}
// [`notUpgradeOrderList.${index}.${name}`]:
notUpgradeOrderList[index][name] = value
this.setData({
notUpgradeOrderList
}, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
})
},
changeGender(e) {
let { notUpgradeOrderList } = this.data
let { gender, index } = e.currentTarget.dataset
wx.vibrateShort()
notUpgradeOrderList[index]['customerSex'] = gender
this.setData({
notUpgradeOrderList
// ['orderObj.customer.customerSex']: gender
})
},
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 { type } = i.currentTarget.dataset
let { orderObj, dateObj, isCarBrand } = this.data
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
let key = this.checkRequired(orderObj)
// debugger
if (key) {
this.showToast(toastList[key])
wx.pageScrollTo({
selector: `.${key}`
})
return
}
for (let index = 0; index < notUpgradeOrderList.length; index++) {
if (!notUpgradeOrderList[index].customerName) {
return this.showToast(`请输入第${index + 1}位客户姓名`)
}
if (!notUpgradeOrderList[index].baseSceneCode) {
return this.showToast(`请选择第${index + 1}位客户场景名称`)
}
if (!phoneRex.test(notUpgradeOrderList[index].customerPhone)) {
this.showToast(`请输入第${index + 1}位客户正确的手机号`)
return
}
if (!notUpgradeOrderList[index].deliveryDate) {
return this.showToast(`请选择第${index + 1}位客户交付日期`)
}
const today = dateObj.maxDate
if (
notUpgradeOrderList[index].inviteDate &&
!isInviteDateAllowedForSubmit(notUpgradeOrderList[index], today)
) {
return this.showToast(`第${index + 1}位客户到店日期不能早于今天`)
}
if (isCarBrand && !notUpgradeOrderList[index].carSeriesName) {
return this.showToast(`请选择第${index + 1}位客户车型`)
}
// if (isStandNo && !notUpgradeOrderList[index].standNo) {
// return this.showToast(`请输入第${index + 1}位客户车架号`)
// }
}
orderObj = {
...orderObj,
// notUpgradeOrderList,
createDate: dateObj.today
}
if (type == 'success') {
orderObj.preliminaryOrders = (notUpgradeOrderList || []).map(
buildPreliminaryOrderSubmitItem
)
} else {
orderObj.notUpgradeOrderList = notUpgradeOrderList
}
this.showLoading('提交中...')
// return
const apiName =
type == 'success' ? 'createPrerecordedOrderBatch' : 'notUpgradeOrder'
// 选择车型会有数据干扰 删除参数
delete orderObj.customer
api[apiName](orderObj).then(res => {
wx.hideLoading()
// console.log(orderObj, res)
let { code, data, message } = res
if (code == 0) {
// 状态更新 需刷新工单列表和预约管理列表
wx.$util.refreshPageData()
this.showToast({
icon: 'success',
title: '提交成功'
})
// wx.$router.back()
// wx.$router.go('tabindex.index')
wx.$router.go('tabIndex.index')
// if (save) {
// wx.showModal({
// title: '温馨提示',
// content: '保存成功',
// showCancel: false,
// confirmText: '知道了',
// confirmColor: '#347BFF',
// success(_res_) {
// if (_res_.confirm) {
// wx.$router.back(page => {
// page.search && page.search()
// })
// }
// }
// })
// } else {
// wx.$refresh = true
// // wx.$router.redirectTo('confirmOrder', data)
// wx.$router.redirectTo('orderDetail', data)
// // 暂时保留跳转页面
// // wx.$router.go('confirmOrder', data)
// }
} else {
this.showToast(message)
}
})
},
checkRequired(obj) {
// 导入动态校验字段
// console.log(requiredList) ...requiredList,
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 } = this.data
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
if (phoneShow && orderObj.merchantName && orderObj.employeeName) {
// && !orderObj.customer.customerPhone
// let list = phoneShow.shopMerchantPhoneList
let phoneConfig =
phoneShow.find(item => {
item.shopMerchantId == orderObj.merchantId
}) || phoneShow.pop()
console.log(phoneConfig)
notUpgradeOrderList.forEach(item => {
item.customerPhone = item.customerPhone || phoneConfig?.phoneNumber
})
this.setData({
notUpgradeOrderList
})
}
},
/**
* 拉取商户录单配置,与 createOrder/defeatOrder 共用 carTypeRequiredFlag 驱动车型必填。
*/
getSetting() {
let { isStandNo, isCarBrand } = this.data
getYQorderInfo()
.then(merchantSettingInfo => {
if (merchantSettingInfo.carTypeRequiredFlag == 'Y') isCarBrand = true
if (merchantSettingInfo.standNoRequiredFlag == 'Y') isStandNo = true
this.setData({
isStandNo,
isCarBrand,
phoneShow: wx.$util.deepClone(merchantSettingInfo.yqPhoneConfig)
})
})
.catch(err => {
console.log(err)
})
},
init(userInfo) {
let { orderObj } = this.data
// console.log(userInfo)
// if (!orderObj.sellerMerchantName) {
orderObj.sellerMerchantName = userInfo.merchantName
orderObj.sellerMerchantId = userInfo.merchantId
orderObj.sellerName = userInfo.name
orderObj.sellerUserId = userInfo.uuid
this.setData({
orderObj
})
},
initOPtions(res) {
if (res.customerName) {
// if (query) {
// 解码
for (const key in res) {
res[key] = decodeURIComponent(res[key])
}
// options.query = query
// }
console.log(res, 'res')
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()
this.getUserSceneList()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
// this.getConfig()
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.setTimeList()
},
onRoute(res) {
console.log(res, 'onroute')
res && this.initOPtions(res)
this.getSetting()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
onUnload: () => {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {}
})