<template>
  <div>
    <el-dialog :title="dialogtitle" :visible="visible" @close="cancel" width="1000px" append-to-body
      :destroy-on-close="true" center>
      <!-- 案件信息 -->
      <el-form ref="form" :model="formData" :rules="rules" label-width="150px" :disabled="flag == '0'">
        <div style="display: inline-flex">
          <div class="infoIcon"></div>
          <div class="caseInfo">案件信息：</div>
        </div>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="案件编号：" prop="caseNum" v-if="flag !== '2'">
              <el-input v-model="formData.caseNum" placeholder="请输入案件编号" :disabled="flag == '1'" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件名称：" prop="caseName">
              <el-input v-model="formData.caseName" placeholder="请输入案件名称" :disabled="flag == '1'" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件标的：" prop="caseSubjectAmount">
              <el-input v-model="formData.caseSubjectAmount" placeholder="请输入案件标的"
                @input="numberFn('caseSubjectAmount')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款开始日期：" prop="loanStartDate">
              <el-date-picker v-model="formData.loanStartDate" type="datetime" placeholder="借款开始日期"
                @change="setStartTime">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款结束日期：" prop="loanEndDate">
              <el-date-picker v-model="formData.loanEndDate" type="datetime" placeholder="借款结束日期" @change="setEndTime">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同编号：" prop="contractNumber">
              <el-input v-model="formData.contractNumber" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人主张欠本金：" prop="claimPrinciOwed">
              <el-input v-model="formData.claimPrinciOwed" placeholder="请输入" @input="numberFn('claimPrinciOwed')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人主张欠利息：" prop="claimInterestOwed">
              <el-input v-model="formData.claimInterestOwed" placeholder="请输入" @input="numberFn('claimInterestOwed')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人主张违约金：" prop="claimLiquidDamag">
              <el-input v-model="formData.claimLiquidDamag" placeholder="请输入" @input="numberFn('claimLiquidDamag')" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="申请人请求仲裁庭裁决：" prop="requestRule">
              <el-input v-model="formData.requestRule" placeholder="请输入申请人请求仲裁庭裁决" type="textarea"
                :autosize="{ minRows: 4, maxRows: 8 }" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否财产保全申请：" prop="properPreser">
              <el-radio-group v-model="formData.properPreser">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <!-- 应缴费用 -->
          <el-col :span="12" v-if="flag == 0">
            <el-form-item label="应缴费用：" prop="feePayable">
              <el-input v-model="formData.feePayable" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <!-- 申请人仲裁诉求 -->
          <el-col :span="24">
            <el-form-item label="申请人仲裁请求及事实和理由" prop="arbitratClaims">
              <el-input v-model="formData.arbitratClaims" placeholder="请输入申请人仲裁诉求" type="textarea"
                :autosize="{ minRows: 4, maxRows: 8 }" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人案件证据资料上传：" prop="applicantEvidence" v-if="flag !== '0'">
              <el-upload class="upload-demo" ref="fileupload" accept=".png,.jpg,.doc,.docx,.txt,.pdf"
                :action="UploadUrl()" :on-success="handlSuccess" :on-remove="handleRemove" :on-preview="handlePreview"
                :before-remove="beforeRemove" :data="filedata" :headers="headers" multiple :limit="3"
                :on-exceed="handleExceed" :file-list="fileList">
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">
                  文件支持上传.jpg，png，.doc，docx，.txt，.pdf文件
                </div>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人案件证据资料：" v-if="flag == '0' &&
              caseAttachList.length > 0 &&
              applicateArr.length > 0
              ">
              <div v-for="(item, index) in applicateArr" :key="index">
                <a href="#" @click="toFile(item, index)" style="color: blue">
                  {{ item.annexName }}
                </a>
              </div>
            </el-form-item>
          </el-col>
          <!-- 仅详情展示 案件质证环节以后显示被申请人证据-->
          <el-col :span="12">
            <el-form-item label="被申请人案件证据资料：" prop="respondentEvidence" v-if="flag == '0' && caseAttachList.length > 0 && quiltArr.length > 0
              ">
              <div v-for="(item, index) in quiltArr" :key="index">
                <a href="#" @click="toFile1(item, index)" style="color: blue">
                  {{ item.annexName }}
                </a>
              </div>

              <!-- <el-upload
                class="upload-demo"
                action="https://jsonplaceholder.typicode.com/posts/"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :before-remove="beforeRemove"
                multiple
                :limit="3"
                :on-exceed="handleExceed"
                :file-list="fileList"
              >
                <el-button size="small" type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">
                  只能上传jpg/png文件，且不超过500kb
                </div>
              </el-upload> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 申请人主体信息 -->
      <el-form ref="form2" :model="form2" label-width="150px" :disabled="flag == '0'">
        <div v-for="(item, index) in form2.paymentArr" :key="index">
          <div style="display: flex; justify-content: space-between">
            <div style="display: inline-flex">
              <div class="infoIcon"></div>
              <div class="caseInfo">申请人主体信息：</div>
            </div>
            <!-- <p>申请人主体信息：</p> -->
            <el-button type="danger" icon="el-icon-delete" @click="deleteData(index)"
              v-if="form2.paymentArr.length > 1 && flag != '0'"></el-button>
          </div>
          <el-divider></el-divider>
          <el-row>
            <el-col :span="12">
              <el-form-item label="申请人(机构)：" :prop="'paymentArr.' + index + '.name'" :rules="[
                {
                  required: true,
                  message: '申请人不能为空',
                  trigger: 'blur',
                },
                { max: 20, message: '长度应小于20个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.name" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="代码：" :prop="'paymentArr.' + index + '.identityNum'" :rules="[
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.identityNum" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话：" :prop="'paymentArr.' + index + '.contactTelphone'" :rules="[
                {
                  required: true,
                  message: '联系电话不能为空',
                  trigger: 'blur',
                },
                {
                  pattern: /^[1][3,4,5,6,7,8,9][0-9]{9}$/,
                  message: '请输入正确的手机号码',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="item.contactTelphone" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <!-- 新增申请人邮箱 -->
            <el-col :span="12">
              <el-form-item label="邮箱" :prop="'paymentArr.' + index + '.email'" :rules="[
                {
                  required: true,
                  message: '邮箱地址不能为空',
                  trigger: 'blur',
                },
                {
                  pattern:
                    /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,
                  message: '请输入正确的邮箱地址',
                  trigger: 'blur',
                },
              ]">
              <el-input
                v-model="item.email"
                placeholder="请输入电子邮件"
              />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位地址：" :prop="'paymentArr.' + index + '.workAddress'" :rules="[
                {
                  required: true,
                  message: '单位地址不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.workAddress" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位电话：" :prop="'paymentArr.' + index + '.workTelphone'" :rules="[
                {
                  required: true,
                  message: '单位电话不能为空',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="item.workTelphone" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系地址：" :prop="'paymentArr.' + index + '.contactAddress'" :rules="[
                {
                  required: true,
                  message: '联系地址不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.contactAddress" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="申请人住所：" :prop="'paymentArr.' + index + '.residenAffili'" :rules="[
                {
                  required: true,
                  message: '申请人住所不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.residenAffili" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="法定代表人：" :prop="'paymentArr.' + index + '.compLegalPerson'" :rules="[
                {
                  required: true,
                  message: '法定代表人不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.compLegalPerson" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="法定代表人职位：" :prop="'paymentArr.' + index + '.compLegalperPost'" :rules="[
                {
                  required: true,
                  message: '法定代表人职位不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.compLegalperPost" placeholder="请输入" />
              </el-form-item>
            </el-col>
          </el-row>
          <div style="display: inline-flex">
            <div class="infoIcon"></div>
            <div class="caseInfo2">代理人信息：</div>
          </div>
          <!-- <p>代理人信息：</p> -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="姓名：" :prop="'paymentArr.' + index + '.nameAgent'" :rules="[
                {
                  required: true,
                  message: '姓名不能为空',
                  trigger: 'blur',
                },
                { max: 20, message: '长度应小于20个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.nameAgent" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证号：" :prop="'paymentArr.' + index + '.identityNumAgent'" :rules="[
                {
                  required: true,
                  message: '身份证号不能为空',
                  trigger: 'blur',
                },
                {
                  pattern:
                    /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
                  message: '请输入正确的身份证号码',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="item.identityNumAgent" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话：" :prop="'paymentArr.' + index + '.contactTelphoneAgent'" :rules="[
                {
                  required: true,
                  message: '联系电话不能为空',
                  trigger: 'blur',
                },
                {
                  pattern: /^[1][3,4,5,6,7,8,9][0-9]{9}$/,
                  message: '请输入正确的手机号码',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="item.contactTelphoneAgent" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系地址：" :prop="'paymentArr.' + index + '.contactAddressAgent'" :rules="[
                {
                  required: true,
                  message: '联系地址不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="item.contactAddressAgent" placeholder="请输入" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <!-- <el-button
        v-if="flag == 1 || flag == 2"
        type="primary"
        plain
        @click="generateForm"
        >新增申请人主体信息</el-button
      > -->
      <!-- 被申请人主体信息 -->
      <el-form ref="form3" label-width="150px" :disabled="flag == '0'" :model="form3">
        <div v-for="(itm, index) in form3.paymentArr1" :key="index + form2.paymentArr.length">
          <div style="display: flex; justify-content: space-between">
            <div style="display: inline-flex">
              <div class="infoIcon"></div>
              <div class="caseInfo">被申请人主体信息：</div>
            </div>
            <!-- <p>被申请人主体信息：</p> -->
            <el-button type="danger" icon="el-icon-delete" @click="deleteData1(index)"
              v-if="form3.paymentArr1.length > 1 && flag != '0'"></el-button>
          </div>
          <el-divider></el-divider>
          <el-row>
            <el-col :span="12">
              <el-form-item label="被申请人姓名" :prop="'paymentArr1.' + index + '.name'" :rules="[
                {
                  required: true,
                  message: '被申请人不能为空',
                  trigger: 'blur',
                },
                { max: 20, message: '长度应小于20个字符', trigger: 'blur' }
              ]">
                <el-input v-model="itm.name" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证号：" :prop="'paymentArr1.' + index + '.identityNum'" :rules="[
                {
                  required: true,
                  message: '身份证号不能为空',
                  trigger: 'blur',
                },
                {
                  pattern:
                    /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
                  message: '请输入正确的身份证号码',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="itm.identityNum" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话：" :prop="'paymentArr1.' + index + '.contactTelphone'" :rules="[
                {
                  required: true,
                  message: '联系电话不能为空',
                  trigger: 'blur',
                },
                {
                  pattern: /^[1][3,4,5,6,7,8,9][0-9]{9}$/,
                  message: '请输入正确的手机号码',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="itm.contactTelphone" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="邮箱" :prop="'paymentArr1.' + index + '.email'" :rules="[
                {
                  required: true,
                  message: '邮箱地址不能为空',
                  trigger: 'blur',
                },
                {
                  pattern:
                    /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,
                  message: '请输入正确的邮箱地址',
                  trigger: 'blur',
                },
              ]">
                <el-input
                  v-model="itm.email"
                  placeholder="请输入电子邮件"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位地址：" :prop="'paymentArr1.' + index + '.workAddress'" :rules="[
                {
                  required: true,
                  message: '单位地址不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="itm.workAddress" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位电话：" :prop="'paymentArr1.' + index + '.workTelphone'" :rules="[
                {
                  required: true,
                  message: '单位电话不能为空',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="itm.workTelphone" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系地址：" :prop="'paymentArr1.' + index + '.contactAddress'" :rules="[
                {
                  required: true,
                  message: '联系地址不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="itm.contactAddress" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="被申请人住所：" :prop="'paymentArr1.' + index + '.residenAffili'" :rules="[
                {
                  required: true,
                  message: '被申请人住所不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="itm.residenAffili" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="被申请人性别：" :prop="'paymentArr1.' + index + '.responSex'" :rules="[
                {
                  required: true,
                },
              ]">
                <el-radio-group v-model="itm.responSex">
                  <el-radio label="1">男</el-radio>
                  <el-radio label="0">女</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="被申请人出生年月日：" :prop="'paymentArr1.' + index + '.responBirth'" :rules="[
                {
                  required: true,
                  message: '被申请人出生年月日不能为空',
                  trigger: 'blur',
                },
              ]">
                <el-date-picker v-model="itm.responBirth" :picker-options="pickerOptions" type="datetime"
                  placeholder="被申请人出生年月日">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <div style="display: inline-flex">
            <div class="infoIcon"></div>
            <div class="caseInfo2">代理人信息：</div>
          </div>
          <!-- <p>代理人信息：</p> -->
          <el-row>
            <el-col :span="12">
              <el-form-item label="姓名：" :prop="'paymentArr1.' + index + '.nameAgent'" :rules="[
                {
                  required: true,
                  message: '姓名不能为空',
                  trigger: 'blur',
                },
                { max: 20, message: '长度应小于20个字符', trigger: 'blur' }
              ]">
                <el-input v-model="itm.nameAgent" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <!--  -->
              <el-form-item label="身份证号：" :prop="'paymentArr1.' + index + '.identityNumAgent'" :rules="[
                {
                  required: true,
                  message: '身份证号不能为空',
                  trigger: 'blur',
                },
                {
                  pattern:
                    /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
                  message: '请输入正确的身份证号码',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="itm.identityNumAgent" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话：" :prop="'paymentArr1.' + index + '.contactTelphoneAgent'" :rules="[
                {
                  required: true,
                  message: '联系电话不能为空',
                  trigger: 'blur',
                },
                {
                  pattern: /^[1][3,4,5,6,7,8,9][0-9]{9}$/,
                  message: '请输入正确的手机号码',
                  trigger: 'blur',
                },
              ]">
                <el-input v-model="itm.contactTelphoneAgent" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系地址：" :prop="'paymentArr1.' + index + '.contactAddressAgent'" :rules="[
                {
                  required: true,
                  message: '联系地址不能为空',
                  trigger: 'blur',
                },
                { max: 50, message: '长度应小于50个字符', trigger: 'blur' }
              ]">
                <el-input v-model="itm.contactAddressAgent" placeholder="请输入" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <!-- <el-button
        v-if="flag == 1 || flag == 2"
        type="primary"
        plain
        @click="generateForm1()"
        >新增被申请人主体信息</el-button
      > -->
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="flag != 0" class="endbutton"><span>确 定</span></el-button>
        <el-button @click="cancel" class="endbutton1"><span>取 消</span></el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import moment from "moment"; //导入文件
import { getToken } from "@/utils/auth";
import { addCaseApply, editCaseApply } from "@/api/caseAccess/caseEntry";
export default {
  props: [
    "visible",
    "dialogtitle",
    "form",
    "getcaseApply",
    "flag",
    "initpaymentArr",
    "initpaymentArr1",
    "queryParams",
    "caseAttachList",
  ],
  data() {
    return {
      formData: this.form,
      filedata: {
        annexType: 2,
      },
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      form2: {
        paymentArr: [
          {
            identityType: 1,
            name: "",
            identityNum: "",
            contactTelphone: "",
            email: "",
            workAddress: "",
            workTelphone: "",
            contactAddress: "",
            nameAgent: "",
            contactTelphoneAgent: "",
            contactAddressAgent: "",
            residenAffili: ""
          },
        ],
      }, //申请人主体信息
      form3: {
        paymentArr1: [
          {
            identityType: 2,
            name: "",
            identityNum: "",
            contactTelphone: "",
            email: "",
            workAddress: "",
            workTelphone: "",
            contactAddress: "",
            nameAgent: "",
            contactTelphoneAgent: "",
            contactAddressAgent: "",
            responSex: 1,
            responBirth: "",
            residenAffili: ""
          },
        ],
      }, //被申请人主体信息
      // 表单校验
      rules: {
        // caseNum: [
        //   {
        //     required: true,
        //     message: "案件编号不能为空",
        //     trigger: "blur",
        //   },
        //   { max: 20, message: "长度应小于20个字符", trigger: "blur" },
        // ],
        caseSubjectAmount: [
          {
            required: true,
            message: "案件标的不能为空",
            trigger: "blur",
          },
        ],
        caseName: [
          {
            required: true,
            message: "案件名称不能为空",
            trigger: "blur",
          },
        ],
        loanStartDate: [
          {
            required: true,
            message: "借款开始日期不能为空",
            trigger: "blur",
          },
        ],
        loanEndDate: [
          {
            required: true,
            message: "借款结束日期不能为空",
            trigger: "blur",
          },
        ],
        name: [
          {
            required: true,
            message: "申请人姓名不能为空",
            trigger: "blur",
          },
        ],
        contractNumber: [
          {
            required: true,
            message: "合同编号不能为空",
            trigger: "blur",
          },
        ],
        claimPrinciOwed: [
          {
            required: true,
            message: "申请人主张欠本金不能为空",
            trigger: "blur",
          },
        ],
        claimInterestOwed: [
          {
            required: true,
            message: "申请人主张欠利息不能为空",
            trigger: "blur",
          },
        ],
        Overduedays: [
          {
            required: true,
            message: "逾期天数不能为空",
            trigger: "blur",
          },
        ],
        claimLiquidDamag: [
          {
            required: true,
            message: "申请人主张违约金不能为空",
            trigger: "blur",
          },
        ],
        arbitratClaims: [
          {
            required: true,
            message: "请输入申请人仲裁诉求",
            trigger: "blur",
          },
        ],
        feePayable: [
          {
            required: true,
          },
        ],
      },
      // annexId: '',
      caseAttachListArr: [],
      fileList: [],
      applicateArr: [],
      quiltArr: [],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6;
        }
      }
    };
  },
  watch: {
    initpaymentArr: {
      handler(val) {
        if (val) {
          this.applicateArr = [];
          this.quiltArr = [];
          this.formData = this.form;
          this.fileList = [];
          if (this.flag == "1" || this.flag == "0") {
            this.form2.paymentArr = this.initpaymentArr;
            this.form3.paymentArr1 = this.initpaymentArr1;
            this.caseAttachList.forEach((item) => {
              if (item.annexType == 2) {
                this.applicateArr.push({
                  annexName: item.annexName,
                  annexPath: item.annexPath,
                });
              }
              if (item.annexType == 6) {
                this.quiltArr.push({
                  annexName: item.annexName,
                  annexPath: item.annexPath,
                });
              }
            });
            if (this.caseAttachList.length > 0) {
              this.caseAttachListArr = this.caseAttachList 
            }
            this.caseAttachList.forEach((item) => {
              if (item.annexType == 2) {
                this.fileList.push(item)
              }
            });
            this.fileList.forEach((item) => {
              item["name"] = item.annexName;
              item["certificatePath"] = item.annexPath;
            });
          }
          if (this.flag == "2") {
            this.form2.paymentArr = [
              {
                identityType: 1,
                name: "",
                identityNum: "",
                contactTelphone: "",
                email: "",
                workAddress: "",
                workTelphone: "",
                contactAddress: "",
                nameAgent: "",
                contactTelphoneAgent: "",
                contactAddressAgent: "",
              },
            ];
            this.form3.paymentArr1 = [
              {
                identityType: 2,
                name: "",
                identityNum: "",
                contactTelphone: "",
                email: "",
                workAddress: "",
                workTelphone: "",
                contactAddress: "",
                nameAgent: "",
                contactTelphoneAgent: "",
                contactAddressAgent: "",
              },
            ];
          }
        }
      },
      deep: true,
    },
  },
  methods: {
    numberFn(p) {
      this.formData[p] =
        this.formData[p]
          .replace(/[^\d^\.]+/g, "")
          .replace(/^0+(\d)/, "$1")
          .replace(/^\./, "0.")
          .match(/^\d*(\.?\d{0,2})/g)[0] || "";
    },
    UploadUrl() {
      return window.location.origin + "/API/evidence/upload";
    },
    handlePreview(file) {
      if (this.flag == "2") {
        window.open(
          window.location.origin + "/API" + file.response.data.annexName,
          "_blank"
        );
      } else if (this.flag == "1") {
        window.open(
          window.location.origin + "/API" + file.certificatePath,
          "_blank"
        );
      }
    },

    // 文件上传成功
    handlSuccess(res, file) {
      this.caseAttachListArr.push(
        res.data,
      );
    },
    // 文件超出个数限制时的钩子
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length
        } 个文件`
      );
    },
    // 删除文件之前的钩子，参数为上传的文件和文件列表，若返回 false 或者返回 Promise 且被 reject，则停止删除。
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    handleRemove(file, fileList) {
      // (this.caseAttachListArr = []),
        // fileList.forEach((item) => {
        //   this.caseAttachListArr.push( item.response.data );
        // });
    },
    // 取消
    cancel() {
      this.$emit("cancel");
    },
    // 校验借款开始日期与结束日期
    setStartTime() {
      if (
        this.setTime(this.formData.loanStartDate) >=
        this.setTime(this.formData.loanEndDate)
      ) {
        this.$message.error("借款开始日期应早于借款结束日期");
        this.formData.loanStartDate = "";
        this.formData.loanEndDate = "";
      }
    },
    setEndTime() {
      if (
        this.setTime(this.formData.loanEndDate) <=
        this.setTime(this.formData.loanStartDate)
      ) {
        this.$message.error("借款结束日期应晚于借款开始日期");
        this.formData.loanStartDate = "";
        this.formData.loanEndDate = "";
      }
    },
    setTime(val) {
      const date = new Date(val);
      const time = date.getTime();
      return time;
    },

    // 新增申请人主体信息
    generateForm() {
      this.form2.paymentArr.push({
        identityType: 1,
        name: "",
        identityNum: "",
        contactTelphone: "",
        email: "",
        workAddress: "",
        workTelphone: "",
        contactAddress: "",
        nameAgent: "",
        contactTelphoneAgent: "",
        contactAddressAgent: "",
      });
    },
    // 新增被申请人主体信息
    generateForm1() {
      this.form3.paymentArr1.push({
        identityType: 2,
        name: "",
        identityNum: "",
        contactTelphone: "",
        email: "",
        workAddress: "",
        workTelphone: "",
        contactAddress: "",
        nameAgent: "",
        contactTelphoneAgent: "",
        contactAddressAgent: "",
      });
    },
    // 删除申请人主体信息
    deleteData(index) {
      this.form2.paymentArr.splice(index, 1);
    },
    // 删除被申请人主体信息
    deleteData1(index) {
      this.form3.paymentArr1.splice(index, 1);
    },
    // 提交立案申请 addCaseApply
    submitForm() {
      this.$refs["form"].validate((valid) => {
        this.formData.loanStartDate = moment(
          this.formData.loanStartDate
        ).format("YYYY-MM-DD HH:mm:ss");
        this.formData.loanEndDate = moment(this.formData.loanEndDate).format(
          "YYYY-MM-DD HH:mm:ss"
        );
        if (valid) {
          this.$refs["form2"].validate((valid) => {
            if (valid) {
              this.$refs["form3"].validate((vail) => {
                if (vail) {
                  this.formData.caseAffiliates = [
                    ...this.form2.paymentArr,
                    ...this.form3.paymentArr1,
                  ];
                  this.formData.caseAttachList = [...this.caseAttachListArr];
                  this.formData.caseAffiliates[1].responBirth = moment(this.formData.caseAffiliates[1].responBirth).format(
                    "YYYY-MM-DD HH:mm:ss"
                  );
                  if (this.formData.id) {
                    editCaseApply({
                      ...this.formData,
                      caseAffiliates: this.formData.caseAffiliates,
                    }).then((res) => {
                      if (res.code == 200) {
                        this.$modal.msgSuccess("修改成功");
                        this.$emit("cancel");
                        this.getcaseApply(this.queryParams);
                      }
                    });
                  } else {
                    addCaseApply({
                      ...this.formData,
                      caseAffiliates: this.formData.caseAffiliates,
                    }).then((response) => {
                      if (response.code == 200) {
                        this.$modal.msgSuccess("新增成功");
                        this.$emit("cancel");
                        this.getcaseApply(this.queryParams);
                      }
                    });
                  }
                }
              });
            }
          });
        }
      });
    },
    // 详情显示，展示申请人案件文件
    toFile(item, index) {
      window.open(
        window.location.origin + "/API" + this.applicateArr[index].annexPath,
        "_black"
      );
    },
    // 被申请人文件
    toFile1(item, index) {
      window.open(
        window.location.origin + "/API" + this.quiltArr[index].annexPath,
        "_black"
      );
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__body {
  height: 700px !important;
  overflow: auto !important;
}

::v-deep .el-dialog {
  width: 800px;
  background: #ffffff;
  border-radius: 20px;
}

.caseInfo {
  font-size: 17px;
  font-weight: 600;
}

.caseInfo2 {
  font-size: 15px;
  font-weight: 550;
}

.infoIcon {
  width: 4px;
  // height: 17px;
  background-color: #0072ff;
  margin-right: 5px;
}

.el-date-editor {
  width: 100%;
}

.endbutton {
  width: 154px;
  height: 37px;
  background: #0072ff;
  border-radius: 19px;

  span {
    width: 96px;
    height: 15px;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #ffffff;
  }
}

.endbutton1 {
  width: 154px;
  height: 37px;
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-radius: 19px;

  span {
    width: 31px;
    height: 13px;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #959595;
  }
}
</style>