ghOrder.vue 38.5 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
<template>
  <div class="order-container-page">
    <!--  2.查看 6.重新提交  5.定损审核  7.核赔审核  8.运营经理审核 -->
    <template v-if="pageType == 2">
      <!-- 该组件是详情页,在里面判断是否有是核赔环节还是定损环节来是否展示两个tab -->
      <WatchData :accountMatchResultList="accountMatchResultList" :lossTypeList.sync="lossTypeList" :otherInfoData.sync="otherInfoData" :images="insuranceAttachmentConfigs" :images2="claimsAttachmentConfigs" :itemsList.sync="itemList" :repotData.sync="repotData" :accountList.sync="accountList" :watchData.sync="watchData"></WatchData>
    </template>
    <!-- routeInfo.status 查看ghIndex.vue文件的statusList,status>10就是签名授权以及待核赔往后的流程了 -->
    <template v-else-if="(pageType == 5 || pageType == 7 || pageType == 8) && routeInfo.status < 11">
      <CheckData @getCurrentLoosType="getLossType" :lossTypeList.sync="lossTypeList" :otherInfoData.sync="otherInfoData" :itemList.sync="itemList" :insuranceAttachmentConfigs.sync="insuranceAttachmentConfigs" :repotData.sync="repotData"></CheckData>
    </template>
    <template v-else-if="((pageType == 5 || pageType == 7 || pageType == 8) && routeInfo.status > 10) || (routeInfo.status == 2 && pageType == 6)">
      <div class="tab_wrap">
        <el-tabs v-model="activeName">
          <el-tab-pane class="bg" label="核赔信息" name="first">
            <!-- 该组件是核赔提交信息 -->
            <CheckClaims @getWarningInfo="getWarningInfo" :accountMatchResultList="accountMatchResultList" ref="checkclaims" @getCurrentLoosType="getLossType" :lossTypeList.sync="lossTypeList" @changeObjectType="changeObjectType" :insuranceAttachmentConfigs.sync="claimsAttachmentConfigs" :repotData.sync="repotData" :itemsList.sync="itemList" :accountForm.sync="accountForm"></CheckClaims>
          </el-tab-pane>
          <el-tab-pane class="bg" label="定损信息" name="second">
            <!-- 该组件是定损提交信息 此时是核赔阶段,定损是只能看的,所以isDisabled为true-->
            <CheckData @getCurrentLoosType="getLossType" :lossTypeList.sync="lossTypeList" :isDisabled="true" :otherInfoData.sync="otherInfoData" :itemList.sync="itemList" :insuranceAttachmentConfigs.sync="insuranceAttachmentConfigs" :repotData.sync="repotData"></CheckData>
          </el-tab-pane>
        </el-tabs>
      </div>
    </template>
    <!-- 底部按钮 -->

    <div v-if="pageType != 2 && activeName != 'second' && orderMsg.status != 26" class="btn-box">
      <el-button plain class="btn-three" @click="toBackList">取消</el-button>
      <el-button plain class="btn-three" @click="toSaveOrder">保存</el-button>
      <el-button type="danger" class="danger-btn" plain @click="endCaseFn()">结束案件</el-button>
      <el-button plain @click="toNoPassOrder">不通过</el-button>
      <el-button type="primary" @click="toPassOrder">通过</el-button>
    </div>
    <!-- 状态 26 是待运营经理审核 -->
    <div v-if="pageType != 2 && activeName != 'second' && orderMsg.status == 26" class="btn-box">
      <el-button plain class="btn-three" @click="toBackList">取消</el-button>
      <el-button plain @click="toNoPassOrder">不通过</el-button>
      <el-button type="primary" @click="toPassOrderAddWarning">通过</el-button>
    </div>

    <qrCode :bottom="320" phone="400 6123 886" phoneTitle="定损及核赔服务咨询" :codeUrl="qrcodUrl"></qrCode>
    <!-- 弹窗 -->

    <GLDialog class="gl-form-page gl-form-min" title="审核不通过" mode="mid" :visible.sync="showNoPassDialog" @onOk="comfirmNoPass" @onCancel="cancleNoPass">
      <glsx-combi-form ref="noPassRef" :isInline="false" labelWidth="154px" defaultWidth="284px" :formObj="noPassObj" :formData="noPassForm"></glsx-combi-form>
    </GLDialog>
    <GLDialog class="gl-form-page gl-form-min" title="审核通过,请输入批准金额" mode="mid" :visible.sync="showPassedDialog" @onOk="comfirmPass" @onCancel="canclePass">
      <div class="passed-wrap">
        <div class="passed-item" v-for="(item, index) in itemList" :key="index">
          <span class="name">{{ item.serviceItemName }}</span>
          <div class="set-price">
            <li>
              <label for="">预估损失金额/元:</label>
              <el-input @input="validPrice($event, index, 'applyAmount')" @blur="changePrice($event, index, 'applyAmount')" size="small" maxlength="10" placeholder="请输入预估损失金额" v-model="item.applyAmount"></el-input>
            </li>
            <li>
              <label for="">定损批准金额/元:</label>
              <el-input @input="validPrice($event, index, 'approveAmount')" @blur="changePrice($event, index, 'approveAmount')" size="small" maxlength="10" placeholder="请输入定损批准金额" v-model="item.approveAmount"></el-input>
            </li>
          </div>
        </div>
      </div>
    </GLDialog>
  </div>
