FirstStep.js
13.1 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
import constantData from "../constant/firstData";
const IMG_URL =
"https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/";
import fn from "../constant/ruleFn";
const defaultLabelWidth = "var(--fontSize140)";
import api from "~/api/api";
import newApi from "~/packageUsedCar/api";
import { validateVin, formatVinInput } from "~/utils/vinVaildate";
import Dialog from "@vant/weapp/dialog/dialog";
Component({
options: {
styleIsolation: "shared", // 自定义覆盖vant样式
},
/**
* 组件的属性列表
*/
properties: {
serviceInfo: {
type: Object,
value: () => {},
observer: function (n) {
// this.dealFormRule();
},
},
// 页面存放表单对象的对象名
dataAttrName: {
type: String,
value: null,
},
evalOrderBasicReqDTO: {
type: Object,
value: () => ({}),
},
// 是否为编辑模式
isEdit: {
type: Boolean,
value: false,
observer: function (newVal) {
// 根据 isEdit 状态设置车牌号字段的 disabled 属性
const { secondObj } = this.data;
const licensePlateField = secondObj.customerFormList.find(
(item) => item.name === "licensePlate"
);
if (licensePlateField) {
licensePlateField.disabled = newVal;
this.setData({
secondObj: secondObj,
});
}
},
},
},
lifetimes: {
attached() {
this.getEmployee();
this.getShopMerchantPointConfig();
},
},
/**
* 组件的初始数据
*/
data: {
IMG_URL,
imgShow: false,
imgType: "rule",
defaultLabelWidth,
vinValid: null,
secondObj: constantData.firstObj,
formRule: constantData.formRule,
energyFormRule: constantData.energyFormRule,
oilFormRule: constantData.oilFormRule,
extendServiceFormRule: constantData.extendServiceFormRule,
isShowObj: {
car: true,
customer: true,
product: true,
info: true,
store: true,
retrofit: true,
},
codeToAttr: {
YB0001: "invoice",
YB0003: "driveFront",
YB0004: "driveBack",
YB0002: "contract",
YB0005: "other",
QS0001: "retrofitInvoice",
QS0002: "retrofit",
},
imgToInfo: {
invoice: {
code: "YB0001",
label: "购车发票",
},
driveFront: {
code: "YB0003",
label: "行驶证主页",
},
driveBack: {
code: "YB0004",
label: "行驶证副页",
},
contract: {
code: "YB0002",
label: "合同购买时里程数",
},
other: {
code: "YB0005",
},
retrofitInvoice: {
code: "QS0001",
label: "发票或收据",
},
retrofit: {
code: "QS0002",
label: "加改装部位",
},
},
imgObj: {
invoice: [],
driveFront: [],
driveBack: [],
contract: [],
other: [],
retrofitInvoice: [],
retrofit: [],
},
popObj: {
popValue: "",
},
tireObjList: constantData.tireObjList,
retrofitInfo: {
inclueType: 1,
},
referrerPicker: false,
deliveryPicker: false,
customerInfoBox: false,
employeeList: [],
orderObj: {},
pointsMultiRole: "N",
},
/**
* 组件的方法列表
*/
methods: {
changeInclueType(e) {
const { types } = e.target.dataset;
let formData = this.getPageData();
formData.addOnsFlag = types;
this.setData({
"retrofitInfo.inclueType": types,
formData,
});
},
// 切换排量/功率
changeType(e) {
let { type, index } = e.currentTarget.dataset;
let idName = "extendService";
let childCom = this.selectComponent("#" + idName + index);
childCom.parentSetData("displacementPowerFlag", type);
this.setData({
[`serviceInfo.goodInfoList[${index}].displacementPowerFlag`]: type,
});
},
// 获取推荐人列表
getEmployee() {
let userInfo = wx.$util.getStorageSync("dj_boutique_user_info");
this.setData({
userInfo,
});
let params = {
merchantId: userInfo.default4SStoreInfo.merchantId,
};
api.getEmployeeList(params).then((res) => {
if (res.code == 0) {
this.setData({
employeeList: res.data,
});
} else {
wx.$util.showToast(res.message || "接口异常");
}
});
},
getShopMerchantPointConfig() {
let { userInfo } = this.data;
let oParams = {};
oParams.merchantId = userInfo.shopMerchantId;
api.getShopMerchantPointConfig(oParams).then((res) => {
let updateData = {
pointsMultiRole: res.data.pointsMultiRole,
};
if (res.data.pointsMultiRole != "Y") {
updateData["secondObj.customerFormList[0].label"] = "推荐人";
}
this.setData(updateData);
});
},
handleReferrerPicker() {
// 通知页面显示 picker(移到页面级别避免被 scroll-view 遮挡)
this.triggerEvent("showReferrerPicker");
// 保留原有逻辑,以防页面没有处理事件
this.setData({
referrerPicker: true,
});
},
handleDeliveryPicker() {
// 通知页面显示 picker(移到页面级别避免被 scroll-view 遮挡)
this.triggerEvent("showDeliveryPicker");
// 保留原有逻辑,以防页面没有处理事件
this.setData({
deliveryPicker: true,
});
},
onBuyNewCarChange(e) {
let thisPage = wx.$router.getPageInstance();
thisPage.setData({
["formData.carBaseReqDTO.buyNewCar"]: e.detail,
});
},
onHasAccidentChange(e) {
let thisPage = wx.$router.getPageInstance();
thisPage.setData({
["formData.carBaseReqDTO.hasAccident"]: e.detail,
});
},
handleInput(e) {
let thisPage = wx.$router.getPageInstance();
// 直接使用 e.detail.value,即使为空字符串也要使用,不能回退到 e.detail 对象
let value = e.detail.value ?? "";
// 确保 value 是字符串类型
if (typeof value !== "string") {
value = String(value || "");
}
// 限制最大长度为200字
const maxLength = 200;
if (value.length > maxLength) {
value = value.substring(0, maxLength);
}
thisPage.setData({
["formData.carBaseReqDTO.conditionDescription"]: value,
});
},
handleSalesChange(e) {
let { userInfo } = this.data;
let idx = e.detail.value || 0;
let { employeeList } = this.data;
// 安全检查
if (
!employeeList ||
!Array.isArray(employeeList) ||
employeeList.length === 0
) {
console.error("handleSalesChange: employeeList is empty or invalid");
wx.showToast({
title: "员工列表为空",
icon: "none",
});
return;
}
if (idx < 0 || idx >= employeeList.length) {
console.error(
"handleSalesChange: invalid index",
idx,
employeeList.length
);
wx.showToast({
title: "选择无效",
icon: "none",
});
return;
}
const selectedEmployee = employeeList[idx];
if (!selectedEmployee || !selectedEmployee.uuid) {
console.error(
"handleSalesChange: selectedEmployee is invalid",
selectedEmployee
);
wx.showToast({
title: "员工信息无效",
icon: "none",
});
return;
}
let thisPage = wx.$router.getPageInstance();
thisPage.setData({
["formData.evalOrderBasicReqDTO.sellerUserId"]: selectedEmployee.uuid,
["formData.evalOrderBasicReqDTO.sellerName"]:
selectedEmployee.staffName || "",
["formData.evalOrderBasicReqDTO.sellerMerchantId"]:
userInfo?.shopMerchantId || "",
["formData.evalOrderBasicReqDTO.sellerMerchantName"]:
userInfo?.shopMerchantName || "",
});
this.setData({
referrerPicker: false,
});
},
handleDeliveryChange(e) {
let idx = e.detail.value || 0;
let { employeeList } = this.data;
// 安全检查
if (
!employeeList ||
!Array.isArray(employeeList) ||
employeeList.length === 0
) {
console.error("handleDeliveryChange: employeeList is empty or invalid");
wx.showToast({
title: "员工列表为空",
icon: "none",
});
return;
}
if (idx < 0 || idx >= employeeList.length) {
console.error(
"handleDeliveryChange: invalid index",
idx,
employeeList.length
);
wx.showToast({
title: "选择无效",
icon: "none",
});
return;
}
const selectedEmployee = employeeList[idx];
if (!selectedEmployee || !selectedEmployee.uuid) {
console.error(
"handleDeliveryChange: selectedEmployee is invalid",
selectedEmployee
);
wx.showToast({
title: "员工信息无效",
icon: "none",
});
return;
}
let thisPage = wx.$router.getPageInstance();
thisPage.setData({
["formData.evalOrderBasicReqDTO.deliveryId"]: selectedEmployee.uuid,
["formData.evalOrderBasicReqDTO.deliveryName"]:
selectedEmployee.staffName || "",
});
this.setData({
deliveryPicker: false,
});
},
chooseCustomerInfo(e) {
console.log("选择客户信息", e);
this.setData({
customerInfoBox: false,
});
},
getPageData() {
let thisPage = wx.$router.getPageInstance();
return thisPage?.data[this.data.dataAttrName];
},
// 表单验证方法
validate(rules) {
const glFormComponent = this.selectComponent("#customer");
if (this.data.vinValid === false) {
return {
message: "车架号校验未通过,请重新输入",
};
}
if (!glFormComponent) {
return {
message: "表单组件未找到",
};
}
return glFormComponent.validate(rules);
},
// 表单输入事件处理
inputEvent(e) {
console.log(e, "inputEvent");
let { attr } = e.detail;
// 车架号输入处理:实时转大写 + 实时校验
if (attr == "vin") {
const thisPage = wx.$router.getPageInstance();
const { dataAttrName, serviceInfo } = this.data;
let value = serviceInfo?.vin || "";
const upperVin = formatVinInput(value);
// 更新为大写(同时更新页面数据和组件数据)
thisPage.setData({
[dataAttrName + ".vin"]: upperVin,
});
// 同步更新组件的 serviceInfo
this.setData({
"serviceInfo.vin": upperVin,
});
// 当输入满17位时,进行实时校验(防抖500ms)
if (upperVin.length === 17) {
validateVin(upperVin)
.then((res) => {
let { valid } = res.data.data;
// 保存 valid 值到组件 data 中
this.setData({
vinValid: valid,
});
})
.catch(() => {
// 校验失败时,设置为 false
this.setData({
vinValid: false,
});
});
} else {
// 长度不足17位时,重置校验状态
this.setData({
vinValid: null,
});
}
}
},
// 表单失去焦点事件处理
inputBlur(e) {
let { attr } = e.detail;
if (attr == "licensePlate") {
const { serviceInfo } = this.data;
console.log(serviceInfo, "serviceInfo");
let value = serviceInfo?.licensePlate || "";
console.log(value, "value");
newApi
.checkRepeat({
licensePlate: value,
})
.then((res) => {
console.log(res, "res");
if (res.data.code == 0) {
if (res.data.data.result == 1) {
Dialog.confirm({
context: this, // 必须指定 context 为组件实例
title: "提示",
message: "已存在相同车牌号的评估单,是否进入编辑流程?",
})
.then(() => {
// on confirm
})
.catch(() => {
// on cancel
});
} else if (res.data.data.result == 2) {
Dialog.confirm({
context: this, // 必须指定 context 为组件实例
title: "提示",
message: "已存在一个30天内有效评估,是否进入详情查看?",
})
.then(() => {
// on confirm
})
.catch(() => {
// on cancel
});
}
}
// if (res.code == 0) {
// this.setData({
// licensePlateValid: true,
// });
// }
});
}
},
},
});