<template>
  <el-tabs v-model="activeName" @tab-click="handleClick" :style="{ padding: '20px' }">
    <!--    承包商item -->
    <el-tab-pane label="承包商单位信息" name="first">
      <bns-cons-info-tabs :items="consUnitInformationItems"></bns-cons-info-tabs>
    </el-tab-pane>
    <el-tab-pane label="" name="second">
      <span slot="label"><i  v-if="isRequest.includes(1)" style="color:red">*</i> 企业资质</span>
      <bns-file-list-tabs
        :items="enterpriseQualificationItems"
        :isShowOptions="paramsData.isExamine"
        :opinionValueOther="opinionValueOther"
        @onCloseFileDialog="onCloseFileDialog"
      ></bns-file-list-tabs>
      <bns-timeline-tabs
        :is-examine="false"
        :btn-show="false"
        :show-type="paramsData.showType"
        :items="approvalItems[0]"
        :audit-type="'企业资质'"
        v-on:reason="getReason"
      />
    </el-tab-pane>
    <el-tab-pane label="安全协议书" name="third">
      <span slot="label"><i  v-if="isRequest.includes(2)" style="color:red">*</i> 安全协议书</span>
      <bns-file-list-tabs
        :items="securityAgreementFileItems"
        :isShowOptions="paramsData.isExamine"
        :opinionValueOther="opinionValueOther"
        @onCloseFileDialog="onCloseFileDialog"
      ></bns-file-list-tabs>
      <bns-timeline-tabs
        :is-examine="false"
        :btn-show="false"
        :show-type="paramsData.showType"
        :items="approvalItems[1]"
        :audit-type="'安全协议书'"
        v-on:reason="getReason"
      />
    </el-tab-pane>
    <el-tab-pane label="四措两案" name="fourth">
       <span slot="label"><i  v-if="isRequest.includes(3)" style="color:red">*</i> 四措两案</span>
      <bns-file-list-tabs
        :items="fourMeasuresAndTwoMeasuresFileItems"
        :isShowOptions="paramsData.isExamine"
        :opinionValueOther="opinionValueOther"
        @onCloseFileDialog="onCloseFileDialog"
      ></bns-file-list-tabs>
      <bns-timeline-tabs
        :is-examine="false"
        :btn-show="false"
        :show-type="paramsData.showType"
        :items="approvalItems[2]"
        :audit-type="'四措两案'"
        v-on:reason="getReason"
      />
    </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" prop="supervisorName">
            <el-input
              v-model="personQueryParams.name"
              placeholder="请输入施工人员姓名"
              maxlength="20"
              show-word-limit
              clearable
              v-no-whitespace
              @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="2" />
            </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-download" size="mini" @click="handleExportPerosn">
              导出
            </el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="personList">
          <el-table-column
            type="index"
            width="55"
            label="序号"
            align="center"
            :index="indexContinuous(personQueryParams.pageNum, personQueryParams.pageSize)"
          />
          <el-table-column label="姓名" width="70" 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="70" 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" prop="homeAddress" />
          <el-table-column label="现地址" width="200" align="center" prop="currentAddress" />
          <el-table-column label="进场日期" width="100" align="center" prop="admissionDate" />
          <el-table-column label="离场日期" width="100" align="center" prop="departureDate" />
          <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="300"
                  :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="批阅状态" align="center" prop="annotation">
            <template slot-scope="scope">
              <!-- 检查是否存在身份证号 -->
              <span v-if="scope.row.annotation == '0'">未批阅</span>
              <span v-else>已批阅</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" width="150" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="handleView(scope.row)">查看</el-button>
              <el-button
                size="mini"
                type="text"
                v-if="scope.row.annotation == '0'"
                @click="addAnnotations(scope.row, '1')"
              >
                批阅
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="personTotal > 0"
          :total="personTotal"
          :page.sync="personQueryParams.pageNum"
          :limit.sync="personQueryParams.pageSize"
          @pagination="getConsPersonList"
        />
        <!--施工人员基本信息查看-->
        <el-dialog title="查看详情" :visible.sync="constructionPersonnelOpen" width="60%">
          <bns-cons-person-details-tabs :items="formData"></bns-cons-person-details-tabs>
          <div
            class="footer"
            v-if="paramsData.btnShow && formData.annotation == '0'"
            style="position: absolute; top: 95%; left: 90%"
          >
            <el-button type="danger" @click="addAnnotations(null, '1')">完成批阅</el-button>
          </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>
        <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>
      </div>
    </el-tab-pane>
    <el-tab-pane label="工器具信息" name="six">
      <div class="app-container">
        <el-form :model="equipQueryParams" ref="equipQueryForm" size="small" :inline="true" label-width="68px">
          <el-form-item label="工器具名称" label-width="140px">
            <el-input
              v-model="equipQueryParams.equipName"
              maxlength="20"
              show-word-limit
              placeholder="请输入工器具名称"
              clearable
              v-no-whitespace
              @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-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="approachDate" />
          <el-table-column label="批阅状态" align="center" prop="annotation">
            <template slot-scope="scope">
              <!-- 检查是否存在身份证号 -->
              <span v-if="scope.row.annotation == '0'">未批阅</span>
              <span v-else>已批阅</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="equipHandleView(scope.row)">查看</el-button>
              <el-button size="mini" type="text" @click="addAnnotations(scope.row, '2')">批阅</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="equipTotal > 0"
          :total="equipTotal"
          :page.sync="equipQueryParams.pageNum"
          :limit.sync="equipQueryParams.pageSize"
          @pagination="getConsEquipList"
        />

        <el-dialog title="查看详情" :visible.sync="equipOpen" width="40%">
          <div>
            <el-form ref="elForm" size="medium" label-width="100px">
              <el-form-item label-width="140px" label="工器具名称">
                <el-input
                  v-model="equipItem.equipName"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                  v-no-whitespace
                ></el-input>
              </el-form-item>
              <el-form-item label-width="140px" label="型号">
                <el-input
                  v-model="equipItem.model"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                  v-no-whitespace
                ></el-input>
              </el-form-item>
              <el-form-item label-width="140px" label="单位">
                <el-input
                  v-model="equipItem.unit"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                  v-no-whitespace
                ></el-input>
              </el-form-item>
              <el-form-item label-width="140px" label="数量">
                <el-input
                  v-model="equipItem.num"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                  v-no-whitespace
                ></el-input>
              </el-form-item>
              <el-form-item label-width="140px" label="设备类型">
                <el-select
                  v-model="equipItem.equipType"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                  v-no-whitespace
                >
                  <el-option
                    v-for="item in equipTypeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                    v-no-whitespace
                  />
                </el-select>
              </el-form-item>
              <el-form-item label-width="140px" label="检测时间">
                <el-input
                  v-model="equipItem.detectionTime"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                  v-no-whitespace
                ></el-input>
              </el-form-item>
              <el-form-item label-width="140px" label="是否强制检测检验">
                <el-select v-model="equipItem.isForceDetection" :disabled="true" clearable :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="下次检测时间">
                <el-input
                  v-model="equipItem.nextDetectionTime"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                  v-no-whitespace
                ></el-input>
              </el-form-item>
              <el-form-item label-width="140px" label="进场时间">
                <el-input
                  v-model="equipItem.approachDate"
                  :disabled="true"
                  clearable
                  :style="{ width: '100%' }"
                  v-no-whitespace
                ></el-input>
              </el-form-item>
              <el-form-item label-width="140px" label="工器具文件"></el-form-item>
              <img
                v-if="equipItem.fileList.length === 0"
                src="@/assets/file/no_file.png"
                alt="暂无数据"
                style="width: 100px; height: 100px; margin-left: 45px"
              />
              <bns-file-list-tabs
                v-else
                :items="equipItem.fileList"
                :style="{ marginLeft: '45px' }"
              ></bns-file-list-tabs>
            </el-form>
          </div>
          <div
            class="footer"
            v-if="paramsData.btnShow && equipItem.annotation == '0'"
            style="position: absolute; top: 95%; left: 85%"
          >
            <el-button type="danger" @click="addAnnotations(null, '2')">完成批阅</el-button>
          </div>
        </el-dialog>
      </div>
    </el-tab-pane>
    <el-tab-pane label="其他材料" name="seven">
      <bns-file-list-tabs
        :items="otherItems"
        :isShowOptions="paramsData.isExamine"
        :opinionValueOther="opinionValueOther"
        @onCloseFileDialog="onCloseFileDialog"
      ></bns-file-list-tabs>
      <bns-timeline-tabs
        :is-examine="false"
        :btn-show="false"
        :show-type="paramsData.showType"
        :items="approvalItems[3]"
        :audit-type="'其他材料'"
        v-on:reason="getReason"
      />
    </el-tab-pane>
    <el-tab-pane label="审批信息" name="eight">
      <div style="">
        <bns-timeline-tabs
          :is-examine="paramsData.isExamine"
          :btn-show="paramsData.btnShow"
          :show-type="paramsData.showType"
          :final-check="paramsData.finalCheck"
          :items="approvalItems[4]"
          :audit-type="'审批信息'"
          :audit-reason="reasonObj"
          v-on:reason="getReason"
          v-on:pass="approvalPass"
          v-on:turnDown="approvalTurnDown"
          v-on:finalInstance="approvalFinalInstance"
          :opinionValueOther="opinionValueOther"
        />
      </div>
    </el-tab-pane>
  </el-tabs>