</template>
<script type="text/ecmascript-6">
import * as dayjs from 'dayjs'
import WatchData from './components/watch/index.vue'
import CheckData from './components/check/index.vue'
import CheckClaims from './components/checkClaims/index.vue'
import qrCode from '@/components/qr-code'
import glsxCombiForm from '@/components/glsx-combi-form'
const injureTypeList = ['drumPack', 'flatTires', 'dehiscence', 'punctureWounds']
// import util from "@/util"
export default {
  name: 'ghOrder',
  components: {
    WatchData,
    CheckData,
    CheckClaims,
    qrCode,
    glsxCombiForm
  },
  data() {
    return {
      routeInfo: {},
      pageType: 1,
      watchData: [], // 查看状态下
      accountList: [],
      repotData: {
        writeOffCode: '',
        reporterName: '',
        reporterPhone: '',
        reportDate: '',
        reimbursementDate: '',
        internalReimbursementDate: '',
        reimbursementAddr: '',
        handlerName: '',
        handlerPhone: '',
        serviceCodes: []
      },
      activeName: 'first',
      accountForm: {
        objectType: 0,
        accountType: 0,
        branchBankCode: '',
        accountName: '',
        accountNo: '',
        bankCity: '',
        payeeIDCardType: '',
        payeeIDCardNo: '',
        payeePhone: '',
        handlerName: '',
        handlerPhone: ''
      },
      // 弹窗
      showNoPassDialog: false,
      showPassedDialog: false,
      noPassObj: {
        reason: '',
        desc: ''
      },
      noPassForm: [
        {
          label: '原因',
          name: 'reason',
          type: 'select',
          isClear: true,
          optionList: [
            {
              confId: 1,
              confName: '拒赔'
            },
            {
              confId: 2,
              confName: '资料不清晰'
            }
          ],
          optionId: 'confId',
          optionLabel: 'confName'
        },
        {
          label: '具体描述:',
          name: 'desc',
          type: 'input',
          inputType: 'textarea',
          rows: 3,
          isClear: true,
          maxlength: 200
        }
      ],
      isSave: true,
      testServiceList: [],
      insuranceAttachmentConfigs: [],
      itemList: [],
      otherInfoData: {},
      claimsAttachmentConfigs: [],
      lossTypeList: [],
      accountMatchResultList: [],
      orderMsg: {
        id: 0,
        status: 0
      }
    }
  },
  mounted() {
    // 获取页面传参:主要是编辑状态和订单状态
    // 5 审核+定损  审核+核赔
    const urlParam = this.$route.params
    const urlQuery = JSON.parse(decodeURIComponent(urlParam.id))
    this.pageType = urlQuery.editNo
    this.routeInfo = urlQuery
    if (this.routeInfo.writeOffCode) {
      this.getDetailData(this.routeInfo.writeOffCode)
    }
  },
  methods: {
    // 获取订单详情
    getDetailData(writeOffCode) {
      this.$apis.claims.getGHClaimsDetailApi({ writeOffCode }).then(res => {
        if (!res.supplementList1?.length) {
          res.supplementList1 = []
          res.supplementList1.push({ content: '', claimsId: res.id })
        }
        if (!res.supplementList2?.length) {
          res.supplementList2 = []
          res.supplementList2.push({ content: '', claimsId: res.id })
        }
        this.orderMsg = {
          id: res.id,
          status: res.status
        }
        this.repotData = {
          id: res.id,
          status: res.status,
          writeOffCode: res.writeOffCode,
          reporterName: res.reporterName,
          reporterPhone: res.reporterPhone,
          reportDate: dayjs(res.reportDate).format('YYYY-MM-DD HH:mm:ss'),
          reimbursementDate: dayjs(res.reimbursementDate).format('YYYY-MM-DD HH:mm:ss'),
          internalReimbursementDate: dayjs(res.internalReimbursementDate || res.reimbursementDate).format('YYYY-MM-DD HH:mm:ss'),
          reimbursementAddr: res.reimbursementAddr,
          handlerName: res.handlerName,
          handlerPhone: res.handlerPhone,
          serviceCodes: [],
          reimbursementProvinceName: res.reimbursementProvinceName || '',
          reimbursementCityName: res.reimbursementCityName || '',
          reimbursementCountiesName: res.reimbursementCountiesName || '',
          contractNo: res.contractNo,
          reimbursementAddress: [res.reimbursementProvinceCode, res.reimbursementCityCode, res.reimbursementCountiesCode],
          reimbursementProvinceCode: res.reimbursementProvinceCode,
          reimbursementCityCode: res.reimbursementCityCode,
          reimbursementCountiesCode: res.reimbursementCountiesCode,
          reimbursementProcess: res.reimbursementProcess,
          approveAmount: res.approveAmount ? (res.approveAmount / 100).toFixed(2) : res.approveAmount,
          applyAmount: res.applyAmount ? (res.applyAmount / 100).toFixed(2) : res.applyAmount,
          supplementList1: res.supplementList1,
          supplementList2: res.supplementList2,
          bankAccountDTO: res.bankAccountDTO,
          attachments1: res.attachments1,
          attachments2: res.attachments2,
          attachments3: res.attachments3,
          claimsAttachmentConfigs2: res.claimsAttachmentConfigs2,
          updatedBy: res.updatedBy,
          expressName:res.expressName,
          expressNo:res.expressNo,
          exceptionImgUrl: res.exceptionImgUrl,
          preStatus: res.preStatus
        }

        // 图片list
        res.insuranceAttachmentConfigs.map(item => {
          let arr = []
          let services = []

          if (item.firstClassifyName.indexOf('其他') != -1) {
            item.secondClassifyList.forEach(el => {
              el.attachmentList.forEach(ele => {
                arr.push(ele)
              })
            })
            item.allImages = arr
          }
          if (item.firstClassifyName.indexOf('定损细节照片') != -1) {
            item.secondClassifyList.forEach(el => {
              if (el.secondClassifyName.indexOf('钥匙') != -1 && el.serviceItemCode == 'SC0006') {
                el.lossType = '3'
              } else if (el.secondClassifyName.indexOf('车牌') != -1 && el.serviceItemCode == 'SC0006') {
                el.lossType = '4'
              }
              services.push(el.serviceItemName)
            })
            item.services = [...new Set(services)]
          }
        })

        res.claimsAttachmentConfigs.map(item => {
          let arr = []
          let services = []
          if (item.firstClassifyName.indexOf('其他') != -1) {
            item.secondClassifyList.forEach(el => {
              el.attachmentList.forEach(ele => {
                arr.push(ele)
              })
            })
            item.allImages = arr
          }
          if (item.firstClassifyName.indexOf('核赔细节照') != -1) {
            item.secondClassifyList.forEach(el => {
              if (el.secondClassifyName.indexOf('钥匙') != -1 && el.serviceItemCode == 'SC0006') {
                el.lossType = '3'
              } else if (el.secondClassifyName.indexOf('车牌') != -1 && el.serviceItemCode == 'SC0006') {
                el.lossType = '4'
              }
              services.push(el.serviceItemName)
            })
            item.services = [...new Set(services)]
          }
          //  else {
          //   item.secondClassifyList.forEach(el => {
          //     if (!el.attachmentList.length) {
          //       el.attachmentList.forEach(ele => {
          //         ;(ele.auditStatus = null), (ele.attachmentFile = '')
          //         ele.reasonForFailure = ''
          //       })
          //     }
          //   })
          // }
        })
        this.insuranceAttachmentConfigs = res.insuranceAttachmentConfigs
        this.claimsAttachmentConfigs = res.claimsAttachmentConfigs

        // 详情处理服务项目数据
        res.itemsList.map(item => {
          item.applyAmount = item.applyAmount ? (item.applyAmount / 100).toFixed(2) : item.applyAmount
          item.approveAmount = item.approveAmount ? (item.approveAmount / 100).toFixed(2) : null
          item.lossAssessmentAmount = item.lossAssessmentAmount ? (item.lossAssessmentAmount / 100).toFixed(2) : item.lossAssessmentAmount
          const priceList = ['purchaseTax', 'depreciation', 'commercialInsurance', 'registrationFee', 'retrofits', 'scooterFare']
          priceList.forEach(eleKey => {
            item[eleKey] =  item[eleKey] ? Number((item[eleKey] / 100).toFixed(2)) : item[eleKey]
          })
          item.lossTypeList = []
          if(item.serviceItemType == 2) {
            item.damageType = item?.damageType ? item.damageType.split(',').map(ele => Number(ele)) : []
          }
          if (item.serviceItemCode == 'SC0006' && item.lossType) {
            item.lossTypeList = item.lossType.split(',')
            this.lossTypeList = item.lossTypeList
          }
          this.$set(item, 'checked', true)
        })
        this.itemList = res.itemsList
        this.handlerWatch(this.repotData, 1)
        this.handlerWatch(res.bankAccountDTO, 2)
        // this.getAccountInfo(res.contractNo)
        this.getOtherInfo(res.contractNo)
        if (res.bankAccountDTO) {
          this.accountForm = res.bankAccountDTO
        }
        res.accountMatchResultList.forEach(el => {
          let arr = []
          el.accountVerifyImagesList.forEach(ele => {
            let obj = { verifyImage: ele.verifyImage }
            arr.push(obj)
          })
          el.accountVerifyImagesList = arr
        })
        this.accountMatchResultList = res.accountMatchResultList
      })
    },
    // 处理查看状态下数据展示
    handlerWatch(obj, type) {
      if (type == 1) {
        this.watchData = [
          {
            name: '报案人:',
            value: obj.reporterName
          },
          {
            name: '报案人电话:',
            value: obj.reporterPhone
          },
          {
            name: '报案日期:',
            value: obj.reportDate
          },
          {
            name: '出险日期:',
            value: obj.reimbursementDate
          },
          {
            name: '出险时间(内部):',
            value: obj.internalReimbursementDate
          },
          {
            name: '出险地点:',
            value: obj.reimbursementProvinceName + obj.reimbursementCityName + obj.reimbursementCountiesName + obj.reimbursementAddr
          }
        ]
      } else if (type == 2) {
        if (!obj) return
        this.accountList = [
          {
            name: '开户行名称:',
            value: obj.openBankName
          },
          {
            name: '账户名称:',
            value: obj.accountName
          },
          {
            name: '收款账号:',
            value: obj.accountNo
          },
          {
            name: '收款账号所在省市:',
            value: obj.accountCityName
          },
          {
            name: '收款人证件类型:',
            value: obj.cardTypeName
          },
          {
            name: '收款人证件号码:',
            value: obj.cardNo
          },
          {
            name: '收款人联系电话:',
            value: obj.phone
          }
        ]
      }
    },
    changeObjectType(newVal) {
      // if (newVal === 1) {
      //   this.saveObj.objectType = newVal
      //   delete this.saveObj.handlerName
      //   delete this.saveObj.handlerPhone
      //   this.accountForm = { ...this.accountForm, ...this.saveObj }
      // } else {
      //   this.saveObj = { ...this.accountForm }
      //   this.getAccountInfo(this.editForm.contractNo)
      // }
    },
    // submitForm(val) {
    //   // val == 1 通过 ,2 不通过
    //   this.cancelDialog(val)
    // },
    // cancelDialog(val) {
    //   // val == 1 通过 ,2 不通过
    //   if (val == 1) {
    //     this.showPassedDialog = false
    //   } else {
    //     this.showNoPassDialog = false
    //   }
    // },
    // 获取其他信息
    getOtherInfo(contractNo) {
      this.$apis.claims.getOrderOherInfo({ contractNo }).then(res => {
        if (res) {
          res.expirationDate = res.expirationDate ? res.effectiveDate + ' 至 ' + dayjs(res.expirationDate).format('YYYY-MM-DD HH:mm:ss') : '2019-12-12 23:59:59'
          res.billingDate = res.billingDate && dayjs(res.billingDate).format('YYYY-MM-DD HH:mm:ss')
          res.invoicePrice = res.invoicePrice / 100
          this.otherInfoData = { ...res, contractNo }
        }
      })
    },
    // 通过订单
    toPassOrder() {
      this.isSave = false
      const _target = this.itemList?.find(item => item.applyAmount && item.lossAssessmentFlag && !item.lossAssessmentAmount)
      if(_target) return this.$message.error(`请输入${_target.serviceItemName}的保险公司定损金额`)
      // applyAmount 预估损失金额 approveAmount 定损批准金额
      if (this.orderMsg.status == 12 || this.orderMsg.status == 2) {
        // const checkList = ['purchaseTax','depreciation','commercialInsurance','registrationFee','retrofits', 'scooterFare']
        // 购置税+折旧费+商业险保费+登记费+加改装件费用+代步车费用    至少一个必填
        const priceTarget =  this.itemList?.find(item => item.serviceItemType == 1 && item.approveAmount > 0 && !item.purchaseTax && !item.depreciation && !item.commercialInsurance && !item.registrationFee && !item.retrofits && !item.scooterFare)
        if(priceTarget) return this.$message.error(`${priceTarget.serviceItemName}的购置税、折旧费、商业险保费、登记费、加改装件费用、代步车费用,至少输入一个`)

        // 最少选择一个损伤类型
        const injureTarget = this.itemList?.find(item => item.serviceItemType == 2 && item.approveAmount > 0 && !item?.damageType?.length)
        if(injureTarget) return this.$message.error(`至少选择一个${injureTarget.serviceItemName}的损伤类型`)

        const isPass = this.verifyImages(this.claimsAttachmentConfigs)
        if (!isPass) {
          this.$message({
            message: '图片需要全部通过才允许此操作',
            type: 'error'
          })
          return
        }
        this.hepeiPass()
        return
      }
      const isPass = this.verifyImages(this.insuranceAttachmentConfigs)
      if (!isPass) {
        this.$message({
          message: '图片需要全部通过才允许此操作',
          type: 'error'
        })
        return
      }
      this.showPassedDialog = true
    },
    // 校验图片是否已全部校验
    verifyImages(arr) {
      let pass = true
      arr.forEach(item => {
        if (item.firstClassifyName.indexOf('其他') == -1) {
          item.secondClassifyList.forEach(child => {
            child.attachmentList.forEach(last => {
              if (!last.auditStatus) {
                if (child.serviceItemCode != 'SC0006' || (child.lossType && this.lossTypeList.includes(child.lossType))) {
                  pass = false
                }
                // 判断auditStatus没通过就报错,但是钥匙及车牌重置服务会因为勾选才显示,存在没通过的
              }
            })
          })
        } else {
          item.allImages.forEach(child => {
            if (!child.auditStatus) {
              pass = false
            }
          })
        }
      })
      return pass
    },
    handleJieGpu(type, isNopass = true) {
      let target = {}
      let arr = []
      if (type == 3) {
        this.repotData.attachments3.forEach(el => {
          let { id, claimsId, attachmentCode, attachmentType, attachmentFile, classifyId, attachmentName, auditStatus, reasonForFailure, auditBy } = el
          let obj = { id, claimsId, attachmentCode, attachmentType, attachmentFile, classifyId, attachmentName, auditStatus, reasonForFailure, auditBy }
          arr.push(obj)
        })
        return arr
      }
      if (type == 2) {
        this.repotData.attachments2.forEach(el => {
          let { id, claimsId, attachmentCode, attachmentType, attachmentFile, classifyId, attachmentName, auditStatus, reasonForFailure, auditBy } = el
          let obj = { id, claimsId, attachmentCode, attachmentType, attachmentFile, classifyId, attachmentName, auditStatus, reasonForFailure, auditBy }
          arr.push(obj)
        })
        return arr
      }
      if (type == 4) {
        let { id, merchantId, cardTypeName, objectType, accountType, openBankCode, accountName, accountNo, accountCityCode, cardTypeCode, phone, cardNo } = this.accountForm
        target = { id, merchantId, cardTypeName, objectType, accountType, openBankCode, accountName, accountNo, accountCityCode, cardTypeCode, phone, cardNo }
        return target
      }
    },
    hepeiPass(isNopass) {
      let obj = this.handlerServices()
      let exobj = this.handlerExplain()
      let imgObj = this.hanlerImg()
      let para = {
        ...this.orderMsg,
        attachments3: this.handleJieGpu(3),
        attachments2: this.handleJieGpu(2),
        ...obj,
        ...exobj,
        ...imgObj,
        bankAccount: this.handleJieGpu(4),
        auditStatus: 1,
        reasonForFailure: '',
        writeOffCode: this.repotData.writeOffCode
      }
      if (isNopass) {
        para.auditStatus = 0
        para.reasonForFailureCode = this.noPassObj.reason
        para.reasonForFailure = this.noPassObj.desc
      }
      if (this.orderMsg.status == 26) {
        let _accountMatchResultList = []
        if (this.queryList && this.queryList.length > 0) {
          const _temArr = JSON.stringify(this.queryList)
          _accountMatchResultList = JSON.parse(_temArr)
          _accountMatchResultList.forEach(el => {
            delete el.matchType
          })
        }
        para.accountMatchResultList = _accountMatchResultList
      }
      let loading = this.createLoading()
      this.$apis.claims.checkClaimsOrderApi(para).then(res => {
        loading.close()
        if (res) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$router.push({ path: '/claims/ghIndex' })
        }
      })
    },
    endCaseFn(){
      this.$confirm('确定结束此案件吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.comfirmPass(1)
          }
        }
      })
    },
    comfirmPass(isEndCase) {
      let para = this.handleParams()
      para.auditStatus = isEndCase ? 2 : 1   // 2结束案件,1 通过
      let loading = this.createLoading()
      this.$apis.claims.checkOrderApi(para).then(res => {
        loading.close()
        if (res) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$router.push({ path: '/claims/ghIndex' })
        }
        this.canclePass()
      })
    },
    canclePass() {
      this.showPassedDialog = false
    },
    // 不通过
    toNoPassOrder() {
      this.showNoPassDialog = true
    },
    // 点击不通过
    comfirmNoPass() {
      if (this.orderMsg.status == 12 || this.orderMsg.status == 2 || this.orderMsg.status == 26) {
        this.hepeiPass(true)
        return
      }
      let para = this.handleParams()
      para.auditStatus = 0
      para.reasonForFailureCode = this.noPassObj.reason
      para.reasonForFailure = this.noPassObj.desc
      let loading = this.createLoading()
      this.$apis.claims.checkOrderApi(para).then(res => {
        loading.close()
        if (res) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$router.push({ path: '/claims/ghIndex' })
        }
        this.cancleNoPass()
      })
    },
    cancleNoPass() {
      this.showNoPassDialog = false
    },
    // 处理定损提交参数
    handleParams() {
      let itemsObj = this.handlerServices()
      let imageObj = this.hanlerImg()
      let explainObj = {}
      if (this.orderMsg.status != 12) {
        explainObj = this.handlerExplain()
      }
      let para = {
        ...explainObj,
        ...imageObj,
        ...itemsObj,
        ...this.orderMsg,
        writeOffCode: this.repotData.writeOffCode,
        contractNo: this.repotData.contractNo,
        reporterName: this.repotData.reporterName,
        reporterPhone: this.repotData.reporterPhone,
        reportDate: this.repotData.reportDate ? dayjs(this.repotData.reportDate).format('YYYY-MM-DD HH:mm:ss') : '',
        reimbursementDate: this.repotData.reimbursementDate ? dayjs(this.repotData.reimbursementDate).format('YYYY-MM-DD HH:mm:ss') : '',
        internalReimbursementDate: this.repotData.internalReimbursementDate ? dayjs(this.repotData.internalReimbursementDate).format('YYYY-MM-DD HH:mm:ss') : '',
        handlerName: this.repotData.handlerName,
        handlerPhone: this.repotData.handlerPhone,
        reimbursementCountiesCode: this.repotData.reimbursementCountiesCode,
        reimbursementCityCode: this.repotData.reimbursementCityCode,
        reimbursementProvinceCode: this.repotData.reimbursementProvinceCode,
        reimbursementAddr: this.repotData.reimbursementAddr,
        reimbursementProcess: this.repotData.reimbursementProcess,
        applyAmount: this.repotData.applyAmount ? (Number(this.repotData.applyAmount) * 10 * 10).toFixed(0) : 0,
        signatureAuth: this.repotData.signatureAuth || ''
      }

      return para
    },
    // 案件补充说明
    handlerExplain() {
      let obj = {}
      if (this.orderMsg.status == 12 || this.orderMsg.status == 2) {
        this.repotData.supplementList2.forEach((item, index) => {
          let idx = `supplementList2[${index}].id`
          let claimsId = `supplementList2[${index}].claimsId`
          let content = `supplementList2[${index}].content`
          let suppType = `supplementList2[${index}].suppType`
          let operation = `supplementList2[${index}].operation`
          let temp = {
            [idx]: item.id,
            [claimsId]: this.orderMsg.id,
            [content]: item.content,
            [suppType]: item.suppType,
            [operation]: this.isSave && !item.id ? 0 : 1
          }
          Object.assign(obj, temp)
        })
      } else {
        this.repotData.supplementList1.forEach((item, index) => {
          let idx = `supplementList1[${index}].id`
          let claimsId = `supplementList1[${index}].claimsId`
          let content = `supplementList1[${index}].content`
          let suppType = `supplementList1[${index}].suppType`
          let operation = `supplementList1[${index}].operation`
          let temp = {
            [idx]: item.id,
            [claimsId]: this.orderMsg.id,
            [content]: item.content,
            [suppType]: item.suppType,
            [operation]: this.isSave && !item.id ? 0 : 1
          }
          Object.assign(obj, temp)
        })
      }

      return obj
    },
    // 图片数据处理
    hanlerImg() {
      let imgs = []
      let serviceImgs = []
      if (this.orderMsg.status == 12 || this.orderMsg.status == 2) {
        this.claimsAttachmentConfigs.forEach((item, index) => {
          if (item.firstClassifyName.indexOf('其他') != -1) {
            item.secondClassifyList.forEach(el => {
              el.attachmentList = item.allImages
              el.attachmentList.forEach(ele => {
                ele.attachmentCode = el.attachmentCode
                ele.secondClassifyName = el.secondClassifyName
                imgs.push(ele)
              })
            })
          } else {
            item.secondClassifyList.forEach(el => {
              el.attachmentList.forEach(ele => {
                ele.secondClassifyName = el.secondClassifyName
                imgs.push(ele)
              })
            })
          }
        })
      } else {
        this.insuranceAttachmentConfigs.forEach((item, index) => {
          if (item.firstClassifyName.indexOf('其他') != -1) {
            item.secondClassifyList.forEach(el => {
              el.attachmentList = item.allImages
              el.attachmentList.forEach(ele => {
                ele.secondClassifyName = el.secondClassifyName
                imgs.push(ele)
              })
            })
          } else {
            item.secondClassifyList.forEach(el => {
              if (el.serviceItemName == '钥匙及车牌重置服务' && this.lossTypeList.includes(el.lossType)) {
                el.attachmentList.forEach(ele => {
                  ele.secondClassifyName = el.secondClassifyName
                  serviceImgs.push(ele)
                })
              } else {
                el.attachmentList.forEach(ele => {
                  ele.secondClassifyName = el.secondClassifyName
                  imgs.push(ele)
                })
              }
            })
          }
        })
      }
      if (serviceImgs.length) {
        imgs = [...serviceImgs, ...imgs]
      }
      let obj = {}
      let type = this.orderMsg.status == 12 || this.orderMsg.status == 2 ? 2 : 1
      imgs.forEach((item, index) => {
        let idx = `attachments${type}[${index}].id`
        let claimsId = `attachments${type}[${index}].claimsId`
        let secondClassifyName = `attachments${type}[${index}].secondClassifyName`
        let attachmentCode = `attachments${type}[${index}].attachmentCode`
        let attachmentFile = `attachments${type}[${index}].attachmentFile`
        let attachmentType = `attachments${type}[${index}].attachmentType`
        let attachmentName = `attachments${type}[${index}].attachmentName`
        let auditStatus = `attachments${type}[${index}].auditStatus`
        let reasonForFailure = `attachments${type}[${index}].reasonForFailure`
        let auditBy = `attachments${type}[${index}].auditBy`
        let classifyId = `attachments${type}[${index}].classifyId`
        let temp = {
          [idx]: item.id,
          [claimsId]: this.orderMsg.id,
          [secondClassifyName]: item.secondClassifyName,
          [attachmentCode]: item.attachmentCode,
          [attachmentFile]: item.attachmentFile,
          [attachmentType]: item.attachmentType,
          [attachmentName]: item.attachmentName,
          [auditStatus]: item.auditStatus,
          [reasonForFailure]: item.reasonForFailure,
          [auditBy]: item.auditBy,
          [classifyId]: item.classifyId
        }
        Object.assign(obj, temp)
      })
      return obj
    },
    // 获取车牌钥匙选择类型
    getLossType(e) {
      this.lossTypeList = e
    },
    // 核赔审核,定损审核提交的时候,金额那一块的数据处理
    handlerServices() {
      let itemObj = {}
      this.itemList.forEach((item, index) => {
        let idx = `itemsList[${index}].id`
        let serviceItemCode = `itemsList[${index}].serviceItemCode`
        let serviceItemName = `itemsList[${index}].serviceItemName`
        let writeOffCode = `itemsList[${index}].writeOffCode`
        let contractNo = `itemsList[${index}].contractNo`
        let approveAmount = `itemsList[${index}].approveAmount`
        let applyAmount = `itemsList[${index}].applyAmount`
        let lossAssessmentAmount = `itemsList[${index}].lossAssessmentAmount`
        let purchaseTax = `itemsList[${index}].purchaseTax`
        let depreciation = `itemsList[${index}].depreciation`
        let commercialInsurance = `itemsList[${index}].commercialInsurance`
        let registrationFee = `itemsList[${index}].registrationFee`
        let retrofits = `itemsList[${index}].retrofits`
        let scooterFare = `itemsList[${index}].scooterFare`
        let claimsId = `itemsList[${index}].claimsId`
        let lossType = `itemsList[${index}].lossType`
        let damageType = `itemsList[${index}].damageType`
        let temp = {
          [idx]: item.id,
          [serviceItemCode]: item.serviceItemCode,
          [serviceItemName]: item.serviceItemName,
          [writeOffCode]: this.repotData.writeOffCode,
          [contractNo]: this.repotData.contractNo,
          [approveAmount]: this.handlePrice(item.approveAmount) || 0,
          [applyAmount]: this.handlePrice(item.applyAmount) || 0,
          [lossAssessmentAmount]:  this.handlePrice(item.lossAssessmentAmount) || 0,
          [purchaseTax]: this.handlePrice(item.purchaseTax),
          [depreciation]: this.handlePrice(item.depreciation),
          [commercialInsurance]:  this.handlePrice(item.commercialInsurance),
          [registrationFee]: this.handlePrice(item.registrationFee),
          [retrofits]: this.handlePrice(item.retrofits),
          [scooterFare]:  this.handlePrice(item.scooterFare),
          [claimsId]: this.orderMsg.id,
          [lossType]: item.serviceItemCode == 'SC0006' ? item.lossTypeList.join(',') : item.lossType,
          [damageType] : item.serviceItemType == 2 && item?.damageType?.length ? item.damageType.join(',') : ''
        }
        Object.assign(itemObj, temp)
      })
      return itemObj
    },
    handlePrice(price) {
      return price ? (Number(price) * 10 * 10).toFixed(0) : null
    },
    // 保存草稿参数
    savePara() {
      const operation = 0
      let itemObj = this.handlerServices()
      let imgObj = this.hanlerImg()
      let explainObj = this.handlerExplain()
      let para = {
        ...itemObj,
        ...imgObj,
        ...explainObj,
        operation,
        ...this.orderMsg,
        writeOffCode: this.repotData.writeOffCode,
        contractNo: this.repotData.contractNo,
        reporterName: this.repotData.reporterName,
        reporterPhone: this.repotData.reporterPhone,
        reportDate: this.repotData.reportDate ? dayjs(this.repotData.reportDate).format('YYYY-MM-DD HH:mm:ss') : '',
        reimbursementDate: this.repotData.reimbursementDate ? dayjs(this.repotData.reimbursementDate).format('YYYY-MM-DD HH:mm:ss') : '',
        internalReimbursementDate: this.repotData.internalReimbursementDate ? dayjs(this.repotData.internalReimbursementDate).format('YYYY-MM-DD HH:mm:ss') : '',
        handlerName: this.repotData.handlerName,
        handlerPhone: this.repotData.handlerPhone,
        reimbursementCountiesCode: this.repotData.reimbursementCountiesCode,
        reimbursementCityCode: this.repotData.reimbursementCityCode,
        reimbursementProvinceCode: this.repotData.reimbursementProvinceCode,
        reimbursementAddr: this.repotData.reimbursementAddr,
        reimbursementProcess: this.repotData.reimbursementProcess,
        applyAmount: this.repotData.applyAmount ? (Number(this.repotData.applyAmount) * 10 * 10).toFixed(0) : 0
      }
      let claims = {
        operation,
        ...itemObj,
        ...explainObj,
        ...this.orderMsg,
        attachments3: this.handleJieGpu(3),
        // attachments2: this.handleJieGpu(2),
        bankAccount: this.handleJieGpu(4),
        writeOffCode: this.repotData.writeOffCode,
        ...imgObj
      }
      return this.orderMsg.status == 12 || this.orderMsg.status == 2 ? claims : para
    },
    // 保存订单
    toSaveOrder() {
      this.isSave = true
      let para = this.savePara()
      const name = this.orderMsg.status == 12 || this.orderMsg.status == 2 ? 'saveClaimsCG' : 'saveCG'
      let loading = this.createLoading()
      this.$apis.claims[name](para).then(res => {
        if(res){
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.toBackList()
        }
      }).finally(end => {
        loading.close()
      })
    },
    // 返回上一页
    toBackList() {
      this.$router.push({ path: '/claims/ghIndex' })
    },
    // 输入校验
    validPrice(e, id, type) {
      let checkPlan = '' + this.itemList[id][type]
      checkPlan = checkPlan
        .replace(/[^\d.]/g, '')
        .replace(/\.{2,}/g, '.')
        .replace(/^\./g, '')
        .replace('.', '$#$')
        .replace(/\./g, '')
        .replace('$#$', '.')
      if (checkPlan.indexOf('.') < 0 && checkPlan !== '') {
        checkPlan = parseFloat(checkPlan) + ''
      } else if (checkPlan.indexOf('.') >= 0) {
        checkPlan = checkPlan.replace(/^()*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数
      }
      this.$set(this.itemList[id], type, checkPlan)
    },
    changePrice(e, id, type) {
      if (!e.target.value) return
      const len = e.target.value.length
      let lastStr = e.target.value.charAt(len - 1)
      if (lastStr === '.') {
        this.$set(this.itemList[id], type, e.target.value.substr(0, len - 1))
      }
      if(type == 'applyAmount'){
        const minPrice = 1
        if (Number(e.target.value) < minPrice) {
          this.$set(this.itemList[id], type, 1)
        }
      }

      const maxPrice = 200000
      if (Number(e.target.value) > maxPrice) {
        this.$set(this.itemList[id], type, maxPrice)
      }
    },
    createLoading() {
      const loading = this.$loading({
        lock: true,
        text: 'loading...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.5)',
        customClass: 'loadingClass'
      })
      return loading
    },
    // 预警信息版本
    getWarningInfo(e) {
      this.queryList = e
    },
    toPassOrderAddWarning() {
      this.hepeiPass()
    }
  }
}
</script>
<style lang="scss" scoped>
.passed-wrap {
  font-family: PingFangSC-Regular, PingFang SC;
  color: #333333;
  .passed-item {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
    .name {
      font-size: 14px;
    }
    .set-price {
      background: #f9f9f9;
      padding: 20px;
      list-style: none;
      margin-top: 10px;
      li {
        margin-bottom: 20px;
        display: flex;
        align-items: center;
        &:last-child {
          margin-bottom: 0;
        }
        label {
          width: 154px;
          display: inline-block;
          text-align: right;
        }
      }
      .el-input {
        width: 284px;
        margin-right: 60px;
      }
    }
  }
}
.btn-box {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 16px 0 20px 0;
}

.danger-btn {
  border-color: #f56c6c;
  color: #f56c6c;
}
.danger-btn:hover {
  background: #f56c6c;
  border-color: #f56c6c;
  color: #fff;
}
.danger-btn:focus {
  background: #dd6161;
  border-color: #dd6161;
  color: #fff;
  outline: 0;
}
</style>