addListDetail.js 43.8 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 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
// 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_array: ['受益人1', '受益人2'],
          unit: ''
        }],
        beneficiaryindex: -1,
        tempfavoree: [], // 已选择的受益人
        beneficiaryList: [],
        name: '', //受益人的名字,
        beneficiary_name: '',
        imgs: [],
        main_risk: [],
        unit: '',
        unit2: '',
        unit3: '',
        unit4: '',
        applicant_name: '',
        recognizee_name: '',
        rang_beneficiary: [],
        risk_list: [{
          name: '',
          mo: [],
          project_time: '',
          title: '',
          num: ''
        }],
        main_array: [],
        warranty_one: '',
        warranty_two: {},
        guarantee_name: '',
        long_money: {},
        time_name: '',
        type_money: '',
        more: [],
        guarantee: [],
        InfoId: 0,
        def_id: '',
        edit_state: false,
        risk_listitm: '',
        storge_state: false,
      },

      //保单号
      policyNum(e) {
        this.setData({
          in_num: e.detail.value,
        })
      },

      //保单号
      setFirm(e) {
        this.setData({
          firm: e.detail.value,
        })
      },

      //投保人
      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]
        })
      },

      //主险名称
      setRiskName(e) {
        // console.log(e)
        this.setData({
          main_risks: e.detail.value,
        })
        // console.log(this.data.main_risks)
      },

      //保费
      yearMoney(e) {
        this.setData({
          year_money: e.detail.value,
        })
      },

      //设置银行
      setBank(e) {
        this.setData({
          bank: e.detail.value,
        })
      },

      //设置账号
      setBankNum(e) {
        this.setData({
          bank_num: e.detail.value,
        })
      },

      //合同生效日
      compactTime(e) {
        this.setData({
          compact_time: e.detail.value,
        })
        this.countImpletionTime()
        this.countImpletionTime2()
      },

      //缴费期满日
      impletionTime(e) {
        this.setData({
          impletion_time: e.detail.value,
        })
      },

      //主险保障期
      periodTime(e) {
        this.setData({
          period_index: e.detail.value,
        })
      },

      //保障项目弹窗
      ensureProject(e) {
        this.setData({
          edit_state: false
        })

        let that = this;
        let type = e.currentTarget.dataset.type;
        let index = e.currentTarget.dataset.xulie;
        let tempProjectlist = Object.assign(this.data.projectlist, {});
        // 已经添加的附加险
        let risk_list = Object.assign(this.data.risk_list, {});
        console.log(risk_list)
        let tempRist = risk_list[index].mo;
        console.log(tempRist)
        // 已经添加的主险
        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].choose_status = true
                  for (let g in tempProjectlist[i].title) {
                    tempProjectlist[i].title[g].t_id == tempMain_list[j].t_id ? tempProjectlist[i].title[g].label_state = true : ''
                   
                  }
                }
              }
            }
          }
          } else {
            if (tempRist.length) {
              for (let i in tempProjectlist) {
                for (let j in tempRist) {
                  if (tempProjectlist[i].id == tempRist[j].id) {
                    tempProjectlist[i].choose_status = true
                    for (let g in tempProjectlist[i].title) {
                      console.log(tempProjectlist[i].title[g])
                      tempProjectlist[i].title[g].t_id == tempMain_list[j].t_id ? tempProjectlist[i].title[g].label_state = true : ''
                    }
                  }
                }
              }
            }
          }

          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 = ''
              if (title[i].current == '') {
                title[i].label_state = false
              }
            }
            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,
            })
            if (this.data.inforid != 0) {
              edit_state: false
            }
          },

          //确认选择的推荐方案
          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])
                console.log(main_array)
              }
            }

            if (main_array != '') {
              wx.showToast({
                title: '添加成功',
                icon: 'none'
              })

              if (type == 'fujiaxian') {
                let tempRist = that.data.risk_list;
                console.log(tempRist)
                tempRist[index]['mo'] = main_array;
                that.setData({
                  risk_list: tempRist,
                  risk_listitm: tempRist
                })
                console.log(this.data.risk_list)
              } else {
                that.setData({
                  main_array: main_array,
                })
              }
              console.log(this.data.main_array)
            }
            setTimeout(function() {
              that.ensureProjectList()
              that.setData({
                popup_state: false
              })
              wx.setNavigationBarTitle({
                title: '添加保单',
              })
            }, 800)


            console.log(this.data.risk_list)
          },

          //重组主险的保障项目
          tempMain() {
            var main_array = this.data.main_array
            var warranty_one1 = []
            // console.log(main_array)
            for (var i = 0; i < main_array.length; i++) {
              var temp = {}
              for (var j = 0; j < main_array[i].title.length; j++) {
                if (main_array[i].choose_status) {
                  if (main_array[i].title[j].label_state) {
                    temp.id = main_array[i].id
                    temp.name = main_array[i].name
                    temp.num = main_array[i].num
                    temp.title = main_array[i].title[j].name
                    temp.t_id = main_array[i].title[j].t_id
                  }
                }
              }
              warranty_one1.push(temp)
              this.setData({
                guarantee: warranty_one1
              })
            }

          },

          //主险名称
          addRiskName(e) {
            var risk_list = this.data.risk_list
            var index = e.currentTarget.dataset.index
            risk_list[index].name = e.detail.value
            this.setData({
              risk_list: risk_list
            })
          },

          //主险保障其
          addRiskUnit(e) {
            var risk_list = this.data.risk_list
            var index = e.currentTarget.dataset.index
            risk_list[index].num = e.detail.value
            this.setData({
              risk_list: risk_list
            })
          },

          //重组附加险整体数据结构
          tempAddRisk() {
            var risk_list = this.data.risk_list

            var sub_array = []
            var temp_risk = this.data.risk_listitm;
            var temp = this.data.risk_listitm;

            for (var i = 0; i < temp.length; i++) {
              for (var j = 0; j < temp[i].mo.length; j++) {
                for (var k = 0; k < temp[i].mo[j].title.length; k++) {
                  if (temp[i].name != '') {
                    // var temp = {}
                    // var subtemp = {}
                    if (temp[i].mo[j].choose_status) {
                      if (temp[i].mo[j].title[k].label_state) {
                        temp_risk[i].name = temp[i].name
                        temp_risk[i].num = temp[i].num
                        temp_risk[i].title = temp[i].title
                        temp_risk[i].mo[j].t_id = temp[i].mo[j].title[k].t_id
                        temp_risk[i].mo[j].id = temp[i].mo[j].id
                        temp_risk[i].mo[j].name = temp[i].mo[j].name
                        temp_risk[i].mo[j].num = temp[i].mo[j].num
                        temp_risk[i].mo[j].title = temp[i].mo[j].title[k].name
                        console.log(temp_risk)
                      }
                    }
                  }
                }
              }

              this.setData({
                more: temp_risk
              })
            }

          },

          //选择受益人姓名
          beneficiarySelect(e) {
            if (this.data.inforid != 0) {
              this.setData({
                edit_state: false
              })
            }
            var index = e.currentTarget.dataset.mindex
            var beneficiary_list = Object.assign(this.data.beneficiary_list, {});
            // 获取当前已选择的收益人
            let tempBenefice = Object.assign(this.data.beneficiaryList, {})
            // 当前选择的收益人
            let nowPerson = beneficiary_list[index].name_array[e.detail.value];
            // 判断受益人是否已经添加
            const add = tempBenefice.every((tempBenefice) => {
              return tempBenefice != nowPerson
            })
            if (add) {
              beneficiary_list[index].beneficiary_name = nowPerson;
              tempBenefice.push(nowPerson)
            } else {
              wx.showToast({
                title: '请不要重复添加受益人',
                icon: 'none'
              })
            }

            this.setData({
              beneficiary_list: beneficiary_list,
              beneficiaryList: tempBenefice
            })

          },

          //添加收益比例
          addUnit(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_array: this.data.insure,
                unit: ''
              }
            }
            this.setData({
              beneficiary_list: list
            })
            console.log(this.data.beneficiary_list)
          },

          //重组添加受益人
          tempBeneficiary() {
            var beneficiary_list = this.data.beneficiary_list
            var len = beneficiary_list.length;
            var tempfavoree1 = [];
            for (var i = 0; i < beneficiary_list.length; i++) {
              var temp = {}
              if (beneficiary_list[i].unit != '') {
                temp.name = beneficiary_list[i].beneficiary_name
                temp.unit = beneficiary_list[i].unit;
              }
              tempfavoree1.push(temp)
              this.setData({
                tempfavoree: tempfavoree1
              })

            }
          },

          //删除收益人
          deletebenefict(e) {
            let index = e.currentTarget.dataset.index;
            let tempbenefict = Object.assign(this.data.beneficiary_list, {});
            let beneficiaryList = Object.assign(this.data.beneficiaryList, {});
            // 获取当前选项的受益人
            let person = tempbenefict[index].beneficiary_name;
            tempbenefict.splice(index, 1);
            if (person) beneficiaryList.splice(beneficiaryList.indexOf(person), 1)

            this.setData({
              beneficiaryList: beneficiaryList,
              beneficiary_list: tempbenefict
            })
          },

          //添加附加险
          addRisk() {
            if (this.data.inforid != 0) {
              this.setData({
                edit_state: false
              })
            }
            var risk_list = Object.assign(this.data.risk_list, {});
            var len = risk_list.length
            risk_list[len] = {
              name: '',
              mo: [],
              project_time: '',
              title: '',
              num: ''
            }
            this.setData({
              risk_list: risk_list
            })
          },

          //删除附加险
          deleteRisk(e) {
            let index = e.currentTarget.dataset.index;
            let risk_list = Object.assign(this.data.risk_list, {});
            risk_list.splice(index, 1);
            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) {
            if (this.data.inforid != 0) {
              this.setData({
                edit_state: false
              })
            }
            var guarantee_name = e.detail.value
            this.setData({
              guarantee_name: e.detail.value
            })
            this.countImpletionTime2()
          },

          //选择各项单位
          selectUnit(e) {
            var unit = e.currentTarget.dataset.unit
            this.setData({
              unit: unit
            })
            this.countImpletionTime2()
          },

          //重组保障期数据格式
          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
            this.setData({
              warranty_two: warranty_two
            })
          },


          //计算缴费期满日,主线保障其
          countImpletionTime2() {
            var guarantee_name = parseInt(this.data.guarantee_name)
            var unit = this.data.unit
            var compact_time = this.data.compact_time
            var year = parseInt(new Date(compact_time).getFullYear())
            console.log(year)
            var month = parseInt(new Date(compact_time).getMonth() + 1)
            var day = parseInt(new Date(compact_time).getDate())
            // var impletion_time = this.data.impletion_time
            var warranty_one = this.data.warranty_one

            var tempbirth_time = ''
            var birthday = '1995-04-20'
            var birthday_year = parseInt(new Date(birthday).getFullYear())

            if (compact_time == '') {
              wx.showToast({
                title: '请选择合同生效日',
                icon: 'none'
              })
            } else {
              if (unit == '年') {
                var temp_year = (year + guarantee_name)
                var temp_day = day - 1
                if (month < 10) month = "0" + month;
                if (temp_day < 10) temp_day = "0" + temp_day;
                // impletion_time = temp_year + '-' + month + '-' + temp_day
                warranty_one = temp_year + '-' + month + '-' + temp_day
              } else if (unit == '岁') {
                var temp_year = (birthday_year + guarantee_name - 1)
                var temp_year2 = (birthday_year + guarantee_name)
                var temp_month = month
                if (temp_month < 10) temp_month = "0" + temp_month;
                if (month < 10) month = "0" + month;
                if (day < 10) day = "0" + day;
                // impletion_time = temp_year + '-' + temp_month + '-' + day
                warranty_one = temp_year2 + '-' + month + '-' + day
              } else if (unit == '终身') {
                // impletion_time = '终身缴费'
                warranty_one = '终身'
              }
              this.setData({
                // impletion_time: impletion_time,
                warranty_one: warranty_one
              })
            }
          },

          //缴费时长
          burningTime(e) {
            if (this.data.inforid != 0) {
              this.setData({
                edit_state: false
              })
            }
            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
            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() + 1)
            var day = parseInt(new Date(compact_time).getDate())
            var impletion_time = this.data.impletion_time
            // var warranty_one = this.data.warranty_one

            var tempbirth_time = ''
            var birthday = '1995-04-20'
            var birthday_year = parseInt(new Date(birthday).getFullYear())

            if (compact_time == '') {
              wx.showToast({
                title: '请选择合同生效日',
                icon: 'none'
              })
            } else {
              if (unit == '年') {
                var temp_year = (year + time_name)
                var temp_day = day - 1
                if (month < 10) month = "0" + month;
                if (temp_day < 10) temp_day = "0" + temp_day;
                impletion_time = temp_year + '-' + month + '-' + temp_day
                // warranty_one = temp_year + '-' + month + '-' + temp_day
              } else if (unit == '岁') {
                var temp_year = (birthday_year + time_name - 1)
                var temp_year2 = (birthday_year + time_name)
                var temp_month = month
                if (temp_month < 10) temp_month = "0" + temp_month;
                if (month < 10) month = "0" + month;
                if (day < 10) day = "0" + day;
                impletion_time = temp_year + '-' + temp_month + '-' + day
                // warranty_one = temp_year2 + '-' + month + '-' + day
              } else if (unit == '终身') {
                impletion_time = '终身缴费'
                // warranty_one = '终身'
              }
              this.setData({
                impletion_time: impletion_time,
                // warranty_one: warranty_one
              })
            }
          },

          //缴费方式
          selectUnit3(e) {
            var unit = e.currentTarget.dataset.unit
            this.setData({
              unit3: unit,
              type_money: unit
            })
          },

          //附加险保障其
          selectUnit4(e) {
            var unit = e.currentTarget.dataset.unit;
            let index = e.currentTarget.dataset.index;
            let risk_list = Object.assign(this.data.risk_list, {});
            risk_list[index].title = unit
            this.setData({
              risk_list: risk_list
            })
          },

          //家庭成员
          familyMember() {
            var FamilyId = this.data.FamilyId
            let url = 'counselor/familyname'
            let params = {
              FamilyId: FamilyId,
            }
            app.post(url, params).then((res) => {
              // console.log(res)
              var beneficiary_list = this.data.beneficiary_list
              for (var i in beneficiary_list) {
                beneficiary_list[i].name_array = res.data.data.list
              }
              // console.log(beneficiary_list)

              if (res.data.code == 200) {
                this.setData({
                  insure: res.data.data.list,
                  recognizee: res.data.data.list,
                  beneficiary_list: beneficiary_list,
                })
              }
            })
          },

          //设置缓存
          setStorge(e) {
            this.tempBeneficiary()
            this.tempWarranty()
            this.tempburningTime()
            this.tempMain()
            this.tempAddRisk()
            var favoree = JSON.stringify(this.data.tempfavoree)
            var warranty_two = JSON.stringify(this.data.warranty_two)
            var long_money = JSON.stringify(this.data.long_money)
            var more = JSON.stringify(this.data.more)
            var guarantee = JSON.stringify(this.data.guarantee)
            var warn = ""; //弹框时提示的内容
            var in_num = this.data.in_num
            var firm = this.data.firm
            var applicant = this.data.applicant_name
            var recognizee = this.data.recognizee_name
            var main_risks = this.data.main_risks
            var year_money = this.data.year_money
            var compact_time = this.data.compact_time
            var impletion_time = this.data.impletion_time
            var warranty_one = JSON.stringify(this.data.warranty_one)
            var type_money = this.data.type_money
            var bank = this.data.bank
            var bank_num = this.data.bank_num
            var picurl = JSON.stringify(this.data.imgs)
            let url = 'counselor/inforsave'
            let params = {
              // InfoId: this.data.inforid,
              def_id: this.data.def_id,
              in_num: in_num,
              firm: firm,
              applicant: applicant,
              recognizee: recognizee,
              favoree: favoree,
              main_risks: main_risks,
              guarantee: guarantee,
              year_money: year_money,
              warranty_two: warranty_two,
              compact_time: compact_time,
              impletion_time: impletion_time,
              warranty_one: warranty_one,
              long_money: long_money,
              type_money: type_money,
              bank: bank,
              bank_num: bank_num,
              more: more,
              picurl: picurl,
            }
            app.post(url, params).then((res) => {
              if (res.data.code == 200) {
                wx.navigateBack({
                  delta: 1,
                })
                this.setData({
                  storge_state: true
                })
                var storge_state = true
                wx.setStorageSync('storge_state', storge_state)
              }
            })
          },

          //获取缓存内容
          getStorage() {
            let url = 'counselor/inforCopy'
            let params = {
              def_id: this.data.def_id,
            }
            app.post(url, params).then((res) => {
              console.log(res)
              if (res.data.code == 200) {
                var warranty_two = res.data.data.def.warranty_two
                var unit = this.data.unit
                unit = warranty_two.title
                var long_money = res.data.data.def.long_money
                var unit2 = this.data.unit2
                unit2 = long_money.title
                var type_money = res.data.data.def.type_money
                var unit3 = this.data.unit3
                unit3 = type_money
                var beneficiary_list = res.data.data.def.favoree
                for (var obj in beneficiary_list) {
                  beneficiary_list[obj].beneficiary_name = beneficiary_list[obj].name
                  beneficiary_list[obj].name_array = this.data.insure
                }

                this.setData({
                  imgs: res.data.data.def.picurl,
                  type_money: res.data.data.def.type_money,
                  unit3: unit3,
                  year_money: res.data.data.def.year_money,
                  long_money: res.data.data.def.long_money,
                  unit2: unit2,
                  in_num: res.data.data.def.in_num,
                  firm: res.data.data.def.firm,
                  main_risks: res.data.data.def.main_risks,
                  main_array: res.data.data.def.guarantee,
                  applicant_name: res.data.data.def.applicant,
                  recognizee_name: res.data.data.def.recognizee,
                  warranty_one: res.data.data.def.warranty_one,
                  warranty_two: res.data.data.def.warranty_two,
                  unit: unit,
                  compact_time: res.data.data.def.compact_time,
                  impletion_time: res.data.data.def.impletion_time,
                  bank: res.data.data.def.bank,
                  bank_num: res.data.data.def.bank_num,
                  risk_list: res.data.data.def.more,
                  beneficiary_list: beneficiary_list,
                  edit_state: true,
                })
              }
            })
          },

          //完成保单添加
          listVerify(e) {
            if (this.data.inforid == 0 || this.data.inforid == undefined) {
              this.tempBeneficiary()
              this.tempWarranty()
              this.tempburningTime()
              this.tempMain()
              this.tempAddRisk()
              var favoree = JSON.stringify(this.data.tempfavoree)
              var warranty_two = JSON.stringify(this.data.warranty_two)
              var long_money = JSON.stringify(this.data.long_money)
              var more = JSON.stringify(this.data.more)
              var guarantee = JSON.stringify(this.data.guarantee)
            } else if (this.data.edit_state) {
              var favoree = JSON.stringify(this.data.beneficiary_list)
              var warranty_two = JSON.stringify(this.data.warranty_two)
              var long_money = JSON.stringify(this.data.long_money)
              var more = JSON.stringify(this.data.risk_list)
              var guarantee = JSON.stringify(this.data.main_array)
            } else {
              this.tempBeneficiary()
              this.tempWarranty()
              this.tempburningTime()
              this.tempMain()
              this.tempAddRisk()
              var favoree = JSON.stringify(this.data.tempfavoree)
              var warranty_two = JSON.stringify(this.data.warranty_two)
              var long_money = JSON.stringify(this.data.long_money)
              var more = JSON.stringify(this.data.more)
              var guarantee = JSON.stringify(this.data.guarantee)
            }

            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 main_risks = e.detail.value.main_risks

            var year_money = e.detail.value.year_money
            var compact_time = this.data.compact_time
            var impletion_time = this.data.impletion_time
            var warranty_one = JSON.stringify(this.data.warranty_one)
            var type_money = this.data.type_money
            var bank = e.detail.value.bank
            var bank_num = e.detail.value.bank_num
            var picurl = JSON.stringify(this.data.imgs)

            var continue1 = e.detail.target.dataset.type
            var complete = e.detail.target.dataset.type

            if (in_num == '') {
              warn = '请输入保单号!'
            } else if (firm == '') {
              warn = '请输入所属公司!'
            } else if (applicant == '') {
              warn = '请输入投保人!'
            } else if (recognizee == '') {
              warn = '请输入被保险人!'
            } else if (favoree == '') {
              warn = '请输入受益人!'
            } else if (main_risks == '') {
              warn = '请输入主险名称!'
            } else if (year_money == '') {
              warn = '请输入年交保费!'
            } else if (compact_time == '') {
              warn = '请输入合同生效日!'
            } else if (warranty_two.num == '') {
              warn = '请输入保障期!'
            } else if (long_money.num == '') {
              warn = '请输入缴费时长!'
            } else if (type_money == '') {
              warn = '请输入缴费方式!'
            } else if (bank == '') {
              warn = '请输入续费银行!'
            } else if (bank_num == '') {
              warn = '请输入续费账号!'
            } else if (!(/^[0-9]+.?[0-9]*/.test(bank_num))) {
              warn = '请输入正确续费账号!'
            } else if (impletion_time == '') {
              warn = '请输入缴费期满日!'
            } else if (warranty_one == '') {
              warn = '请输入主险保障期!'
            } else if (more == '') {
              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,
                main_risks: main_risks,
                guarantee: guarantee,
                year_money: year_money,
                warranty_two: warranty_two,
                compact_time: compact_time,
                impletion_time: impletion_time,
                warranty_one: warranty_one,
                long_money: long_money,
                type_money: type_money,
                bank: bank,
                bank_num: bank_num,
                more: more,
                picurl: picurl,
              }
              app.post(url, params).then((res) => {
                if (res.data.code == 200) {
                  if (continue1 == 'continue1') {
                    wx.showToast({
                      title: '添加成功',
                      icon: 'none',
                      duration: 2000,
                    })
                    this.setData({
                      in_num: '',
                      firm: '',
                      applicant_name: '',
                      recognizee_name: '',
                      // beneficiary_list: [{
                      //   name_array: [],
                      //   unit: ''
                      // }],
                      main_risks: '',
                      main_array: '',
                      year_money: '',
                      compact_time: '',
                      warranty_two: '',
                      long_money: '',
                      bank: '',
                      bank_num: '',
                      impletion_time: '',
                      warranty_one: '',
                      // risk_list:'',
                      imgs: '',
                      unit: '',
                      unit2: '',
                      unit3: '',
                      unit4: '',
                    })
                  } else if (complete == 'complete') {
                    wx.showToast({
                      title: '添加成功',
                      icon: 'none',
                      duration: 2000,
                    })
                    wx.navigateBack({
                      delta: 1,
                    })
                  }
                }
              })
            }

            if (flag == true) {
              wx.showToast({
                title: warn,
                icon: 'none'
              })
            }

          },



          //获取编辑保单接口
          getlistVerify() {
            let url = 'counselor/infordef'
            let params = {
              InfoId: this.data.inforid,
            }
            app.post(url, params).then((res) => {
              if (res.data.code == 200) {
                var warranty_two = res.data.data.def.warranty_two
                var unit = this.data.unit
                unit = warranty_two.title
                var long_money = res.data.data.def.long_money
                var unit2 = this.data.unit2
                unit2 = long_money.title
                var type_money = res.data.data.def.type_money
                var unit3 = this.data.unit3
                unit3 = type_money
                var beneficiary_list = res.data.data.def.favoree
                for (var obj in beneficiary_list) {
                  beneficiary_list[obj].beneficiary_name = beneficiary_list[obj].name
                  beneficiary_list[obj].name_array = this.data.insure
                }

                var risk_list = res.data.data.def.more
                var projectlist = this.data.projectlist

                for (var i = 0; i < risk_list.length; i++) {
                  for (var j = 0; j < projectlist.length; j++) {
                    for (var k = 0; k < projectlist[j].title.length; k++) {
                      if (risk_list[i].id == projectlist[j].id) {
                        if (risk_list[i].title == projectlist[j].title[k].name) {
                          var title = {}
                          title.name = projectlist[j].title[k]
                        }
                      }
                    }
                  }
                }

                var warranty_two = res.data.data.def.warranty_two
                var guarantee_name = warranty_two.num

                var long_money = res.data.data.def.long_money
                var time_name = long_money.num

                this.setData({
                  imgs: res.data.data.def.picurl,
                  type_money: res.data.data.def.type_money,
                  unit3: unit3,
                  year_money: res.data.data.def.year_money,
                  long_money: res.data.data.def.long_money,
                  unit2: unit2,
                  in_num: res.data.data.def.in_num,
                  firm: res.data.data.def.firm,
                  main_risks: res.data.data.def.main_risks,
                  main_array: res.data.data.def.guarantee,
                  applicant_name: res.data.data.def.applicant,
                  recognizee_name: res.data.data.def.recognizee,
                  warranty_one: res.data.data.def.warranty_one,
                  warranty_two: res.data.data.def.warranty_two,
                  unit: unit,
                  compact_time: res.data.data.def.compact_time,
                  impletion_time: res.data.data.def.impletion_time,
                  bank: res.data.data.def.bank,
                  bank_num: res.data.data.def.bank_num,
                  risk_list: risk_list,
                  beneficiary_list: beneficiary_list,
                  edit_state: true,
                  guarantee_name: guarantee_name,
                  time_name: time_name,
                })
              }
            })
          },

          /**
           * 生命周期函数--监听页面加载
           */
          onLoad: function(options) {
            this.ensureProjectList()
            this.setData({
              def_id: options.def_id,
              inforid: options.inforid,
              FamilyId: options.FamilyId,
              recognizee_name: options.name
            })
            if (options.inforid == undefined) {
              this.setData({
                inforid: 0
              })
            }
            if (options.FamilyId != '') {
              this.familyMember()
            }
            if (options.inforid != undefined) {
              this.getlistVerify()
            }

            if (wx.getStorageSync('storge_state') && options.inforid == undefined) {
              this.getStorage()
            }
          },

          /**
           * 生命周期函数--监听页面初次渲染完成
           */
          onReady: function() {

          },

          /**
           * 生命周期函数--监听页面显示
           */
          onShow: function() {

          },

          /**
           * 生命周期函数--监听页面隐藏
           */
          onHide: function() {

          },

          /**
           * 生命周期函数--监听页面卸载
           */
          onUnload: function() {

          },

          /**
           * 页面相关事件处理函数--监听用户下拉动作
           */
          onPullDownRefresh: function() {

          },

          /**
           * 页面上拉触底事件的处理函数
           */
          onReachBottom: function() {

          },

          /**
           * 用户点击右上角分享
           */
          onShareAppMessage: function() {

          }
      })