<template>
  <el-container>
    <el-main style="height: 82vh; overflow: auto">
      <el-form :model="form" ref="form" :rules="formRules" style="margin-top: 20px">
        <el-tabs v-model="activeName" @tab-click="handleClick" :style="{ padding: '20px', height: '90%' }">
          <el-tab-pane :label="labelText" name="first">
            <bns-sub-info-tabs v-if="this.$store.state.user.userType === '03'" :items="basicInformationItems" />
            <bns-cons-info-tabs v-else :items="basicInformationItems" />
          </el-tab-pane>
          <el-tab-pane name="second">
            <span slot="label">
              <i style="color: red" v-if="qualificationStatus">*</i>
              企业资质
            </span>
            <el-form-item label="" prop="enterpriseQualificationItems">
              <uploadFile
                :limit="9"
                :multiple="true"
                :accept="accept"
                :uploadList.sync="form.enterpriseQualificationItems"
                @picturePreview="picturePreview"
                v-on:delFile="delFile"
                :class="{ disabled: this.paramsData.type === 'view' }"
                v-on:up="handleFileChange('form', 'enterpriseQualificationItems')"
              ></uploadFile>
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane name="third">
            <span slot="label">
              <i style="color: red" v-if="securityAgreementStatus">*</i>
              安全协议书
            </span>
            <el-form-item label="" prop="securityAgreementFileItems">
              <uploadFile
                :limit="9"
                :multiple="true"
                :accept="accept"
                :uploadList.sync="form.securityAgreementFileItems"
                @picturePreview="picturePreview"
                v-on:delFile="delFile"
                :class="{ disabled: this.paramsData.type === 'view' }"
                v-on:up="handleFileChange('form', 'securityAgreementFileItems')"
              ></uploadFile>
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane name="fourth">
            <span slot="label">
              <i style="color: red" v-if="fourMeasuresAndTwoMeasuresStatus">*</i>
              四措两案
            </span>
            <el-form-item label="" prop="fourMeasuresAndTwoMeasuresFileItems">
              <uploadFile
                :limit="9"
                :multiple="true"
                :accept="accept"
                :uploadList.sync="form.fourMeasuresAndTwoMeasuresFileItems"
                @picturePreview="picturePreview"
                v-on:delFile="delFile"
                :disabled="this.paramsData.type === 'view'"
                :class="{ disabled: this.paramsData.type === 'view' }"
                v-on:up="handleFileChange('form', 'fourMeasuresAndTwoMeasuresFileItems')"
              ></uploadFile>
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane label="施工人员信息" name="five">
            <div class="app-container">
              <el-form :model="personQueryParams" ref="personQueryForm" size="small" :inline="true" label-width="68px">
                <el-form-item label="施工人员姓名" label-width="140px">
                  <el-input
                    v-model="personQueryParams.name"
                    v-no-whitespace
                    maxlength="20"
                    show-word-limit
                    placeholder="请输入施工人员姓名"
                    clearable
                    @keyup.enter.native="handleQueryPerson"
                  />
                </el-form-item>
                <el-form-item label="状态" prop="status">
                  <el-select v-model="personQueryParams.status" placeholder="请选择状态" clearable>
                    <el-option label="在场" value="1" />
                    <el-option label="离场" value="0" />
                  </el-select>
                </el-form-item>
                <el-form-item label="人员进场时间范围" label-width="150px">
                  <el-date-picker
                    v-model="timeRange"
                    type="daterange"
                    align="right"
                    :editable="false"
                    unlink-panels
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryPerson">
                    搜索
                  </el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="resetQueryPerson">重置</el-button>
                  <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAddPerson"
                    v-if="this.paramsData.type !== 'view'"
                  >
                    新增
                  </el-button>
                  <el-button type="primary" plain icon="el-icon-upload" size="mini" @click="handlePersonImport">
                    基础数据上传
                  </el-button>
                  <el-button type="primary" plain icon="el-icon-upload" size="mini" @click="handleFileImport">
                    文件上传
                  </el-button>
                  <!--                  <el-button-->
                  <!--                    type="primary"-->
                  <!--                    plain-->
                  <!--                    icon="el-icon-download"-->
                  <!--                    size="mini"-->
                  <!--                    @click="handleExportPerosn"-->
                  <!--                  >导出-->
                  <!--                  </el-button>-->
                </el-form-item>
              </el-form>
              <el-table v-loading="loading" :data="personList">
                <el-table-column
                  label="序号"
                  type="index"
                  width="55"
                  align="center"
                  :index="indexContinuous(personQueryParams.pageNum, personQueryParams.pageSize)"
                />
                <el-table-column label="姓名" width="130" align="center" prop="name" />
                <el-table-column label="岗位" width="100" align="center" prop="postName" />
                <el-table-column label="特殊工种种类" width="100" align="center" prop="specialJobType" />
                <el-table-column label="体检文件" width="100" align="center">
                  <template slot-scope="scope">
                    <el-button size="mini" @click="handleShow(scope.row, 1)">查看</el-button>
                  </template>
                </el-table-column>
                <el-table-column label="保险文件" width="100" align="center">
                  <template slot-scope="scope">
                    <el-button size="mini" @click="handleShow(scope.row, 2)">查看</el-button>
                  </template>
                </el-table-column>
                <el-table-column label="特殊工种文件" width="100" align="center">
                  <template slot-scope="scope">
                    <el-button size="mini" @click="handleShow(scope.row, 3)">查看</el-button>
                  </template>
                </el-table-column>
                <el-table-column label="其他文件" width="100" align="center">
                  <template slot-scope="scope">
                    <el-button size="mini" @click="handleShow(scope.row, 4)">查看</el-button>
                  </template>
                </el-table-column>
                <el-table-column label="性别" width="50" align="center" prop="sex" />
                <el-table-column label="年龄" width="50" align="center" prop="age" />
                <el-table-column label="联系方式" width="120" align="center">
                  <template slot-scope="scope">
                    <!-- 检查是否存在身份证号 -->
                    <span v-if="scope.row.phone">{{ hideSensitiveInfo(scope.row.phone) }}</span>
                    <span v-else>-</span>
                  </template>
                </el-table-column>
                <el-table-column label="籍贯" width="200" align="center" prop="nativePlace" />
                <el-table-column label="身份证号码" width="160" align="center">
                  <template slot-scope="scope">
                    <!-- 检查是否存在身份证号 -->
                    <span v-if="scope.row.idCard">{{ hideSensitiveInfo(scope.row.idCard) }}</span>
                    <span v-else>-</span>
                  </template>
                </el-table-column>
                <el-table-column label="民族" width="70" align="center" prop="nation" />
                <el-table-column label="家庭地址" width="200" align="center" show-overflow-tooltip prop="homeAddress" />
                <el-table-column
                  label="现地址"
                  width="200"
                  align="center"
                  show-overflow-tooltip
                  prop="currentAddress"
                />
                <el-table-column label="人脸照片" align="center" prop="faceUrl">
                  <template slot-scope="scope">
                    <el-popover placement="right" title="" trigger="hover">
                      <img
                        :src="`${scope.row.faceUrl ? lookFaceFile + scope.row.faceUrl : ''}`"
                        :min-width="100"
                        :height="300"
                        alt="照片"
                      />
                      <img
                        slot="reference"
                        :src="`${scope.row.faceUrl ? lookFaceFile + scope.row.faceUrl : ''}`"
                        style="max-height: 50px; max-width: 50px"
                        :alt="`${scope.row.faceUrl ? lookFaceFile + scope.row.faceUrl : ''}`"
                      />
                    </el-popover>
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  fixed="right"
                  width="150"
                  align="center"
                  class-name="small-padding fixed-width"
                  v-if="this.paramsData.type !== 'view'"
                >
                  <template slot-scope="scope">
                    <el-button size="mini" type="text" @click="handleEdit(scope.row)">编辑</el-button>
                    <el-button size="mini" type="text" @click="handleDel(scope.row)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>

              <pagination
                v-show="total > 0"
                :total="total"
                :page.sync="personQueryParams.pageNum"
                :limit.sync="personQueryParams.pageSize"
                @pagination="getSubPersonList"
              />

              <el-dialog title="文件查看" :visible.sync="document" width="80%" top="5vh" append-to-body>
                <div style="width: 100%; height: 720px">
                  <bns-file-list-tabs :items="fileList" />
                </div>
              </el-dialog>
              <el-dialog title="文件查看" :visible.sync="documentPreview" width="80%" top="5vh" append-to-body>
                <div style="width: 100%; height: 720px">
                  <bns-kkFile-preview :items="kkFilePreview"></bns-kkFile-preview>
                </div>
              </el-dialog>

              <!--施工人员基本信息查看-->
              <el-dialog
                title="人员信息"
                :visible.sync="constructionPersonnelOpen"
                width="60%"
                v-if="constructionPersonnelOpen"
                :destroy-on-close="true"
                :close-on-click-modal="false"
                :before-close="handleClose"
              >
                <el-form ref="personForm" :model="personItems" :rules="personRules" size="medium" label-width="100px">
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="姓名" prop="consName">
                        <el-input
                          v-model="personItems.consName"
                          placeholder="请输入姓名"
                          clearable
                          maxlength="15"
                          show-word-limit
                          v-no-whitespace
                          :style="{ width: '100%' }"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="性别" prop="sex">
                        <el-select
                          v-model="personItems.sex"
                          placeholder="请选择性别"
                          clearable
                          :style="{ width: '100%' }"
                        >
                          <el-option label="男" value="0"></el-option>
                          <el-option label="女" value="1"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="年龄" prop="age">
                        <el-input
                          v-model="personItems.age"
                          placeholder="请输入年龄"
                          clearable
                          v-no-whitespace
                          :style="{ width: '100%' }"
                          maxlength="2"
                          show-word-limit
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="联系方式" prop="phone">
                        <el-input
                          v-model="personItems.phone"
                          placeholder="请输入联系方式"
                          clearable
                          v-no-whitespace
                          :disabled="disabled"
                          @blur="checkIsExistPerson"
                          maxlength="11"
                          show-word-limit
                          :style="{ width: '100%' }"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="籍贯" prop="natives">
                        <el-input
                          v-model="personItems.natives"
                          placeholder="请输入籍贯"
                          clearable
                          v-no-whitespace
                          :style="{ width: '100%' }"
                          maxlength="80"
                          show-word-limit
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="民族" prop="nation">
                        <el-input
                          v-model="personItems.nation"
                          placeholder="请输入民族"
                          clearable
                          v-no-whitespace
                          :style="{ width: '100%' }"
                          maxlength="10"
                          show-word-limit
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="身份证号码" prop="idCard">
                        <el-input
                          v-model="personItems.idCard"
                          placeholder="请输入身份证号码"
                          clearable
                          v-no-whitespace
                          :style="{ width: '100%' }"
                          maxlength="18"
                          show-word-limit
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="家庭住址" prop="homeAddress">
                        <el-input
                          v-model="personItems.homeAddress"
                          placeholder="请输入家庭住址"
                          clearable
                          v-no-whitespace
                          :style="{ width: '100%' }"
                          maxlength="30"
                          show-word-limit
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="现地址" prop="address">
                        <el-input
                          v-model="personItems.address"
                          placeholder="请输入现地址"
                          clearable
                          v-no-whitespace
                          :style="{ width: '100%' }"
                          maxlength="30"
                          show-word-limit
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="岗位" prop="post">
                        <el-select
                          v-model="personItems.post"
                          placeholder="请选择岗位"
                          @change="handlePostChange"
                          :style="{ width: '100%' }"
                          clearable
                        >
                          <el-option
                            v-for="item in postOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                            :style="{ width: '100%' }"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue" v-if="showSpecialWorkType">
                    <el-col :span="11">
                      <el-form-item label-width="120px" label="特殊工种种类" prop="workType">
                        <el-input
                          v-model="personItems.workType"
                          placeholder="请输入特殊工种种类"
                          clearable
                          v-no-whitespace
                          :style="{ width: '100%' }"
                          maxlength="30"
                          show-word-limit
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="24">
                      <el-form-item
                        label-width="120px"
                        label="人脸照片"
                        :style="{ width: '100%' }"
                        prop="facePhotoList"
                      >
                        <uploadFile
                          :limit="1"
                          :accept="`.png, .jpg, .jpeg`"
                          :uploadList.sync="personItems.facePhotoList"
                          @picturePreview="picturePreview"
                          v-on:up="handleFileChange('personForm', 'facePhotoList')"
                        ></uploadFile>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="24">
                      <el-form-item label-width="120px" label="体检文件" prop="medicalExaminationList">
                        <uploadFile
                          :limit="5"
                          :accept="accept"
                          :uploadList.sync="personItems.medicalExaminationList"
                          @picturePreview="picturePreview"
                          v-on:delFile="delFile"
                          v-on:up="handleFileChange('personForm', 'medicalExaminationList')"
                        ></uploadFile>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="24">
                      <el-form-item label-width="120px" label="保险文件" prop="elseImgList">
                        <uploadFile
                          :limit="5"
                          :accept="accept"
                          :uploadList.sync="personItems.elseImgList"
                          @picturePreview="picturePreview"
                          v-on:delFile="delFile"
                          v-on:up="handleFileChange('personForm', 'elseImgList')"
                        ></uploadFile>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue" v-if="showSpecialWorkType">
                    <el-col :span="24">
                      <el-form-item label-width="120px" label="特殊工种文件" prop="specialTypeOfWorkList">
                        <uploadFile
                          :limit="5"
                          :accept="accept"
                          :uploadList.sync="personItems.specialTypeOfWorkList"
                          @picturePreview="picturePreview"
                          v-on:delFile="delFile"
                          v-on:up="handleFileChange('personForm', 'specialTypeOfWorkList')"
                        ></uploadFile>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row type="flex" align="top" :gutter="gutterValue">
                    <el-col :span="24">
                      <el-form-item label-width="120px" label="其他文件">
                        <uploadFile
                          :limit="5"
                          :accept="accept"
                          :uploadList.sync="personItems.otherFilesList"
                          @picturePreview="picturePreview"
                          v-on:delFile="delFile"
                        ></uploadFile>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                  <el-button type="primary" @click="submitPersonForm" v-preventReClick="5000">提 交</el-button>
                  <el-button @click="personCancel">取 消</el-button>
                </div>
              </el-dialog>

              <el-dialog :title="upload.title" :visible.sync="upload.open" width="25%">
                <el-form label-width="80px" label-position="left" :model="formFile" ref="form" :rules="ruleFile">
                  <el-form-item label="文件上传" prop="fileList">
                    <el-upload
                      ref="upload"
                      :limit="1"
                      accept=".zip"
                      :show-file-list="true"
                      class="upload-demo"
                      action="#"
                      :file-list="formFile.fileList"
                      :on-change="fileChange"
                      :on-remove="handleRemove"
                      :before-upload="beforeUpload"
                      :auto-upload="false"
                      drag
                    >
                      <i class="el-icon-upload"></i>
                      <div class="el-upload__text">
                        将文件拖到此处，或
                        <em>点击上传</em>
                      </div>
                      <div class="el-upload__tip" slot="tip"></div>
                      <div class="el-upload__tip" style="color: red" slot="tip">提示：仅允许导入“zip”格式文件！</div>
                    </el-upload>
                  </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                  <el-button type="primary" @click="submitFileForm" v-preventReClick="5000">确 定</el-button>
                  <el-button @click="upload.open = false">取 消</el-button>
                </div>
              </el-dialog>

              <el-dialog :title="`人员基础数据导入`" :visible.sync="personBasicOpen" width="60%" style="height: 1000px">
                <div style="padding: 15px; width: 100%; height: 750px">
                  <el-steps :active="active" :finish-status="status" align-center>
                    <el-step title="选择文件"></el-step>
                    <el-step title="数据预览"></el-step>
                    <el-step title="异常数据"></el-step>
                    <el-step title="导入完成"></el-step>
                  </el-steps>
                  <div class="step1" style="margin-bottom: 30px">
                    <div
                      style="
                        display: flex;
                        flex-direction: column;
                        padding: 20px;
                        margin-left: 7%;
                        margin-top: 20px;
                        border: 1px solid #ababab;
                        border-radius: 5px;
                        margin-right: 7%;
                      "
                      v-if="active === 1"
                    >
                      <span style="font-size: 18px; font-weight: bold">模板下载</span>
                      <span style="font-size: 16px; margin-top: 10px">
                        请按照数据模板的格式准备导入数据，模板中的表头名称不可更改，表头行不能删除
                      </span>
                      <el-button
                        type="text"
                        style="float: left; margin-top: 10px; width: 60px"
                        @click="downloadTemplate"
                      >
                        下载模板
                      </el-button>
                      <!--                      <span style="font-size: 16px;color: #8a8a8a;margin-top: 10px;cursor: pointer" @click="downloadTemplate"-->
                      <!--                      >下载模板</span>-->
                    </div>
                    <div
                      style="
                        display: flex;
                        flex-direction: column;
                        padding: 20px;
                        margin-left: 7%;
                        margin-top: 20px;
                        border: 1px solid #ababab;
                        border-radius: 5px;
                        margin-right: 7%;
                      "
                      v-if="active === 1"
                    >
                      <span style="font-size: 18px; font-weight: bold">上传文件</span>
                      <span style="font-size: 16px; margin-top: 10px">
                        文件后缀名必须为xls或xlsx(即Excel格式),文件大小不得大于10Mb,最多支持1000行数据
                      </span>
                      <input type="file" id="excel-file" style="display: none" />
                      <el-form ref="form" :model="formPerson" style="margin-top: 10px" :rules="rulesPerson">
                        <el-form-item prop="fileList">
                          <el-upload
                            multiple
                            drag
                            accept=" .doc, .docx, .xls, .xlsx, .ppt, .pptx, .pdf "
                            :show-file-list="true"
                            class="upload-demo"
                            action="#"
                            :limit="1"
                            :file-list="formPerson.fileList"
                            :on-change="filePersonChange"
                            :on-remove="handlePersonRemove"
                            :before-upload="beforePersonUpload"
                            :auto-upload="false"
                            ref="upload"
                          >
                            <i class="el-icon-upload"></i>
                            <div class="el-upload__text">
                              将文件拖到此处，或
                              <em>点击上传</em>
                            </div>
                            <div class="el-upload__text">只能上传 xls/xlsx 文件，且不超过10MB</div>
                          </el-upload>
                        </el-form-item>
                      </el-form>
                      <div style="display: flex; flex-direction: column">
                        <div style="margin-top: 10px; font-weight: 600; font-size: 16px">特别提示</div>
                        <div style="margin-top: 10px; font-weight: 400; font-size: 12px">
                          1. 人员手机号唯一，不可重复
                        </div>
                        <div style="margin-top: 10px; font-weight: 400; font-size: 12px">
                          2. 导入过程中如发现相同手机号数据，则停止导入
                        </div>
                      </div>
                    </div>
                  </div>

                  <div class="step2" style="margin-bottom: 30px">
                    <div
                      v-if="active === 2"
                      style="
                        height: 680px;
                        overflow-x: auto;
                        overflow-y: auto;
                        display: flex;
                        flex-direction: column;
                        padding: 20px;
                        margin-left: 7%;
                        margin-top: 20px;
                        margin-right: 7%;
                      "
                    >
                      <div
                        v-if="errorLine.length > 0 || errorPhone.length > 0"
                        style="background: #ebebeb; padding: 10px"
                      >
                        <div style="font-size: 16px; font-weight: 600; margin-bottom: 10px; color: red">异常数据</div>
                        <div v-if="errorLine.length > 0" style="width: 100%">
                          行数：{{ errorLine.join(',') }}
                          有空数据或者错误数据
                        </div>
                        <div v-if="errorPhone.length > 0" style="width: 100%">
                          表格中手机号存在重复，请先删除重复的数据项！
                        </div>
                        <div
                          v-if="errorPhone.length > 0"
                          style="margin-top: 10px; font-weight: 400; font-size: 16px; width: 100%"
                        >
                          重复的手机号:{{ errorPhone }}
                        </div>
                      </div>
                      <!-- 这里展示excel数据的表格 -->
                      <el-table
                        :data="excelData"
                        style="width: 100%; height: 700px; overflow-x: auto; overflow-y: auto"
                      >
                        <!-- 表格列定义 -->
                        <el-table-column prop="arg0" width="55" align="center" />
                        <el-table-column prop="arg1" width="120" align="center" />
                        <el-table-column prop="arg2" width="120" align="center" />
                        <el-table-column prop="arg3" width="120" align="center" />
                        <el-table-column prop="arg4" width="120" align="center" />
                        <el-table-column prop="arg5" width="120" align="center" />
                        <el-table-column prop="arg6" width="120" align="center" />
                        <el-table-column prop="arg7" width="120" align="center" />
                        <el-table-column prop="arg8" width="120" align="center" />
                        <el-table-column prop="arg9" width="120" align="center" />
                        <el-table-column prop="arg10" width="120" align="center" />
                        <el-table-column prop="arg11" width="120" align="center" />
                      </el-table>
                    </div>
                  </div>

                  <div class="step3" style="margin-bottom: 30px">
                    <div v-if="active === 3">
                      <div
                        style="
                          display: flex;
                          flex-direction: column;
                          padding: 20px;
                          margin-left: 7%;
                          margin-top: 20px;
                          margin-right: 7%;
                          margin-bottom: 30px;
                        "
                      >
                        <span style="font-size: 16px; margin-top: 10px">
                          以下是已经在库的手机号（人员已经录入），请先根据手机号删除相应行内容，然后再进行导入
                        </span>
                        <span style="margin-top: 10px; width: 100%">
                          {{ errorCode.substring(1, errorCode.length - 1) }}
                        </span>
                      </div>
                    </div>
                  </div>

                  <div class="step4" style="margin-bottom: 30px">
                    <div v-if="active === 4">
                      <div
                        style="
                          display: flex;
                          flex-direction: column;
                          padding: 20px;
                          margin-left: 7%;
                          margin-top: 100px;
                          margin-right: 7%;
                          align-items: center;
                          justify-content: center;
                        "
                      >
                        <img src="@/assets/file/import_success_blue.png" alt="导入成功" />
                        <span style="margin-top: 20px; font-size: 18px">
                          数据导入成功，请在列表中查看，提交审核之前请先上传相关人员的文件！
                        </span>
                      </div>
                    </div>
                  </div>
                  <div v-if="type === '导入'">
                    已导入：{{ importedCount }} / 1000
                    <el-progress :percentage="importProgress"></el-progress>
                  </div>
                  <div class="el-footer" style="position: absolute; top: 90%; left: 76%; margin-top: 10px">
                    <el-button
                      type="primary"
                      style="margin-top: 12px"
                      @click="before"
                      v-if="active === 2 || active === 3"
                    >
                      上一步
                    </el-button>
                    <el-button
                      type="primary"
                      style="margin-top: 12px"
                      @click="next"
                      v-if="active === 0 || active === 1"
                    >
                      下一步
                    </el-button>
                    <el-button
                      type="primary"
                      style="margin-top: 12px"
                      @click="importExcel"
                      v-if="active === 2 && errorLine.length === 0 && errorPhone.length === 0"
                    >
                      导入
                    </el-button>
                    <el-button type="primary" plain style="margin-top: 12px; margin-bottom: 10px" @click="personClose">
                      关闭
                    </el-button>
                  </div>
                </div>
              </el-dialog>

              <!--生成工作证-->
              <el-dialog title="生成工作证" :visible.sync="workCardOpen" width="30%">
                <el-form ref="elForm" :model="formData" size="medium" label-width="100px">
                  <bns-generate-work-card-tabs :items="workCardItems"></bns-generate-work-card-tabs>
                </el-form>
              </el-dialog>
            </div>
          </el-tab-pane>
          <el-tab-pane label="工器具信息" name="six" v-if="this.$store.state.user.userType === '02'">
            <div class="app-container">
              <el-form :model="equipQueryParams" ref="equipQueryForm" size="small" :inline="true" label-width="68px">
                <el-form-item label="工器具名称" label-width="120px">
                  <el-input
                    v-model="equipQueryParams.equipName"
                    v-no-whitespace
                    placeholder="请输入工器具名称"
                    clearable
                    @keyup.enter.native="equipHandleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="mini" @click="equipHandleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="equipResetQuery">重置</el-button>
                  <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    v-if="this.paramsData.type !== 'view'"
                    @click="equipAddBtn"
                  >
                    新增
                  </el-button>
                  <el-button type="primary" plain icon="el-icon-download" size="mini" @click="equipHandleExport">
                    导出
                  </el-button>
                </el-form-item>
              </el-form>
              <el-table v-loading="loading" :data="equipList">
                <el-table-column
                  type="index"
                  width="55"
                  label="序号"
                  align="center"
                  :index="indexContinuous(equipQueryParams.pageNum, equipQueryParams.pageSize)"
                />
                <el-table-column label="工器具名称" align="center" prop="equipName" />
                <el-table-column label="型号" align="center" prop="model" />
                <el-table-column label="单位" align="center" prop="unit" />
                <el-table-column label="数量" align="center" prop="num" />
                <el-table-column label="设备类型" align="center" prop="equipType" />
                <el-table-column label="检测时间" align="center" prop="detectionTime" />
                <el-table-column label="进场日期" align="center" prop="admissionDate" />
                <el-table-column
                  label="操作"
                  align="center"
                  fixed="right"
                  class-name="small-padding fixed-width"
                  v-if="this.paramsData.type !== 'view'"
                >
                  <template slot-scope="scope">
                    <el-button size="mini" type="text" @click="equipHandleEdit(scope.row)">编辑</el-button>
                    <el-button size="mini" type="text" @click="equipHandleDel(scope.row)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <pagination
                v-show="equipTotal > 0"
                :total="equipTotal"
                :page.sync="equipQueryParams.pageNum"
                :limit.sync="equipQueryParams.pageSize"
                @pagination="getEquipList"
              />

              <el-dialog
                title="查看详情"
                :visible.sync="equipOpen"
                width="40%"
                v-if="equipOpen"
                :destroy-on-close="true"
                :close-on-click-modal="false"
                :before-close="handleClose"
              >
                <div>
                  <el-form ref="equipForm" size="medium" :model="equipItem" label-width="100px" :rules="rules">
                    <el-form-item label-width="140px" label="工器具名称" prop="equipName">
                      <el-input
                        v-model="equipItem.equipName"
                        clearable
                        v-no-whitespace
                        maxlength="100"
                        show-word-limit
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label-width="140px" label="型号" prop="model">
                      <el-input
                        v-model="equipItem.model"
                        clearable
                        maxlength="20"
                        v-no-whitespace
                        show-word-limit
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label-width="140px" label="单位" prop="unit">
                      <el-input
                        v-model="equipItem.unit"
                        clearable
                        maxlength="10"
                        v-no-whitespace
                        show-word-limit
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label-width="140px" label="数量" prop="num">
                      <el-input
                        v-model="equipItem.num"
                        clearable
                        maxlength="10"
                        v-no-whitespace
                        show-word-limit
                        :style="{ width: '100%' }"
                      ></el-input>
                    </el-form-item>
                    <el-form-item label-width="140px" label="设备类型" prop="equipType">
                      <el-select v-model="equipItem.equipType" :style="{ width: '100%' }">
                        <el-option
                          v-for="item in equipTypeOptions"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        />
                      </el-select>
                    </el-form-item>
                    <el-form-item label-width="140px" label="检测时间" prop="detectionTime">
                      <el-date-picker
                        v-model="equipItem.detectionTime"
                        type="date"
                        :editable="false"
                        style="width: 100%"
                        placeholder="选择检测时间"
                      ></el-date-picker>
                    </el-form-item>
                    <el-form-item label-width="140px" label="是否强制检测检验" prop="isForceDetection">
                      <el-select
                        v-model="equipItem.isForceDetection"
                        placeholder="请选择是否强制检测检验"
                        style="width: 100%"
                      >
                        <el-option label="是" value="1" />
                        <el-option label="否" value="0" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label-width="140px" label="下次检测时间" prop="nextDetectionTime">
                      <el-date-picker
                        v-model="equipItem.nextDetectionTime"
                        type="date"
                        :editable="false"
                        style="width: 100%"
                        placeholder="选择下次检测时间"
                      ></el-date-picker>
                    </el-form-item>
                    <el-form-item label-width="140px" label="工器具文件" prop="instrumentDocumentFiles">
                      <uploadFile
                        :limit="5"
                        :accept="accept"
                        :uploadList.sync="equipItem.instrumentDocumentFiles"
                        @picturePreview="picturePreview"
                        v-on:delFile="delFile"
                        v-on:up="handleFileChange('equipForm', 'instrumentDocumentFiles')"
                      ></uploadFile>
                    </el-form-item>
                  </el-form>
                </div>
                <div slot="footer" class="dialog-footer">
                  <el-button type="primary" @click="submitEquipForm" v-preventReClick="5000">提 交</el-button>
                  <el-button @click="equipCancel">取 消</el-button>
                </div>
              </el-dialog>
            </div>
          </el-tab-pane>
          <el-tab-pane label="其他材料" name="seven">
            <el-form-item label="" prop="">
              <uploadFile
                :limit="20"
                :multiple="true"
                :accept="accept"
                :uploadList.sync="form.otherFileItems"
                @picturePreview="picturePreview"
                v-on:delFile="delFile"
                :class="{ disabled: this.paramsData.type === 'view' }"
              ></uploadFile>
            </el-form-item>
          </el-tab-pane>
          <el-tab-pane label="审批信息" name="eight">
            <bns-timeline-tabs
              :is-examine="false"
              :btn-show="false"
              final-check="0"
              :show-type="1"
              :items="approvalItems"
            />
          </el-tab-pane>
        </el-tabs>
      </el-form>
    </el-main>
    <el-footer style="border-top: 1px solid gray; padding: 15px" v-if="this.paramsData.type !== 'view'">
      <el-button type="primary" plain style="float: right" @click="cancel">取消</el-button>
      <el-button
        type="primary"
        style="float: right; margin-right: 20px"
        @click="submit('提交')"
        v-preventReClick="5000"
      >
        提交审核
      </el-button>
      <el-button
        type="primary"
        style="float: right; margin-right: 10px"
        @click="submit('保存')"
        v-preventReClick="5000"
      >
        保存
      </el-button>
    </el-footer>

    <el-dialog title="文件预览" :visible.sync="fileOpen" width="80%" append-to-body>
      <div style="width: 100%; height: 720px">
        <bns-kkFile-preview :items="fileItems"></bns-kkFile-preview>
      </div>
    </el-dialog>
  </el-container>
