<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工号" prop="employeeid">
        <el-input
          v-model="queryParams.employeeid"
          placeholder="请输入员工号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="裂解" prop="cracking" label-width="50">
        <el-checkbox v-model="cracking" @change="handleQuery"></el-checkbox>
      </el-form-item>
      <el-form-item label="热区" prop="hotarea" label-width="50">
        <el-checkbox v-model="hotarea" @change="handleQuery"></el-checkbox>
      </el-form-item>
      <el-form-item label="冷区" prop="coldarea" label-width="50">
        <el-checkbox v-model="coldarea" @change="handleQuery"></el-checkbox>
      </el-form-item>
      <el-form-item label="芳烃" prop="aromatic" label-width="50">
        <el-checkbox v-model="aromatic" @change="handleQuery"></el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['training:worklicensecertificate:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['training:worklicensecertificate:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['training:worklicensecertificate:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['training:worklicensecertificate:add']"
          icon="el-icon-refresh"
          size="mini"
          @click="syncStaff"
        >同步人员数据</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :element-loading-text="loadingText" :data="worklicensecertificateList" @selection-change="handleSelectionChange" :height="clientHeight" border
              :cell-style="tableCellStyle"
              :header-cell-style="tableHeaderStyle">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="name" :show-overflow-tooltip="true"/>
      <el-table-column label="员工号" align="center" prop="employeeid" :show-overflow-tooltip="true"/>
      <el-table-column label="身份证件号" align="center" prop="idnum" :show-overflow-tooltip="true" width="150"/>
      <el-table-column label="班组" align="center" prop="classes" :show-overflow-tooltip="true"/>
      <el-table-column label="职务" align="center" prop="post" :show-overflow-tooltip="true"/>
      <el-table-column label="证件类型" align="center" prop="idtype" :show-overflow-tooltip="true"/>
      <el-table-column label="证件号" align="center" prop="worklicenseIdnum" :show-overflow-tooltip="true" width="120"/>
      <el-table-column label="岗位">
        <el-table-column label="裂解" align="center" prop="cracking" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.cracking == 1 ? "YES" : "NO" }}</span>
            <el-button v-if="scope.row.cracking == 1" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'license-cracking')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="热区" align="center" prop="hotarea" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.hotarea == 1 ? "YES" : "NO" }}</span>
            <el-button v-if="scope.row.hotarea == 1" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'license-hotarea')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="冷区" align="center" prop="coldarea" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.coldarea == 1 ? "YES" : "NO" }}</span>
            <el-button v-if="scope.row.coldarea == 1" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'license-coldarea')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="芳烃" align="center" prop="aromatic" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.aromatic == 1 ? "YES" : "NO" }}</span>
            <el-button v-if="scope.row.aromatic == 1" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'license-aromatic')"  circle></el-button>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="取复证日期" align="center" prop="recertificatedate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recertificatedate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="有效期" align="center" prop="validity" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validity, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="压力容器和管道证书（4年复审）">
        <el-table-column label="压力容器" align="center" prop="container" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.container }}</span>
            <el-button v-if="scope.row.container != null" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-container')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="压力管道" align="center" prop="pipe" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.pipe }}</span>
            <el-button v-if="scope.row.pipe != null" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-pipe')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="取证日期" align="center" prop="reviewdate" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.reviewdate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="有效期" align="center" prop="pipevalidity" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.pipevalidity, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="证件号" align="center" prop="certificateNo" :show-overflow-tooltip="true" width="120"/>
      </el-table-column>
      <el-table-column label="锅炉证书（4年）">
        <el-table-column label="锅炉证" align="center" prop="boilerid" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.boilerid }}</span>
            <el-button v-if="scope.row.boilerid != null" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-boilerid')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="有效期" align="center" prop="boilvalidity" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.boilvalidity, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="危险化学品安全生产（3年复审，6年有效期）">
        <el-table-column label="加氢工艺" align="center" prop="hydrogenation" :show-overflow-tooltip="true" width="180">
          <template slot-scope="scope">
            <span>{{ scope.row.hydrogenation }}</span>
            <el-button v-if="scope.row.hydrogenation != null" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-hydrogenation')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="有效期" align="center" prop="hydvalidity" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.hydvalidity, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="复审" align="center" prop="hydnextreview" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.hydnextreview, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="裂化工艺" align="center" prop="crackingid" :show-overflow-tooltip="true" width="180">
          <template slot-scope="scope">
            <span>{{ scope.row.crackingid }}</span>
            <el-button v-if="scope.row.crackingid != null" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-crackingid')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="有效期" align="center" prop="crackingvalidity" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.crackingvalidity, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="复审" align="center" prop="crackingreview" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.crackingreview, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="制冷与空调作业" align="center" prop="refrigeration" :show-overflow-tooltip="true" width="180">
          <template slot-scope="scope">
            <span>{{ scope.row.refrigeration }}</span>
            <el-button v-if="scope.row.refrigeration != null" icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-refrigeration')"  circle></el-button>
          </template>
        </el-table-column>
        <el-table-column label="有效期" align="center" prop="refrigerationvalidity" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.refrigerationvalidity, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="复审" align="center" prop="refrigerationview" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.refrigerationview, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="班组长安全生产合格证（3年复审）">
        <el-table-column label="最近培训日期" align="center" prop="foremantrain" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.foremantrain, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="本次复审" align="center" prop="foremanreview" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.foremanreview, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="下次复审" align="center" prop="foremannextreview" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.foremannextreview, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="附件" align="center" width="80">
          <template slot-scope="scope">
            <el-button icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-foremantrain')"  circle></el-button>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="建筑消防（无复审）">
        <el-table-column label="取证日期" align="center" prop="fireProtection" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.fireProtection, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="附件" align="center" width="80">
          <template slot-scope="scope">
            <el-button icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-fireProtection')"  circle></el-button>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="锅炉水质处理">
        <el-table-column label="最近培训日期" align="center" prop="waterdate" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.waterdate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="附件" align="center" width="80">
          <template slot-scope="scope">
            <el-button icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-waterdate')"  circle></el-button>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="锅炉能效">
        <el-table-column label="最近培训日期" align="center" prop="energydate" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.energydate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="附件" align="center" width="80">
          <template slot-scope="scope">
            <el-button icon="el-icon-folder" style="color:#6e96fa;" @click="handleDoc(scope.row , 'certificate-energydate')"  circle></el-button>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="openStaffResume(scope.row)"
          >一人一档</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['training:worklicensecertificate:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['training:worklicensecertificate:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改上岗证/作业证书一览对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名" />
            </el-form-item>
            <el-form-item label="员工号" prop="employeeid">
              <el-input v-model="form.employeeid" placeholder="请输入员工号" />
            </el-form-item>
            <el-form-item label="身份证件号" prop="idnum">
              <el-input v-model="form.idnum" placeholder="请输入身份证件号" />
            </el-form-item>
            <el-form-item label="班组" prop="classes">
              <el-input v-model="form.classes" placeholder="请输入班组" />
            </el-form-item>
            <el-form-item label="职务" prop="post">
              <el-input v-model="form.post" placeholder="请输入职务" />
            </el-form-item>
            <el-form-item :label="$t('证件类型')" prop="idtype">
              <el-input v-model="form.idtype" :placeholder="$t('请输入') + $t('证件类型')" />
            </el-form-item>
            <el-form-item label="证件号" prop="worklicenseIdnum">
              <el-input v-model="form.worklicenseIdnum" placeholder="请输入证件号" />
            </el-form-item>
            <el-col :span="6">
              <el-form-item :label="$t('裂解')" prop="cracking">
                <el-checkbox v-model="form.cracking"></el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item :label="$t('压缩')" prop="hotarea">
                <el-checkbox v-model="form.hotarea"></el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item :label="$t('分离')" prop="coldarea">
                <el-checkbox v-model="form.coldarea"></el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item :label="$t('芳烃')" prop="aromatic">
                <el-checkbox v-model="form.aromatic"></el-checkbox>
              </el-form-item>
            </el-col>
            <el-form-item label="取复证日期" prop="recertificatedate">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.recertificatedate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择取复证日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="有效期" prop="validity">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.validity"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择有效期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="压力容器" prop="container">
              <el-input v-model="form.container" placeholder="请输入压力容器" />
            </el-form-item>
            <el-form-item label="压力管道" prop="pipe">
              <el-input v-model="form.pipe" placeholder="请输入压力管道" />
            </el-form-item>
            <el-form-item label="取证日期" prop="reviewdate">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.reviewdate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择取证日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="有效期" prop="pipevalidity">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.pipevalidity"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择有效期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="证件号" prop="certificateNo">
              <el-input v-model="form.certificateNo" placeholder="请输入证件号" />
            </el-form-item>
            <el-form-item label="锅炉证" prop="boilerid">
              <el-input v-model="form.boilerid" placeholder="请输入锅炉证" />
            </el-form-item>
            <el-form-item label="有效期" prop="boilvalidity">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.boilvalidity"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择有效期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="归属部门" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="加氢工艺" prop="hydrogenation">
              <el-input v-model="form.hydrogenation" placeholder="请输入加氢工艺" />
            </el-form-item>
            <el-form-item label="有效期" prop="hydvalidity">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.hydvalidity"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择有效期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="复审" prop="hydnextreview">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.hydnextreview"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择复审">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="裂化工艺" prop="crackingid">
              <el-input v-model="form.crackingid" placeholder="请输入裂化工艺" />
            </el-form-item>
            <el-form-item label="有效期" prop="crackingvalidity">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.crackingvalidity"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择有效期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="复审" prop="crackingreview">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.crackingreview"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择复审">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="制冷与空调作业" prop="refrigeration">
              <el-input v-model="form.refrigeration" placeholder="请输入制冷与空调作业" />
            </el-form-item>
            <el-form-item label="有效期" prop="refrigerationvalidity">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.refrigerationvalidity"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择有效期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="复审" prop="refrigerationview">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.refrigerationview"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择复审">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="班组长最近培训日期" prop="foremantrain">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.foremantrain"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择班组长最近培训日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="班组长本次复审" prop="foremanreview">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.foremanreview"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择班组长本次复审">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="班组长下次复审" prop="foremannextreview">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.foremannextreview"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择班组长下次复审">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="建筑消防取证日期" prop="fireProtection">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.fireProtection"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择建筑消防取证日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="锅炉水质处理最近培训日期" prop="waterdate">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.waterdate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择锅炉水质处理最近培训日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="锅炉能效最近培训日期" prop="energydate">
              <el-date-picker clearable size="small" style="width: 200px"
                              v-model="form.energydate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择锅炉能效最近培训日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 报告附件对话框 -->
    <el-dialog  :close-on-click-modal="false" v-dialogDrag :title="doc.title" :visible.sync="doc.open" width="1000px" append-to-body >
      <el-upload ref="doc"
                 :limit="50"
                 :headers="doc.headers"
                 :action="doc.url + '?pType=' + doc.pType + '&pId=' + doc.pId"
                 :disabled="doc.isUploading"
                 :on-progress="handleFileDocProgress"
                 :on-success="handleFileDocSuccess"
                 :auto-upload="true"
                 drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
      </el-upload>
      <el-table :data="doc.commonfileList" border>
        <el-table-column :label="$t('文件名')" align="center" prop="fileName" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <a  class="link-type"  @click="handleDownload(scope.row)">
              <span>{{ scope.row.fileName }}</span>
            </a>
          </template>
        </el-table-column>
        <el-table-column :label="$t('大小(Kb)')" align="center" prop="fileSize" :show-overflow-tooltip="true" width="80" />
        <el-table-column :label="$t('上传人')" align="center" prop="creator" :show-overflow-tooltip="true" width="120"/>
        <!--        <el-table-column :label="$t('培训日期')" align="center" prop="pDate"  width="150">-->
        <!--          <template slot-scope="scope">-->
        <!--            <el-date-picker-->
        <!--              v-if="scope.row.isEdit"-->
        <!--              v-model="scope.row.pDate"-->
        <!--              type="date"-->
        <!--              value-format="yyyy-MM-dd"-->
        <!--              placeholder="日期">-->
        <!--            </el-date-picker>-->
        <!--            <span v-else>{{ parseTime(scope.row.pDate, '{y}-{m}-{d}') }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column :label="$t('操作')" align="center" width="220" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.fileName.endsWith('pdf')"
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleSee(scope.row)"
            >{{ $t('预览') }}</el-button>
            <el-button v-hasPermi="['training:trainingrecords:file']"  type="text" size="small" v-if="scope.row.isEdit" @click="save(scope.row)">保存</el-button>
            <el-button type="text" size="small" v-if="scope.row.isEdit" @click="cancelFile(scope.row, scope.$index)">取消</el-button>
            <!--            <el-button v-hasPermi="['training:trainingrecords:file']" v-if="!scope.row.isEdit" @click="edit(scope.row)" icon="el-icon-edit" type="text" size="mini">编辑</el-button>-->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-download"
              @click="handleDownload(scope.row)"
            >{{ $t('下载') }}</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDeleteDoc(scope.row)"
              v-hasPermi="['training:trainingrecords:file']"
            >{{ $t('删除') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- pdf预览 -->
      <el-dialog  :close-on-click-modal="false" v-dialogDrag :title="pdf.title" :visible.sync="pdf.open" width="1300px" append-to-body>
        <div style="margin-top: -60px;float: right;margin-right: 40px;">
          <el-button size="mini" type="text" @click="openPdf">{{$t('新页面打开PDF')}}</el-button></div>
        <div style="margin-top: -30px">
          <iframe :src="pdf.pdfUrl" frameborder="0" width="100%" height="700px"></iframe>
        </div>
      </el-dialog>
      <div slot="footer" class="dialog-footer">
        <el-button @click="doc.open = false">{{ $t('返 回') }}</el-button>
      </div>
    </el-dialog>
    <staff-resume v-if="staffResumeVisible" ref="staffResume"></staff-resume>
  </div>
</template>

<script>
import { syncStaff, listWorklicensecertificate, getWorklicensecertificate, delWorklicensecertificate, addWorklicensecertificate, updateWorklicensecertificate, exportWorklicensecertificate, importTemplate} from "@/api/training/worklicensecertificate";
import { treeselect } from "@/api/system/dept";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {addCommonfile, allFileList, delCommonfile, updateCommonfile} from "@/api/common/commonfile";
import StaffResume from "./staffResume"

export default {
  name: "Worklicensecertificate",
  components: { Treeselect, StaffResume },
  data() {
    return {
      // 遮罩层
      loading: true,
      loadingText: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 上岗证/作业证书一览表格数据
      worklicensecertificateList: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      clientHeight:300,
      // 是否显示弹出层
      open: false,
        // 用户导入参数
        upload: {
            // 是否显示弹出层（用户导入）
            open: false,
            // 弹出层标题（用户导入）
            title: "",
            // 是否禁用上传
            isUploading: false,
            // 是否更新已经存在的用户数据
            updateSupport: 0,
            // 设置上传的请求头部
            headers: { Authorization: "Bearer " + getToken() },
            // 上传的地址
            url: process.env.VUE_APP_BASE_API + "/training/worklicensecertificate/importData"
        },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        name: null,
        employeeid: null,
        idnum: null,
        classes: null,
        post: null,
        idtype: null,
        worklicenseIdnum: null,
        boiler: null,
        cracking: null,
        hotarea: null,
        coldarea: null,
        aromatic: null,
        recertificatedate: null,
        validity: null,
        container: null,
        pipe: null,
        reviewdate: null,
        pipevalidity: null,
        certificateNo: null,
        boilerid: null,
        boilvalidity: null,
        hydrogenation: null,
        hydvalidity: null,
        hydnextreview: null,
        crackingid: null,
        crackingvalidity: null,
        crackingreview: null,
        refrigeration: null,
        refrigerationvalidity: null,
        refrigerationview: null,
        foremantrain: null,
        foremanreview: null,
        foremannextreview: null,
        fireProtection: null,
        waterdate: null,
        energydate: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "唯一标识ID不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        employeeid: [
          { required: true, message: "员工号不能为空", trigger: "blur" }
        ],
        idnum: [
          { required: true, message: "身份证件号不能为空", trigger: "blur" }
        ],
        classes: [
          { required: true, message: "班组不能为空", trigger: "blur" }
        ],
        post: [
          { required: true, message: "职务不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "部门编号不能为空", trigger: "blur" }
        ]
      },
      doc: {
        file: "",
        // 是否显示弹出层（报告附件）
        open: false,
        // 弹出层标题（报告附件）
        title: "附件",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 报告附件上传位置编号
        ids: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/commonfile/uploadFile",
        commonfileList: null,
        queryParams: {
          pId: null,
          pType: 'training'
        },
        pType: 'training',
        pId: null,
        form: {}
      },
      pdf : {
        title: '',
        pdfUrl: '',
        numPages: null,
        open: false,
        pageNum: 1,
        pageTotalNum: 1,
        loadedRatio: 0,
      },
      staffResumeVisible: false,
      boiler: false,
      cracking: false,
      hotarea: false,
      coldarea: false,
      aromatic: false,
    };
  },
  watch: {
        // 根据名称筛选部门树
        deptName(val) {
            this.$refs.tree.filter(val);
        }
   },
  created() {
      //设置表格高度对应屏幕高度
      this.$nextTick(() => {
          this.clientHeight = document.body.clientHeight -250
      })
    this.getList();
    this.getTreeselect();
  },
  methods: {
    // 同步人员数据
    syncStaff() {
      this.loading = true;
      this.loadingText = '同步中...'
      syncStaff({}).then(response => {
        this.msgSuccess("同步成功");
        this.loading = false;
        this.getList();
      });
    },
    tableHeaderStyle({row, column, rowIndex, columnIndex}) {
      let style = "text-align:center;";
      if ((rowIndex === 0 && columnIndex === 8) || (rowIndex === 1 && columnIndex === 0)
        || (rowIndex === 1 && columnIndex === 1) || (rowIndex === 1 && columnIndex === 2)
        || (rowIndex === 1 && columnIndex === 3)
        ||(rowIndex === 0 && columnIndex === 9) || (rowIndex === 0 && columnIndex === 10)
        || (rowIndex === 1 && columnIndex === 21) || (rowIndex === 1 && columnIndex === 22)
        || (rowIndex === 1 && columnIndex === 23) || (rowIndex === 1 && columnIndex === 20)
        || (rowIndex === 0 && columnIndex === 14)) {
        return style += "background:#DDFFDD;";
      }
      if ((rowIndex === 0 && columnIndex === 11) || (rowIndex === 1 && columnIndex === 5)
        || (rowIndex === 1 && columnIndex === 6) || (rowIndex === 1 && columnIndex === 7)
        || (rowIndex === 1 && columnIndex === 8) || (rowIndex === 1 && columnIndex === 4)
        || (rowIndex === 1 && columnIndex === 25) || (rowIndex === 1 && columnIndex === 24)
        || (rowIndex === 0 && columnIndex === 15)) {
        return style += "background:#FFFFDD;";
      }
      if ((rowIndex === 0 && columnIndex === 12) || (rowIndex === 1 && columnIndex === 10)
        || (rowIndex === 1 && columnIndex === 9) || (rowIndex === 1 && columnIndex === 27)
        || (rowIndex === 1 && columnIndex === 26) || (rowIndex === 0 && columnIndex === 16)) {
        return style += "background:#DDFFFF;";
      }
      if ((rowIndex === 0 && columnIndex === 13) || (rowIndex === 1 && columnIndex === 12)
        || (rowIndex === 1 && columnIndex === 13) || (rowIndex === 1 && columnIndex === 14)
        || (rowIndex === 1 && columnIndex === 15) || (rowIndex === 1 && columnIndex === 16)
        || (rowIndex === 1 && columnIndex === 17) || (rowIndex === 1 && columnIndex === 18)
        || (rowIndex === 1 && columnIndex === 19) || (rowIndex === 1 && columnIndex === 11)
        || (rowIndex === 1 && columnIndex === 29) || (rowIndex === 1 && columnIndex === 28
          || (rowIndex === 0 && columnIndex === 17))) {
        return style += "background:rgb(229, 249, 175);";
      }
    },
    // 单元格样式
    tableCellStyle( {row, column, rowIndex, columnIndex} ) {
      let style = "";
      if (row.isHighlight == 1) {
        style += " color: red;";
      }
      if (columnIndex === 8||columnIndex === 9||columnIndex === 10||columnIndex === 11
        ||columnIndex === 12||columnIndex === 13 ||columnIndex === 31
        ||columnIndex === 32||columnIndex === 33||columnIndex === 30) {
        return style += "background:#DDFFDD;";
      } else if (columnIndex === 15||columnIndex === 16||columnIndex === 17||columnIndex === 18
        ||columnIndex === 14 ||columnIndex === 35||columnIndex === 34) {
        return style += "background:#FFFFDD;";
      } else if (columnIndex === 20||columnIndex === 19||columnIndex === 37||columnIndex === 36) {
        return style += "background:#DDFFFF;";
      } else if (columnIndex === 22||columnIndex === 23||columnIndex === 24 ||columnIndex === 25
        ||columnIndex === 26||columnIndex === 27 ||columnIndex === 28||columnIndex === 29
        ||columnIndex === 21 ||columnIndex === 39||columnIndex === 38) {
        return style += "background:rgb(229, 249, 175);";
      } else {
        return style;
      }
    },
    openStaffResume(row){
      this.staffResumeVisible = true
      this.$nextTick(() => {
        this.$refs.staffResume.init(row)
      })
    },
    /** 删除按钮操作 */
    handleDeleteDoc(row) {
      const ids = row.id || this.ids;
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: "warning"
      }).then(function() {
        return delCommonfile(ids);
      }).then(() => {
        this.getFileList()
        this.msgSuccess(this.$t('删除成功'));
      })
    },
    // 文件下载处理
    handleDownload(row) {
      var name = row.fileName;
      var url = row.fileUrl;
      var suffix = url.substring(url.lastIndexOf("."), url.length);
      const a = document.createElement('a')
      a.setAttribute('download', name)
      a.setAttribute('target', '_blank')
      a.setAttribute('href', process.env.VUE_APP_BASE_API + url)
      a.click()
    },
    openPdf(){
      window.open(this.pdf.pdfUrl);//path是文件的全路径地址
    },
    handleSee (row){
      // window.open(process.env.VUE_APP_BASE_API +'/pdf/web/viewer.html?file=' + process.env.VUE_APP_BASE_API + row.fileUrl);//path是文件的全路径地址
      this.pdf.open =true
      this.pdf.title = row.fileName
      this.pdf.pdfUrl = process.env.VUE_APP_BASE_API +'/pdf/web/viewer.html?file=' + process.env.VUE_APP_BASE_API + row.fileUrl
    },
    // 上一页
    prePage() {
      let page = this.pdf.pageNum
      page = page > 1 ? page - 1 : this.pdf.pageTotalNum
      this.pdf.pageNum = page
    },
    // 下一页
    nextPage() {
      let page = this.pdf.pageNum
      page = page < this.pdf.pageTotalNum ? page + 1 : 1
      this.pdf.pageNum = page
    },
    //附件上传中处理
    handleFileDocProgress(event, file, fileList) {
      this.doc.file = file;
      this.doc.isUploading = true;
    },
    //附件上传成功处理
    handleFileDocSuccess(response, file, fileList) {
      this.doc.isUploading = false;
      this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true });
      this.getFileList()
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      if (response.data[0] != null) {
        this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据') + "，" + this.$t('第') + response.data + this.$t('行数据出现错误导入失败')+"。", this.$t('导入结果'), { dangerouslyUseHTMLString: true });
      }else {
        this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据'), this.$t('导入结果'), { dangerouslyUseHTMLString: true });
      }
      this.getList();
    },
    /** 报告附件按钮操作 */
    handleDoc(row , fileType) {
      var workType = "";
      if (fileType === "license-boiler"){
        workType = '开工锅炉上岗证';
      } else if (fileType === "license-cracking"){
        workType = '裂解上岗证';
      }else if (fileType === "license-hotarea"){
        workType = '压缩上岗证';
      }else if (fileType === "license-coldarea"){
        workType = "分离上岗证";
      }else if (fileType === "license-aromatic"){
        workType = "芳烃上岗证";
      }else if (fileType === "certificate-container"){
        workType = "压力容器作业证书";
      }else if (fileType === "certificate-pipe"){
        workType = "压力管道作业证书";
      }else if (fileType === "certificate-boilerid"){
        workType = "锅炉证";
      }else if (fileType === "certificate-hydrogenation"){
        workType = "加氢工艺作业证书";
      }else if (fileType === "certificate-crackingid"){
        workType = "裂化工艺作业证书";
      }else if (fileType === "certificate-refrigeration"){
        workType = "制冷与空调作业证书";
      }else if (fileType === "certificate-foremantrain"){
        workType = "班组长安全生产合格证";
      }else if (fileType === "certificate-fireProtection"){
        workType = "建筑消防作业证书";
      }else if (fileType === "certificate-waterdate"){
        workType = "锅炉水质处理作业证书";
      }else if (fileType === "certificate-energydate"){
        workType = "锅炉能效作业证书";
      }
      this.doc.pType = fileType
      this.doc.queryParams.pType = fileType
      this.doc.id = row.id;
      this.doc.title = row.name + '的' + workType + '附件';
      this.doc.open = true;
      this.doc.queryParams.pId = row.id
      this.doc.pId = row.id
      this.getFileList();
    },
    getFileList (){
      allFileList(this.doc.queryParams).then(response => {
        response.forEach(element => {
          element["isEdit"] = false
        });
        response.forEach(element => {
          element["isAdd"] = false
        });
        this.doc.commonfileList = response;
      });
    },
    /** 查询上岗证/作业证书一览列表 */
    getList() {
      this.loading = true;
      this.loadingText = '查询中...'
      listWorklicensecertificate(this.queryParams).then(response => {
        this.worklicensecertificateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     /** 查询部门下拉树结构 */
     getTreeselect() {
          treeselect().then(response => {
              this.deptOptions = response.data;
          });
     },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        employeeid: null,
        idnum: null,
        classes: null,
        post: null,
        idtype: null,
        worklicenseIdnum: null,
        boiler: null,
        cracking: null,
        hotarea: null,
        coldarea: null,
        aromatic: null,
        recertificatedate: null,
        validity: null,
        container: null,
        pipe: null,
        reviewdate: null,
        pipevalidity: null,
        certificateNo: null,
        boilerid: null,
        boilvalidity: null,
        hydrogenation: null,
        hydvalidity: null,
        hydnextreview: null,
        crackingid: null,
        crackingvalidity: null,
        crackingreview: null,
        refrigeration: null,
        refrigerationvalidity: null,
        refrigerationview: null,
        foremantrain: null,
        foremanreview: null,
        foremannextreview: null,
        fireProtection: null,
        waterdate: null,
        energydate: null,
        delFlag: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.boiler == true) {
        this.queryParams.boiler = "1";
      } else {
        this.queryParams.boiler = null;
      }
      if (this.cracking == true) {
        this.queryParams.cracking = "1";
      } else {
        this.queryParams.cracking = null;
      }
      if (this.hotarea == true) {
        this.queryParams.hotarea = "1";
      } else {
        this.queryParams.hotarea = null;
      }
      if (this.coldarea == true) {
        this.queryParams.coldarea = "1";
      } else {
        this.queryParams.coldarea = null;
      }
      if (this.aromatic == true) {
        this.queryParams.aromatic = "1";
      } else {
        this.queryParams.aromatic = null;
      }
      console.log(this.boiler)
      console.log(this.queryParams)
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.boiler = false;
      this.cracking = false;
      this.hotarea = false;
      this.coldarea = false;
      this.aromatic = false;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加上岗证/作业证书一览";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWorklicensecertificate(id).then(response => {
        this.form = response.data;
        if (this.form.boiler == 1) {
          this.form.boiler = true;
        } else {
          this.form.boiler = false;
        }
        if (this.form.cracking == 1) {
          this.form.cracking = true;
        } else {
          this.form.cracking = false;
        }
        if (this.form.hotarea == 1) {
          this.form.hotarea = true;
        } else {
          this.form.hotarea = false;
        }
        if (this.form.coldarea == 1) {
          this.form.coldarea = true;
        } else {
          this.form.coldarea = false;
        }
        if (this.form.aromatic == 1) {
          this.form.aromatic = true;
        } else {
          this.form.aromatic = false;
        }
        this.open = true;
        this.title = "修改上岗证/作业证书一览";
      });
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form)
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.boiler == true) {
            this.form.boiler = 1;
          } else {
            this.form.boiler = 0;
          }
          if (this.form.cracking == true) {
            this.form.cracking = 1;
          } else {
            this.form.cracking = 0;
          }
          if (this.form.hotarea == true) {
            this.form.hotarea = 1;
          } else {
            this.form.hotarea = 0;
          }
          if (this.form.coldarea == true) {
            this.form.coldarea = 1;
          } else {
            this.form.coldarea = 0;
          }
          if (this.form.aromatic == true) {
            this.form.aromatic = 1;
          } else {
            this.form.aromatic = 0;
          }
          if (this.form.id != null) {
            updateWorklicensecertificate(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWorklicensecertificate(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWorklicensecertificate(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有上岗证/作业证书一览数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportWorklicensecertificate(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    },
      /** 导入按钮操作 */
      handleImport() {
          this.upload.title = "用户导入";
          this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
          importTemplate().then(response => {
              this.download(response.msg);
          });
      },
      // // 文件上传中处理
      // handleFileUploadProgress(event, file, fileList) {
      //     this.upload.isUploading = true;
      // },
      // // 文件上传成功处理
      // handleFileSuccess(response, file, fileList) {
      //     this.upload.open = false;
      //     this.upload.isUploading = false;
      //     this.$refs.upload.clearFiles();
      //     this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      //     this.getList();
      // },
      // 提交上传文件
      submitFileForm() {
          this.$refs.upload.submit();
      }
  }
};
</script>
