addListDetail.js
22.7 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
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
// pages/addListDetail/addListDetail.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
recognizee: ['被保人', '被保人2'],
recognizee_index: 0,
period_time: ['10年', '20年'],
period_index: -1,
compact_time: '',
impletion_time: '',
popup_state: false,
projectlist: [],
label_state: false,
insure: ['投保人', '投保人2'],
insureindex: -1,
beneficiary_list: [{
name: ['受益人1', '受益人2'],
unit: ''
}],
tempfavoree: [],
beneficiaryindex: -1,
beneficiary_name: '',
imgs: [],
main_risk: [],
unit: '',
unit2: '',
unit3: '',
unit4: '',
applicant_name: '',
recognizee_name: '',
rang_beneficiary: [],
risk_list: [{
name: '',
projectlist: [],
project_time: ''
}],
main_array: [],
warranty_one: [],
warranty_two: [],
guarantee_name: '',
long_money: [],
time_name: '',
type_money: '',
},
//投保人
insureSelect(e) {
var insure = this.data.insure
this.setData({
insureindex: e.detail.value,
applicant_name: insure[e.detail.value]
})
},
//选择被保险人
recognizeeSelect(e) {
var recognizee = this.data.recognizee
this.setData({
recognizeeindex: e.detail.value,
recognizee_name: recognizee[e.detail.value]
})
},
//合同生效日
compactTime(e) {
this.setData({
compact_time: e.detail.value,
})
},
//缴费期满日
impletionTime(e) {
this.setData({
impletion_time: e.detail.value,
})
},
//主险保障期
periodTime(e) {
this.setData({
period_index: e.detail.value,
})
},
//保障项目弹窗
ensureProject(e) {
let that = this;
let type = e.currentTarget.dataset.type;
let index = e.currentTarget.dataset.xulie;
let tempProjectlist = Object.assign(this.data.projectlist, {});
// 已经添加的附加险
let rist_list = Object.assign(this.data.risk_list, {});
let tempRist = rist_list[index].projectlist;
// 已经添加的主险
let tempMain_list = Object.assign(this.data.main_array, {})
if (type == 'zhuxian') {
if (tempMain_list.length > 0) {
for (let i in tempProjectlist) {
for (let j in tempMain_list) {
if (tempProjectlist[i].id == tempMain_list[j].id) {
tempProjectlist[i] = tempMain_list[j]
}
}
}
}
} else {
if (tempRist.length) {
for (let i in tempProjectlist) {
for (let j in tempRist) {
if (tempProjectlist[i].id == tempRist[j].id) {
tempProjectlist[i] = tempRist[j]
}
}
}
}
}
wx.setNavigationBarTitle({
title: '选择保障项目',
})
this.setData({
popup_state: true,
addType: type,
xulie: index,
projectlist: tempProjectlist
})
},
// 调取保障项目接口
ensureProjectList() {
var main_risk = this.data.main_risk
let url = 'counselor/sageguard'
let params = {}
app.post(url, params).then((res) => {
if (res.data.code == 200) {
var projectlist = res.data.data.def;
for (var i = 0; i < projectlist.length; i++) {
projectlist[i].choose_status = false
for (var j = 0; j < projectlist[i].title.length; j++) {
projectlist[i].title[j].label_state = false
}
projectlist[i].title[0].current = 0
projectlist[i].title[0].label_state = true
}
this.setData({
projectlist: res.data.data.def
})
// console.log(this.data.projectlist)
}
})
},
//保障项目单位
getUnit(e) {
var main_risk = this.data.main_risk
var index = e.currentTarget.dataset.index;
var sindex = e.currentTarget.dataset.sindex;
var projectlist = this.data.projectlist;
var title = projectlist[index].title
for (var i = 0; i < title.length; i++) {
title[i].current = ''
}
projectlist[index].title[sindex].current = sindex
if (projectlist[index].title[sindex].current == sindex) {
projectlist[index].title[sindex].label_state = true
}
this.setData({
projectlist: projectlist,
})
},
//保障项目金额
popupNum(e) {
var index = e.currentTarget.dataset.index;
var projectlist = this.data.projectlist;
if (projectlist[index].choose_status) {
projectlist[index].num = e.detail.value
}
console.log(main_risk)
this.setData({
projectlist: projectlist
})
},
//选择保障项目
popupState(e) {
var index = e.currentTarget.dataset.index;
var projectlist = this.data.projectlist;
projectlist[index].choose_status = !projectlist[index].choose_status;
// console.log(projectlist)
this.setData({
projectlist: projectlist
})
},
//确认选择的推荐方案
confirmCase() {
let index = this.data.xulie;
let type = this.data.addType;
var that = this
var main_array = []
var projectlist = Object.assign(this.data.projectlist, {})
for (var i = 0; i < projectlist.length; i++) {
if (projectlist[i].choose_status) {
main_array.push(projectlist[i])
}
}
if (main_array != '') {
wx.showToast({
title: '添加成功',
icon: 'none'
})
if (type == 'fujiaxian') {
let tempRist = that.data.risk_list;
tempRist[index]['projectlist'] = main_array;
that.setData({
risk_list: tempRist,
})
} else {
that.setData({
main_array: main_array,
})
}
console.log(this.data.main_array)
// var temp = main_array
// for (var i = 0; i < main_array.length; i++) {
// for (var j = 0; j < main_array[i].title.length; j++) {
// if (main_array[i].title[j].label_state) {
// main_array[i].title = main_array[i].title[j].name
// }
// console.log(main_array)
// }
// }
// that.setData({
// main_array: main_array
// })
}
setTimeout(function() {
that.ensureProjectList()
that.setData({
popup_state: false
})
wx.setNavigationBarTitle({
title: '添加保单',
})
}, 1000)
},
//主线保障期
tempMain() {
// var main_array = this.data.main_array
// var warranty_one = this.data.warranty_one
// var temp = {}
// var len = main_array.length
// for (var i = 0; i < main_array.length; i++) {
// if (main_array[i].choose_status) {
// temp.num = main_array[i].beneficiary_name
// temp.title = main_array[i].name
// warranty_one.push(temp)
// }
// var hash = {};
// var temrecommend = warranty_one.reduce(function (item, next) {
// hash[next.name] ? '' : hash[next.name] = true && item.push(next);
// return item
// }, [])
// console.log(temrecommend)
// this.setData({
// warranty_one: temrecommend
// })
// }
},
//选择受益人姓名
beneficiarySelect(e) {
// console.log(e)
var index = e.currentTarget.dataset.mindex
var beneficiary_list = this.data.beneficiary_list;
for (var i = 0; i < beneficiary_list.length; i++) {
for (var j = 0; j < beneficiary_list[i].name.length; j++) {
var beneficiary_name = beneficiary_list[i].name[e.detail.value]
beneficiary_list[index].beneficiary_name = beneficiary_name
// console.log(beneficiary_list)
}
}
// let tempRangArry = this.data.rang_beneficiary;
// tempRangArry[index] = beneficiary_list[index].name[e.detail.value]
// console.log(tempRangArry)
this.setData({
beneficiaryindex: e.detail.value,
beneficiary_list: beneficiary_list
})
},
//添加收益比例
addUnit(e) {
// console.log(e)
var beneficiary_list = this.data.beneficiary_list;
beneficiary_list[beneficiary_list.length - 1].unit = e.detail.value;
this.setData({
beneficiary_list: beneficiary_list,
})
},
//添加受益人
addPersons(e) {
var list = this.data.beneficiary_list;
var len = list.length
if (list[len - 1].beneficiary_name == undefined) {
wx.showToast({
title: '请选择受益人',
icon: 'none'
})
} else if (list[len - 1].unit == '') {
console.log('unit')
wx.showToast({
title: '请输入收益比',
icon: 'none'
})
} else {
list[len] = {
name: ['受益人1', '受益人2'],
unit: ''
}
}
this.setData({
beneficiary_list: list
})
console.log(this.data.beneficiary_list)
},
//重组添加受益人
tempBeneficiary() {
var beneficiary_list = this.data.beneficiary_list
var tempfavoree = this.data.tempfavoree
var temp = {}
var len = beneficiary_list.length
for (var i = 0; i < beneficiary_list.length; i++) {
if (beneficiary_list[i].unit != '') {
temp.name = beneficiary_list[i].beneficiary_name
temp.unit = beneficiary_list[i].unit
tempfavoree.push(temp)
}
var hash = {};
var temrecommend = tempfavoree.reduce(function(item, next) {
hash[next.name] ? '' : hash[next.name] = true && item.push(next);
return item
}, [])
// console.log(temrecommend)
this.setData({
tempfavoree: temrecommend
})
}
},
//添加附加险
addRisk() {
var risk_list = Object.assign(this.data.risk_list, {});
var len = risk_list.length
risk_list[len] = {
name: '',
projectlist: [],
project_time: ''
}
this.setData({
risk_list: risk_list
})
},
//上传图片
uploadImage() {
let that = this;
wx.chooseImage({
count: 6,
sizeType: ['original', 'compressed'],
success: function(res) {
let successUp = 0; //成功个数
let failUp = 0; //失败个数
let i = 0; //第几个
let tempFilePaths = res.tempFilePaths //总文件
let length = res.tempFilePaths.length //总共个数
wx.showNavigationBarLoading()
wx.showLoading({
title: '上传中',
})
that.uploadAllfile(tempFilePaths, successUp, failUp, i, length)
},
fail: function(res) {}
})
},
//上传图片接口调取
uploadAllfile(filePaths, successUp, failUp, i, length) {
let that = this
let strtime = +new Date()
wx.uploadFile({
url: 'https://insurance.w.broteam.cn/pubilc/upload', //仅为示例,非真实的接口地址
filePath: filePaths[i],
name: 'picurl',
formData: {
'strtime': strtime,
'token': app.strTime(strtime)
},
success: function(res) {
wx.hideNavigationBarLoading()
wx.hideLoading()
if (res.statusCode == '200') {
let imgTemp = that.data.imgs;
let curImg = JSON.parse(res.data).data.picurl;
if (imgTemp.length < 6) {
imgTemp.push("http://" + curImg)
that.setData({
imgs: imgTemp
})
wx.showToast({
title: '上传成功',
icon: 'none',
duration: 2000,
})
} else {
wx.showToast({
title: '图片上限6张',
icon: 'none',
duration: 2000,
})
}
} else {
wx.showModal({
title: '提示',
content: res.msg,
showCancel: false
})
}
},
fail: function(res) {
wx.hideNavigationBarLoading()
wx.hideLoading()
},
complete: () => {
i++;
if (i == length) {
// console.log('总共' + successUp + '张上传成功,' + failUp + '张上传失败!');
} else { //递归调用uploadDIY函数
this.uploadAllfile(filePaths, successUp, failUp, i, length);
}
},
})
},
//预览图片
viewImg(e) {
var imgs = this.data.imgs
var current = e.currentTarget.dataset.index
wx.previewImage({
//当前显示图片
current: imgs[current],
//所有图片
urls: imgs
})
},
//删除图片
deleteImg(e) {
var imgs = this.data.imgs;
var index = e.currentTarget.dataset.index;
imgs.splice(index, 1);
this.setData({
imgs: imgs
});
},
//保障期
warrantyTwo(e) {
var guarantee_name = e.detail.value
this.setData({
guarantee_name: guarantee_name
})
},
//选择各项单位
selectUnit(e) {
var unit = e.currentTarget.dataset.unit
this.setData({
unit: unit
})
},
//重组保障期数据格式
tempWarranty() {
var guarantee_name = this.data.guarantee_name
var unit = this.data.unit
var warranty_two = this.data.warranty_two
warranty_two.num = guarantee_name
warranty_two.title = unit
// console.log(warranty_two)
this.setData({
warranty_two: warranty_two
})
},
//缴费时长
burningTime(e) {
var time_name = e.detail.value
this.setData({
time_name: time_name
})
this.countImpletionTime()
},
selectUnit2(e) {
var unit = e.currentTarget.dataset.unit
this.setData({
unit2: unit
})
this.countImpletionTime()
},
//重组缴费时长数据格式
tempburningTime() {
var time_name = this.data.time_name
var unit = this.data.unit2
var long_money = this.data.long_money
long_money.num = time_name
long_money.title = unit
console.log(long_money)
this.setData({
long_money: long_money
})
},
//计算缴费期满日
countImpletionTime() {
var time_name = parseInt(this.data.time_name)
var unit = this.data.unit2
var compact_time = this.data.compact_time
var year = parseInt(new Date(compact_time).getFullYear())
var month = parseInt(new Date(compact_time).getMonth())
var day = parseInt(new Date(compact_time).getDate())
var runnian = ''
var cha=''
var birthday='1995-04-20'
var birthday_year = parseInt(new Date(birthday).getFullYear())
var tempbirth_time=''
if (unit == '年') {
var millSeconds = Math.abs(nDate) - (1 * 24 * 60 * 60 * 1000);
// runnian = parseInt(time_name / 4)
// cha = time_name - runnian
// var dateTemp = compact_time.split("-");
// var nDate = new Date(dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]);
// var millSeconds = Math.abs(nDate) + (((cha * 365) + (runnian*366) )* 24 * 60 * 60 * 1000) - (1 * 24 * 60 * 60 * 1000);
// var rDate = new Date(millSeconds);
// var year = rDate.getFullYear();
// var month = rDate.getMonth() + 1;
// if (month < 10) month = "0" + month;
// var date = rDate.getDate();
// if (date < 10) date = "0" + date;
// console.log(year + "-" + month + "-" + date);
}else if(unit=='岁'){
var temp_year = (birthday_year + time_name - 1)
var temp_month = month
tempbirth_time = temp_year + '-' + temp_month + '-'+day
console.log(tempbirth_time)
}
},
//缴费方式
selectUnit3(e) {
var unit = e.currentTarget.dataset.unit
this.setData({
unit3: unit,
type_money: unit
})
},
selectUnit4(e) {
var unit = e.currentTarget.dataset.unit
this.setData({
unit4: unit
})
},
// 保单验证&&上传保单
listVerify(e) {
this.tempBeneficiary()
this.tempWarranty()
this.tempburningTime()
var warn = ""; //弹框时提示的内容
var flag = true; //判断信息输入是否完整判断弹窗
var in_num = e.detail.value.policy_num
var firm = e.detail.value.company;
var applicant = this.data.applicant_name
var recognizee = this.data.recognizee_name
var favoree = this.data.tempfavoree
var main_risks = e.detail.value.main_risks
var year_money = e.detail.value.year_money
var compact_time = this.data.compact_time
var warranty_two = this.data.warranty_two
var type_money = this.data.type_money
var warranty_one = this.data.main_array
var impletion_time = this.data.impletion_time
var warranty = e.detail.value.Guarantee_period
var bank = e.detail.value.Renew_bank
var bank_num = e.detail.value.renew_num
var coverage = e.detail.value.base_money
var picurl = JSON.stringify(this.data.imgs)
var guarantee = JSON.stringify(this.data.selectitem) //保障项目
var more = JSON.stringify(this.data.addlist)
// if (this.data.inforid != undefined) {
if (in_num == '') {
warn = '请输入保单号!'
} else if (firm == '') {
warn = '请输入所属公司!'
} else if (applicant == '') {
warn = '请输入投保人!'
} else if (recognizee == '') {
warn = '请输入被保险人!'
} else if (favoree == '') {
warn = '请输入受益人!'
} else if (compact_time == '') {
warn = '请输入合同生效日!'
} else if (impletion_time == '') {
warn = '请输入缴费期满日!'
} else if (warranty == '') {
warn = '请输入保障期!'
} else if (bank == '') {
warn = '请输入续费银行!'
} else if (bank_num == '') {
warn = '请输入续费账号!'
} else if (!(/^[0-9]+.?[0-9]*/.test(bank_num))) {
warn = '请输入正确续费账号!'
} else if (year_money == '') {
warn = '请输入年交保费!'
} else if (main_risks == '') {
warn = '请输入主险名称!'
} else if (coverage == '') {
warn = '请输入主险基本保额!'
} else if (more.length == 2) {
warn = '请上传上传附加险!'
} else if (guarantee.length == 0) {
warn = '请选择保障项目!'
} else if (picurl.length == 2) {
warn = '请选择图片!'
} else {
flag = false
// 添加、修改保单接口调取
let url = 'counselor/inforuodate'
let params = {
InfoId: this.data.inforid,
def_id: this.data.def_id,
in_num: in_num,
firm: firm,
applicant: applicant,
recognizee: recognizee,
favoree: favoree,
compact_time: compact_time,
impletion_time: impletion_time,
warranty: warranty,
bank: bank,
bank_num: bank_num,
year_money: year_money,
main_risks: main_risks,
coverage: coverage,
more: more,
guarantee: guarantee,
picurl: picurl
}
app.post(url, params).then((res) => {
if (res.data.code == 200) {
wx.navigateBack({
delta: 1,
})
}
})
}
// }
// else {
// if (in_num == '') {
// warn = '请输入保单号!'
// } else if (firm == '') {
// warn = '请输入所属公司!'
// } else if (applicant == '') {
// warn = '请输入投保人!'
// } else if (recognizee == '') {
// warn = '请输入被保险人!'
// } else if (favoree == '') {
// warn = '请输入受益人!'
// } else if (compact_time == '') {
// warn = '请输入合同生效日!'
// } else if (impletion_time == '') {
// warn = '请输入缴费期满日!'
// } else if (warranty == '') {
// warn = '请输入保障期!'
// } else if (bank == '') {
// warn = '请输入续费银行!'
// } else if (bank_num == '') {
// warn = '请输入续费账号!'
// } else if (!(/^[0-9]+.?[0-9]*/.test(bank_num))) {
// warn = '请输入正确续费账号!'
// } else if (year_money == '') {
// warn = '请输入年交保费!'
// } else if (main_risks == '') {
// warn = '请输入主险名称!'
// } else if (coverage == '') {
// warn = '请输入主险基本保额!'
// } else if (more.length == 2) {
// warn = '请上传上传附加险!'
// } else if (guarantee.length == 2) {
// warn = '请选择保障项目!'
// } else if (picurl.length == 2) {
// warn = '请选择图片!'
// } else {
// flag = false
// // 添加、修改保单接口调取
// let url = 'counselor/inforuodate'
// let params = {
// def_id: this.data.def_id,
// in_num: in_num,
// firm: firm,
// applicant: applicant,
// recognizee: recognizee,
// favoree: favoree,
// compact_time: compact_time,
// impletion_time: impletion_time,
// warranty: warranty,
// bank: bank,
// bank_num: bank_num,
// year_money: year_money,
// main_risks: main_risks,
// coverage: coverage,
// more: more,
// guarantee: guarantee,
// picurl: picurl
// }
// app.post(url, params).then((res) => {
// var projectlist = this.data.projectlist
// for (var i = 0; i < projectlist.length; i++) {
// projectlist[i].status = false
// }
// if (res.data.code == 200) {
// var continue1 = e.detail.target.dataset.type
// var complete = e.detail.target.dataset.type
// if (continue1 == 'continue1') {
// wx.showToast({
// title: '添加成功',
// icon: 'none',
// duration: 2000,
// })
// this.setData({
// nullNum: '',
// addlist: [{
// name: '',
// num: '',
// title: ''
// }],
// projectlist: projectlist,
// imgs: [],
// compact_time: '',
// impletion_time: ''
// })
// } else if (complete == complete) {
// wx.showToast({
// title: '添加成功',
// icon: 'none',
// duration: 2000,
// })
// wx.navigateBack({
// delta: 1,
// })
// }
// }
// })
// }
// }
if (flag == true) {
wx.showToast({
title: warn,
icon: 'none'
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.ensureProjectList()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})