</template>
<script>
import bnsSubInfoTabs from '@/components/pro-tabs/bns-sub-info-tabs.vue'
import bnsConsInfoTabs from '@/components/pro-tabs/bns-cons-info-tabs.vue'
import bnsFileListTabs from '@/components/pro-tabs/bns-file-list-tabs.vue'
import bnsGenerateWorkCardTabs from '@/components/pro-tabs/bns-generate-work-card-tabs.vue'
import bnsKkFilePreview from '@/components/pro-tabs/bns-kkFile-preview'
import uploadFile from '@/views/pro/admissionRequest/uploadFile.vue'
import XLSX from '@/utils/xlsx.full.min'
import { StrUtil } from '@/utils/StrUtil'
import { importPersonData } from '@/api/importData/importData'

import { getSubPersonList, getSubDetailsInfo, getConsDetailsInfo, getEquipDetails } from '@/api/pro/outsourcingPro'
import {
  selectFile,
  getUploadMaterialOptions,
  checkIsExistPerson,
  dictTableOption,
  getTemplateLink,
  downloadFile,
} from '@/api/tool/select'
import BnsConsPersonDetailsTabs from '@/components/pro-tabs/bns-cons-person-details-tabs.vue'
import {
  addAdmissionRequest,
  addEntranceRequest,
  getData,
  delPerson,
  delEquip,
  submitApproval,
  judgeIsFileComplete,
} from '@/api/pro/admissionRequest'
import { getFileData, getParams, hideSensitiveInfo, indexContinuous, lookFaceFile, parseTime } from '@/utils/bonus'
import { addEquip, getEquipList } from '@/api/pro/cons/equip'
import numberUtils from '@/utils/validate'
import { decryptCBC } from '@/utils/aescbc'
import { importPersonZip } from '@/api/importData/importData'
import BnsTimelineTabs from '@/components/pro-tabs/bns-timeline-tabs.vue'
import { approvalHistory } from '@/api/terminalEquipment/deviceInformation'
import debounce from 'lodash/debounce'

