SecondStep.js
9.52 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
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: () => ({}),
},
},
lifetimes: {},
/**
* 组件的初始数据
*/
data: {
IMG_URL,
imgShow: false,
imgType: "rule",
defaultLabelWidth,
vinValid: null,
secondObj: constantData.licenseObj,
formRule: constantData.formRule,
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 || "接口异常");
}
});
},
handleReferrerPicker() {
this.setData({
referrerPicker: true,
});
},
handleDeliveryPicker() {
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();
let value = e.detail.value || e.detail;
thisPage.setData({
["formData.carBaseReqDTO.conditionDescription"]: value,
});
},
// 处理原车主住址输入
handleAddressInput(e) {
let thisPage = wx.$router.getPageInstance();
// 直接使用 e.detail.value,避免空字符串回退到 e.detail 对象
let value = e.detail.value ?? "";
// 限制最大长度为52字
const maxLength = 52;
if (value.length > maxLength) {
value = value.substring(0, maxLength);
}
const { dataAttrName } = this.data;
thisPage.setData({
[dataAttrName + ".previousOwnerAddress"]: value,
});
// 同步更新组件的 serviceInfo
this.setData({
"serviceInfo.previousOwnerAddress": value,
});
},
handleSalesChange(e) {
let idx = e.detail.value || 0;
let { employeeList } = this.data;
let thisPage = wx.$router.getPageInstance();
thisPage.setData({
["formData.evalOrderBasicReqDTO.sellerUserId"]: employeeList[idx].uuid,
["formData.evalOrderBasicReqDTO.sellerName"]:
employeeList[idx].staffName,
});
this.setData({
referrerPicker: false,
});
},
handleDeliveryChange(e) {
let idx = e.detail.value || 0;
let { employeeList } = this.data;
let thisPage = wx.$router.getPageInstance();
thisPage.setData({
["formData.evalOrderBasicReqDTO.deliveryId"]: employeeList[idx].uuid,
["formData.evalOrderBasicReqDTO.deliveryName"]:
employeeList[idx].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) {
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,
// });
// }
});
}
},
},
});