addClaims.js 40 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
// packageStoreAssistant/packageEquityClaims/pages/addClaims/addClaims.js
import { claimsApi } from '~/api/api'
import { equityApi } from '~/api/api'
import Util from '~/utils/util'
import NP from 'number-precision'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId: '',
    curStatus: '',
    activeTabIdx: 0,  
    damageDisabled: false, // 禁用定损信息
    isDamageStage: true, // 定损阶段
    isSync: false,  // 是否已经同步合同号
    activeTabList: [],  // 展开收起的数组
    reasonForFailure: '',  // 不通过描述
    reasonForFailureCode: 1, // 不通过原因 1:拒赔 2:资料不清晰
    tabList: ['核赔信息', '定损信息'],
    statusList: [  //进度条
        {
            nameObj: {
                1: '待受理',
                2: '已受理',
                3: '已失效'
            },
            type: 1,
            active: true
        },
        {
            nameObj: {
                1: '待定损',
                2: '已定损',
                3: '定损不通过',
            },
            type: 1,
            active: false
        },
        {
            nameObj: {
                1: '待核赔',
                2: '已核赔',
                3: '核赔不通过',
            },
            type: 1,
            active: false
        },
        {
            nameObj: {
                1: '待支付',
                2: '已支付',
            },
            type: 1,
            active: false
        }
    ],
    formDataList: [
        {
            type: 'input',
            label: '合同号',
            require: true,
            maxlength: '30',
            key: 'contractNo',
            slotName: 'syncBtn',
            isDisabled: false,
            isHide: false
        },
        {
          type: 'input',
          label: '核销码',
          require: true,
          maxlength: '30',
          key: 'writeOffCode',
          slotName: 'syncBtn',
          isDisabled: false,
          isHide: true
        },
        {
            type: 'input',
            label: '报案人',
            require: true,
            maxlength: '20',
            key: 'reporterName'
        },
        {
            type: 'input',
            label: '报案人电话',
            maxlength: '11',
            require: true,
            key: 'reporterPhone'
        },
        {
            type: 'time',
            label: '报案日期',
            require: true,
            key: 'reportDate'
        },
        {
            type: 'time',
            label: '出险日期',
            require: true,
            key: 'reimbursementDate'
        },
        {
            type: 'region',
            label: '出险地址',
            require: true,
            key: 'reimbursementAddress',
            optionData: {}
        },
        {
            type: 'textarea',
            label: '出险详细地址',
            require: true,
            key: 'reimbursementAddr'
        },
    ],
    merchantFormList: [
        {
            type: 'input',
            label: '经办人',
            maxlength: '20',
            require: true,
            key: 'handlerName'
        },
        {
            type: 'input',
            label: '经办人电话',
            maxlength: '11',
            require: true,
            key: 'handlerPhone'
        },
        {
            type: 'textarea',
            label: '出险经过描述',
            require: true,
            maxlength: '200',
            key: 'reimbursementProcess'
        },
        {
            type: '',
            label: '申请核赔服务',
            require: true,
            addHtml: 'serviceSlot'
        }
    ],
    collectDataList: [
        {
            type: 'radio',
            label: '收款对象',
            key: 'objectType',
            optionList: [ {
                code: 0,
                name:'店面'
            },
              {
                code:1,
                name:'其他'
            }],
            optionKey: 'code'
        }
    ],
    accountDataList: [
        {
            type: 'radio',
            label: '账户类型',
            key: 'accountType',
            optionList: [ {
                code: 0,
                name:'对公'
            },
              {
                code:1,
                name:'对私'
            }],
            optionKey: 'code'
        },
        {
            type: 'select',
            label: '开户行名称',
            require: true,
            key: 'openBankCode',
            optionList: [],
            optionKey: 'code'
        },
        {
            type: 'input',
            label: '账户名称',
            require: true,
            maxlength: 60,
            key: 'accountName'
        },
        {
            type: 'input',
            label: '收款账号',
            require: true,
            maxlength: 25,
            key: 'accountNo'
        },
        {
            type: 'select',
            label: '收款账号所在省市',
            require: true,
            key: 'accountCityCode',
            optionList: [],
            optionKey: 'code'
        },
        {
            type: 'select',
            label: '收款人证件类型',
            require: true,
            key: 'cardTypeCode',
            optionList: [],
            optionKey: 'code'
        },
        {
            type: 'input',
            label: '收款人证件号码',
            require: true,
            maxlength: 25,
            key: 'cardNo'
        },
        {
            type: 'input',
            label: '收款人联系电话',
            require: true,
            maxlength: 11,
            key: 'phone'
        },
    ],
    accountFormData: {
        objectType: 0,
        accountType: '',
        openBankCode: '',
        accountName: '',
        accountNo: '',
        accountCityCode: '',
        cardTypeCode: '',
        cardNo: '',
        phone: '',
        approveAmount: '',
        applyAmount: '',
    },
    copyAccountData: {},
    otherFormData:{
        expressName: '',
        expressNo: ''
    },
    formData: {
        contractNo: '',
        writeOffCode: '',
        reporterName: '',
        reporterPhone: '',
        reportDate: '',
        reimbursementDate: '',
        reimbursementAddr: '',
        reimbursementAddress: '',
        handlerName: '',
        handlerPhone: '',
        reimbursementProcess: '',
        source: ''
    },
    fileTabs: [
        {
            label: '基础资料',
            name: 'base',
            isRequire: 1,
            fileList: []
        },
        {
            label: '定损细节照片',
            name: 'detail',
            isRequire: 1,
            fileList: []
        },
        {
            label: '现场照片',
            name: 'onSite',
            isRequire: 1,
            fileList: []
        },
        {
            label: '其他资料(非必传)',
            name: 'other',
            fileList: []
        }
    ],
    claimsFileTabs:[
        {
            label: '核赔细节照片',
            name: 'detail',
            isRequire: 1,
            fileList: []
        },
        {
            label: '其他资料',
            name: 'other',
            fileList: []
        }
    ],
    itemsList: [],
    onlyExampleConfig: {onlyExample: true},
    curSupplementList: [{content: ''}],
    supplementList1: [],
    copyFileList: [],
    terminationShow: false,
    descriptionText: ''
  },
  closeTermination() {
    this.setData({terminationShow: false})
  },
  // 核赔阶段 切换定损/核赔页
  changeTab(e) {
    const { index } = e.currentTarget.dataset
    this.setData({
        activeTabIdx: index
    })
  },
  setStatusInfo(status) {
    //32待受理 33待定损 35定损不通过  34定损通过   23待核赔 25核赔不通过 1待支付 3已支付 40已失效
    const _statusList1 = [33, 35, 34, 23, 25, 1, 3]
    const _statusList2 = [23, 25, 1, 3]
    const isDamageStage = [32, 33, 35, 40].includes(status)
    let {statusList} = this.data
    // type = 1, 代表 还没有到达这个状态, type=2代表已经到达了这个状态, 3代表失败状态
    statusList.forEach((item,index)=> {
        if(index==0 && status != 32 && status != 40) {      
            item.type = 2
            item.active = false
        }
        if (index == 0 && status == 40) {
          item.type = 3
          item.active = false
        }
        if(index==3 && status==3) {
            item.type = 2
            item.active = true
        }
        if(index==1 || index==2) {
            let list = index==1 ? _statusList1 : _statusList2
            const idx = list.indexOf(status)
            if(idx>-1 && idx<3) item.active = true
            item.type = idx < 1 ? 1 : idx == 1 ? 3: 2
        }
    })
    this.setData({
        damageDisabled: status!=32 && status!=35,
        claimsDisabled: [23, 1, 3].includes(status),
        statusList,
        orderStatus: status,
        activeTabIdx: isDamageStage ? 1 : 0,
        isDamageStage
    })
  },
  //选择服务类型
  changeChecked(e) {
    const { itemsList, formData } = this.data
    const {index, checked} = e.currentTarget.dataset
    let obj = itemsList[index] || {}
    // 调接口判断合同服务项目是否已终止
    equityApi.checkItemsApi({contractNo: formData.contractNo, serviceCode: obj.serviceItemCode}).then(res => {
      if (res.checkFlag) {
        this.setData({
          descriptionText: `${res.reason}`,
          terminationShow: true,
          [`itemsList[${index}].checked`]: false
        })
        return
      } else {
        itemsList.forEach((item,idx) => {
          if(index == idx) {
            item.checked = true
            if(!checked){
              // 选中服务的时候损失类型 赋默认值
              if(item.serviceItemType==5){
                  item.lossType = 1
              }
              if(item.serviceItemType == 4){
                  item.lossType = 3
              }
              this.changeFileList(item.serviceItemType, item.serviceItemCode, item.lossType)
            }
          }else{
            if(!checked){
              item.checked = false
            }
          }
        })
        this.setData({
          itemsList
        })
      }
    })
  },
  changeFileList(serviceItemType, serviceItemCode, lossType, list) {
    const { copyFileList } = this.data
    let fileTabs = list || this.data.fileTabs
    if(serviceItemType==4){
        fileTabs[1].fileList = copyFileList.filter(ele => ele.firstClassifyName=='定损细节照片' && ele.serviceItemCode == serviceItemCode && ele.secondClassifyName.includes(lossType==3 ? '钥匙': '车牌'))
    }else{
        fileTabs[1].fileList = copyFileList.filter(ele => ele.firstClassifyName=='定损细节照片' && ele.serviceItemCode == serviceItemCode)
    }
    if(serviceItemType==3){
        fileTabs[0].fileList = copyFileList.filter(ele => ele.firstClassifyName=='基础资料' && ele.secondClassifyName!='人车合照' && ele.secondClassifyName!='前挡车架号')
    }else{
        fileTabs[0].fileList = copyFileList.filter(ele => ele.firstClassifyName=='基础资料')
        // let hasRen = fileTabs[0].fileList.find(item => item.secondClassifyName=='人车合照')
        // if(!hasRen){
        //     let renTarget = copyFileList.find(item => item.secondClassifyName=='人车合照')
        //     fileTabs[0].fileList.push(renTarget)
        // }
    }
    if(list) {
        return list
    }else{
        this.setData({
            fileTabs
        })
    }
  },
  changeLossType(e) {
    const {value, index, row} = e.currentTarget.dataset
    if(row.serviceItemType==4) {
        this.changeFileList(row.serviceItemType, row.serviceItemCode, value)
    }
    this.setData({
        [`itemsList[${index}].lossType`] : value
    })
  },
  // 输入预估损失金额和保险定损金额, 只能输入数字和小数点,保留两位小数,最大值是2000000, 大于0(在提交的时候检验)
  inputPrice(e) {
    const { index, key } = e.currentTarget.dataset
    const { value } = e.detail
    let newVal =
    ("" + value) 
      .replace(/[^\d^\.]+/g, "") 
      .replace(/^0+(\d)/, "$1") 
      .replace(/^\./, "0.")
      .match(/^\d*(\.?\d{0,2})/g)[0] || "";
    let MAX_NUM = 2000000
    if(+newVal>=MAX_NUM) newVal = MAX_NUM
    this.setData({
        [`itemsList[${index}].${key}`] : newVal
    })
  },
  // 同步合同号,
  syncContract(e) {
    const { contractNo } = this.data.formData
    if(!contractNo) return wx.showToast({title: '请输入正确的合同号', icon: 'none'})
    const params = {
        contractNo
    }
    claimsApi.syncContractInfoApi(params).then(res => {
        console.log(res, 'sync')
        if(res) {
            this.setDetailInfo(res)
        }
    })
  },
  //获取核赔的参数
  getClaimsParams(operation) {
    const { otherFormData,curSupplementList, claimsFileTabs, accountFormData, orderId: claimsId} = this.data
    let bankAccount = Util.deepClone(accountFormData)
    bankAccount.openBankCode = accountFormData.openBankCode.code
    bankAccount.openBankName = accountFormData.openBankCode.name
    bankAccount.accountCityCode = accountFormData.accountCityCode.code
    bankAccount.accountCityName = accountFormData.accountCityCode.name
    bankAccount.cardTypeCode = accountFormData.cardTypeCode.code
    bankAccount.cardTypeName = accountFormData.cardTypeCode.name
    if(accountFormData.objectType!=1) { 
        //首款对象为店面,账号类型只能是对公
        bankAccount.accountType = 0
    }
    delete bankAccount.applyAmount
    delete bankAccount.approveAmount
    let attachments2 = []
    claimsFileTabs.forEach(item => {
        item.fileList.forEach(ele => {
            const { id: classifyId, sonId, secondClassifyName, attachmentFile, attachmentType, attachmentCode, attachmentName, auditStatus, reasonForFailure, auditBy } = ele
            if(attachmentFile) {
                attachments2.push({id: sonId, claimsId, classifyId, secondClassifyName, attachmentFile, attachmentType, attachmentCode, attachmentName, auditStatus, reasonForFailure, auditBy})
            }
        })
    })
    let supplementList2 = [...curSupplementList, ...this.data.supplementList2]?.map(item => {
        let {id, content} = item
        //(item.operation || 0) 草稿的时候,保留详情接口返回的原有的operation
        return {id,  operation: operation==1 ? 1 : (item.operation || 0), claimsId, content , suppType: 2}
    })?.filter(item => item.content)
    return {
        ...otherFormData,
        attachments2,
        supplementList2,
        bankAccount
    }
  },
  // 定损提交需要的参数
  getParams(operation) {
    const {fileTabs, curSupplementList, orderId: claimsId} = this.data
    let formData = Util.deepClone(this.data.formData)
    if(formData.reimbursementAddress?.length == 3){
        let addrList = formData.reimbursementAddress
        const cityList = ['310100', '120100', '110100', '500100']
        if(cityList.includes(addrList[1].code)){
            addrList[1].code = this.changeCharacter(addrList[1]?.code)
        }
        formData.reimbursementProvinceCode = addrList[0].code
        formData.reimbursementProvinceName = addrList[0].name
        formData.reimbursementCityCode = addrList[1].code
        formData.reimbursementCityName = addrList[1].name
        formData.reimbursementCountiesCode = addrList[2].code
        formData.reimbursementCountiesName = addrList[2].name
        delete formData.reimbursementAddress
    }
    formData.reportDate = formData.reportDate+ ':00'
    formData.reimbursementDate = formData.reimbursementDate+ ':00'
    let attachments1 = []
    fileTabs.forEach(item => {
        item.fileList.forEach(ele => {
            const { id: classifyId, sonId, secondClassifyName, attachmentFile, attachmentType, attachmentCode, attachmentName, auditStatus, reasonForFailure, auditBy } = ele
            if(attachmentFile) {
                attachments1.push({id: sonId, claimsId, classifyId, secondClassifyName, attachmentFile, attachmentType, attachmentCode, attachmentName, auditStatus, reasonForFailure, auditBy})
            }
        })
    })
    let itemsList = []
    let applyPriceTotal = 0
    this.data.itemsList.forEach(item => {
        const {applyAmount, serviceItemCode, serviceItemName, id, contractNo, approveAmount, lossAssessmentAmount, lossType } = item
        if(item.checked) {
            applyPriceTotal = NP.plus(applyPriceTotal, applyAmount || 0)
            let _obj = {
                id,
                lossType,
                contractNo,
                serviceItemCode,
                serviceItemName,
                claimsId,
                approveAmount:  approveAmount ? NP.times(approveAmount, 100) : approveAmount,
                applyAmount: applyAmount ? NP.times(applyAmount, 100) : applyAmount,
                lossAssessmentAmount: lossAssessmentAmount ? NP.times(lossAssessmentAmount, 100) : lossAssessmentAmount
            }
            itemsList.push(_obj)
        }
    })
    let supplementList1 = [...curSupplementList, ...this.data.supplementList1]?.map(item => {
        let {id, content} = item
        //(item.operation || 0) 草稿的时候,保留详情接口返回的原有的operation
        return {id,  operation: operation==1 ? 1 : (item.operation || 0), claimsId, content , suppType: 1}
    })?.filter(item => item.content)
    return {
        id: claimsId || '',
        applyAmount: applyPriceTotal ? NP.times(applyPriceTotal, 100) : applyPriceTotal,
        operation,
        ...formData,
        attachments1,
        itemsList,
        supplementList1
    }
  },
  //定损和核赔提交时校验数据
  validData() {
    const {isDamageStage, formDataList, merchantFormList, formData, itemsList, fileTabs, claimsFileTabs,  collectDataList, accountDataList, accountFormData} = this.data    
    let tip = ''
    let formList = isDamageStage ? [...formDataList, ...merchantFormList] : [...collectDataList, ...accountDataList]
    let _formData = isDamageStage ? formData : accountFormData
    const phoneReg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/
    const phoneKeyList = ['phone', 'handlerPhone', 'reporterPhone']
    for(let i=0; i<formList.length; i++){
        const item = formList[i]
        const _value = typeof _formData[item.key] === 'string' ? _formData[item.key].trim() : _formData[item.key]
        if(!item.addHtml && !_value && _value!==0 && !item.isHide){
            tip = `${item.type == 'input' || item.type == 'textarea' ? '请输入' : '请选择'}${item.label}`
            break;
        }else if(phoneKeyList.includes(item.key) && !phoneReg.test(_value)){
            tip = `请输入正确的${item.label}`
            break;
        }
    }
    if(tip) {
        return wx.showToast({title: tip, icon: 'none'})
    }
    if(isDamageStage && (new Date(formData.reimbursementDate)> new Date(formData.reportDate))) {
        return wx.showToast({title: '出险日期不能大于报案日期', icon: 'none'})
    }
    // isDamageStage 定损时才需要检验,核赔的时候不检验
    if(isDamageStage) {
        const serviceTarget = itemsList.find(item => item.checked)
        if(serviceTarget) {
            const { applyAmount, serviceItemName, lossAssessmentFlag, lossAssessmentAmount } = serviceTarget
            if(!applyAmount) {
                return wx.showToast({title: `请输入预估损失金额`, icon: 'none'})
            }else{
                if(+applyAmount<1) return wx.showToast({title: `预估损失金额必须大于1`, icon: 'none'})
            }
            if(lossAssessmentFlag) {
                if(!lossAssessmentAmount){
                    return wx.showToast({title: `请输入保险公司定损金额`, icon: 'none'})
                }else{
                    if(+lossAssessmentAmount<1) return wx.showToast({title: `保险公司定损金额必须大于1`, icon: 'none'})
                }
            }
        }else{
            return wx.showToast({title: '请选择一项核赔服务', icon: 'none'})
        }
    }
    let _fileTabs =  isDamageStage ? fileTabs : claimsFileTabs
    for(let i=0; i<_fileTabs.length; i++){
        const item = _fileTabs[i]
        if(item.name != 'other'){
            const _exist = item.fileList.find(item => item.isRequire && !item.attachmentFile)
            if(_exist){
                tip = `请上传全部的${item.label}`
                break;
            }
        }
        const _errorFileItem = item.fileList.find(item => item.auditStatus === 0)
        if(_errorFileItem) {
            tip = `请重新上传审核失败的图片`
            break;
        }
    }
    if(tip) {
        return wx.showToast({title: tip, icon: 'none'})
    }
  },
  //点击草稿和提交按钮 operation 0存草稿,1提交
  saveInfo(e) {
    const {isDamageStage} = this.data
    const { operation } = e. currentTarget.dataset
    if (isDamageStage) {
      let {formData, itemsList} = this.data
      let obj = itemsList?.find(v => v.checked)
      // 调接口判断合同服务项目是否已终止
      if (obj?.serviceItemCode && formData?.contractNo && operation == 1) {
        equityApi.checkItemsApi({contractNo: formData.contractNo, serviceCode: obj.serviceItemCode}).then(res => {
          if (res.checkFlag) {
            this.setData({
              descriptionText: `${res.reason}`,
              terminationShow: true
            })
            return false
          }
          const valid  = operation && this.validData()
          if(valid) return
          this.commitDamage(operation)
        })
      } else {
        const valid  = operation && this.validData()
        if(valid) return
        this.commitDamage(operation)
      }
    } else {
      const valid  = operation && this.validData()
      if(valid) return
      this.commitClaims(operation)
    }
  },
  // 核赔 存草稿||提交
  commitClaims(operation) {
    const damageParams = this.getParams(operation)
    const params = {
        ...this.getClaimsParams(operation),
        operation,
        id: damageParams.id,
        itemsList: damageParams.itemsList
    }
    console.log(params, '核赔参数')
    claimsApi.saveClaimsInfoApi(params).then(res => {
        if(res) {
            this.backPage()
        }
    })
  },
  backPage() {
    wx.navigateBack()
  },
  // 定损 存草稿||提交
  commitDamage(operation) {
    if(!this.data.isSync) return wx.showToast({title: '请同步合同号', icon: 'none'})
    if(this.data.formData.reporterName?.trim()?.length < 2) return wx.showToast({title: '报案人字数必须大于等于两个字', icon: 'none'})
    let params = this.getParams(operation)
    params.dataSource = params.source // 核赔单来源,防止与封装共用方法参数同名被覆盖,传dataSource
    claimsApi.saveDamageInfoApi(params).then(res => {
        if(res) {
            this.backPage()
        }
    })
  },
  //设置 账户的信息
  setAccountData(obj) {
    let accountFormData = Util.deepClone(this.data.accountFormData)
    for(let key in accountFormData){
        if(key == 'openBankCode'){
            accountFormData[key] = {code: obj[key], name: obj.openBankName}
        }else if(key == 'accountCityCode'){
            accountFormData[key] = {code: obj[key], name: obj.accountCityName}
        }else if(key == 'cardTypeCode'){
            accountFormData[key] = {code: obj[key], name: obj.cardTypeName }
        }else{
            accountFormData[key] = obj[key]
        }
    }
    accountFormData.accountType = obj.accountType || 0
    accountFormData.objectType = obj.objectType || 0
    console.log(accountFormData, obj, 'accountFormData')
    return accountFormData
  },
  // 点击同步||调详情接口时,回显参数(定损和核赔的都走这里)
  async setDetailInfo(res, fromDetail){
    let { formData, fileTabs, supplementList1, accountFormData, otherFormData, isDamageStage, claimsFileTabs, supplementList2, formDataList } = this.data
    let  { reimbursementProvinceCode: pCode,  reimbursementProvinceName: pName, 
        reimbursementCityCode: cCode, reimbursementCityName: cName,
        reimbursementCountiesCode: csCode, reimbursementCountiesName: csName} = res
    for(let key in formData) {    // 回显报案信息(客户提交)
        formData[key] = res[key] || '' 
    }
    
    if(fromDetail) {   // 调详情接口时,需要回显接口返回来的
        formData.reportDate = new Date(formData.reportDate).format('yyyy-MM-dd hh:mm')
        formData.reimbursementDate = new Date(formData.reimbursementDate).format('yyyy-MM-dd hh:mm')
    }else{ // 点击同步的时候, 默认是现在的时间
        formData.reportDate = new Date().format('yyyy-MM-dd hh:mm')
        formData.reimbursementDate = new Date().format('yyyy-MM-dd hh:mm')
    }
    
    if(pCode  && cCode && csCode) { 
        const cityList = ['310000', '120000', '110000', '500000']
        // 对应的省市区编号,但是因为接口返回来的数据,四个直辖市所对应的市级编号和省级编号一致,如110000,导致省市区选择组件有问题
        // 因为组件的市级编号要110100, 为什么没有叫后端改返回来的数据? 因为要和pc端一直,pc端从第一版的市级编号就是和省级编号一致的,改了有问题
        if(cityList.includes(cCode)){
            cCode = this.changeCharacter(cCode)
        }
        formData.reimbursementAddress = [
            {code: pCode, name: pName},
            {code: cCode, name: cName},
            {code: csCode, name: csName},
        ]
    }
    let otherList1 = []
    const otherFileItem = res.attachmentConfigs1.find(item => item.firstClassifyName.indexOf('其他资料')>-1)
    if(res.attachments1?.length) {
        if(otherFileItem) {
            otherList1 = res.attachments1?.filter(item => item.classifyId == otherFileItem.id)?.map(_target => {
                return {...otherFileItem, ..._target, secondClassifyName: otherFileItem.secondClassifyName, id: otherFileItem.id,  sonId: _target.id}
            }) || []
        }
        res.attachmentConfigs1 = res.attachmentConfigs1?.map(item => {
            const { secondClassifyName, id } = item
            const _target = res.attachments1?.find(ele => ele.classifyId == item.id && item.firstClassifyName.indexOf('其他资料')==-1)
            if(_target) {
                item = {...item, ..._target, secondClassifyName, id, sonId: _target.id}
            }
            return item
        })
    }
    if(!this.data.damageDisabled && otherList1?.length < 50) {
        otherList1.push(otherFileItem)
    }
    this.setData({
        copyFileList: res.attachmentConfigs1
    })
    fileTabs.forEach(item => {
        if(item.name == 'other') {
            item.fileList = otherList1
        }else{
          // 未选择申请核赔服务项目时,不展示定损细节照片项
          let isCheckedItem = res.itemsList?.findIndex(v => v.checked)
          item.fileList = item.name == 'detail' && (!fromDetail || isCheckedItem < 0) ? [] : res.attachmentConfigs1.filter(ele => item.label == ele.firstClassifyName)
        }
    })
    let itemsList = res.itemsList?.map(item => {
        if(item.checked && fromDetail) {
            fileTabs = this.changeFileList(item.serviceItemType, item.serviceItemCode, item.lossType, fileTabs)
        }
        const { applyAmount, lossAssessmentAmount, approveAmount } = item
        return {
            ...item, 
            checked: !!item.checked,
            approveAmount: approveAmount ? NP.divide(approveAmount, 100) : approveAmount,
            lossAssessmentAmount: lossAssessmentAmount ? NP.divide(lossAssessmentAmount, 100) : lossAssessmentAmount,
            applyAmount: applyAmount ? NP.divide(applyAmount, 100) : applyAmount
        }
    })
    supplementList1 = res.supplementList1?.map(item => {
        return {
            ...item,
            operationTime:  new Date(item.operationTime).format('yyyy-MM-dd hh:mm:ss')
        }
    }) || []
    // C端申请的理赔服务单 source: 3(B端 ) 4(C端)
    if (res?.source === 4) {
      const updatedFormDataList = formDataList?.map(v => {
        if (v.key === 'contractNo') {
          return { ...v, isHide: true } // 隐藏合同号
        }
        if (v.key === 'writeOffCode') {
          return { ...v, isHide: false } // 显示核销码
        }
        return v // 其他项保持不变
      })
      this.setData({
        formDataList: updatedFormDataList
      })
      // 待受理或已失效
      if (res?.status == 32 || res.status == 40) {
        // 客户提交的信息不可修改 processingDisabled
        this.setData({ processingDisabled: true })
      }
    }
    this.setData({
        reasonForFailure: res.reasonForFailure,
        reasonForFailureCode: res.reasonForFailureCode,
        orderId: res.id,
        curStatus: res.status,
        formData,
        itemsList,
        fileTabs,
        supplementList1,
        isSync: true,
        'formDataList[0].isDisabled' : true
    })

    // 回显核赔数据
    if(!isDamageStage) {
        let _accountObj = null
        if(res.status == 34 || res.status == 25) {
            // 提交核赔的时候才需要带出门店的收款账号信息
            _accountObj = await this.getAccountInfo()
            this.data.copyAccountData = _accountObj
        }
        accountFormData = this.setAccountData(_accountObj ? _accountObj : (res.bankAccountDTO || {}))
        accountFormData.approveAmount = res.approveAmount ? NP.divide(res.approveAmount, 100) : res.approveAmount
        accountFormData.applyAmount = res.applyAmount ? NP.divide(res.applyAmount, 100) : res.applyAmount
        otherFormData.expressName = res.expressName
        otherFormData.expressNo = res.expressNo
        let otherList2 = []
        const otherFileItem2 = res.attachmentConfigs2.find(item => item.firstClassifyName.indexOf('其他资料')>-1)
        if(res.attachments2?.length) {
            if(otherFileItem2) {
                otherList2 = res.attachments2?.filter(item => item.classifyId == otherFileItem2.id)?.map(_target => {
                    return {...otherFileItem2, ..._target, secondClassifyName: otherFileItem2.secondClassifyName, id: otherFileItem2.id,  sonId: _target.id}
                }) || []
            }
            res.attachmentConfigs2 = res.attachmentConfigs2?.map(item => {
                const { secondClassifyName, id } = item
                const _target = res.attachments2?.find(ele => ele.classifyId == item.id && item.firstClassifyName.indexOf('其他资料')==-1)
                if(_target) {
                    item = {...item, ..._target, secondClassifyName, id, sonId: _target.id}
                }
                return item
            })
        }
        if(!this.data.claimsDisabled && otherList2?.length < 50) {
            otherList2.push(otherFileItem2)
        }
        claimsFileTabs.forEach(item => {
            if(item.name == 'other') {
                item.fileList = otherList2
            }else{
                item.fileList = res.attachmentConfigs2.filter(ele => item.label == ele.firstClassifyName)
            }
        })
        supplementList2 = res.supplementList2?.map(item => {
            return {
                ...item,
                operationTime:  new Date(item.operationTime).format('yyyy-MM-dd hh:mm:ss')
            }
        }) || []
        this.setData({
            'accountDataList[0].isHide' : accountFormData.objectType!=1,
            otherFormData,
            accountFormData,
            claimsFileTabs,            
            supplementList2,
            attachmentConfigs3: res.attachmentConfigs3 || []
        })
    }
    console.log(this.data.accountFormData, '设置数据结束')
  },
  //输入说明
  inputSupplement(e) {
    const { index } = e.currentTarget.dataset
    console.log(e)
    this.setData({
        [`curSupplementList[${index}].content`] : e.detail.value
    })
  },
  //点击 新增说明
  addSupplement() {
    const { curSupplementList } = this.data
    const targetIdx = curSupplementList.findIndex(item => !item.content)
    if(targetIdx>-1) {
        return wx.showToast({title: `请输入说明${targetIdx+1}`, icon: 'none'})
    }
    curSupplementList.push({content: ''})
    this.setData({
        curSupplementList
    })
  },
  toUploadPage(e) {
    console.log(e)
    const { item, index} = e.currentTarget.dataset
    let fileInfo = JSON.stringify({ item, index})
    wx.navigateTo({
      url: `../addFile/addFile?fileInfo=${fileInfo}&disabled=${(this.data.damageDisabled || (this.data.processingDisabled && item.label == '现场照片')) ? 1 : 2}`,
    });
  },
  dataChange(e) {
    const {key, value} = e.detail
    console.log(key, value)
    this.setData({
        [`formData.${key}`]: value
    })
  },
  accountDataChange(e) {
    const {key, value} = e.detail
    if(key=='objectType' && (this.data.curStatus == 34 || this.data.curStatus == 25)) {
        const { copyAccountData, accountFormData } = this.data
        let obj = {}
        if(value==0) {
            obj = this.setAccountData(copyAccountData || {})
        }else{
            obj = {
                objectType: 1,
                accountType: 0,
                openBankCode: '',
                accountName: '',
                accountNo: '',
                accountCityCode: '',
                cardTypeCode: '',
                cardNo: '',
                phone: '',
            }
        }
        obj.approveAmount = accountFormData.approveAmount,
        obj.applyAmount = accountFormData.applyAmount,
        this.setData({
            'accountDataList[0].isHide' : value!=1,
            accountFormData : obj
        })
    }else{
        this.setData({
            [`accountFormData.${key}`]: value
        })
    }
  },
  inputExpress(e) {
    const {key} = e.currentTarget.dataset
    const { value } = e.detail
    this.setData({
        [`otherFormData.${key}`]: value
    })
  },
  openExpressDialog() {
    this.setData({
        addressVisible: !this.data.addressVisible
    })
  },
  getDetail(id) {
    claimsApi.getDetailInfoApi({id}).then(res => {
        if(res) {
            this.setDetailInfo(res, true)
        }
    })
  },
  changeCharacter(str) {
    let changestr = str[3] == '1' ? '0' : '1'
    return str?.substring(0, 3) + changestr + str?.substring(4);
  },
  // 上传文件
  upload(e) {
    const { claimsFileTabs } = this.data
    const {row, index, subindex} = e.currentTarget.dataset
    let name = claimsFileTabs?.[index]?.name
    let arr = e.detail?.map(v => {
      v = {
        ...row,
        attachmentType: v.type, 
        attachmentFile: v.url
      }
      return v
    })
    if (name == 'other') {
      let { fileList } = claimsFileTabs[index]
      let fileArr = fileList?.filter(val => val.attachmentFile && val.attachmentType)?.concat(arr)
      if (fileArr?.length < 50) {
        fileArr.push(row)
      }
      this.setData({
        [`claimsFileTabs[${index}].fileList`]: fileArr
      })
    } else {
      this.setData({
        [`claimsFileTabs[${index}].fileList[${subindex}]`]: arr[0]
      })
    }
    // const {type: attachmentType, url: attachmentFile} = e.detail
    // const {row, index, subindex} = e.currentTarget.dataset
    // let file = {...row, attachmentType, attachmentFile}
    // let name = claimsFileTabs?.[index]?.name
    // if(name == 'other') {
    //     let { fileList } = claimsFileTabs[index]
    //     fileList[subindex] = file
    //     // 限制由9张该为50张
    //     if(fileList.length<50){
    //         fileList.push(row)
    //     }
    //     this.setData({
    //         [`claimsFileTabs[${index}].fileList`]: fileList
    //     })
    // }else{
    //     this.setData({
    //         [`claimsFileTabs[${index}].fileList[${subindex}]`]: file
    //     })
    // }
  },
  // 删除图片
  delImg(e) {
    const { claimsFileTabs } = this.data
    const { index, subindex} = e.currentTarget.dataset
    let name = claimsFileTabs?.[index]?.name
    let { fileList } = claimsFileTabs[index]
    if(name == 'other' && subindex != 49) { // 等于other和index!=49时,splice删除文件, 否则删除文件的字段值
        fileList.splice(subindex, 1)
        this.setData({
            [`claimsFileTabs[${index}].fileList`]: fileList
        })
    }else{
        this.setData({
            [`claimsFileTabs[${index}].fileList[${subindex}].attachmentFile`]: '',
            [`claimsFileTabs[${index}].fileList[${subindex}].attachmentType`]: '',
            [`claimsFileTabs[${index}].fileList[${subindex}].auditStatus`]: null,
            [`claimsFileTabs[${index}].fileList[${subindex}].reasonForFailure`]: '',
            [`claimsFileTabs[${index}].fileList[${subindex}].sonId`]: ''
        })
    }
  },
  onLoad(options) {
    console.log(options, 'options')
    //32待受理 33待定损 35定损不通过  34定损通过   23待核赔 25核赔不通过 1待支付 3已支付
    this.setStatusInfo(+options.status)
    if(options.id) {
        this.getDetail(options.id)
    }
    this.getAreaData()
    this.getCommonData()
  },
  // 获取账户选择项数据
  getCommonData() {
    claimsApi.getCommonDataApi({}).then(res => {
        if(res){
            const _obj = {openBankCode: 'branchBank', accountCityCode: 'accountCity', cardTypeCode: 'cardType'}
            for(let key in _obj){
                const idx = this.data.accountDataList.findIndex(item => item.key == key)
                if(idx>-1) {
                    this.setData({
                        [`accountDataList[${idx}].optionList`] : res[_obj[key]]
                    })
                }
            }
        }
    })
  },
  // 获取省市区数据
  getAreaData() {
    claimsApi.getAreaDataApi({}).then(res => {
        if(res?.length) {
            const idx = this.data.formDataList.findIndex(item => item.key == 'reimbursementAddress')
            if(idx>-1) {
                this.setData({
                    [`formDataList[${idx}].optionData`] : this.transformRegionData(res)
                })
            }
        }
        console.log(this.data.formDataList, 'formDataList')
    })
  },
  // 核赔的时候,需要调这个接口,获取门店以前设置过的账户信息
  getAccountInfo() {
    return new Promise((resolve, reject) => {
        const { contractNo } = this.data.formData
        claimsApi.getAccountInfoApi({ contractNo }).then(res => {
            if(res) {
                resolve(res)
            }
        }).finally(end => {
            console.log(888, '请求结束')
        })
    })
    
  },
  //处理接口返回来的出现地址数据列表
  transformRegionData(data) {
    const _this = this
    const areaList = {
      province_list: {},
      city_list: {},
      county_list: {}
    };
    const cityList = ['310000', '120000', '110000', '500000']
    function flattenRegion(region, level) {
      if (!region) return;
  
      // 根据级别存储地区信息
      switch (level) {
        case 1:
          areaList.province_list[region.value] = region.label;
          break;
        case 2:
          if(cityList.includes(region.value)) {
            region.value = _this.changeCharacter(region?.value)
          }
          areaList.city_list[region.value] = region.label;
          break;
        case 3:
          areaList.county_list[region.value] = region.label;
          break;
        default:
          break;
      }
  
      // 递归处理子地区
      if (Array.isArray(region.children)) {
        region.children.forEach(child => flattenRegion(child, level + 1));
      }
    }
  
    // 开始递归处理
    data.forEach(region => flattenRegion(region, 1));
  
    return areaList;
  },
  //展开  收起每一项
  slideContent(e) {
    const { name } = e.currentTarget.dataset
    let {activeTabList} = this.data
    let idx = activeTabList.findIndex(item => item==name)
    if(idx > -1) {
        activeTabList.splice(idx, 1)
    }else{
        activeTabList.push(name)
    }
    this.setData({
        activeTabList
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow(options) {
    console.log(this.data, 123222)
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})