export default {
  components: {
    BnsTimelineTabs,
    BnsConsPersonDetailsTabs,
    bnsConsInfoTabs,
    bnsSubInfoTabs,
    bnsFileListTabs,
    bnsGenerateWorkCardTabs,
    uploadFile,
    bnsKkFilePreview,
  },
  computed: {
    labelText() {
      return this.$store.state.user.userType === '02' ? '承包商单位信息' : '分包商单位信息'
    },
  },
  data() {
    return {
      paramsData: {},
      delFileIds: [],
      disabled: false,
      id: undefined,
      uuid: '',
      equipUuid: '',
      proId: undefined,
      consId: undefined,
      qualificationStatus: false,
      securityAgreementStatus: false,
      fourMeasuresAndTwoMeasuresStatus: false,
      accept: '.pdf, .doc, .docx, .png, .jpg, .jpeg',
      timeRange: [],
      postOptions: [],
      equipTypeOptions: [],
      equipOpen: false,
      fileOpen: false,
      document: false,
      documentPreview: false,
      fileList: [],
      kkFilePreview: {
        filePreviewUrl: '',
        fileName: '',
        showDownloadButton: false,
      },
      fileItems: {},
      showSpecialWorkType: false,
      active: 1,
      importedCount: 0,
      importProgress: 0,
      status: 'success',
      excelData: [],
      errorLine: [],
      errorPhone: [],
      errorCode: '',
      type: '',
      formPerson: {
        fileList: [],
        proId: undefined,
        uploadType: undefined,
      },
      rulesPerson: {
        fileList: [{ required: true, message: '请先选择需要导入的excel文件', trigger: 'blur' }],
      },
      personBasicOpen: false,
      equipItem: {
        id: 0,
        equipName: '',
        equipType: '',
        model: '',
        num: '',
        unit: '',
        detectionTime: '',
        isForceDetection: 0,
        nextDetectionTime: '',
        instrumentDocumentFiles: [],
      },
      personItems: {
        id: undefined,
        consUserId: '',
        consName: undefined,
        sex: undefined,
        phone: undefined,
        idCard: undefined,
        native: undefined,
        homeAddress: undefined,
        currentAddress: undefined,
        post: undefined,
        workType: undefined,
        facePhotoList: [],
        medicalExaminationList: [],
        elseImgList: [],
        specialTypeOfWorkList: [],
        otherFilesList: [],
      },
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: '上传压缩文件',
      },
      formFile: {
        fileList: [],
      },
      ruleFile: {
        fileList: [{ required: true, message: '请上传文件', trigger: 'blur' }],
      },
      //当前激活的标签页
      activeName: 'first',
      //监理信息单位弹出层
      constructionPersonnelOpen: false,
      //生成工作证弹出层
      workCardOpen: false,
      //时间范围选择器
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            },
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            },
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            },
          },
        ],
      },
      gutterValue: parseInt('21', 10),
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      equipTotal: 0,
      //分包商单位信息
      basicInformationItems: {},
      // 施工人员基本信息查询参数
      personQueryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        status: undefined,
        startDate: undefined,
        endDate: undefined,
      },
      equipQueryParams: {
        pageNum: 1,
        pageSize: 10,
        equipName: undefined,
      },
      // 施工人员基本信息表格数据
      personList: [],
      equipList: [],
      //工作证信息
      workCardItems: {},
      // 人员详情  表单参数
      formData: {},
      form: {
        //企业资质
        enterpriseQualificationItems: [],
        //安全协议书
        securityAgreementFileItems: [],
        //四措两案
        fourMeasuresAndTwoMeasuresFileItems: [],
        otherFileItems: [],
      },
      // 表单校验
      formRules: {
        enterpriseQualificationItems: [{ required: true, message: '请上传企业资质文件', trigger: 'change' }],
        securityAgreementFileItems: [{ required: true, message: '请上传安全协议书文件', trigger: 'change' }],
        fourMeasuresAndTwoMeasuresFileItems: [{ required: true, message: '请上传四措两案文件', trigger: 'change' }],
      },
      personRules: {
        consName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        sex: [{ required: true, message: '请选择性别', trigger: 'change' }],
        age: [
          { required: true, message: '请输入年龄', trigger: 'blur' },
          {
            pattern: /^[0-9]+$/,
            message: '请输入数字',
            trigger: 'blur',
          },
        ],
        phone: [{ required: true, validator: numberUtils.checkPhone, trigger: 'blur' }],
        natives: [{ required: true, message: '请输入籍贯', trigger: 'blur' }],
        nation: [{ required: true, message: '请输入民族', trigger: 'blur' }],
        idCard: [{ required: true, validator: numberUtils.checkIdCardNumber, trigger: 'blur' }],
        homeAddress: [{ required: true, message: '请输入家庭住址', trigger: 'blur' }],
        address: [{ required: true, message: '请输入现地址', trigger: 'blur' }],
        post: [{ required: true, message: '请选择岗位', trigger: 'change' }],
        workType: [{ required: true, message: '请输入特殊工种种类', trigger: 'blur' }],
        // facePhotoList: [
        //   { required: true, message: '请上传人脸照片', trigger: 'change' }
        // ],
        medicalExaminationList: [{ required: true, message: '请上传体检文件', trigger: 'change' }],
        elseImgList: [{ required: true, message: '请上传保险文件', trigger: 'change' }],
        specialTypeOfWorkList: [{ required: true, message: '请上传特殊工种文件', trigger: 'change' }],
      },
      rules: {
        equipName: [{ required: true, message: '请输入工器具名称', trigger: 'blur' }],
        model: [{ required: true, message: '请输入工器具型号', trigger: 'blur' }],
        unit: [{ required: true, message: '请输入工器具单位', trigger: 'blur' }],
        num: [
          { required: true, message: '请输入工器具数量', trigger: 'blur' },
          {
            pattern: /^[0-9]+$/,
            message: '请输入数字',
            trigger: 'blur',
          },
        ],
        equipType: [{ required: true, message: '请输入工器具类型', trigger: 'blur' }],
        detectionTime: [{ required: true, message: '请选择检测时间', trigger: 'blur' }],
        nextDetectionTime: [{ required: true, message: '请选择下次检测时间', trigger: 'blur' }],
        instrumentDocumentFiles: [{ required: true, message: '请选择工器具文件', trigger: 'change' }],
        isForceDetection: [{ required: true, message: '请选择是否强制检测检验', trigger: 'change' }],
      },
      lookFaceFile: '',
      templateLink: '',
      approvalItems: [],
    }
  },
  created() {
    this.lookFaceFile = lookFaceFile()
    if (this.$store.state.user.userType === '02') {
      //如果是承包商账号，加载校验项
      this.getUploadMaterialOptions()
    } else {
      this.qualificationStatus = true
      this.securityAgreementStatus = true
      this.fourMeasuresAndTwoMeasuresStatus = true
    }
    const params = this.$route.params && this.$route.params.data
    this.paramsData = JSON.parse(decryptCBC(params))
    const type = this.paramsData.type
    //获取基础信息
    this.getDetailsInfo()
    // if (type !== 'add') {
    //如果是编辑页面，加载企业资质、安全协议书、四措两案、其他材料文件
    this.getEnterpriseQualificationFile()
    this.getSecurityAgreementFile()
    this.getFourMeasuresAndTwoMeasuresFile()
    this.getOtherFile()
    // }
    // 获取施工人员列表信息
    this.getSubPersonList()
    // 获取工器具列表信息
    this.getEquipList()
    this.approvalHistory()
  },
  watch: {
    'equipItem.equipType': function (newVal) {
      this.updateRules(newVal)
    },
  },
  mounted() {
    this.updateRules(this.equipItem.equipType)
  },
  methods: {
    lookFaceFile,
    approvalHistory() {
      console.log('this.paramsData.taskId:' + this.paramsData.taskId)
      approvalHistory({ taskId: this.paramsData.taskId }).then(res => {
        this.approvalItems = res.data
      })
    },
    getTemplateLink() {
      const params = {
        dictType: 'sys_template_link',
        dictValue: '2',
      }
      getTemplateLink(params).then(response => {
        this.templateLink = response.msg
      })
    },
    /** 文件查看按钮操作 */
    handleShow(row, informationType) {
      this.loading = true
      const arr = {
        1: '体检文件',
        2: '保险文件',
        3: '特殊工种文件',
        4: '其他文件',
      }
      selectFile({
        classification: 9,
        uuid: row.uuid,
        informationType: informationType,
        fromType: 2,
      }).then(response => {
        console.log(response)
        if (response.data.length === 0) {
          this.fileList = []
          this.$message.warning(arr[informationType] + '暂无')
        } else if (response.data.length === 1) {
          this.kkFilePreview = {
            filePreviewUrl: response.data[0].filePath,
            fileName: response.data[0].fileName,
            showDownloadButton: false,
          }
          this.documentPreview = true
        } else {
          this.fileList = response.data
          this.document = true
        }
        this.loading = false
      })
    },
    updateRules(equipType) {
      if (equipType == 2) {
        this.$set(this.rules, 'instrumentDocumentFiles', [
          { required: true, message: '请上传工器具文件', trigger: 'change' },
        ])
      } else {
        this.$set(this.rules, 'instrumentDocumentFiles', [])
      }
    },
    indexContinuous,
    hideSensitiveInfo,
    getParams,
    //处理上传文件
    getFileData,
    handleFileChange(form, name) {
      // 手动校验
      this.$refs[form].validateField(name)
    },
    //上传组件-图片查看
    picturePreview(file) {
      console.log(file)
      this.fileItems = {
        filePreviewUrl: file.filePreviewUrl,
        fileName: file.name,
      }
      this.fileOpen = true
    },
    delFile(e) {
      console.log(e)
      if (!this.delFileIds.includes(e)) {
        this.delFileIds.push(e)
      }
      console.log(this.delFileIds)
    },
    // 岗位选择改变事件
    handlePostChange(label) {
      // 当岗位选择为特殊工种时，显示特殊工种种类输入框
      if (label === '1') {
        this.showSpecialWorkType = true
      } else {
        this.showSpecialWorkType = false
        // 清空特殊工种种类输入框的值
        this.form.workType = ''
      }
    },
    //获取岗位选项
    getPostType() {
      const params = {
        dictType: 'sys_cons_post',
        dictValue: '',
      }
      dictTableOption(params).then(response => {
        this.postOptions = response.data
      })
    },
    // 获取设备类型
    getEquipType() {
      const params = {
        dictType: 'sys_tools_type',
        dictValue: '',
      }
      dictTableOption(params).then(response => {
        this.equipTypeOptions = response.data
      })
    },
    //获取承包商上传材料选项以及必填项加载
    getUploadMaterialOptions() {
      const params = {
        proId: this.$store.state.user.thisIds.proId,
        consUuid: this.$store.state.user.thisIds.consUuid,
        consId: this.$store.state.user.thisIds.consId,
      }
      getUploadMaterialOptions(params).then(response => {
        console.log(response)
        const options = response.data
        this.formRules = {}
        for (let i = 0; i < options.length; i++) {
          switch (options[i].value) {
            case '1':
              this.qualificationStatus = true
              this.formRules.enterpriseQualificationItems = [
                { required: true, message: '请上传企业资质文件', trigger: 'change' },
              ]
              break
            case '2':
              this.securityAgreementStatus = true
              this.formRules.securityAgreementFileItems = [
                { required: true, message: '请上传安全协议书文件', trigger: 'change' },
              ]
              break
            case '3':
              this.fourMeasuresAndTwoMeasuresStatus = true
              this.formRules.fourMeasuresAndTwoMeasuresFileItems = [
                { required: true, message: '请上传四措两案文件', trigger: 'change' },
              ]
              break
          }
        }
        this.loading = false
      })
    },
    //施工人员进出场日期转换
    changTime() {
      this.personQueryParams.admissionDate = this.timeRange[0]
      this.personQueryParams.departureDate = this.timeRange[1]
    },
    /** 基础信息查询 */
    getDetailsInfo() {
      this.loading = true
      const params = {
        proId: this.$store.state.user.thisIds.proId,
        consUuid: this.$store.state.user.thisIds.consUuid,
        subUuid: '',
      }
      if (this.$store.state.user.userType === '02') {
        getConsDetailsInfo(params).then(response => {
          this.basicInformationItems = response
          this.basicInformationItems.corporatePhone = hideSensitiveInfo(response.corporatePhone)
          this.loading = false
        })
      } else {
        params.subUuid = this.$store.state.user.thisIds.subUuid
        params.uuid = this.$store.state.user.thisIds.uuid
        getSubDetailsInfo(params).then(response => {
          console.log(response)
          this.basicInformationItems = response
          this.basicInformationItems.corporatePhone = hideSensitiveInfo(response.corporatePhone)
          this.loading = false
        })
      }
    },
    /** 获取企业资质文件 */
    getEnterpriseQualificationFile() {
      const params = {
        uuid: this.$store.state.user.thisIds.uuid,
        classification: '3',
        fromType: '1',
        informationType: '1',
      }
      selectFile(params).then(response => {
        this.form.enterpriseQualificationItems = response.data
        this.handleFileChange('form', 'enterpriseQualificationItems')
      })
    },
    /** 获取安全协议书文件 */
    getSecurityAgreementFile() {
      const params = {
        uuid: this.$store.state.user.thisIds.uuid,
        classification: '3',
        fromType: '1',
        informationType: '2',
      }
      selectFile(params).then(response => {
        console.log('--------------' + JSON.stringify(response.data))
        this.form.securityAgreementFileItems = response.data
        this.handleFileChange('form', 'securityAgreementFileItems')
      })
    },
    /** 获取四措两案文件 */
    getFourMeasuresAndTwoMeasuresFile() {
      const params = {
        uuid: this.$store.state.user.thisIds.uuid,
        classification: '3',
        fromType: '1',
        informationType: '3',
      }
      selectFile(params).then(response => {
        console.log('========' + JSON.stringify(response.data))
        this.form.fourMeasuresAndTwoMeasuresFileItems = response.data
        this.handleFileChange('form', 'fourMeasuresAndTwoMeasuresFileItems')
      })
    },
    /**获取其他材料文件*/
    getOtherFile() {
      const params = {
        uuid: this.$store.state.user.thisIds.uuid,
        classification: '3',
        fromType: '1',
        informationType: '5',
      }
      selectFile(params).then(response => {
        this.form.otherFileItems = response.data
      })
    },
    /**施工人员信息查询*/
    getSubPersonList() {
      this.loading = true
      this.personQueryParams.consUuid = this.$store.state.user.thisIds.consUuid
      this.personQueryParams.proId = this.$store.state.user.thisIds.proId
      this.personQueryParams.userType = this.$store.state.user.userType
      if (this.$store.state.user.userType === '03') {
        this.personQueryParams.subUuid = this.$store.state.user.thisIds.subUuid
      }
      this.changTime()
      console.log(this.personQueryParams)
      getSubPersonList(this.personQueryParams).then(response => {
        this.personList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    //获取工器具列表信息
    getEquipList() {
      this.loading = true
      this.equipQueryParams.consUuid = this.$store.state.user.thisIds.consUuid
      this.equipQueryParams.proId = this.$store.state.user.thisIds.proId
      getEquipList(this.equipQueryParams).then(response => {
        this.equipList = response.rows
        this.equipTotal = response.total
        this.loading = false
      })
    },
    handleQueryPerson() {
      this.personQueryParams.pageNum = 1
      this.getSubPersonList()
    },
    /** 重置按钮操作 */
    resetQueryPerson() {
      this.personQueryParams.name = undefined
      this.personQueryParams.status = undefined
      this.timeRange = []
      this.personQueryParams.startDate = undefined
      this.personQueryParams.endDate = undefined
      this.handleQueryPerson()
    },
    /** 人员新增 */
    handleAddPerson() {
      this.resetPersonForm()
      this.getPostType()
      this.personItems.consUserId = ''
      this.disabled = false
      this.constructionPersonnelOpen = true
    },
    // 重置人员表单
    resetPersonForm() {
      this.personItems = {
        id: undefined,
        name: undefined,
        sex: undefined,
        phone: undefined,
        idCard: undefined,
        native: undefined,
        homeAddress: undefined,
        currentAddress: undefined,
        postName: undefined,
        specialJob: undefined,
        facePhotoList: [],
        medicalExaminationList: [],
        elseImgList: [],
        specialTypeOfWorkList: [],
        otherFilesList: [],
      }
    },
    /** 导出按钮操作 */
    handleExportPerosn() {
      this.derive(
        'system/post/export',
        {
          ...this.queryParams,
        },
        `post_${new Date().getTime()}.xlsx`
      )
    },
    // 点击tab事件  切换tab
    handleClick(tab, event) {
      console.log(tab, event)
    },
    /**人员编辑*/
    handleEdit(row) {
      this.uuid = row.uuid
      this.constructionPersonnelOpen = true
      this.workCardOpen = false
      this.disabled = true
      const params = {
        uuid: row.uuid,
        consUserId: row.id,
      }
      this.getPostType()
      getData(params).then(response => {
        console.log(response)
        this.personItems = response.data
        this.handlePostChange(this.personItems.post)
        this.loading = false
      })
    },
    close() {
      this.constructionPersonnelOpen = false
      this.workCardOpen = false
    },
    /**检查是否当前工程下是否存在该人员*/
    async checkIsExistPerson() {
      const params = {
        phone: this.personItems.phone,
        proId: this.$store.state.user.thisIds.proId,
        type: this.paramsData.type,
        userId: this.personItems.id,
      }
      try {
        const response = await checkIsExistPerson(params)
        if (response.code === 500) {
          this.$message({
            message: response.msg,
            type: 'error',
          })
          // 返回 false 或者其他值，表示单位名称已存在
          return false
        } else {
          // 返回 true 或者其他值，表示单位名称不存在重复
          return true
        }
      } catch (error) {
        return false
      }
    },
    /**提交人员表单*/
    async submitPersonForm() {
      this.$refs['personForm'].validate(async valid => {
        if (!valid) {
          return false
        } else {
          this.personItems.proId = this.$store.state.user.thisIds.proId
          this.personItems.subUuid = this.$store.state.user.thisIds.subUuid
          this.personItems.contUuid = this.$store.state.user.thisIds.consUuid
          this.personItems.supUuid = this.$store.state.user.thisIds.supUuid
          this.personItems.userType = this.$store.state.user.userType
          this.personItems.uuid = this.uuid
          this.personItems.delFileIds = this.delFileIds.join(',')
          console.log(this.personItems)
          const reqData = new FormData()
          reqData.append('params', JSON.stringify(this.personItems))
          // 使用 Promise.all 并行处理文件数据获取，提高效率
          Promise.all([
            this.getFileData(this.personItems.facePhotoList),
            this.getFileData(this.personItems.medicalExaminationList),
            this.getFileData(this.personItems.elseImgList),
            this.getFileData(this.personItems.specialTypeOfWorkList),
            this.getFileData(this.personItems.otherFilesList),
          ]).then(([facePhotoList, medicalExaminationList, elseImgList, specialTypeOfWorkList, otherFilesList]) => {
            if (!facePhotoList || facePhotoList.length === 0) {
              reqData.append('facePhotoList', new Blob())
            } else {
              facePhotoList.forEach(item => reqData.append('facePhotoList', item))
            }
            if (!medicalExaminationList || medicalExaminationList.length === 0) {
              reqData.append('medicalExaminationList', new Blob())
            } else {
              medicalExaminationList.forEach(item => reqData.append('medicalExaminationList', item))
            }
            if (!elseImgList || elseImgList.length === 0) {
              reqData.append('elseImgList', new Blob())
            } else {
              elseImgList.forEach(item => reqData.append('elseImgList', item))
            }
            if (!specialTypeOfWorkList || specialTypeOfWorkList.length === 0) {
              reqData.append('specialTypeOfWorkList', new Blob())
            } else {
              specialTypeOfWorkList.forEach(item => reqData.append('specialTypeOfWorkList', item))
            }
            if (!otherFilesList || otherFilesList.length === 0) {
              reqData.append('otherFilesList', new Blob())
            } else {
              otherFilesList.forEach(item => reqData.append('otherFilesList', item))
            }
            addAdmissionRequest(reqData).then(response => {
              if (this.personItems.consUserId !== '') {
                this.$modal.msgSuccess('修改成功')
              } else {
                this.$modal.msgSuccess('新增成功')
              }
              this.resetPersonForm()
              this.$refs.personForm.resetFields()
              this.delFileIds = []
              this.getSubPersonList()
              this.constructionPersonnelOpen = false
              this.fileList = []
            })
          })
        }
      })
    },
    /**人员删除*/
    handleDel(row) {
      this.$modal
        .confirm('是否确认删除姓名为<span style="color: red">' + row.name + '</span>的数据项？')
        .then(function () {
          return delPerson(row.id)
        })
        .then(() => {
          this.getSubPersonList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {})
    },

    equipHandleQuery() {
      this.equipQueryParams.pageNum = 1
      this.getEquipList()
    },
    equipResetQuery() {
      this.equipQueryParams.equipName = undefined
      this.equipHandleQuery()
    },
    equipHandleExport() {
      // this.download('system/post/export', {
      //   ...this.queryParams
      // }, `post_${new Date().getTime()}.xlsx`)
    },
    //工器具编辑功能
    equipHandleEdit(row) {
      this.equipOpen = true
      const params = {
        id: row.id,
        uuid: row.uuid,
      }
      console.log(params)
      this.equipUuid = row.uuid
      this.getEquipType()
      getEquipDetails(params).then(response => {
        console.log(response.data)
        this.equipItem = response.data
        console.log(this.equipItem)
        this.loading = false
      })
    },
    equipHandleDel(row) {
      this.$modal
        .confirm('是否确认删除工器具名称为<span style="color: red">' + row.equipName + '</span>的数据项？')
        .then(function () {
          return delEquip(row.id)
        })
        .then(() => {
          this.getEquipList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {})
    },
    equipAddBtn() {
      this.equipItem = {
        id: 0,
        equipName: '',
        equipType: '',
        model: '',
        num: '',
        unit: '',
        detectionTime: '',
        isForceDetection: '0',
        nextDetectionTime: '',
        instrumentDocumentFiles: [],
      }
      this.getEquipType()
      this.equipOpen = true
    },
    async submitEquipForm() {
      this.$refs['equipForm'].validate(async valid => {
        if (!valid) {
          return false
        } else {
          if (this.equipItem.detectionTime >= this.equipItem.nextDetectionTime) {
            this.$message({
              message: '检测不能早于或等于下次检测时间',
              type: 'error',
            })
            return false
          }

          this.equipItem.proId = this.$store.state.user.thisIds.proId
          this.equipItem.consId = this.$store.state.user.thisIds.consId
          this.equipItem.consUuid = this.$store.state.user.thisIds.consUuid
          this.equipItem.detectionTime = parseTime(this.equipItem.detectionTime, '{y}-{m}-{d}')
          this.equipItem.nextDetectionTime = parseTime(this.equipItem.nextDetectionTime, '{y}-{m}-{d}')
          if (this.equipItem.id !== 0) {
            this.equipItem.uuid = this.equipUuid
          }
          this.equipItem.delFileIds = this.delFileIds.join(',')
          const reqData = new FormData()
          reqData.append('params', JSON.stringify(this.equipItem))
          Promise.all([this.getFileData(this.equipItem.instrumentDocumentFiles)]).then(([instrumentDocumentFiles]) => {
            if (!instrumentDocumentFiles || instrumentDocumentFiles.length === 0) {
              reqData.append('instrumentDocumentFiles', new Blob())
            } else {
              instrumentDocumentFiles.forEach(item => reqData.append('instrumentDocumentFiles', item))
            }
            addEquip(reqData)
              .then(response => {
                if (this.equipItem.id !== 0) {
                  this.$modal.msgSuccess('修改成功')
                } else {
                  this.$modal.msgSuccess('新增成功')
                }
                this.equipUuid = ''
                this.equipOpen = false
                this.delFileIds = []
                this.getEquipList()
              })
              .catch(error => {
                // 增加错误处理
                this.$modal.msgError('新增失败：' + error.message)
              })
          })
        }
      })
    },
    equipCancel() {
      this.equipItem = {}
      this.equipItem.fileList = []
      this.equipItem.specialTypeOfWorkList = []
      this.equipOpen = false
    },
    personCancel() {
      this.resetPersonForm()
      this.constructionPersonnelOpen = false
    },
    async submit(submitType) {
      let flag = true

      if (submitType === '提交') {
        const param = {
          ...this.getParams(),
          taskType: this.$store.state.user.userType === '02' ? '2' : '3',
          taskId: this.paramsData.type === 'edit' ? this.paramsData.taskId : '',
          uuid: this.$store.state.user.thisIds.uuid,
          parentUuid: this.$store.state.user.thisIds.parentUuid,
        }

        if (this.qualificationStatus && this.form.enterpriseQualificationItems.length === 0) {
          this.$message({
            message: '请先上传企业资质文件！！',
            type: 'error',
          })
          return false
        }

        if (this.securityAgreementStatus && this.form.securityAgreementFileItems.length === 0) {
          this.$message({
            message: '请先上传安全协议书文件！！',
            type: 'error',
          })
          return false
        }

        if (this.fourMeasuresAndTwoMeasuresStatus && this.form.fourMeasuresAndTwoMeasuresFileItems.length === 0) {
          this.$message({
            message: '请先上传四措两案文件！！',
            type: 'error',
          })
          return false
        }

        try {
          const response = await judgeIsFileComplete(param)
          console.log('response=====', response)
          if (response.msg === '部分人员文件不存在，请先仔细核对，上传相关文件！') {
            this.$message({
              message: '部分人员文件不存在，请先仔细核对，上传相关文件！',
              type: 'error',
            })
            return false
          }
        } catch (error) {
          this.$message({
            message: '文件检查失败，请稍后重试！',
            type: 'error',
          })
          return false
        }
      }

      if (!flag) {
        return false
      } else {
        this.$refs['form'].validate(async valid => {
          if (submitType === '提交' && !valid) {
            return this.$modal.msgError('请完善全部上传信息')
          } else {
          }
          this.form.proId = this.$store.state.user.thisIds.proId
          this.form.consUuid = this.$store.state.user.thisIds.consUuid
          this.form.userType = this.$store.state.user.userType
          this.form.uuid = this.$store.state.user.thisIds.uuid
          if (this.$store.state.user.userType === '03') {
            this.form.subUuid = this.$store.state.user.thisIds.subUuid
          }
          this.form.delFileIds = this.delFileIds.join(',')
          this.form.submitType = submitType
          console.log(this.form)

          const reqData = new FormData()
          reqData.append('params', JSON.stringify(this.form))

          try {
            const [
              enterpriseQualificationItems,
              securityAgreementFileItems,
              fourMeasuresAndTwoMeasuresFileItems,
              otherFileItems,
            ] = await Promise.all([
              this.getFileData(this.form.enterpriseQualificationItems),
              this.getFileData(this.form.securityAgreementFileItems),
              this.getFileData(this.form.fourMeasuresAndTwoMeasuresFileItems),
              this.getFileData(this.form.otherFileItems),
            ])

            if (!enterpriseQualificationItems || enterpriseQualificationItems.length === 0) {
              reqData.append('enterpriseQualificationItems', new Blob())
            } else {
              enterpriseQualificationItems.forEach(item => reqData.append('enterpriseQualificationItems', item))
            }

            if (!securityAgreementFileItems || securityAgreementFileItems.length === 0) {
              reqData.append('securityAgreementFileItems', new Blob())
            } else {
              securityAgreementFileItems.forEach(item => reqData.append('securityAgreementFileItems', item))
            }

            if (!fourMeasuresAndTwoMeasuresFileItems || fourMeasuresAndTwoMeasuresFileItems.length === 0) {
              reqData.append('fourMeasuresAndTwoMeasuresFileItems', new Blob())
            } else {
              fourMeasuresAndTwoMeasuresFileItems.forEach(item =>
                reqData.append('fourMeasuresAndTwoMeasuresFileItems', item)
              )
            }

            if (!otherFileItems || otherFileItems.length === 0) {
              reqData.append('otherFileItems', new Blob())
            } else {
              otherFileItems.forEach(item => reqData.append('otherFileItems', item))
            }

            await addEntranceRequest(reqData)
            if (submitType === '提交') {
              this.submitApply()
            } else {
              this.$modal.msgSuccess('保存成功')
              this.$tab.closePage()
            }
          } catch (error) {
            this.$modal.msgError('提交失败')
          }
        })
      }
    },
    /**
     * 提交审批
     */
    submitApply() {
      console.log(this.getParams())
      const param = {
        ...this.getParams(),
        taskType: this.$store.state.user.userType === '02' ? '2' : '3',
        taskId: this.paramsData.type === 'edit' ? this.paramsData.taskId : '',
        uuid: this.$store.state.user.thisIds.uuid,
        parentUuid: this.$store.state.user.thisIds.parentUuid,
      }
      console.log('param=' + JSON.stringify(param))
      submitApproval(param).then(response => {
        console.log('response=' + JSON.stringify(response))
        if (response.code === 200) {
          if (response.msg === '此审核类型未配置相对应的审核流，请联系管理员配置后再次提交') {
            this.$modal.msgError(response.msg)
          } else {
            this.$modal.msgSuccess('提交成功')
          }
          this.$tab.closePage()
          this.$router.push({ path: '/index', query: { result: 1 } })
        }
      })
    },
    cancel() {
      this.$tab.closePage()
    },
    save() {},
    handleClose() {
      this.$confirm('确认关闭？')
        .then(_ => {
          this.equipCancel()
          this.personCancel()
        })
        .catch(_ => {})
    },
    /**
     * 人员基础数据上传
     */
    handlePersonImport() {
      this.getTemplateLink()
      this.personBasicOpen = true
      this.formPerson.fileList = []
    },
    next() {
      if (this.formPerson.fileList.length === 0) {
        this.$message.warning('请先选择需要导入的excel文件')
        return
      }
      this.active++
      this.status = 'success'
    },
    personClose() {
      this.personBasicOpen = false
      this.formPerson.fileList = []
    },
    before() {
      this.active--
      this.status = 'success'
      if (this.active === 1) {
        this.excelData = []
        this.errorCode = ''
        this.errorPhone = []
        this.errorLine = []
        this.fileList = []
        this.formPerson.fileList = []
      }
    },
    downloadTemplate() {
      downloadFile(this.templateLink, '施工人员.zip')
    },
    importExcel: debounce(function () {
      this.loading = true
      let data = []
      for (let i = 1; i < this.excelData.length; i++) {
        data.push(this.excelData[i])
      }
      const param = {
        proId: this.$store.state.user.thisIds.proId,
        consUuid: this.$store.state.user.thisIds.consUuid,
        subUuid: this.$store.state.user.thisIds.subUuid,
        supUuid: this.$store.state.user.thisIds.supUuid,
        uuid: this.$store.state.user.thisIds.uuid,
        userType: this.$store.state.user.userType,
        importArgList: data,
      }
      importPersonData(param).then(response => {
        if (response.code === 200) {
          if (response.msg === '导入成功') {
            this.$modal.msgSuccess('导入成功')
            this.active = 4
            this.formPerson.fileList = []
            this.excelData = []
            this.getSubPersonList()
            this.loading = false
          } else {
            this.errorCode = response.msg
            this.active = 3
            this.status = 'error'
          }
        }
      })
    }, 500),
    beforePersonUpload(file) {
      const isExcel = /\.(xlsx|xls)$/.test(file.name)
      if (!isExcel) {
        this.$message.error('只能上传.xlsx、.xls 文件!')
        this.formPerson.fileList = []
        return false
      }
      return true
    },
    /** 获取文件数据 */
    filePersonChange(file, fileList) {
      console.log(fileList)
      const isExcel = /\.(xlsx|xls)$/.test(file.name)
      if (!isExcel) {
        this.$message.error('只能上传.xlsx、.xls 文件!')
        this.formPerson.fileList = []
        return false
      }
      // 检查文件大小
      if (file.size > 1024 * 1024 * 10) {
        // 10MB 限制
        this.$message.warning('文件大小不能超过10MB')
        fileList = fileList.filter(item => item.uid !== file.uid)
      } else {
        const reader = new FileReader()

        reader.onload = e => {
          if (e.target && e.target.result) {
            try {
              const data = new Uint8Array(e.target.result)
              console.log('读取成功:', data)
              const workbook = XLSX.read(data, { type: 'array' })
              const firstSheetName = workbook.SheetNames[0]
              const worksheet = workbook.Sheets[firstSheetName]
              let jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 })
              const maxColumns = jsonData.reduce((max, row) => Math.max(max, row.length), 0)
              if (maxColumns !== 12) {
                this.active = 1
                this.formPerson.fileList = []
                this.$message.warning('请选择正确的excel进行数据导入  ')
              }
              // 计算最大行数
              const maxRows = jsonData.length
              if (maxRows === 1) {
                this.active = 1
                this.formPerson.fileList = []
                this.$message.warning('表格数据为空，请先填写相关数据，再进行导入')
              }
              this.errorLine = []
              let uuid = StrUtil.generateSimpleUUID()
              for (let i = 0; i < jsonData.length; i++) {
                if (
                  StrUtil.isBlank(jsonData[i][1]) ||
                  StrUtil.isBlank(jsonData[i][2]) ||
                  StrUtil.isBlank(jsonData[i][3]) ||
                  StrUtil.isBlank(jsonData[i][4]) ||
                  StrUtil.isBlank(jsonData[i][5]) ||
                  StrUtil.isBlank(jsonData[i][6]) ||
                  StrUtil.isBlank(jsonData[i][7]) ||
                  StrUtil.isBlank(jsonData[i][8]) ||
                  StrUtil.isBlank(jsonData[i][9]) ||
                  StrUtil.isBlank(jsonData[i][10])
                ) {
                  this.errorLine.push(jsonData[i][0])
                } else {
                  if (jsonData[i][10] === '特殊工种' && StrUtil.isBlank(jsonData[i][11])) {
                    this.errorLine.push(jsonData[i][0])
                  }
                }
                const rowData = {
                  arg0: jsonData[i][0],
                  arg1: jsonData[i][1],
                  arg2: jsonData[i][2],
                  arg3: jsonData[i][3],
                  arg4: jsonData[i][4],
                  arg5: jsonData[i][5],
                  arg6: jsonData[i][6],
                  arg7: jsonData[i][7],
                  arg8: jsonData[i][8],
                  arg9: jsonData[i][9],
                  arg10: jsonData[i][10],
                  arg11: jsonData[i][11],
                  uuid: uuid,
                  personType: jsonData[i][10] === '特殊工种' ? '1' : jsonData[i][10] === '普通职工' ? '2' : '0',
                  sex: jsonData[i][2] === '男' ? '0' : '1',
                }
                const isDuplicate = this.excelData.some(item => item.arg4 === rowData.arg4)
                if (isDuplicate) {
                  this.errorPhone.push(rowData.arg4)
                }
                this.excelData.push(rowData)
              }
              if (this.excelData.length > 999) {
                this.$message.warning('数据量大于1000行')
              }
            } catch (error) {
              console.error('处理 Excel 文件时出错:', error)
            }
          } else {
            console.error('文件读取结果无效:', e.target)
          }
        }
        reader.onerror = error => {
          console.error('文件读取错误:', error)
        }

        // 确保 file.raw 存在并有效
        if (file.raw) {
          reader.readAsArrayBuffer(file.raw)
        } else {
          console.error('文件对象无效')
        }
      }

      // 更新 fileList 状态
      this.formPerson.fileList = fileList
    },
    //移除文件
    handlePersonRemove(file) {
      this.formPerson.fileList.splice(this.formPerson.fileList.indexOf(file), 1)
      this.$emit('input', this.listToString(this.formPerson.fileList))
    },

    /**
     * 人员文件上传
     */
    handleFileImport() {
      this.upload.title = '上传压缩文件'
      this.upload.open = true
    },
    // 对象转成指定字符串分隔
    listToString(list, separator) {
      let strs = ''
      separator = separator || ','
      for (let i in list) {
        strs += list[i].url + separator
      }
      return strs !== '' ? strs.substr(0, strs.length - 1) : ''
    },
    beforeUpload(file) {
      console.log('beforeUpload')
      const isZip = /\.(zip|ZIP|Zip)$/.test(file.name)

      if (!isZip) {
        this.$message.error('只能上传.zip 文件!')
        return false
      }
      return true
    },
    /** 获取文件数据 */
    fileChange(file, fileList) {
      // 检查文件大小
      if (file.size > 1024 * 1024 * 600) {
        // 10MB 限制
        this.$message.warning('文件大小不能超过600MB')
        fileList = fileList.filter(item => item.uid !== file.uid)
      }
      // 更新 fileList 状态
      this.formFile.fileList = fileList
    },
    //移除文件
    handleRemove(file) {
      this.formFile.fileList.splice(this.formFile.fileList.indexOf(file), 1)
      this.$emit('input', this.listToString(this.formFile.fileList))
    },
    submitFileForm: debounce(function () {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (!this.formFile.fileList[0].name.toLowerCase().endsWith('.zip')) {
            this.$message.error('请上传zip文件')
            this.formFile.fileList = []
            return
          }
          const reqData = new FormData()
          reqData.append('proId', this.$store.state.user.thisIds.proId)
          reqData.append('consUuid', this.$store.state.user.thisIds.consUuid)
          reqData.append('subUuid', this.$store.state.user.thisIds.subUuid)
          reqData.append('uuid', this.$store.state.user.thisIds.uuid)
          reqData.append('userType', this.$store.state.user.userType)

          Promise.all([this.getFileData(this.formFile.fileList)]).then(([fileList]) => {
            fileList.forEach(item => reqData.append('fileList', item))
            importPersonZip(reqData).then(response => {
              if (response.code === 200) {
                console.log(response)
                if (response.result === '无数据问题') {
                  this.$modal.msgSuccess('导入成功')
                  this.upload.open = false
                  this.formFile.fileList = []
                } else {
                  let content
                  if (response.result.split('&&').length === 1) {
                    content = '<span>' + response.result.split('&&')[0] + '</span>'
                  } else {
                    content =
                      '<span>' + response.result.split('&&')[0] + '<br/>' + response.result.split('&&')[1] + '</span>'
                  }
                  this.$confirm(content, '文件导入提示', {
                    cancelButtonText: '关闭',
                    type: 'warning',
                    dangerouslyUseHTMLString: true,
                  }).catch(() => {
                    // 取消
                  })
                }
                this.upload.open = false
                this.getSubPersonList()
                this.formFile.fileList = []
              }
            })
          })
        } else {
          return false
        }
      })
    }, 500),
  },
}
</script>
<style scoped></style>
