serviceInfo.js
15.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
// packageEquity/pages/carEquity/serviceInfo/serviceInfo.js
import carLifeApi from '../../../carEquityApi'
import secondStepData from '../components/constant/secondStepData'
import constantData from '../components/constant/constantList'
const sussObj = {
type: 'success',
title: '提单成功',
tipTxt: '- 提单合同支持分享或保存 -',
btnTxt: '查看合同'
}
const errorObj = {
type: 'error',
title: '出单失败',
tipTxt: '',
btnTxt: '重新提单'
}
const warningObj = {
type: 'warning',
title: '信息确认',
tipTxt: '',
btnTxt: '继续出单'
}
Page({
/**
* 页面的初始数据
*/
data: {
userInfo: {},
serviceInfo: {
seatesNum: 5,
servicePeriod: '1'
},
// 二次确认车架号
conSecondObj: {
vin: ''
},
// 页面存放表单对象的对象名
dataAttrName: 'serviceInfo',
// step: 'first',
step: '',
routeInfo: {},
contractNo: '',
url: '',
isBack: false,
apiObj: {
detail: 'getEquityDetail',
handler: 'getEquityHandler'
},
tireObjList: secondStepData.tireObjList,
// 弹窗
isDialogShow: false,
dialogObj: {},
scrollTop: 0,
cardSetting: true,
isAsk: false,
// vin二次确认弹窗
showVinDialog: false,
secFormData: {},
tempVin: '',
e: {}
},
getPickerObj(obj) {
let data = []
if (!obj) {
return data
}
obj.forEach(item => {
if (item.type == 'select') {
data.push(item)
}
})
return data
},
dealData(obj) {
if (!obj) {
return {}
}
/** 默认值
* customerType 客户类型 个人 1
* buyCarType 购车类型 全款车 1
* 第一受益人 默认 客户姓名
*/
if (!obj.customerType) {
obj.customerType = 1
}
if (typeof obj.buyCarType != 'number') {
obj.buyCarType = 1
}
if (!obj.compensationName) {
obj.compensationName = obj.customerName
}
// 金额处理,分-元
let pricelist = ['invoicePrice']
pricelist.forEach(item => {
if (obj[item]) {
obj[item] = (obj[item] / 100).toFixed(2)
}
})
// 商品服务费,分-元
let priceList = ['actualSalesPrice']
obj.goodInfoList.forEach((item, idx) => {
priceList.forEach(k => {
obj.goodInfoList[idx][k] = item[k] === null ? null : (item[k] / 100).toFixed(2)
})
if (item.vehicleRegistrationDate) {
item.vehicleRegistrationDate = new Date(item.vehicleRegistrationDate).format('yyyy-MM-dd')
}
if (item.buyDate) {
item.buyDate = new Date(item.buyDate).format('yyyy-MM-dd')
}
if (item.qualityBeginDate) {
item.qualityBeginDate = new Date(item.qualityBeginDate).format('yyyy-MM-dd')
}
if (item.itemsCode == 'YB0003') {
item.gearbox = item.gearbox || ''
item.vehicleNature = typeof item.vehicleNature == 'number' ? item.vehicleNature : 1
let val = constantData.vehicleNatureList.find(k => k.optionId == item.vehicleNature)
if (val) {
item.vehicleNatureName = val.optionLabel
}
}
})
// picker-label处理
let pickerList = []
Object.keys(secondStepData.secondObj).forEach(item => {
let target = secondStepData.secondObj[item]
pickerList = pickerList.concat(this.getPickerObj(target))
})
pickerList.forEach(item => {
if (item.optionList.length) {
let val = item.optionList.find(k => k[item.optionId] == obj[item.name])
if (val) {
obj[item.labelName] = val[item.optionLabel]
}
}
})
// 时间处理
let timeList = ['billingDate', 'effectiveDate']
timeList.forEach(item => {
switch (item) {
case 'billingDate':
obj[item] = obj[item] ? new Date(obj[item]).format('yyyy-MM-dd') : new Date().format('yyyy-MM-dd')
break
case 'effectiveDate':
let nextDay = new Date(new Date().setDate(new Date().getDate() + 1))
if (obj[item] && obj[item] > nextDay) {
obj[item] = new Date(obj[item]).format('yyyy-MM-dd')
} else {
obj[item] = nextDay.format('yyyy-MM-dd')
}
break
default:
if (obj[item]) {
obj[item] = new Date(obj[item]).format('yyyy-MM-dd')
}
break
}
})
return obj
},
dealTireObj() {
let { tireObjList, serviceInfo } = this.data
if (serviceInfo?.attributeList) {
serviceInfo?.attributeList.forEach((item, idx) => {
if (item.attributeValue) {
serviceInfo[tireObjList[idx].attr] = item.attributeValue
}
})
this.setData({
serviceInfo
})
}
},
getDetail() {
let { routeInfo, apiObj } = this.data
if (!routeInfo?.apiName) {
return
}
if (routeInfo?.apiName == 'detail' && !routeInfo?.contractNo) {
wx.$util.showToast('合同号有误,请重新选择')
}
if (routeInfo?.apiName == 'handler' && !routeInfo?.orderId) {
wx.$util.showToast('订单号有误,请重新选择')
}
let params = {
contractNo: this.data.routeInfo.contractNo,
orderId: this.data.routeInfo.orderId
}
carLifeApi[apiObj[routeInfo?.apiName]](params).then(res => {
if (res.code == 0) {
let data = this.dealData(res.data)
// console.log(object);
if (data.goodId) {
// 权益卡
this.getInterestCardSetting(data.goodId)
}
// data.attachmentList = data.attachmentList
data?.goodInfoList?.forEach(val => {
if (val.printType == 2 && !['YB0001', 'YB0002', 'YB0003'].includes(val.itemsCode)) val.displacementPowerFlag = val.displacementPowerFlag || 0 // 默认是选中排量
})
// 判断购买商品是否全部是延保allWarrantyFlag
const allWarrantyFlag = data?.goodInfoList?.some(v => v.printType != 2)
this.setData({
serviceInfo: data,
['serviceInfo.attachmentList']:data?.attachmentList||[],
['serviceInfo.allWarrantyFlag']: !allWarrantyFlag ? 1 : 0, // 0 显示生效日期 1不显示
step: data.mode ? 'second' : 'first'
})
this.dealTireObj()
} else {
wx.$util.showToast(res.message || '接口异常')
}
})
},
getInterestCardSetting(id) {
// 是否要新增实体卡 字段 Y要 N不要
carLifeApi.goodsInfoGetDetailById({ id }).then(res => {
console.log('res', res)
// this.setData({
// cardSetting:false
// })
let { code, data } = res
console.log(data, 'data')
if (res.code == 0) {
const entityCardFlag = data.upgradeGoods.entityCardFlag
console.log(entityCardFlag, 'entityCardFlag')
entityCardFlag != 'Y' &&
this.setData({
cardSetting: false
})
// let data = res.data[0]
// this.setData({
// 'serviceInfo.interestCardSetting':data.interestCardSetting
// })
}
})
},
// ocr图片识别
reWrite(type, data) {
console.log(type, data)
let { serviceInfo } = this.data
if (type == 'vehicleCertificate') {
let { vinNo: vin, seatingCapacity: seatesNum, engineNo: engineNo, carColor: vehicleColor } = data
serviceInfo = Object.assign(serviceInfo, {
vin,
seatesNum,
engineNo,
vehicleColor
})
}
if (type == 'idCard') {
let { name: customerName, address: customerAddress, cardNo: cardNo } = data
serviceInfo = Object.assign(serviceInfo, {
customerName,
customerAddress,
cardNo,
customerType: 1,
customerTypeName: '个人'
})
console.log(serviceInfo, 'serviceInfo')
}
this.setData({
serviceInfo
})
},
handleFirstConfirm(e) {
this.setData({
step: 'second'
})
wx.setNavigationBarTitle({
title: '服务信息确认'
})
},
dealComfirmData(obj) {
if (!obj) {
return {}
}
// 金额处理,分-元
let pricelist = ['invoicePrice']
pricelist.forEach(item => {
if (obj[item]) {
obj[item] = (obj[item] * 100).toFixed(0)
}
})
// 商品服务费,分-元
let priceList = ['actualSalesPrice']
obj.goodInfoList.forEach((item, idx) => {
priceList.forEach(k => {
obj.goodInfoList[idx][k] = (item[k] === null || item[k] === '') ? null : (item[k] * 100).toFixed(0)
})
})
return obj
},
confirm(e) {
var typeObj = {
draft: 0,
confirm: 1
}
let _this = this
let { serviceInfo, isAsk } = this.data
if (isAsk) {
return true
}
let type = e.detail?.type || 'draft'
let params = this.dealComfirmData(JSON.parse(JSON.stringify(serviceInfo)))
// 0草稿,1提单
params.operationType = typeObj[type]
params.addOnsFlag = serviceInfo.addOnsFlag==2?0:1
if (params?.allWarrantyFlag == 1) { // 全部为延保商品 不传生效日期
delete params.effectiveDate
}
delete params.allWarrantyFlag
console.log(params, '调接口---')
this.setData({
isAsk: true
})
// return
carLifeApi.updateEquity(params).then(res => {
if (res.code == '0') {
if (type == 'confirm') {
this.setData({
dialogObj: JSON.parse(JSON.stringify(sussObj)),
isDialogShow: true,
contractNo: res.data[0].contractNo,
contractNoList: res.data
})
} else {
// wx.$router.reLaunch('packageEquity.equityPage')
wx.$router.reLaunch('packageEquity.equityPage', { tabIndex: 2 })
}
} else {
wx.$util.showToast(res.message || '接口异常')
}
}).finally(() => {
_this.setData({
isAsk: false
})
})
},
// 错误跳转
handleErrorJump(e) {
let { height } = e.detail
this.setData({
scrollTop: height // 滚动到的位置(距离顶部 px)
})
},
secondChange() {
let { showVinDialog } = this.data
this.setData({
showVinDialog: !showVinDialog
})
},
handleSecClose() {
let { tempVin } = this.data
this.setData({
secFormData: {
carVin: ''
},
isAsk: false
})
if (tempVin) {
this.setData({
['serviceInfo.vin']: tempVin,
tempVin: ''
})
}
this.secondChange()
},
handleSecConfirm(e) {
let { detail } = e
this.setData({
['serviceInfo.vin']: detail.carVin,
tempVin: detail.carVin
})
this.api()
},
api() {
let { serviceInfo, conSecondObj, isAsk, e } = this.data
this.setData({
isAsk: true
})
carLifeApi
.checkVin({
vin: serviceInfo.vin
})
.then(res => {
this.setData({
isAsk: false
})
if (res.code == '0') {
this.confirm(e)
} else if (res.code == '-2') {
if (conSecondObj.vin == serviceInfo.vin) {
this.confirm(e)
this.setData({
['conSecondObj.vin']: '',
e: {}
})
} else {
this.setData({
['conSecondObj.vin']: serviceInfo.vin,
dialogObj: res?.message?.includes('该车架已经购买过') ? JSON.parse(JSON.stringify(warningObj)) : JSON.parse(JSON.stringify(errorObj)),
['dialogObj.tipTxt']: res.message,
isDialogShow: true,
e: {}
})
}
} else {
this.setData({
dialogObj: res?.message?.includes('该车架已经购买过') ? JSON.parse(JSON.stringify(warningObj)) : JSON.parse(JSON.stringify(errorObj)),
['dialogObj.tipTxt']: res.message,
isDialogShow: true,
e: {}
})
wx.$util.showToast(res.message || '接口异常')
}
})
},
handleSecondConfirm(e) {
console.log(e)
let { serviceInfo, conSecondObj, isAsk, noCheckVinFlag } = this.data
if (isAsk) {
return true
}
if (e.detail?.type == 'confirm') {
// 校验过车架号重复后,不再做确认,直接提交表单
if (noCheckVinFlag) return this.confirm(e)
this.setData({
secFormData: {
carVin: serviceInfo.vin
},
e: e
})
this.secondChange()
} else {
this.confirm(e)
}
},
handleTipClick(e) {
let { type } = e.currentTarget.dataset
if (type == 'success') {
let { contractNoList } = this.data
contractNoList.length == 1 ? this.getUrl() : wx.$router.redirectTo('previewList', { list: contractNoList })
// this.getUrl()
return true
}
let params = {
detail: {
type: 'confirm'
}
}
this.handleSecondConfirm(params)
},
handleTipClose(e) {
// let { type } = e.currentTarget.dataset
// if (type == 'success') {
// this.getUrl()
// return true
// }
this.setData({
isDialogShow: false
})
if (e.detail?.type == 'warning') return this.setData({noCheckVinFlag: true})
wx.$router.reLaunch('packageEquity.equityPage', { tabIndex: 2 })
},
// 合同地址
getUrl() {
wx.$util.showLoading('加载中...')
let params = {
contractNo: this.data.contractNo
}
carLifeApi.printContract(params).then(res => {
console.log(res)
wx.hideLoading()
if (res.code == '0') {
this.setData({
url: res.data
})
this.handleDownload()
console.log(this.data.url)
} else {
wx.$util.showToast(res.message || '接口异常')
}
})
},
handleDownload() {
let { url } = this.data
let _this = this
if (!url) {
wx.$util.showToast('没有合同')
return
}
wx.downloadFile({
// 示例 url,并非真实存在
url: url,
success: function (res) {
const manage = wx.getFileSystemManager()
let file = url.split('/')
let fileName = file[file.length - 1]
manage.saveFile({
tempFilePath: res.tempFilePath,
filePath: wx.env.USER_DATA_PATH + '/' + fileName,
success: function (res) {
wx.openDocument({
filePath: wx.env.USER_DATA_PATH + '/' + fileName,
fileType: 'pdf',
showMenu: true,
success: function (res) {
console.log('打开文档成功')
_this.setData({
isBack: true
})
}
})
}
})
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options, 'options')
this.setData({
userInfo: wx.$util.getStorageSync('dj_boutique_user_info')
})
//删---start
// this.setData({
// routeInfo: options
// })
// this.getDetail()
//删---end
// wx.$router.getData(res => {
// this.setData({
// routeInfo: res
// })
// console.log(this.data.routeInfo)
// this.getDetail()
// })
},
onRoute(options) {
console.log(options)
this.setData({
routeInfo: options
})
this.getDetail()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() { },
/**
* 生命周期函数--监听页面显示
*/
onShow() {
let { isBack } = this.data
if (isBack) {
wx.$router.reLaunch('packageEquity.equityPage', { tabIndex: 2 })
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() { },
/**
* 生命周期函数--监听页面卸载
*/
onUnload() { },
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() { },
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() { },
/**
* 用户点击右上角分享
*/
onShareAppMessage() { }
})