FirstStep.js
19.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
// packageEquity/pages/carEquity/components/FirstStep/FirstStep.js
import data from '../constant/stepData'
import fn from '../constant/ruleFn'
import carLifeApi from '~/packageEquity/carEquityApi'
import commonApi from '~/api/api'
const defaultLabelWidth = 'var(--fontSize140)'
import Util from '~/utils/util'
import { validateVin, formatVinInput } from '~/utils/vinVaildate'
import { ImgUrl } from '~/config'
var timeUtil = require('~/utils/timeFormat/time-utils.js')
import {
EQUITY_CUSTOMER_TAGS,
formatEquityCustomerTags,
formatEquityDeliveryDateForDisplay,
isEquityActualDeliveryDateMissing,
isEquityActualDeliveryDateVisible,
parseEquityCustomerTags,
reconcileEquityCustomerDailyFields,
serializeEquityCustomerTags
} from '../../services/customerDailyFields.helpers.js'
const IMG_URL = ImgUrl + '/'
// import api from '~/api/api'
Component({
options: {
styleIsolation: 'apply-shared'
},
/**
* 组件的属性列表
*/
properties: {
serviceInfo: {
type: Object,
observer: function (n) {
const orderInfo = this.properties.orderInfo || {}
this.setData({
formData: n,
customerTagsText: formatEquityCustomerTags(n?.customerTags),
actualDeliveryDateText: formatEquityDeliveryDateForDisplay(
n?.actualDeliveryDate
),
dailyFieldVisibility: {
actualDeliveryDate: isEquityActualDeliveryDateVisible({
salesType: n?.salesType,
baseSceneName: orderInfo.baseSceneName,
baseSceneCode: orderInfo.baseSceneCode
})
}
})
}
},
orderInfo: {
type: Object,
observer: function (n) {
if (n?.modifyEquityQuotation) {
this.setData({
// activeNames: ['3'],
disable: true
})
} else {
this.setData({
disable: false
})
}
const owner = this.properties.serviceInfo || {}
this.setData({
dailyFieldVisibility: {
actualDeliveryDate: isEquityActualDeliveryDateVisible({
salesType: owner.salesType,
baseSceneName: n?.baseSceneName,
baseSceneCode: n?.baseSceneCode
})
}
})
}
},
// 页面存放表单对象的对象名
dataAttrName: {
type: String,
value: null
},
subBtnShow: {
type: Boolean,
value: true
},
mode: {
type: Number,
value: 1
}
},
observers: {
'mode': function (value, old) {
console.log(value, old, 'mode');
if (value != 1) {
this.setData({
first: data.firstObj,
formRule: data.formRule
})
}
}
// 'orderInfo.outTradeNo': function (value) {
// console.log(value, 'outTradeNo')
// value && this.setData({
// textNameObj: {
// confirmName: '下一步(1/4)'
// // cancelName: '存草稿'
// }
// })
// }
},
/**
* 组件的初始数据
*/
data: {
IMG_URL,
defaultLabelWidth,
formData: {},
employeeList: [],
disable: true,
first: '',
formRule: '',
// first: data.firstObjSimple,
// formRule: data.formRuleSimple,
referrerPicker: false,
deliveryPicker:false,
textNameObj: {
confirmName: '下一步(1/4)',
cancelName: '存草稿'
},
vinValid: true,
createAllGoodsFlag: 1,
showSceneSelect: false,
sceneColumns: [],
sceneDefaultIndex: 0,
equityCustomerTagOptions: EQUITY_CUSTOMER_TAGS,
equityCustomerTagDraftOptions: [],
equityCustomerTagsPopup: false,
customerTagsText: '',
actualDeliveryDateText: '',
actualDeliveryDateMax: timeUtil.getTodayDateStr(),
dailyFieldVisibility: {
actualDeliveryDate: false
}
},
lifetimes: {
async attached() {
// 会员权益简版 mode=1:observer 只在 mode!=1 时注入 first/formRule,这里补上否则校验规则为空、客户来源等不生效
if (this.properties.mode == 1) {
this.setData({
first: data.firstObjSimple,
formRule: data.formRuleSimple
})
}
this.getEmployee()
this.getShopMerchantPointConfig()
await this.prefillRecentScene()
this.getUserSceneList()
// 没有才走获取档案接口逻辑修改配置,有是必填优先及更高
// 在createOrderCarQuotationSimple 页面做逻辑判断
// this.getYqStoreConfig()
}
},
/**
* 组件的方法列表
*/
methods: {
/**
* 一次性应用父页面生成的必填配置,再按需读取园区档案互通配置。
* 父页面不直接 setData,避免组件处于 first/formRule 的中间状态。
*
* @param {{first:object,formRule:object,shouldLoadStoreConfig?:boolean}} config 表单配置
* @returns {Promise<void>} 配置与可选门店档案加载完成
*/
async applyFormConfig(config = {}) {
this.setData({
first: config.first,
formRule: config.formRule
})
if (config.shouldLoadStoreConfig) await this.getYqStoreConfig()
},
syncEquityCustomerDailyFields(owner, sceneContext = this.properties.orderInfo || {}) {
const nextOwner = reconcileEquityCustomerDailyFields(
owner || this.properties.serviceInfo || {},
{
baseSceneName: sceneContext.baseSceneName,
baseSceneCode: sceneContext.baseSceneCode
}
)
this.triggerEvent('ownerChange', { patch: nextOwner })
this.setData({
customerTagsText: formatEquityCustomerTags(nextOwner.customerTags),
actualDeliveryDateText: formatEquityDeliveryDateForDisplay(
nextOwner.actualDeliveryDate
),
dailyFieldVisibility: {
actualDeliveryDate: isEquityActualDeliveryDateVisible({
salesType: nextOwner.salesType,
baseSceneName: sceneContext.baseSceneName,
baseSceneCode: sceneContext.baseSceneCode
})
}
})
},
handlePickerChange(e) {
if (e.detail?.attr !== 'salesType') return
this.syncEquityCustomerDailyFields(this.properties.serviceInfo)
},
openEquityCustomerTagsPopup() {
if (this.data.disable) return
const selected = new Set(
parseEquityCustomerTags(this.properties.serviceInfo?.customerTags)
)
this.setData({
equityCustomerTagsPopup: true,
equityCustomerTagDraftOptions: EQUITY_CUSTOMER_TAGS.map(item => ({
...item,
checked: selected.has(item.value)
}))
})
},
onToggleEquityCustomerTag(e) {
const index = Number(e.currentTarget.dataset.index)
this.setData({
equityCustomerTagDraftOptions: (
this.data.equityCustomerTagDraftOptions || []
).map((item, itemIndex) =>
itemIndex === index ? { ...item, checked: !item.checked } : item
)
})
},
onCancelEquityCustomerTags() {
this.setData({ equityCustomerTagsPopup: false })
},
onConfirmEquityCustomerTags() {
const customerTags = serializeEquityCustomerTags(
(this.data.equityCustomerTagDraftOptions || [])
.filter(item => item.checked)
.map(item => item.value)
)
this.setData({ equityCustomerTagsPopup: false })
this.syncEquityCustomerDailyFields({
...(this.properties.serviceInfo || {}),
customerTags
})
},
onEquityDeliveryDateChange(e) {
if (this.data.disable) return
this.syncEquityCustomerDailyFields({
...(this.properties.serviceInfo || {}),
actualDeliveryDate: e.detail.value || ''
})
},
async prefillRecentScene(options = {}) {
const {
refreshGoods = true,
resolveName = false,
onResolved
} = options || {}
const userInfo = wx.$util.getUserInfo() || {}
const orderInfo = this.properties.orderInfo || {}
if (orderInfo?.baseSceneCode) return
try {
const res = await commonApi.getRecentUserScene({
sceneType: String(userInfo.sceneType ?? ''),
phone: userInfo.phone
})
const recent = res?.code == 0 ? res?.data : null
const baseSceneCode = recent?.baseSceneCode || ''
if (!baseSceneCode) return
const sceneContext = {
...orderInfo,
baseSceneCode,
sceneType: recent?.sceneType
}
this.triggerEvent('orderChange', {
patch: {
baseSceneCode,
sceneType: recent?.sceneType
}
})
if (resolveName) this.getUserSceneList()
this.syncEquityCustomerDailyFields(this.properties.serviceInfo, sceneContext)
if (refreshGoods) {
this.triggerEvent('resetGoodsRequested', { reason: 'recent-scene' })
}
if (typeof onResolved === 'function') onResolved(baseSceneCode, recent)
} catch (error) {
console.warn('最近使用场景回填失败', error)
}
},
getUserSceneList() {
const userInfo = wx.$util.getUserInfo() || {}
commonApi
.getUserScene({
sceneType: String(userInfo.sceneType ?? ''),
phone: userInfo.phone,
merchantId: userInfo.shopMerchantId || ''
})
.then(res => {
const list = res?.code == 0 && res?.data?.length ? res.data : []
const sceneColumns = list.map(item => ({
...item,
name: item.name || item.staffName
}))
const orderInfo = this.properties.orderInfo || {}
const code = orderInfo?.baseSceneCode || ''
const idx = code
? sceneColumns.findIndex(s => s.baseSceneCode == code)
: 0
const currentScene = code && idx >= 0 ? sceneColumns[idx] : null
this.setData({
sceneColumns,
sceneDefaultIndex: idx >= 0 ? idx : 0
})
if (currentScene) {
const patch = {
baseSceneName: currentScene.name || '',
sceneType: currentScene.sceneType
}
this.triggerEvent('orderChange', { patch })
this.syncEquityCustomerDailyFields(this.properties.serviceInfo, {
...orderInfo,
...patch
})
}
})
.catch(() => {
this.setData({
sceneColumns: []
})
})
},
onCloseSceneSelect() {
this.setData({
showSceneSelect: false
})
},
onConfirmSceneSelect(e) {
const scene = e.detail.value || {}
const userInfo = wx.$util.getUserInfo() || {}
const orderInfo = this.properties.orderInfo || {}
const prevCode = orderInfo.baseSceneCode || ''
const nextCode = scene.baseSceneCode || ''
const selectedScene = {
...scene,
baseSceneCode: nextCode,
baseSceneName: scene.name || scene.staffName || ''
}
this.triggerEvent('sceneChange', {
previousCode: prevCode,
scene: selectedScene
})
this.syncEquityCustomerDailyFields(this.properties.serviceInfo, {
...orderInfo,
...selectedScene
})
scene.baseSceneCode &&
commonApi
.saveUserScene({
baseSceneCode: scene.baseSceneCode,
sceneType: userInfo.sceneType,
phone: userInfo.phone
})
.catch(() => {})
this.setData({
showSceneSelect: false
})
},
handleScenePicker() {
const orderInfo = this.properties.orderInfo || {}
if (orderInfo.resetOrder) {
wx.$util.showToast('场景名称不能修改')
return
}
this.getUserSceneList()
this.setData({
showSceneSelect: true
})
},
getShopMerchantPointConfig() {
console.log(1111111111)
let { userInfo } = this.data
let oParams = {}
oParams.merchantId = userInfo.shopMerchantId
commonApi.getShopMerchantPointConfig(oParams).then(res => {
const { pointsMultiRole, createAllGoodsFlag } = res.data
this.setData({
pointsMultiRole,
createAllGoodsFlag
})
// 触发事件通知父页面更新配置
this.triggerEvent('updateConfig', {
createAllGoodsFlag
})
})
},
// 推荐人
// handleSalesChange(e) {
// let idx = e.detail.value || 0
// this.setData({
// 'formData.referrerId': this.data.employeeList[idx].uuid,
// 'formData.referrer': this.data.employeeList[idx].staffName
// })
// },
inputEvent(e) {
let {
attr
} = e.detail
// 车架号输入处理:实时转大写 + 实时校验
if (attr == 'carVin') {
const value = e.detail.value || ''
const upperVin = formatVinInput(value)
this.triggerEvent('ownerChange', { patch: { carVin: upperVin } })
// 当输入满17位时,进行实时校验(防抖500ms)
if (upperVin.length === 17) {
validateVin(upperVin).then(res => {
let { valid } = res.data.data;
console.log("upperVinRes",valid);
// 保存 valid 值到组件 data 中
this.setData({
vinValid: valid
});
}).catch(() => {
console.log("upperVinErr",upperVin);
})
}
}
// 是车价就重新筛选商品列表
if (attr == 'price') {
this.triggerEvent('resetGoodsRequested', { reason: 'vehicle-price' })
}
},
handleReferrerPicker() {
this.setData({
referrerPicker: true
})
},
handleDeliveryPicker() {
this.setData({
deliveryPicker: true
})
},
handleSalesChange(e) {
// let value = e.detail
console.log(e)
let idx = e.detail.value || 0
let {
employeeList,
disable
} = this.data
if (disable) return false
this.triggerEvent('orderChange', {
patch: {
referrerId: employeeList[idx].uuid,
referrer: employeeList[idx].staffName
}
})
},
handleDeliveryChange(e) {
// let value = e.detail
let idx = e.detail.value || 0
let {
employeeList,
disable
} = this.data
if (disable) return false
this.triggerEvent('orderChange', {
patch: {
deliveryId: employeeList[idx].uuid,
deliveryName: employeeList[idx].staffName
}
})
},
// 获取推荐人列表
getEmployee() {
let userInfo = wx.$util.getStorageSync('dj_boutique_user_info')
this.setData({
userInfo
})
let params = {
merchantId: userInfo.default4SStoreInfo.merchantId
}
carLifeApi.getEmployeeList(params).then(res => {
if (res.code == 0) {
this.setData({
employeeList: res.data
})
} else {
wx.$util.showToast(res.message || '接口异常')
}
})
},
navOcr(e) {
// idCard:1,
// vehicleCertificate:5
let {
type
} = e.currentTarget.dataset
console.log(type)
// wx.$router.go('ocrEquityModules', { type })
wx.$router.go(`ocrEquityModules?type=${type}`)
},
btnTap(e) {
// console.log(e)
let {
name
} = e.detail
if (name == 'confirm') {
// this.triggerEvent('confirm')
// 需要校验
this.handleConfirm()
} else {
this.triggerEvent('editSave')
}
},
handleConfirm() {
var {
dataAttrName,
formRule,
pointsMultiRole,
vinValid,
dailyFieldVisibility
} = this.data
const orderInfo = this.properties.orderInfo || {}
const owner = this.properties.serviceInfo || {}
if (!orderInfo.referrerId) {
wx.$util.showToast(pointsMultiRole=='Y'?'请选择销售顾问/录单员':'请选择推荐人')
return false
}
if (!orderInfo.baseSceneCode) {
wx.$util.showToast('请选择场景名称')
return false
}
if(pointsMultiRole=='Y'){
if (!orderInfo.deliveryId) {
wx.$util.showToast('请选择交付专员')
return false
}
if(orderInfo.deliveryId==orderInfo.referrerId){
wx.$util.showToast('销售顾问/录单员与交付专员不能选取同一人')
return false
}
}
// 车架号校验
const carVin = owner.carVin
if (carVin) {
const isCarVinRequired = formRule?.carVin?.some(rule => rule.required === true) // 再次判断一下车架号是否必填项
// 前置判断
if (carVin.length !== 17 && isCarVinRequired) {
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 (
isEquityActualDeliveryDateMissing(
dailyFieldVisibility.actualDeliveryDate,
owner.actualDeliveryDate
)
) {
wx.$util.showToast('实际交付日期不能为空')
return false
}
let validObj = fn.checkRequired(owner, formRule)
if (validObj) {
wx.$util.showToast(validObj.message)
return false
}
// debugger
this.triggerEvent('confirm')
return true
},
showCustomPop() {
this.setData({
customerInfoBox: true
})
},
chooseCustomerInfo(e) {
console.log(e)
let {
customer
} = e.detail
this.triggerEvent('customerSelected', { customer })
this.setData({ customerInfoBox: false })
},
onCustomerInfoCancel() {
this.setData({ customerInfoBox: false })
},
changeGender(e) {
let {
gender
} = e.currentTarget.dataset
wx.vibrateShort()
this.triggerEvent('ownerChange', { patch: { ownerGender: gender } })
},
bindRegionChange(e) {
const { values } = e.detail.detail
let city = Array.from(new Set([...values.map(e => e.name)]))
this.triggerEvent('ownerChange', { patch: { city: city.join('-') } })
},
// 品牌车型
handleJumpBrand(e) {
// wx.$router.go('packageEquity.carBrands')
this.setData({
showCarBrands: true, // 选择时再加载车型组件
carBrandBox: true
})
},
chooseCar(e) {
let { carBrand, carBrandId, carChildsBrandId, carChildsBrandName, carSeriesId, carSeriesName } = e.detail
this.triggerEvent('ownerChange', {
patch: {
carBrand,
carBrandId,
carChildsBrandId,
carChildsBrandName,
carSeriesId,
carSeriesName
}
})
if (carSeriesId) {
this.triggerEvent('resetGoodsRequested', { reason: 'vehicle-series' })
}
},
/**获取园区配置 */
async getYqStoreConfig() {
const {
merchantId: yqMerchantId
} = wx.$util.getUserInfo(), {
first
} = this.data, {
data
} = await commonApi.getYqStoreConfig({
yqMerchantId
})
let {
customerFormList,
carFormList
} = first
//是否配置园区店面档案互通 Y / N
if (data) {
if (data.customerExchangeFlag == 'N') {
customerFormList = customerFormList?.filter(item => !item.configItem)
carFormList = carFormList?.filter(item => !item.configItem)
}
}
this.setData({
['first.customerFormList']: customerFormList,
['first.carFormList']: carFormList,
showCustomeBtn: data.customerExchangeFlag == 'Y'
})
},
}
})