</template>
<script>
import { getMyToDoNum, hideSensitiveInfo, indexContinuous, lookFaceFile, parseTime } from '@/utils/bonus'
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 bnsConsPersonDetailsTabs from '@/components/pro-tabs/bns-cons-person-details-tabs.vue'
import bnsKkFilePreview from '@/components/pro-tabs/bns-kkFile-preview.vue'
import {
  addAnnotations,
  getConsDetailsInfo,
  getSubList,
  getConsPersonList,
  getConsEquipList,
  getConsMaterialsList,
  getConstructionPersonnelDetails,
  getEquipDetails, getProRequest,
} from '@/api/pro/outsourcingPro'
import { selectFile, downloadFile, dictTableOption } from '@/api/tool/select'
import BnsTimelineTabs from '@/components/pro-tabs/bns-timeline-tabs.vue'

import { approvalHistory } from '@/api/terminalEquipment/deviceInformation'
import { submitPersonApproval } from '@/api/pro/subManagement/subList'
import { decryptCBC } from '@/utils/aescbc'
import { getProOptions } from '@/api/pro/subManagement/approval/personApproval'

export default {
  components: {
    BnsTimelineTabs,
    bnsConsInfoTabs,
    bnsSubInfoTabs,
    bnsFileListTabs,
    bnsGenerateWorkCardTabs,
    bnsConsPersonDetailsTabs,
    bnsKkFilePreview,
  },
  data() {
    return {
      paramsData: {},
      timeRange: [],
      materialsTimeRange: [],
      equipItem: {
        fileList: [],
      },
      filePreview: {},
      viewOpen: false,
      equipOpen: false,
      proId: undefined,
      consId: undefined,
      equipTypeOptions: [],
      //当前激活的标签页
      activeName: 'first',
      //施工人员详情弹出层
      constructionPersonnelOpen: false,
      //生成工作证弹出层
      workCardOpen: false,
      document: false,
      documentPreview: false,
      fileList: [],
      kkFilePreview: {
        filePreviewUrl: '',
        fileName: '',
        showDownloadButton: 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,
      personTotal: 0,
      isRequest:'1',
      equipTotal: 0,
      materialsTotal: 0,
      //承包商单位信息
      consUnitInformationItems: {},
      // 分包商信息查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        subName: undefined,
      },
      // 施工人员基本信息查询参数
      personQueryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        status: undefined,
        admissionDate: undefined,
        departureDate: undefined,
      },
      // 工器具信息查询参数
      equipQueryParams: {
        pageNum: 1,
        pageSize: 10,
        equipName: undefined,
      },
      // 施工材料文件信息查询参数
      materialsQueryParams: {
        pageNum: 1,
        pageSize: 10,
        fileName: undefined,
        name: undefined,
        startDate: undefined,
        endDate: undefined,
      },
      //企业资质
      enterpriseQualificationItems: [],
      //安全协议书
      securityAgreementFileItems: [],
      //四措两案
      fourMeasuresAndTwoMeasuresFileItems: [],
      //其他材料
      otherItems: [],
      // 分包商基本信息表格数据
      subList: [],
      // 施工人员基本信息表格数据
      personList: [],
      // 工器具信息表格数据
      equipList: [],
      // 施工材料文件表格数据
      materialsList: [],
      //工作证信息
      workCardItems: {},
      // 人员详情  表单参数
      formData: {
        facePhoto: [],
        physicalExaminationFile: [],
        insuranceFile: [],
        otherFile: [],
        annotation: '0',
      },
      //审批意见集合
      reasonObj: [
        {
          auditType: '企业资质',
          reason: '',
        },
        {
          auditType: '安全协议书',
          reason: '',
        },
        {
          auditType: '四措两案',
          reason: '',
        },
        {
          auditType: '其他材料',
          reason: '',
        },
        {
          auditType: '审批信息',
          reason: '',
        },
      ],
      reason: '',
      approvalItems: [],
      lookFaceFile: '',

      // 阅读文件时的意见
      opinionValueOther: '',
    }
  },
  created() {
    this.lookFaceFile = lookFaceFile()
    const params = this.$route.params && this.$route.params.data
    this.paramsData = JSON.parse(decryptCBC(params))
    this.proId = this.paramsData.proId
    this.consUuid = this.paramsData.consUuid
    this.init()
    console.log('this.paramsData:' + JSON.stringify(this.paramsData))
  },
  methods: {
    indexContinuous,
    lookFaceFile,
    hideSensitiveInfo,
    /** 文件查看按钮操作 */
    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
      })
    },

    getReason(e) {
      const index = this.reasonObj.findIndex(item => item.auditType === e.auditType)
      if (index !== -1) {
        this.reasonObj.splice(index, 1, e)
      } else {
        this.reasonObj.push(e)
      }
      let reason = ''
      for (let i = 0; i < this.reasonObj.length; i++) {
        reason += this.reasonObj[i].reason + '@@'
      }
      this.reason = reason.substring(0, reason.length - 2)
    },
    changTime() {
      this.personQueryParams.admissionDate = this.timeRange[0]
      this.personQueryParams.departureDate = this.timeRange[1]
    },
    changMaterialsTime() {
      this.materialsQueryParams.startDate = this.materialsTimeRange[0]
      this.materialsQueryParams.endDate = this.materialsTimeRange[1]
    },
    /**初始化数据*/
    init() {
      this.getProRequests();
      this.approvalHistory()
      this.getConsDetailsInfo()
      this.getEnterpriseQualification()
      this.getSecurityAgreement()
      this.getFourMeasuresAndTwoMeasures()
      this.getOtherFileList()
      this.getConsPersonList()
      this.getConsEquipList()
    },
    approvalHistory() {
      console.log('this.paramsData.taskId:' + this.paramsData.taskId)
      approvalHistory({ taskId: this.paramsData.taskId }).then(res => {
        console.log(res)
        for (let i = 0; i < 5; i++) {
          const arr = res.data.map(item => ({
            ...item,
            reason: item.reason && item.reason.length > 0 ? item.reason.split('@@')[i] : '',
          }))
          this.approvalItems.push(arr)
        }
        console.log(this.approvalItems)
      })
    },
    /**获取承包商基本信息*/
    getConsDetailsInfo() {
      const params = {
        consUuid: this.consUuid,
        proId: this.proId,
      }
      this.loading = true
      getConsDetailsInfo(params).then(response => {
        this.consUnitInformationItems = response
        this.consUnitInformationItems.corporatePhone = hideSensitiveInfo(response.corporatePhone)
        this.loading = false
      })
    },
    addAnnotations(row, type) {
      let params
      if (type === '1') {
        params = {
          uuid: row ? row.uuid : this.formData.uuid,
          taskId: this.paramsData.taskId,
          type: type,
        }
      } else {
        params = {
          uuid: this.equipItem.uuid || row.uuid,
          taskId: this.paramsData.taskId,
          type: type,
        }
      }
      addAnnotations(params).then(response => {
        this.$modal.msgSuccess('批阅成功')
        this.constructionPersonnelOpen = false
        this.equipOpen = false
        if (type === '1') {
          this.getConsPersonList()
        } else {
          this.getConsEquipList()
        }
      })
    },
    /**获取企业资质*/
    getEnterpriseQualification() {
      const params = {
        proId: this.proId,
        consUuid: this.consUuid,
        classification: '2',
        fromType: '1',
        informationType: '1',
      }
      selectFile(params).then(response => {
        this.enterpriseQualificationItems = []
        this.enterpriseQualificationItems = response.data
      })
    },
    /** 获取工程下拉选 */
    getProRequests() {
      console.log('this.paramsData.consUuid:' + this.paramsData.consUuid)
      console.log('this.paramsData.proId:' + this.paramsData.proId)
      let dataParam={
        supId:this.paramsData.consUuid,
        proId: this.paramsData.proId
      }
      getProRequest(dataParam).then(res => {
        this.isRequest=res.msg;

      })
    },
    /**获取安全协议书*/
    getSecurityAgreement() {
      const params = {
        proId: this.proId,
        consUuid: this.consUuid,
        classification: '2',
        fromType: '1',
        informationType: '2',
      }
      selectFile(params).then(response => {
        this.securityAgreementFileItems = []
        this.securityAgreementFileItems = response.data
      })
    },
    /**获取四措两案*/
    getFourMeasuresAndTwoMeasures() {
      const params = {
        proId: this.proId,
        consUuid: this.consUuid,
        classification: '2',
        fromType: '1',
        informationType: '3',
      }
      selectFile(params).then(response => {
        this.fourMeasuresAndTwoMeasuresFileItems = []
        this.fourMeasuresAndTwoMeasuresFileItems = response.data
      })
    },
    /**获取四措两案*/
    getOtherFileList() {
      const params = {
        proId: this.proId,
        consUuid: this.consUuid,
        classification: '2',
        fromType: '1',
        informationType: '5',
      }
      selectFile(params).then(response => {
        this.otherItems = []
        this.otherItems = response.data
      })
    },
    /**分包商信息查询*/
    getSubList() {
      this.loading = true
      this.queryParams.consId = this.consId
      this.queryParams.proId = this.proId
      this.queryParams.consUuid = this.$store.state.user.thisIds.consUuid
      getSubList(this.queryParams).then(response => {
        this.subList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /**分包商信息查询*/
    getConsPersonList() {
      this.loading = true
      this.personQueryParams.consUuid = this.paramsData.consUuid
      this.personQueryParams.proId = this.proId
      this.personQueryParams.taskId = this.paramsData.taskId
      this.changTime()
      getConsPersonList(this.personQueryParams).then(response => {
        this.personList = response.rows
        this.personTotal = response.total
        this.loading = false
      })
    },
    /**工器具信息查询*/
    getConsEquipList() {
      this.loading = true
      this.equipQueryParams.consUuid = this.paramsData.consUuid
      this.equipQueryParams.uuid = this.paramsData.consUuid
      this.equipQueryParams.taskId = this.paramsData.taskId
      this.equipQueryParams.proId = this.proId
      this.equipQueryParams.type = '2'
      getConsEquipList(this.equipQueryParams).then(response => {
        this.equipList = response.rows
        this.equipTotal = response.total
        this.loading = false
      })
    },
    /**施工材料信息查询*/
    getConsMaterialsList() {
      this.loading = true
      this.materialsQueryParams.consId = this.consId
      this.materialsQueryParams.proId = this.proId
      this.changMaterialsTime()
      getConsMaterialsList(this.materialsQueryParams).then(response => {
        this.materialsList = response.rows
        this.materialsTotal = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getSubList()
    },
    handleQueryPerson() {
      this.queryParams.pageNum = 1
      this.getConsPersonList()
    },
    equipHandleQuery() {
      this.queryParams.pageNum = 1
      this.getConsEquipList()
    },
    materialsHandleQuery() {
      this.queryParams.pageNum = 1
      this.getConsMaterialsList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.subName = undefined
      this.handleQuery()
    },
    /** 重置按钮操作 */
    resetQueryPerson() {
      this.personQueryParams.name = undefined
      this.personQueryParams.status = undefined
      this.personQueryParams.admissionDate = undefined
      this.personQueryParams.departureDate = undefined
      this.timeRange = []
      this.handleQueryPerson()
    },
    /** 重置按钮操作 */
    equipResetQuery() {
      this.equipQueryParams.equipName = undefined
      this.equipHandleQuery()
    },
    /** 重置按钮操作 */
    materialsResetQuery() {
      this.materialsQueryParams.startDate = undefined
      this.materialsQueryParams.endDate = undefined
      this.materialsTimeRange = []
      this.materialsQueryParams.fileName = undefined
      this.materialsQueryParams.name = undefined
      this.materialsHandleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      this.derive(
        'system/post/export',
        {
          ...this.queryParams,
        },
        `post_${new Date().getTime()}.xlsx`
      )
    },
    /** 导出按钮操作 */
    handleExportPerosn() {
      this.derive(
        'system/post/export',
        {
          ...this.queryParams,
        },
        `post_${new Date().getTime()}.xlsx`
      )
    },
    /** 导出按钮操作 */
    equipHandleExport() {
      this.derive(
        'system/post/export',
        {
          ...this.queryParams,
        },
        `post_${new Date().getTime()}.xlsx`
      )
    },
    /** 导出按钮操作 */
    materialsHandleExport() {
      this.derive(
        'system/post/export',
        {
          ...this.queryParams,
        },
        `post_${new Date().getTime()}.xlsx`
      )
    },
    // 点击tab事件  切换tab
    handleClick(tab, event) {
      //切换tab  重获加载数据
    },
    /**人员基本信息查看*/
    handleView(row) {
      this.supervisorOpen = false
      this.workCardOpen = false
      this.constructionPersonnelOpen = true
      const params = {
        id: row.id,
        uuid: row.uuid,
        consUuid: this.paramsData.consUuid,
        proId: this.paramsData.proId,
      }
      getConstructionPersonnelDetails(params).then(response => {
        console.log(response)
        this.formData = response.data
        this.formData.annotation = row.annotation
        this.loading = false
      })
    },
    close() {
      this.supervisorOpen = false
      this.workCardOpen = false
    },
    /**弹出工作证页面按钮*/
    handleGenerate(row) {
      this.workCardOpen = true
      this.workCardItems = {
        proName: row.proName,
        faceUrl: row.faceUrl,
        name: row.name,
        phone: row.phone,
        postName: row.postName,
      }
    },
    /**工器具详情*/
    equipHandleView(row) {
      this.equipOpen = true
      const params = {
        id: row.id,
        uuid: row.uuid,
        consUuid: this.paramsData.consUuid,
        proId: this.paramsData.proId,
      }
      this.getEquipType()
      getEquipDetails(params).then(response => {
        this.equipItem = response.data
        this.equipItem.annotation = row.annotation
        this.loading = false
      })
    },
    // 获取设备类型
    getEquipType() {
      const params = {
        dictType: 'sys_tools_type',
        dictValue: '',
      }
      dictTableOption(params).then(response => {
        this.equipTypeOptions = response.data
      })
    },
    /**预览文件*/
    materialsHandlePreview(row) {
      this.viewOpen = true
      this.filePreview = {
        filePreviewUrl: row.filePath,
        fileName: row.fileName,
      }
    },
    /**下载文件*/
    materialsHandleDownload(row) {
      downloadFile(row.filePath, row.fileName)
    },
    /** 审核通过*/
    approvalPass() {
      const param = {
        reason: this.reason === '' ? '@@@@@@@@' : this.reason,
        ...this.paramsData,
        agree: '1',
      }
      this.approval(param, '审批通过')
    },
    /**审核驳回*/
    approvalTurnDown(e) {
      const param = {
        reason: this.reason === '' ? '@@@@@@@@' : this.reason,
        rejectReason: e.rejectReason,
        ...this.paramsData,
        agree: '2',
      }
      this.approval(param, '退回成功')
    },
    /**终审*/
    approvalFinalInstance() {
      const param = {
        reason: this.reason === '' ? '@@@@@@@@' : this.reason,
        ...this.paramsData,
        agree: '3',
      }
      this.approval(param, '终审成功')
    },
    /**
     * 审批方法+
     * @param param
     * @param text
     */
    getMyToDoNum,
    approval(param, text) {
      submitPersonApproval(param).then(response => {
        this.getMyToDoNum()
        console.log('responseresponseresponse', JSON.stringify(response))
        if (response.code === 200) {
          this.$message({
            message: text,
            type: 'success',
          })
          this.$tab.closePage()
        } else {
          this.$message({
            message: response.msg,
            type: 'error',
          })
        }
      })
    },

    // 自定义事件接收意见
    onCloseFileDialog(val) {
      this.opinionValueOther = val
    },
  },
}
</script>
<style scoped></style>
