作者 朱振飞

哈哈

1 -// pages/addListDetail/addListDetail.js  
2 -const app = getApp()  
3 -Page({  
4 -  
5 - /**  
6 - * 页面的初始数据  
7 - */  
8 - data: {  
9 - recognizee: ['被保人', '被保人2'],  
10 - recognizee_index: 0,  
11 - period_time: ['10年', '20年'],  
12 - period_index: -1,  
13 - compact_time: '',  
14 - impletion_time: '',  
15 - popup_state: false,  
16 - projectlist: [],  
17 - label_state: false,  
18 - insure: ['投保人', '投保人2'],  
19 - insureindex: -1,  
20 - beneficiary_list: [{  
21 - name_array: ['受益人1', '受益人2'],  
22 - unit: ''  
23 - }],  
24 - beneficiaryindex: -1,  
25 - tempfavoree: [], // 已选择的受益人  
26 - beneficiaryList: [],  
27 - name: '', //受益人的名字,  
28 - beneficiary_name: '',  
29 - imgs: [],  
30 - main_risk: [],  
31 - unit: '',  
32 - unit2: '',  
33 - unit3: '',  
34 - unit4: '',  
35 - applicant_name: '',  
36 - recognizee_name: '',  
37 - rang_beneficiary: [],  
38 - risk_list: [{  
39 - name: '',  
40 - mo: [],  
41 - project_time: '',  
42 - title: '',  
43 - num: ''  
44 - }],  
45 - main_array: [],  
46 - warranty_one: '',  
47 - warranty_two: {},  
48 - guarantee_name: '',  
49 - long_money: {},  
50 - time_name: '',  
51 - type_money: '',  
52 - more: [],  
53 - guarantee: [],  
54 - InfoId: 0,  
55 - def_id: '',  
56 - edit_state: false,  
57 - risk_listitm: '',  
58 - storge_state: false,  
59 - },  
60 -  
61 - //保单号  
62 - policyNum(e) {  
63 - this.setData({  
64 - in_num: e.detail.value,  
65 - })  
66 - },  
67 -  
68 - //保单号  
69 - setFirm(e) {  
70 - this.setData({  
71 - firm: e.detail.value,  
72 - })  
73 - },  
74 -  
75 - //投保人  
76 - insureSelect(e) {  
77 - var insure = this.data.insure  
78 - this.setData({  
79 - insureindex: e.detail.value,  
80 - applicant_name: insure[e.detail.value],  
81 - })  
82 - },  
83 -  
84 - //选择被保险人  
85 - recognizeeSelect(e) {  
86 - var recognizee = this.data.recognizee  
87 - this.setData({  
88 - recognizeeindex: e.detail.value,  
89 - recognizee_name: recognizee[e.detail.value]  
90 - })  
91 - },  
92 -  
93 - //主险名称  
94 - setRiskName(e) {  
95 - // console.log(e)  
96 - this.setData({  
97 - main_risks: e.detail.value,  
98 - })  
99 - // console.log(this.data.main_risks)  
100 - },  
101 -  
102 - //保费  
103 - yearMoney(e) {  
104 - this.setData({  
105 - year_money: e.detail.value,  
106 - })  
107 - },  
108 -  
109 - //设置银行  
110 - setBank(e) {  
111 - this.setData({  
112 - bank: e.detail.value,  
113 - })  
114 - },  
115 -  
116 - //设置账号  
117 - setBankNum(e) {  
118 - this.setData({  
119 - bank_num: e.detail.value,  
120 - })  
121 - },  
122 -  
123 - //合同生效日  
124 - compactTime(e) {  
125 - this.setData({  
126 - compact_time: e.detail.value,  
127 - })  
128 - this.countImpletionTime()  
129 - this.countImpletionTime2()  
130 - },  
131 -  
132 - //缴费期满日  
133 - impletionTime(e) {  
134 - this.setData({  
135 - impletion_time: e.detail.value,  
136 - })  
137 - },  
138 -  
139 - //主险保障期  
140 - periodTime(e) {  
141 - this.setData({  
142 - period_index: e.detail.value,  
143 - })  
144 - },  
145 -  
146 - //保障项目弹窗  
147 - ensureProject(e) {  
148 - this.setData({  
149 - edit_state: false  
150 - })  
151 -  
152 - let that = this;  
153 - let type = e.currentTarget.dataset.type;  
154 - let index = e.currentTarget.dataset.xulie;  
155 - let tempProjectlist = Object.assign(this.data.projectlist, {});  
156 - // 已经添加的附加险  
157 - let risk_list = Object.assign(this.data.risk_list, {});  
158 - console.log(risk_list)  
159 - let tempRist = risk_list[index].mo;  
160 - console.log(tempRist)  
161 - // 已经添加的主险  
162 - let tempMain_list = Object.assign(this.data.main_array, {})  
163 - if (type == 'zhuxian') {  
164 - if (tempMain_list.length > 0) {  
165 - for (let i in tempProjectlist) {  
166 - for (let j in tempMain_list) {  
167 - if (tempProjectlist[i].id == tempMain_list[j].id) {  
168 - tempProjectlist[i] = tempMain_list[j]  
169 - }  
170 - }  
171 - }  
172 - }  
173 - } else {  
174 - if (tempRist.length) {  
175 - for (let i in tempProjectlist) {  
176 - for (let j in tempRist) {  
177 - if (tempProjectlist[i].id == tempRist[j].id) {  
178 - tempProjectlist[i] = tempRist[j]  
179 - }  
180 - }  
181 - }  
182 - }  
183 - }  
184 -  
185 - wx.setNavigationBarTitle({  
186 - title: '选择保障项目',  
187 - })  
188 -  
189 - this.setData({  
190 - popup_state: true,  
191 - addType: type,  
192 - xulie: index,  
193 - projectlist: tempProjectlist  
194 - })  
195 - // }  
196 - },  
197 -  
198 - // 调取保障项目接口  
199 - ensureProjectList() {  
200 - var main_risk = this.data.main_risk  
201 - let url = 'counselor/sageguard'  
202 - let params = {}  
203 - app.post(url, params).then((res) => {  
204 - if (res.data.code == 200) {  
205 - var projectlist = res.data.data.def;  
206 - for (var i = 0; i < projectlist.length; i++) {  
207 - projectlist[i].choose_status = false  
208 - for (var j = 0; j < projectlist[i].title.length; j++) {  
209 - projectlist[i].title[j].label_state = false  
210 - }  
211 - projectlist[i].title[0].current = 0  
212 - projectlist[i].title[0].label_state = true  
213 - }  
214 - this.setData({  
215 - projectlist: res.data.data.def  
216 - })  
217 - // console.log(this.data.projectlist)  
218 - }  
219 - })  
220 - },  
221 -  
222 - //保障项目单位  
223 - getUnit(e) {  
224 - var main_risk = this.data.main_risk  
225 - var index = e.currentTarget.dataset.index;  
226 - var sindex = e.currentTarget.dataset.sindex;  
227 - var projectlist = this.data.projectlist;  
228 - var title = projectlist[index].title  
229 - for (var i = 0; i < title.length; i++) {  
230 - title[i].current = ''  
231 - if (title[i].current == '') {  
232 - title[i].label_state = false  
233 - }  
234 - }  
235 - projectlist[index].title[sindex].current = sindex  
236 - if (projectlist[index].title[sindex].current == sindex) {  
237 - projectlist[index].title[sindex].label_state = true  
238 - }  
239 - this.setData({  
240 - projectlist: projectlist,  
241 - })  
242 - },  
243 -  
244 - //保障项目金额  
245 - popupNum(e) {  
246 - var index = e.currentTarget.dataset.index;  
247 - var projectlist = this.data.projectlist;  
248 - if (projectlist[index].choose_status) {  
249 - projectlist[index].num = e.detail.value  
250 - }  
251 - this.setData({  
252 - projectlist: projectlist  
253 - })  
254 - },  
255 -  
256 - //选择保障项目  
257 - popupState(e) {  
258 - var index = e.currentTarget.dataset.index;  
259 - var projectlist = this.data.projectlist;  
260 - projectlist[index].choose_status = !projectlist[index].choose_status;  
261 - // console.log(projectlist)  
262 - this.setData({  
263 - projectlist: projectlist,  
264 - })  
265 - if (this.data.inforid != 0) {  
266 - edit_state: false  
267 - }  
268 - },  
269 -  
270 - //确认选择的推荐方案  
271 - confirmCase() {  
272 - let index = this.data.xulie;  
273 - let type = this.data.addType;  
274 - var that = this  
275 - var main_array = []  
276 -  
277 - var projectlist = Object.assign(this.data.projectlist, {})  
278 - for (var i = 0; i < projectlist.length; i++) {  
279 - if (projectlist[i].choose_status) {  
280 - main_array.push(projectlist[i])  
281 - console.log(main_array)  
282 - }  
283 - }  
284 -  
285 - if (main_array != '') {  
286 - wx.showToast({  
287 - title: '添加成功',  
288 - icon: 'none'  
289 - })  
290 -  
291 - if (type == 'fujiaxian') {  
292 - let tempRist = that.data.risk_list;  
293 - console.log(tempRist)  
294 - tempRist[index]['mo'] = main_array;  
295 - that.setData({  
296 - risk_list: tempRist,  
297 - risk_listitm: tempRist  
298 - })  
299 - console.log(this.data.risk_list)  
300 - } else {  
301 - that.setData({  
302 - main_array: main_array,  
303 - })  
304 - }  
305 - console.log(this.data.main_array)  
306 - }  
307 - setTimeout(function() {  
308 - that.ensureProjectList()  
309 - that.setData({  
310 - popup_state: false  
311 - })  
312 - wx.setNavigationBarTitle({  
313 - title: '添加保单',  
314 - })  
315 - }, 800)  
316 -  
317 -  
318 - console.log(this.data.risk_list)  
319 - },  
320 -  
321 - //重组主险的保障项目  
322 - tempMain() {  
323 - var main_array = this.data.main_array  
324 - var warranty_one1 = []  
325 - // console.log(main_array)  
326 - for (var i = 0; i < main_array.length; i++) {  
327 - var temp = {}  
328 - for (var j = 0; j < main_array[i].title.length; j++) {  
329 - if (main_array[i].choose_status) {  
330 - if (main_array[i].title[j].label_state) {  
331 - temp.id = main_array[i].id  
332 - temp.name = main_array[i].name  
333 - temp.num = main_array[i].num  
334 - temp.title = main_array[i].title[j].name  
335 - temp.t_id = main_array[i].title[j].t_id  
336 - }  
337 - }  
338 - }  
339 - warranty_one1.push(temp)  
340 - this.setData({  
341 - guarantee: warranty_one1  
342 - })  
343 - }  
344 -  
345 - },  
346 -  
347 - //主险名称  
348 - addRiskName(e) {  
349 - var risk_list = this.data.risk_list  
350 - var index = e.currentTarget.dataset.index  
351 - risk_list[index].name = e.detail.value  
352 - this.setData({  
353 - risk_list: risk_list  
354 - })  
355 - },  
356 -  
357 - //主险保障其  
358 - addRiskUnit(e) {  
359 - var risk_list = this.data.risk_list  
360 - var index = e.currentTarget.dataset.index  
361 - risk_list[index].num = e.detail.value  
362 - this.setData({  
363 - risk_list: risk_list  
364 - })  
365 - },  
366 -  
367 - //重组附加险整体数据结构  
368 - tempAddRisk() {  
369 - var risk_list = this.data.risk_list  
370 -  
371 - var sub_array = []  
372 - var temp_risk = this.data.risk_listitm;  
373 - var temp = this.data.risk_listitm;  
374 -  
375 - for (var i = 0; i < temp.length; i++) {  
376 - for (var j = 0; j < temp[i].mo.length; j++) {  
377 - for (var k = 0; k < temp[i].mo[j].title.length; k++) {  
378 - if (temp[i].name != '') {  
379 - // var temp = {}  
380 - // var subtemp = {}  
381 - if (temp[i].mo[j].choose_status) {  
382 - if (temp[i].mo[j].title[k].label_state) {  
383 - temp_risk[i].name = temp[i].name  
384 - temp_risk[i].num = temp[i].num  
385 - temp_risk[i].title = temp[i].title  
386 - temp_risk[i].mo[j].t_id = temp[i].mo[j].title[k].t_id  
387 - temp_risk[i].mo[j].id = temp[i].mo[j].id  
388 - temp_risk[i].mo[j].name = temp[i].mo[j].name  
389 - temp_risk[i].mo[j].num = temp[i].mo[j].num  
390 - temp_risk[i].mo[j].title = temp[i].mo[j].title[k].name  
391 - console.log(temp_risk)  
392 - }  
393 - }  
394 - }  
395 - }  
396 - }  
397 -  
398 - this.setData({  
399 - more: temp_risk  
400 - })  
401 - }  
402 -  
403 - },  
404 -  
405 - //选择受益人姓名  
406 - beneficiarySelect(e) {  
407 - if (this.data.inforid != 0) {  
408 - this.setData({  
409 - edit_state: false  
410 - })  
411 - }  
412 - var index = e.currentTarget.dataset.mindex  
413 - var beneficiary_list = Object.assign(this.data.beneficiary_list, {});  
414 - // 获取当前已选择的收益人  
415 - let tempBenefice = Object.assign(this.data.beneficiaryList, {})  
416 - // 当前选择的收益人  
417 - let nowPerson = beneficiary_list[index].name_array[e.detail.value];  
418 - // 判断受益人是否已经添加  
419 - const add = tempBenefice.every((tempBenefice) => {  
420 - return tempBenefice != nowPerson  
421 - })  
422 - if (add) {  
423 - beneficiary_list[index].beneficiary_name = nowPerson;  
424 - tempBenefice.push(nowPerson)  
425 - } else {  
426 - wx.showToast({  
427 - title: '请不要重复添加受益人',  
428 - icon: 'none'  
429 - })  
430 - }  
431 -  
432 - this.setData({  
433 - beneficiary_list: beneficiary_list,  
434 - beneficiaryList: tempBenefice  
435 - })  
436 -  
437 - },  
438 -  
439 - //添加收益比例  
440 - addUnit(e) {  
441 - var beneficiary_list = this.data.beneficiary_list;  
442 - beneficiary_list[beneficiary_list.length - 1].unit = e.detail.value;  
443 - this.setData({  
444 - beneficiary_list: beneficiary_list,  
445 - })  
446 - },  
447 -  
448 - //添加受益人  
449 - addPersons(e) {  
450 - var list = this.data.beneficiary_list;  
451 - var len = list.length  
452 - if (list[len - 1].beneficiary_name == undefined) {  
453 - wx.showToast({  
454 - title: '请选择受益人',  
455 - icon: 'none'  
456 - })  
457 - } else if (list[len - 1].unit == '') {  
458 - console.log('unit')  
459 - wx.showToast({  
460 - title: '请输入收益比',  
461 - icon: 'none'  
462 - })  
463 - } else {  
464 - list[len] = {  
465 - name_array: this.data.insure,  
466 - unit: ''  
467 - }  
468 - }  
469 - this.setData({  
470 - beneficiary_list: list  
471 - })  
472 - console.log(this.data.beneficiary_list)  
473 - },  
474 -  
475 - //重组添加受益人  
476 - tempBeneficiary() {  
477 - var beneficiary_list = this.data.beneficiary_list  
478 - var len = beneficiary_list.length;  
479 - var tempfavoree1 = [];  
480 - for (var i = 0; i < beneficiary_list.length; i++) {  
481 - var temp = {}  
482 - if (beneficiary_list[i].unit != '') {  
483 - temp.name = beneficiary_list[i].beneficiary_name  
484 - temp.unit = beneficiary_list[i].unit;  
485 - }  
486 - tempfavoree1.push(temp)  
487 - this.setData({  
488 - tempfavoree: tempfavoree1  
489 - })  
490 -  
491 - }  
492 - },  
493 -  
494 - //删除收益人  
495 - deletebenefict(e) {  
496 - let index = e.currentTarget.dataset.index;  
497 - let tempbenefict = Object.assign(this.data.beneficiary_list, {});  
498 - let beneficiaryList = Object.assign(this.data.beneficiaryList, {});  
499 - // 获取当前选项的受益人  
500 - let person = tempbenefict[index].beneficiary_name;  
501 - tempbenefict.splice(index, 1);  
502 - if (person) beneficiaryList.splice(beneficiaryList.indexOf(person), 1)  
503 -  
504 - this.setData({  
505 - beneficiaryList: beneficiaryList,  
506 - beneficiary_list: tempbenefict  
507 - })  
508 - },  
509 -  
510 - //添加附加险  
511 - addRisk() {  
512 - if (this.data.inforid != 0) {  
513 - this.setData({  
514 - edit_state: false  
515 - })  
516 - }  
517 - var risk_list = Object.assign(this.data.risk_list, {});  
518 - var len = risk_list.length  
519 - risk_list[len] = {  
520 - name: '',  
521 - mo: [],  
522 - project_time: '',  
523 - title: '',  
524 - num: ''  
525 - }  
526 - this.setData({  
527 - risk_list: risk_list  
528 - })  
529 - },  
530 -  
531 - //删除附加险  
532 - deleteRisk(e) {  
533 - let index = e.currentTarget.dataset.index;  
534 - let risk_list = Object.assign(this.data.risk_list, {});  
535 - risk_list.splice(index, 1);  
536 - this.setData({  
537 - risk_list: risk_list  
538 - })  
539 - },  
540 -  
541 - //上传图片  
542 - uploadImage() {  
543 - let that = this;  
544 - wx.chooseImage({  
545 - count: 6,  
546 - sizeType: ['original', 'compressed'],  
547 - success: function(res) {  
548 - let successUp = 0; //成功个数  
549 - let failUp = 0; //失败个数  
550 - let i = 0; //第几个  
551 - let tempFilePaths = res.tempFilePaths //总文件  
552 - let length = res.tempFilePaths.length //总共个数  
553 - wx.showNavigationBarLoading()  
554 - wx.showLoading({  
555 - title: '上传中',  
556 - })  
557 - that.uploadAllfile(tempFilePaths, successUp, failUp, i, length)  
558 - },  
559 - fail: function(res) {}  
560 - })  
561 - },  
562 -  
563 - //上传图片接口调取  
564 - uploadAllfile(filePaths, successUp, failUp, i, length) {  
565 - let that = this  
566 - let strtime = +new Date()  
567 - wx.uploadFile({  
568 - url: 'https://insurance.w.broteam.cn/pubilc/upload', //仅为示例,非真实的接口地址  
569 - filePath: filePaths[i],  
570 - name: 'picurl',  
571 - formData: {  
572 - 'strtime': strtime,  
573 - 'token': app.strTime(strtime)  
574 - },  
575 - success: function(res) {  
576 - wx.hideNavigationBarLoading()  
577 - wx.hideLoading()  
578 - if (res.statusCode == '200') {  
579 - let imgTemp = that.data.imgs;  
580 - let curImg = JSON.parse(res.data).data.picurl;  
581 - if (imgTemp.length < 6) {  
582 - imgTemp.push("http://" + curImg)  
583 - that.setData({  
584 - imgs: imgTemp  
585 - })  
586 - wx.showToast({  
587 - title: '上传成功',  
588 - icon: 'none',  
589 - duration: 2000,  
590 - })  
591 - } else {  
592 - wx.showToast({  
593 - title: '图片上限6张',  
594 - icon: 'none',  
595 - duration: 2000,  
596 - })  
597 - }  
598 - } else {  
599 - wx.showModal({  
600 - title: '提示',  
601 - content: res.msg,  
602 - showCancel: false  
603 - })  
604 - }  
605 - },  
606 - fail: function(res) {  
607 - wx.hideNavigationBarLoading()  
608 - wx.hideLoading()  
609 - },  
610 - complete: () => {  
611 - i++;  
612 - if (i == length) {  
613 - // console.log('总共' + successUp + '张上传成功,' + failUp + '张上传失败!');  
614 - } else { //递归调用uploadDIY函数  
615 - this.uploadAllfile(filePaths, successUp, failUp, i, length);  
616 - }  
617 - },  
618 - })  
619 - },  
620 -  
621 - //预览图片  
622 - viewImg(e) {  
623 - var imgs = this.data.imgs  
624 - var current = e.currentTarget.dataset.index  
625 - wx.previewImage({  
626 - //当前显示图片  
627 - current: imgs[current],  
628 - //所有图片  
629 - urls: imgs  
630 - })  
631 - },  
632 -  
633 - //删除图片  
634 - deleteImg(e) {  
635 - var imgs = this.data.imgs;  
636 - var index = e.currentTarget.dataset.index;  
637 - imgs.splice(index, 1);  
638 - this.setData({  
639 - imgs: imgs  
640 - });  
641 - },  
642 -  
643 - //保障期  
644 - warrantyTwo(e) {  
645 - if (this.data.inforid != 0) {  
646 - this.setData({  
647 - edit_state: false  
648 - })  
649 - }  
650 - var guarantee_name = e.detail.value  
651 - this.setData({  
652 - guarantee_name: e.detail.value  
653 - })  
654 - this.countImpletionTime2()  
655 - },  
656 -  
657 - //选择各项单位  
658 - selectUnit(e) {  
659 - var unit = e.currentTarget.dataset.unit  
660 - this.setData({  
661 - unit: unit  
662 - })  
663 - this.countImpletionTime2()  
664 - },  
665 -  
666 - //重组保障期数据格式  
667 - tempWarranty() {  
668 - var guarantee_name = this.data.guarantee_name  
669 - var unit = this.data.unit  
670 - var warranty_two = this.data.warranty_two  
671 - warranty_two.num = guarantee_name  
672 - warranty_two.title = unit  
673 - this.setData({  
674 - warranty_two: warranty_two  
675 - })  
676 - },  
677 -  
678 -  
679 - //计算缴费期满日,主线保障其  
680 - countImpletionTime2() {  
681 - var guarantee_name = parseInt(this.data.guarantee_name)  
682 - var unit = this.data.unit  
683 - var compact_time = this.data.compact_time  
684 - var year = parseInt(new Date(compact_time).getFullYear())  
685 - console.log(year)  
686 - var month = parseInt(new Date(compact_time).getMonth() + 1)  
687 - var day = parseInt(new Date(compact_time).getDate())  
688 - // var impletion_time = this.data.impletion_time  
689 - var warranty_one = this.data.warranty_one  
690 -  
691 - var tempbirth_time = ''  
692 - var birthday = '1995-04-20'  
693 - var birthday_year = parseInt(new Date(birthday).getFullYear())  
694 -  
695 - if (compact_time == '') {  
696 - wx.showToast({  
697 - title: '请选择合同生效日',  
698 - icon: 'none'  
699 - })  
700 - } else {  
701 - if (unit == '年') {  
702 - var temp_year = (year + guarantee_name)  
703 - var temp_day = day - 1  
704 - if (month < 10) month = "0" + month;  
705 - if (temp_day < 10) temp_day = "0" + temp_day;  
706 - // impletion_time = temp_year + '-' + month + '-' + temp_day  
707 - warranty_one = temp_year + '-' + month + '-' + temp_day  
708 - } else if (unit == '岁') {  
709 - var temp_year = (birthday_year + guarantee_name - 1)  
710 - var temp_year2 = (birthday_year + guarantee_name)  
711 - var temp_month = month  
712 - if (temp_month < 10) temp_month = "0" + temp_month;  
713 - if (month < 10) month = "0" + month;  
714 - if (day < 10) day = "0" + day;  
715 - // impletion_time = temp_year + '-' + temp_month + '-' + day  
716 - warranty_one = temp_year2 + '-' + month + '-' + day  
717 - } else if (unit == '终身') {  
718 - // impletion_time = '终身缴费'  
719 - warranty_one = '终身'  
720 - }  
721 - this.setData({  
722 - // impletion_time: impletion_time,  
723 - warranty_one: warranty_one  
724 - })  
725 - }  
726 - },  
727 -  
728 - //缴费时长  
729 - burningTime(e) {  
730 - if (this.data.inforid != 0) {  
731 - this.setData({  
732 - edit_state: false  
733 - })  
734 - }  
735 - var time_name = e.detail.value  
736 - this.setData({  
737 - time_name: time_name  
738 - })  
739 - this.countImpletionTime()  
740 - },  
741 -  
742 - selectUnit2(e) {  
743 - var unit = e.currentTarget.dataset.unit  
744 - this.setData({  
745 - unit2: unit  
746 - })  
747 - this.countImpletionTime()  
748 - },  
749 -  
750 - //重组缴费时长数据格式  
751 - tempburningTime() {  
752 - var time_name = this.data.time_name  
753 - var unit = this.data.unit2  
754 - var long_money = this.data.long_money  
755 - long_money.num = time_name  
756 - long_money.title = unit  
757 - this.setData({  
758 - long_money: long_money  
759 - })  
760 - },  
761 -  
762 -  
763 - //计算缴费期满日,主线保障其  
764 - countImpletionTime() {  
765 - var time_name = parseInt(this.data.time_name)  
766 - var unit = this.data.unit2  
767 - var compact_time = this.data.compact_time  
768 - var year = parseInt(new Date(compact_time).getFullYear())  
769 - var month = parseInt(new Date(compact_time).getMonth() + 1)  
770 - var day = parseInt(new Date(compact_time).getDate())  
771 - var impletion_time = this.data.impletion_time  
772 - // var warranty_one = this.data.warranty_one  
773 -  
774 - var tempbirth_time = ''  
775 - var birthday = '1995-04-20'  
776 - var birthday_year = parseInt(new Date(birthday).getFullYear())  
777 -  
778 - if (compact_time == '') {  
779 - wx.showToast({  
780 - title: '请选择合同生效日',  
781 - icon: 'none'  
782 - })  
783 - } else {  
784 - if (unit == '年') {  
785 - var temp_year = (year + time_name)  
786 - var temp_day = day - 1  
787 - if (month < 10) month = "0" + month;  
788 - if (temp_day < 10) temp_day = "0" + temp_day;  
789 - impletion_time = temp_year + '-' + month + '-' + temp_day  
790 - // warranty_one = temp_year + '-' + month + '-' + temp_day  
791 - } else if (unit == '岁') {  
792 - var temp_year = (birthday_year + time_name - 1)  
793 - var temp_year2 = (birthday_year + time_name)  
794 - var temp_month = month  
795 - if (temp_month < 10) temp_month = "0" + temp_month;  
796 - if (month < 10) month = "0" + month;  
797 - if (day < 10) day = "0" + day;  
798 - impletion_time = temp_year + '-' + temp_month + '-' + day  
799 - // warranty_one = temp_year2 + '-' + month + '-' + day  
800 - } else if (unit == '终身') {  
801 - impletion_time = '终身缴费'  
802 - // warranty_one = '终身'  
803 - }  
804 - this.setData({  
805 - impletion_time: impletion_time,  
806 - // warranty_one: warranty_one  
807 - })  
808 - }  
809 - },  
810 -  
811 - //缴费方式  
812 - selectUnit3(e) {  
813 - var unit = e.currentTarget.dataset.unit  
814 - this.setData({  
815 - unit3: unit,  
816 - type_money: unit  
817 - })  
818 - },  
819 -  
820 - //附加险保障其  
821 - selectUnit4(e) {  
822 - var unit = e.currentTarget.dataset.unit;  
823 - let index = e.currentTarget.dataset.index;  
824 - let risk_list = Object.assign(this.data.risk_list, {});  
825 - risk_list[index].title = unit  
826 - this.setData({  
827 - risk_list: risk_list  
828 - })  
829 - },  
830 -  
831 - //家庭成员  
832 - familyMember() {  
833 - var FamilyId = this.data.FamilyId  
834 - let url = 'counselor/familyname'  
835 - let params = {  
836 - FamilyId: FamilyId,  
837 - }  
838 - app.post(url, params).then((res) => {  
839 - // console.log(res)  
840 - var beneficiary_list = this.data.beneficiary_list  
841 - for (var i in beneficiary_list) {  
842 - beneficiary_list[i].name_array = res.data.data.list  
843 - }  
844 - // console.log(beneficiary_list)  
845 -  
846 - if (res.data.code == 200) {  
847 - this.setData({  
848 - insure: res.data.data.list,  
849 - recognizee: res.data.data.list,  
850 - beneficiary_list: beneficiary_list,  
851 - })  
852 - }  
853 - })  
854 - },  
855 -  
856 - //设置缓存  
857 - setStorge(e) {  
858 - this.tempBeneficiary()  
859 - this.tempWarranty()  
860 - this.tempburningTime()  
861 - this.tempMain()  
862 - this.tempAddRisk()  
863 - var favoree = JSON.stringify(this.data.tempfavoree)  
864 - var warranty_two = JSON.stringify(this.data.warranty_two)  
865 - var long_money = JSON.stringify(this.data.long_money)  
866 - var more = JSON.stringify(this.data.more)  
867 - var guarantee = JSON.stringify(this.data.guarantee)  
868 - var warn = ""; //弹框时提示的内容  
869 - var in_num = this.data.in_num  
870 - var firm = this.data.firm  
871 - var applicant = this.data.applicant_name  
872 - var recognizee = this.data.recognizee_name  
873 - var main_risks = this.data.main_risks  
874 - var year_money = this.data.year_money  
875 - var compact_time = this.data.compact_time  
876 - var impletion_time = this.data.impletion_time  
877 - var warranty_one = JSON.stringify(this.data.warranty_one)  
878 - var type_money = this.data.type_money  
879 - var bank = this.data.bank  
880 - var bank_num = this.data.bank_num  
881 - var picurl = JSON.stringify(this.data.imgs)  
882 - let url = 'counselor/inforsave'  
883 - let params = {  
884 - // InfoId: this.data.inforid,  
885 - def_id: this.data.def_id,  
886 - in_num: in_num,  
887 - firm: firm,  
888 - applicant: applicant,  
889 - recognizee: recognizee,  
890 - favoree: favoree,  
891 - main_risks: main_risks,  
892 - guarantee: guarantee,  
893 - year_money: year_money,  
894 - warranty_two: warranty_two,  
895 - compact_time: compact_time,  
896 - impletion_time: impletion_time,  
897 - warranty_one: warranty_one,  
898 - long_money: long_money,  
899 - type_money: type_money,  
900 - bank: bank,  
901 - bank_num: bank_num,  
902 - more: more,  
903 - picurl: picurl,  
904 - }  
905 - app.post(url, params).then((res) => {  
906 - if (res.data.code == 200) {  
907 - wx.navigateBack({  
908 - delta: 1,  
909 - })  
910 - this.setData({  
911 - storge_state: true  
912 - })  
913 - var storge_state = true  
914 - wx.setStorageSync('storge_state', storge_state)  
915 - }  
916 - })  
917 - },  
918 -  
919 - //获取缓存内容  
920 - getStorage() {  
921 - let url = 'counselor/inforCopy'  
922 - let params = {  
923 - def_id: this.data.def_id,  
924 - }  
925 - app.post(url, params).then((res) => {  
926 - console.log(res)  
927 - if (res.data.code == 200) {  
928 - var warranty_two = res.data.data.def.warranty_two  
929 - var unit = this.data.unit  
930 - unit = warranty_two.title  
931 - var long_money = res.data.data.def.long_money  
932 - var unit2 = this.data.unit2  
933 - unit2 = long_money.title  
934 - var type_money = res.data.data.def.type_money  
935 - var unit3 = this.data.unit3  
936 - unit3 = type_money  
937 - var beneficiary_list = res.data.data.def.favoree  
938 - for (var obj in beneficiary_list) {  
939 - beneficiary_list[obj].beneficiary_name = beneficiary_list[obj].name  
940 - beneficiary_list[obj].name_array = this.data.insure  
941 - }  
942 -  
943 - this.setData({  
944 - imgs: res.data.data.def.picurl,  
945 - type_money: res.data.data.def.type_money,  
946 - unit3: unit3,  
947 - year_money: res.data.data.def.year_money,  
948 - long_money: res.data.data.def.long_money,  
949 - unit2: unit2,  
950 - in_num: res.data.data.def.in_num,  
951 - firm: res.data.data.def.firm,  
952 - main_risks: res.data.data.def.main_risks,  
953 - main_array: res.data.data.def.guarantee,  
954 - applicant_name: res.data.data.def.applicant,  
955 - recognizee_name: res.data.data.def.recognizee,  
956 - warranty_one: res.data.data.def.warranty_one,  
957 - warranty_two: res.data.data.def.warranty_two,  
958 - unit: unit,  
959 - compact_time: res.data.data.def.compact_time,  
960 - impletion_time: res.data.data.def.impletion_time,  
961 - bank: res.data.data.def.bank,  
962 - bank_num: res.data.data.def.bank_num,  
963 - risk_list: res.data.data.def.more,  
964 - beneficiary_list: beneficiary_list,  
965 - edit_state: true,  
966 - })  
967 - }  
968 - })  
969 - },  
970 -  
971 - //完成保单添加  
972 - listVerify(e) {  
973 - if (this.data.inforid == 0 || this.data.inforid == undefined) {  
974 - this.tempBeneficiary()  
975 - this.tempWarranty()  
976 - this.tempburningTime()  
977 - this.tempMain()  
978 - this.tempAddRisk()  
979 - var favoree = JSON.stringify(this.data.tempfavoree)  
980 - var warranty_two = JSON.stringify(this.data.warranty_two)  
981 - var long_money = JSON.stringify(this.data.long_money)  
982 - var more = JSON.stringify(this.data.more)  
983 - var guarantee = JSON.stringify(this.data.guarantee)  
984 - } else if (this.data.edit_state) {  
985 - var favoree = JSON.stringify(this.data.beneficiary_list)  
986 - var warranty_two = JSON.stringify(this.data.warranty_two)  
987 - var long_money = JSON.stringify(this.data.long_money)  
988 - var more = JSON.stringify(this.data.risk_list)  
989 - var guarantee = JSON.stringify(this.data.main_array)  
990 - } else {  
991 - this.tempBeneficiary()  
992 - this.tempWarranty()  
993 - this.tempburningTime()  
994 - this.tempMain()  
995 - this.tempAddRisk()  
996 - var favoree = JSON.stringify(this.data.tempfavoree)  
997 - var warranty_two = JSON.stringify(this.data.warranty_two)  
998 - var long_money = JSON.stringify(this.data.long_money)  
999 - var more = JSON.stringify(this.data.more)  
1000 - var guarantee = JSON.stringify(this.data.guarantee)  
1001 - }  
1002 -  
1003 - var warn = ""; //弹框时提示的内容  
1004 - var flag = true; //判断信息输入是否完整判断弹窗  
1005 - var in_num = e.detail.value.policy_num  
1006 - var firm = e.detail.value.company;  
1007 - var applicant = this.data.applicant_name  
1008 - var recognizee = this.data.recognizee_name  
1009 - var main_risks = e.detail.value.main_risks  
1010 -  
1011 - var year_money = e.detail.value.year_money  
1012 - var compact_time = this.data.compact_time  
1013 - var impletion_time = this.data.impletion_time  
1014 - var warranty_one = JSON.stringify(this.data.warranty_one)  
1015 - var type_money = this.data.type_money  
1016 - var bank = e.detail.value.bank  
1017 - var bank_num = e.detail.value.bank_num  
1018 - var picurl = JSON.stringify(this.data.imgs)  
1019 -  
1020 - var continue1 = e.detail.target.dataset.type  
1021 - var complete = e.detail.target.dataset.type  
1022 -  
1023 - if (in_num == '') {  
1024 - warn = '请输入保单号!'  
1025 - } else if (firm == '') {  
1026 - warn = '请输入所属公司!'  
1027 - } else if (applicant == '') {  
1028 - warn = '请输入投保人!'  
1029 - } else if (recognizee == '') {  
1030 - warn = '请输入被保险人!'  
1031 - } else if (favoree == '') {  
1032 - warn = '请输入受益人!'  
1033 - } else if (main_risks == '') {  
1034 - warn = '请输入主险名称!'  
1035 - } else if (year_money == '') {  
1036 - warn = '请输入年交保费!'  
1037 - } else if (compact_time == '') {  
1038 - warn = '请输入合同生效日!'  
1039 - } else if (warranty_two.num == '') {  
1040 - warn = '请输入保障期!'  
1041 - } else if (long_money.num == '') {  
1042 - warn = '请输入缴费时长!'  
1043 - } else if (type_money == '') {  
1044 - warn = '请输入缴费方式!'  
1045 - } else if (bank == '') {  
1046 - warn = '请输入续费银行!'  
1047 - } else if (bank_num == '') {  
1048 - warn = '请输入续费账号!'  
1049 - } else if (!(/^[0-9]+.?[0-9]*/.test(bank_num))) {  
1050 - warn = '请输入正确续费账号!'  
1051 - } else if (impletion_time == '') {  
1052 - warn = '请输入缴费期满日!'  
1053 - } else if (warranty_one == '') {  
1054 - warn = '请输入主险保障期!'  
1055 - } else if (more == '') {  
1056 - warn = '请输入附加险!'  
1057 - } else if (picurl.length == 2) {  
1058 - warn = '请选择图片!'  
1059 - } else {  
1060 - flag = false  
1061 - // 添加、修改保单接口调取  
1062 - let url = 'counselor/inforuodate'  
1063 - let params = {  
1064 - InfoId: this.data.inforid,  
1065 - def_id: this.data.def_id,  
1066 - in_num: in_num,  
1067 - firm: firm,  
1068 - applicant: applicant,  
1069 - recognizee: recognizee,  
1070 - favoree: favoree,  
1071 - main_risks: main_risks,  
1072 - guarantee: guarantee,  
1073 - year_money: year_money,  
1074 - warranty_two: warranty_two,  
1075 - compact_time: compact_time,  
1076 - impletion_time: impletion_time,  
1077 - warranty_one: warranty_one,  
1078 - long_money: long_money,  
1079 - type_money: type_money,  
1080 - bank: bank,  
1081 - bank_num: bank_num,  
1082 - more: more,  
1083 - picurl: picurl,  
1084 - }  
1085 - app.post(url, params).then((res) => {  
1086 - if (res.data.code == 200) {  
1087 - if (continue1 == 'continue1') {  
1088 - wx.showToast({  
1089 - title: '添加成功',  
1090 - icon: 'none',  
1091 - duration: 2000,  
1092 - })  
1093 - this.setData({  
1094 - in_num:'',  
1095 - firm:'',  
1096 - applicant_name:'',  
1097 - recognizee_name:'',  
1098 - // beneficiary_list: [{  
1099 - // name_array: [],  
1100 - // unit: ''  
1101 - // }],  
1102 - main_risks:'',  
1103 - main_array:'',  
1104 - year_money:'',  
1105 - compact_time:'',  
1106 - warranty_two:'',  
1107 - long_money:'',  
1108 - bank:'',  
1109 - bank_num:'',  
1110 - impletion_time:'',  
1111 - warranty_one:'',  
1112 - // risk_list:'',  
1113 - imgs:'',  
1114 - unit:'',  
1115 - unit2: '',  
1116 - unit3: '',  
1117 - unit4: '',  
1118 - })  
1119 - } else if (complete == 'complete') {  
1120 - wx.showToast({  
1121 - title: '添加成功',  
1122 - icon: 'none',  
1123 - duration: 2000,  
1124 - })  
1125 - wx.navigateBack({  
1126 - delta: 1,  
1127 - })  
1128 - }  
1129 - }  
1130 - })  
1131 - }  
1132 -  
1133 - if (flag == true) {  
1134 - wx.showToast({  
1135 - title: warn,  
1136 - icon: 'none'  
1137 - })  
1138 - }  
1139 -  
1140 - },  
1141 -  
1142 -  
1143 -  
1144 - //获取编辑保单接口  
1145 - getlistVerify() {  
1146 - let url = 'counselor/infordef'  
1147 - let params = {  
1148 - InfoId: this.data.inforid,  
1149 - }  
1150 - app.post(url, params).then((res) => {  
1151 - if (res.data.code == 200) {  
1152 - var warranty_two = res.data.data.def.warranty_two  
1153 - var unit = this.data.unit  
1154 - unit = warranty_two.title  
1155 - var long_money = res.data.data.def.long_money  
1156 - var unit2 = this.data.unit2  
1157 - unit2 = long_money.title  
1158 - var type_money = res.data.data.def.type_money  
1159 - var unit3 = this.data.unit3  
1160 - unit3 = type_money  
1161 - var beneficiary_list = res.data.data.def.favoree  
1162 - for (var obj in beneficiary_list) {  
1163 - beneficiary_list[obj].beneficiary_name = beneficiary_list[obj].name  
1164 - beneficiary_list[obj].name_array = this.data.insure  
1165 - }  
1166 -  
1167 - var risk_list = res.data.data.def.more  
1168 - var projectlist = this.data.projectlist  
1169 -  
1170 - for (var i = 0; i < risk_list.length; i++) {  
1171 - for (var j = 0; j < projectlist.length; j++) {  
1172 - for (var k = 0; k < projectlist[j].title.length; k++) {  
1173 - if (risk_list[i].id == projectlist[j].id) {  
1174 - if (risk_list[i].title == projectlist[j].title[k].name) {  
1175 - var title = {}  
1176 - title.name = projectlist[j].title[k]  
1177 - }  
1178 - }  
1179 - }  
1180 - }  
1181 - }  
1182 -  
1183 - var warranty_two = res.data.data.def.warranty_two  
1184 - var guarantee_name = warranty_two.num  
1185 -  
1186 - var long_money = res.data.data.def.long_money  
1187 - var time_name = long_money.num  
1188 -  
1189 - this.setData({  
1190 - imgs: res.data.data.def.picurl,  
1191 - type_money: res.data.data.def.type_money,  
1192 - unit3: unit3,  
1193 - year_money: res.data.data.def.year_money,  
1194 - long_money: res.data.data.def.long_money,  
1195 - unit2: unit2,  
1196 - in_num: res.data.data.def.in_num,  
1197 - firm: res.data.data.def.firm,  
1198 - main_risks: res.data.data.def.main_risks,  
1199 - main_array: res.data.data.def.guarantee,  
1200 - applicant_name: res.data.data.def.applicant,  
1201 - recognizee_name: res.data.data.def.recognizee,  
1202 - warranty_one: res.data.data.def.warranty_one,  
1203 - warranty_two: res.data.data.def.warranty_two,  
1204 - unit: unit,  
1205 - compact_time: res.data.data.def.compact_time,  
1206 - impletion_time: res.data.data.def.impletion_time,  
1207 - bank: res.data.data.def.bank,  
1208 - bank_num: res.data.data.def.bank_num,  
1209 - risk_list: risk_list,  
1210 - beneficiary_list: beneficiary_list,  
1211 - edit_state: true,  
1212 - guarantee_name: guarantee_name,  
1213 - time_name: time_name,  
1214 - })  
1215 - }  
1216 - })  
1217 - },  
1218 -  
1219 - /**  
1220 - * 生命周期函数--监听页面加载  
1221 - */  
1222 - onLoad: function(options) {  
1223 - this.ensureProjectList()  
1224 - this.setData({  
1225 - def_id: options.def_id,  
1226 - inforid: options.inforid,  
1227 - FamilyId: options.FamilyId,  
1228 - recognizee_name: options.name  
1229 - })  
1230 - if (options.inforid == undefined) {  
1231 - this.setData({  
1232 - inforid: 0  
1233 - })  
1234 - }  
1235 - if (options.FamilyId != '') {  
1236 - this.familyMember()  
1237 - }  
1238 - if (options.inforid != undefined) {  
1239 - this.getlistVerify()  
1240 - }  
1241 -  
1242 - if (wx.getStorageSync('storge_state') && options.inforid == undefined) {  
1243 - this.getStorage()  
1244 - }  
1245 - },  
1246 -  
1247 - /**  
1248 - * 生命周期函数--监听页面初次渲染完成  
1249 - */  
1250 - onReady: function() {  
1251 -  
1252 - },  
1253 -  
1254 - /**  
1255 - * 生命周期函数--监听页面显示  
1256 - */  
1257 - onShow: function() {  
1258 -  
1259 - },  
1260 -  
1261 - /**  
1262 - * 生命周期函数--监听页面隐藏  
1263 - */  
1264 - onHide: function() {  
1265 -  
1266 - },  
1267 -  
1268 - /**  
1269 - * 生命周期函数--监听页面卸载  
1270 - */  
1271 - onUnload: function() {  
1272 -  
1273 - },  
1274 -  
1275 - /**  
1276 - * 页面相关事件处理函数--监听用户下拉动作  
1277 - */  
1278 - onPullDownRefresh: function() {  
1279 -  
1280 - },  
1281 -  
1282 - /**  
1283 - * 页面上拉触底事件的处理函数  
1284 - */  
1285 - onReachBottom: function() {  
1286 -  
1287 - },  
1288 -  
1289 - /**  
1290 - * 用户点击右上角分享  
1291 - */  
1292 - onShareAppMessage: function() {  
1293 -  
1294 - }  
1295 -})