<template>
  <div class="app-container">
    <el-form :model="personQueryParams" ref="personQueryForm" size="small" :inline="true" label-width="auto">
      <el-form-item label="施工人员姓名" label-width="120px" prop="supervisorName">
        <el-input
          v-model="personQueryParams.name"
          placeholder="请输入施工人员姓名"
          maxlength="20"
          show-word-limit
          v-no-whitespace
          clearable
          @keyup.enter.native="handleQueryPerson"
        />
      </el-form-item>
      <el-form-item label="工程：" prop="proName">
        <el-select v-model="personQueryParams.proName" placeholder="请选择工程名称" clearable>
          <el-option v-for="item in proOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="承包商：" prop="consName">
        <el-select v-model="personQueryParams.consName" placeholder="请选择承包商" clearable>
          <el-option v-for="item in consOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="分包商：" prop="subName">
        <el-select v-model="personQueryParams.subName" placeholder="请选择分包商" clearable>
          <el-option v-for="item in subOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="personQueryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in statusDict"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item style="display: flex; justify-content: flex-end;">
        <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-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="170" align="center" prop="proName" />
      <el-table-column label="所属承包商" width="170" align="center" prop="consName" />
      <el-table-column label="分包商名称" width="170" align="center" prop="subName" />
      <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="人脸照片" align="center" prop="faceUrl">
        <template slot-scope="scope">
          <el-popover placement="right" title="" trigger="hover">
            <img :src="`${scope.row.facePath ? lookFaceFile+scope.row.facePath : ''}`" :min-width="300" :height="300" alt="照片" />
            <img slot="reference" :src="`${scope.row.facePath ? lookFaceFile+scope.row.facePath : ''}`" style="max-height: 50px; max-width: 50px"
                 :alt="`${scope.row.facePath ? lookFaceFile+scope.row.facePath : ''}`"
            />
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="审批状态" align="center" prop="intoStatus" >
        <template slot-scope="scope">
          <!-- 检查是否存在身份证号 -->
          <span v-if="scope.row.intoStatus">{{ updateStatus(scope.row.intoStatus)
            }}</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"
            v-if="scope.row.status == '1'"
            @click="handleApprove(scope.row)"
          >审批
          </el-button>
          <el-button
            size="mini"
            type="text"
            v-else
            @click="handleView(scope.row)"
          >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['system:audit:query']"
            @click="handleAuditRecord(scope.row)"
          >审核记录
          </el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <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>
</template>
<script>
import { hideSensitiveInfo, indexContinuous, lookFaceFile } from '@/utils/bonus'
import bnsConsPersonDetailsTabs from '@/components/pro-tabs/bns-cons-person-details-tabs.vue'
import bnsGenerateWorkCardTabs from '@/components/pro-tabs/bns-generate-work-card-tabs.vue'
import { getProOptions, getConsOptions, getSubOptions, getList } from '@/api/pro/subManagement/approval/personApproval'
import BnsPersonApprovalTabs from '@/components/pro-tabs/bns-person-approval-tabs.vue'
import BnsPersonApprovalDetailsTabs from '@/components/pro-tabs/bns-person-approval-details-tabs.vue'

import { encryptCBC } from '@/utils/aescbc'
import { dictTableOption, selectFile } from '@/api/tool/select'
import bnsFileListTabs from '@/components/pro-tabs/bns-file-list-tabs.vue'
import bnsKkFilePreview from '@/components/pro-tabs/bns-kkFile-preview.vue'
export default {
  components: {
    bnsKkFilePreview, bnsFileListTabs,
    BnsPersonApprovalDetailsTabs,
    BnsPersonApprovalTabs,
    bnsConsPersonDetailsTabs,
    bnsGenerateWorkCardTabs
  },
  data() {
    return {
      personQueryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        status: '1',
        admissionDate: undefined,
        departureDate: undefined
      },
      statusDict: [],
      personList: [],
      proOptions: [],//工程下拉选项
      consOptions: [],//承包商下拉选项
      subOptions: [],//分包商拉选项
      personTotal: 0,
      loading: true,
      constructionPersonnelOpen: false,
      document: false,
      documentPreview: false,
      fileList: [],
      kkFilePreview: {
        filePreviewUrl: '',
        fileName: '',
        showDownloadButton: false
      },
      auditStatusDict:{
        "1" : "待审批",
        "2" : "审批中",
        "3" : "已通过",
        "4" : "已驳回",
        "5" : "已撤销"
      },
      lookFaceFile:''
    }
  },
  created() {
    this.lookFaceFile = lookFaceFile()
    this.getProOption()
    this.getConsOption()
    this.getSubOption()
    this.getList()
    this.getStatus()
  },
  methods: {
    indexContinuous,
    lookFaceFile,
    hideSensitiveInfo,
    updateStatus(status){
      return this.auditStatusDict[status]
    },
    /** 文件查看按钮操作 */
    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
      })
    },
    //获取工程下拉选项
    getProOption(){
      const params = {
        id: ''
      }
      getProOptions(params).then(res => {
        this.proOptions = res.data
      })
    },
    getStatus() {
      const params = {
        dictType: 'sys_approval_state',
        dictValue: ''
      }
      dictTableOption(params).then(response => {
        this.statusDict = response.data;
      });
    },
    //获取承包商下拉选项
    getConsOption(){
      const params = {
        id: ''
      }
      getConsOptions(params).then(res => {
        this.consOptions = res.data
      })
    },
    //获取分包商下拉选项
    getSubOption(){
      const params = {
        id: ''
      }
      getSubOptions(params).then(res => {
        this.subOptions = res.data
      })
    },
    getList(){
      const proId = this.$store.state.user.thisIds.proId,
        consUuid = this.$store.state.user.thisIds.consUuid,
        userType= this.$store.state.user.userType
      console.log(proId,consUuid)
      const params = {
        proId : proId,
        consUuid : consUuid,
        type: '出场',
        userType:userType,
        enterType: '业主-分包审核',
        ...this.personQueryParams
      }
      getList(params).then(res => {
        this.personList = res.rows
        this.total = res.total
        this.loading = false
      })
    },

    //查询按钮
    handleQueryPerson(){
      this.personQueryParams.pageNum = 1
      this.getList()
    },
    //重置按钮
    resetQueryPerson(){
      this.loading = true;
      this.resetForm("personQueryForm");
      this.handleQueryPerson();
    },
    //审核
    handleApprove(row){
      this.$router.push("/system/subManagement-personApproval-auth/personApproval/" + encryptCBC(JSON.stringify({
        uuid:row.uuid,
        taskId:row.taskId,
        procInstId:row.procInsId,
        contUuid:row.contUuid,
        consUuid:row.consUuid,
        subUuid:row.subUuid,
        showType:2,
        isExamine:true,
        btnShow:true,
        finalCheck: row.finalCheck,
        auditType:'出场'
      })));
    },
    //查看
    handleView(row){
      this.$router.push("/system/subManagement-personApproval-auth/personApproval/" + encryptCBC(JSON.stringify({
        uuid:row.uuid,
        taskId:row.taskId,
        procInstId:row.procInsId,
        contUuid:row.contUuid,
        consUuid:row.consUuid,
        subUuid:row.subUuid,
        showType:1,
        isExamine:false,
        btnShow:false,
        finalCheck: row.finalCheck,
        auditType:'出场'
      })));
    },
    //审核记录
    handleAuditRecord(row){
      this.$router.push("/flow/auditRecord/" + encryptCBC(JSON.stringify({
        taskId: row.taskId,
        checkType:'2'
      })));
    },
  }
}


</script>
<style scoped lang="scss">

</style>
