serviceApply.js
11.9 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
import {
commonApi,
equityApi
} from '../../../api/api'
import dateTimePicker from './util/dateTimePicker'
Page({
/**
* 页面的初始数据
*/
data: {
dateTimeArray: [],
showAuth: false,
// 门店信息
storeInfo: {
name: '',
address: '',
kilomiter: '',
phone: ''
},
// 申请信息
applyInfo: {
carName: '',
time: [],
date: null,
address: '',
detailAddress: '',
upImageURL: ['', '', ''],
},
// 核销码
hxcode: '20049990',
// 核销码状态
codeStatus: true,
// 倒计时
expiredTime: '',
// 车辆图片信息
// carImgInfo: ['车头外观45度照片', '事故现场照片', '损失部位照片']
carImgInfo: [],
// 省市数据
provinceList: [],
// 省市弹框显示
provinceShow: false
},
// 拨打电话
callPhone(e) {
wx.makePhoneCall({
phoneNumber: e.currentTarget.dataset.item,
});
},
// 获取核销码
getHexCode(contractNo) {
clearInterval(this.data.interval)
equityApi.createdQrCode({
contractNo
}).then(res => {
const hxcode = res.writeOffCode
this.downTime(res.remainingExpire)
this.setData({
hxcode
})
})
},
// 倒计时显示时分秒
downTime(time) {
let interval = setInterval(() => {
if (time > 0) {
time = time - 1;
let result = this.secTotime(time);
this.setData({
expiredTime: result,
interval
});
} else {
this.setData({
codeStatus: false,
});
clearInterval(interval);
}
}, 1000);
},
// 将秒转化成时分秒
secTotime(time = 6) {
let str = "";
let h = parseInt((time / 60 / 60) % 24);
let m = parseInt((time / 60) % 60);
let s = parseInt(time % 60);
h = h >= 10 ? h : "0" + h;
m = m >= 10 ? m : "0" + m;
s = s >= 10 ? s : "0" + s;
if (h != "00") {
str = h + "时";
}
if (m != "00") {
str = str + m + "分";
}
if (s != "00") {
str = str + s + "秒";
}
return str;
},
// 复制核销码
setCopyData(e) {
wx.$util.setCopyData(`${e.currentTarget.dataset.item}`, () => {
wx.$util.showToast('复制成功')
})
},
// 地址选择
// bindRegionChange(e) {
// let address = e.detail.value.toString()
// address = address.replace(/,/g, "-")
// this.setData({
// "applyInfo.address": address,
// 'applyInfo.code': e.detail.code
// })
// },
toFillAdress(e) {
this.setData({
'applyInfo.detailAddress': e.detail.value
})
},
// 上传图片
toUploadImage(e) {
const imgIndex = e.currentTarget.dataset.item
let {
upImageURL
} = this.data.applyInfo
let {
carImgInfo
} = this.data
let _this = this
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
console.log(res);
const [tempFiles] = res.tempFilePaths
let imgType = tempFiles.split('.')[1]
let type = imgType == 'unknown' ? 'jpg' : imgType
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.$util.showLoading('上传中...')
commonApi.uploadImg({
file: `${type}@${_res.data}`
}).then(img => {
wx.$util.hideLoading()
carImgInfo[imgIndex].url = img
carImgInfo[imgIndex].fileType = type
// _this.data.applyInfo = []
// _this.data.applyInfo[upImageURL].push(img)
_this.setData({
carImgInfo
// [`applyInfo[${upImageURL}]`]: _this.data.upImageURL
})
})
}
})
}
})
},
// 删除图片
delUploadImage(e) {
const imgIndex = e.currentTarget.dataset.item
let {
carImgInfo
} = this.data
carImgInfo[imgIndex].url = ''
this.setData({
carImgInfo
})
},
// 实例图片预览
previewImage(e) {
const {
current
} = e.currentTarget.dataset
let urls = [current]
wx.$util.previewImage({
urls
})
},
// 表单提交
submitApply(e) {
if (!this.data.codeStatus) {
wx.showToast({
title: '申请失败,您的权益服务已到期',
icon: 'none'
})
return
}
this.submit()
},
onLoad(options) {
const query = JSON.parse(decodeURIComponent(options.param))
this.getDateBasicData(query)
this.getMerchantInfo()
this.getHexCode(query.contractNo)
this.getClaimsList(query.contractNo)
this.getPlaceList()
},
// 获取时间组件基础数据基础及处理页面传参
getDateBasicData(query) {
const dateSet = dateTimePicker.dateTimePicker('', new Date().getFullYear())
this.setData({
'applyInfo.carName': query.vehicleBrandName + query.vehicleShapeName,
dateTimeArr: dateSet.dateTimeArray,
'applyInfo.time': dateSet.dateTime,
query
})
},
// 切换时间
changeDate(e) {
let {
value
} = e.detail
let {
dateTimeArr
} = this.data
let showDate = ''
let arrDate = []
value.forEach((el, index) => {
let temp = `${dateTimeArr[index][el]}`
temp = temp.slice(0, temp.length - 1)
arrDate.push(temp)
})
showDate = arrDate[0] + '-' + arrDate[1] + '-' + arrDate[2] + ' ' + arrDate[3] + ':' + arrDate[4]
this.setData({
'applyInfo.time': value,
'applyInfo.date': showDate,
isFirst: false
})
},
// 计算距离
getDistance(source, target) {
let lat1 = source.lat || 0;
let lng1 = source.lng || 0;
let lat2 = target.lat || 0;
let lng2 = target.lng || 0;
let radLat1 = this.Rad(lat1);
let radLat2 = this.Rad(lat2);
let a = radLat1 - radLat2;
let b = this.Rad(lng1) - this.Rad(lng2);
let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * 6378.137;
s = Math.round(s * 10000) / 10000;
s = '约' + s.toFixed(2) + 'km' //保留两位小数
return s
},
Rad: function (d) { //根据经纬度判断距离
return d * Math.PI / 180.0;
},
// 计算两地距离
computeDistance() {
let {
myLocation,
target
} = this.data
if (!myLocation.lat) return
let distance = this.getDistance(myLocation, target)
this.setData({
'storeInfo.kilomiter': distance,
})
},
// 获取当前定位
getCurrentAdress() {
const address = wx.getStorageSync('address_info')
let myLocation = {}
if (address) {
Object.assign(myLocation, address.location)
}
this.setData({
myLocation
}, () => {
this.computeDistance()
})
},
/**授权失败 */
authFail() {
this.setData({
showAuth: true
})
},
/**授权成功 */
authSuccess() {
this.getLocation()
},
// /**获取当前位置 */
getLocation() {
wx.$Track.getAddressInfo().then(({
location
}) => {
let myLocation = {}
myLocation.lat = location.lat
myLocation.lng = location.lng
this.setData({
myLocation
}, () => {
this.computeDistance()
})
})
},
// 打开地图
openMap() {
const {
target,
} = this.data
wx.openLocation({
latitude: parseFloat(target.lat),
longitude: parseFloat(target.lng),
address: target.address
})
},
/**处理list[index]数据 */
handlerListIndex(arr) {
let obj = {}
arr.forEach((el, index) => {
let fileUrl = `fileList[${index}].fileUrl`
let fileType = `fileList[${index}].fileType`
let classifyId = `fileList[${index}].classifyId`
let fileCode = `fileList[${index}].fileCode`
let temp = {
[fileUrl]: el.url,
[fileType]: el.fileType,
[classifyId]: el.id,
[fileCode]: 4
}
Object.assign(obj, temp)
})
return obj
},
/***业务接口请求区域 */
getMerchantInfo() {
let merchantId = wx.$util.getStorageSync('srcm_shopmall_merchant_id')
wx.$util.showLoading('加载中...')
equityApi.getMerchantInfo({
merchantId
}).then(res => {
wx.hideLoading()
const {
lat,
lng,
merchantAddress,
merchantName,
merchantLegalPersonPhone
} = res
this.setData({
target: {
lat: lat,
lng: lng,
address: merchantAddress,
},
storeInfo: {
name: merchantName,
address: merchantAddress,
phone: merchantLegalPersonPhone
}
}, () => {
this.getCurrentAdress()
})
})
},
/**获取理赔需要上传附件列表 */
getClaimsList(contractNo) {
let arr = []
equityApi.claimsphotoList({
contractNo,
type: 1
}).then(res => {
if (res && res.length) {
res.forEach(el => {
if (el.firstClassifyName == '现场照片') {
arr = el.secondClassifyList
}
})
this.setData({
carImgInfo: arr
})
}
})
},
/**小程序提交报案 */
submit() {
const {
hxcode,
applyInfo,
carImgInfo,
query
} = this.data
if (!applyInfo.date) return wx.$util.showToast('请选择出险日期')
if (!applyInfo.code) return wx.$util.showToast('请选择出险地点')
if (!applyInfo.detailAddress) return wx.$util.showToast('请填写出险地点详细地址')
if (!carImgInfo[0].url) return wx.$util.showToast(`请选择${carImgInfo[0].secondClassifyName}`)
if (!carImgInfo[1].url) return wx.$util.showToast(`请选择${carImgInfo[1].secondClassifyName}`)
if (!carImgInfo[2].url) return wx.$util.showToast(`请选择${carImgInfo[2].secondClassifyName}`)
const nowDate = new Date().getTime()
if (new Date(applyInfo.date) > nowDate) return wx.$util.showToast('出险日期不能大于报案时间')
const file = this.handlerListIndex(carImgInfo)
let para = {
writeOffCode: hxcode,
reimbursementDate: applyInfo.date,
reimbursementProvinceCode: applyInfo.code[0],
reimbursementCityCode: applyInfo.code[1],
reimbursementCountiesCode: applyInfo.code[2],
reimbursementAddr: applyInfo.detailAddress,
...file
}
const singParams = {
vin:query.vin,
serviceItemsList:query.serviceItemsTermsList,
vehicleBrandName:query.vehicleBrandName,
vehicleSeriesName:query.vehicleSeriesName,
vehicleShapeName:query.vehicleShapeName,
merchantName:query.merchantName,
writeOffCode:hxcode,
contractNo:query.contractNo
}
let temp = encodeURIComponent(JSON.stringify(singParams))
let http = encodeURIComponent(JSON.stringify(para))
wx.navigateTo({
url: '/packageEquity/pages/signature/signature?carInfo='+temp+'&http='+http
});
// wx.$util.showLoading('提交中')
// equityApi.claimsSubmit(para).then(res => {
// wx.hideLoading();
// if (res) {
// wx.redirectTo({
// url: '/packageEquity/pages/claimsNote/claimsNote?formPage=apply&hxcode=' + hxcode + `&contractNo=${query.contractNo}`,
// });
// }
// })
},
// 获取国任省市区列表
getPlaceList() {
equityApi.areaList().then(res => {
console.log(res);
this.setData({
provinceList: res
})
})
},
// 展示省市组件
showProvince() {
this.setData({
provinceShow: true
})
},
// 取消省市弹框
cancelProvince() {
this.setData({
provinceShow: false
})
},
// 获取选择的省市code
getProvinceCode(val) {
let address = val.detail.provinceNameData.toString()
address = address.replace(/,/g, "-")
this.setData({
'applyInfo.code': val.detail.codeData,
"applyInfo.address": address
})
}
})