<template>
  <div class="coldfood">
    <div class="search-wrapper">
      <el-form
        :inline="true"
        :model="searchForm"
        class="search_form"
        style="text-align: left"
      >
        <el-form-item label="姓名" label-width="200">
          <el-input
            v-model="searchForm.name"
            placeholder="请输入姓名"
            @keyup.enter.native="onSubmit"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号码">
          <el-input
            v-model="searchForm.phone"
            placeholder="请输入手机号码"
            @keyup.enter.native="onSubmit"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="单位名称">
          <el-input
            v-model="searchForm.unitName"
            placeholder="请输入单位名称"
            @keyup.enter.native="onSubmit"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="操作人">
          <el-input
            v-model="searchForm.recordName"
            placeholder="请输入操作人"
            @keyup.enter.native="onSubmit"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="人才类型" v-if="this.branchCode == '5'">
          <el-select
            v-model="searchForm.talentClassification"
            placeholder="请选择人才类型"
            style="width: 100%"
            @change="onSubmit"
          >
            <el-option
              v-for="item in talentsList"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="认定类型">
          <el-select
            v-model="searchForm.typeCode"
            placeholder="请选择认定类型"
            style="width: 100%"
            @change="onSubmit"
          >
            <el-option
              v-for="item in typeList"
              :key="item.typeCode"
              :label="item.typeName"
              :value="item.typeCode"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="!branchCode" label="责任部门">
          <el-select
            v-model="searchForm.branchCode"
            placeholder="请选择责任部门"
            style="width: 100%"
            @change="onSubmit"
          >
            <el-option
              v-for="item in branchList"
              :key="item.branchCode"
              :label="item.branchName"
              :value="item.branchCode"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
        <br />
        <el-form-item label="排序类型" style="margin-top: 10px">
          <el-radio-group v-model="searchForm.sortType" @change="onSubmit">
            <el-radio label="desc">倒序 </el-radio>
            <el-radio label="asc">顺序 </el-radio>
          </el-radio-group>
          <!-- <el-select
            v-model="searchForm.sortType"
            placeholder="请选择排序类型"
            style="width: 100%"
            @change="onSubmit"
          >
            <el-option label="顺序" value="asc"> </el-option>

            <el-option label="倒叙" value="desc"> </el-option>
          </el-select> -->
        </el-form-item>
        <br />

        <el-form-item label="状态" style="margin-top: 10px">
          <el-radio-group v-model="searchForm.state" @change="onSubmit">
            <el-radio
              :label="item.state"
              v-for="item in stateList"
              :key="item.state"
              >{{ item.stateName }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="table-wrapper1">
      <table-template
        :tableData="tableData"
        :tableColumns="tableColumns"
        :loading="loading"
        :pagination="pagination"
        @Jump="jumpPage"
      >
        <el-table-column
          width="120"
          key="updateTime"
          prop="updateTime"
          label="更新时间"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.updateTime }}</span>
          </template>
        </el-table-column>

        <el-table-column
          width="120"
          prop="talentClassification"
          label="人才类型"
          align="center"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.talentClassification == '1'">
              乡土或创新人才
            </div>
            <div v-else-if="scope.row.talentClassification == '2'">
              学历人才
            </div>
            <div v-else-if="scope.row.talentClassification == '3'">
              技能人才
            </div>
            <div v-else-if="scope.row.talentClassification == '4'">
              专技人才
            </div>
            <div v-else>-</div>
          </template>
        </el-table-column>
        <el-table-column
          width="120"
          prop="overdue"
          label="逾期状态"
          align="center"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.state == 1">
              <div v-if="scope.row.overdue < 3"></div>
              <div
                class="early"
                v-if="scope.row.overdue < 5 && scope.row.overdue >= 3"
              ></div>
              <div class="warning" v-if="scope.row.overdue >= 5"></div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          width="120"
          key="stateName"
          prop="onlineName"
          label="状态"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag
              :type="stateFilter(scope.row.state)"
              :effect="plainFilter(scope.row.state)"
              >{{ scope.row.stateName }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="380" align="left">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" round @click="view(scope.row)"
              >查看</el-button
            >
            <el-button
              type="primary"
              size="mini"
              round
              @click="getRecord(scope.row)"
              >记录</el-button
            >

            <!-- 公示期的单子可以暂停公示 -->
            <el-button
              v-if="scope.row.state === 2"
              type="warning"
              size="mini"
              round
              @click="pause(scope.row.talentCode)"
              >暂停公示</el-button
            >
            <!-- 暂停公示的单子可以恢复公示 -->
            <el-button
              v-if="scope.row.state === 4"
              type="success"
              size="mini"
              round
              @click="recover(scope.row.talentCode)"
              >恢复公示</el-button
            >
            <!-- 审核通过后的单子都可以拉入黑名单撤销 -->
            <el-button
              v-if="
                scope.row.state === 2 ||
                scope.row.state === 3 ||
                scope.row.state === 4
              "
              type="danger"
              size="mini"
              round
              @click="blacklist(scope.row.talentCode)"
              >撤销</el-button
            >
            <!-- 审核通过后的单子都可以打印-->
            <el-button
              size="mini"
              round
              @click="print(scope.row.talentCode, scope.row)"
              >打印</el-button
            >
          </template>
        </el-table-column>
      </table-template>
    </div>
    <!-- 表格end -->

    <!-- 拒绝对话框 -->
    <el-dialog
      title="提示"
      :visible.sync="refuseDialog"
      width="30%"
      class="refuseDialog"
      :before-close="cancelBtn"
    >
      <span
        >确定拒绝该人才的申请吗？确定的话请<span style="color: red"
          >选择或输入</span
        >拒绝原因</span
      >
      <div>
        <el-select
          v-model="refuseValue"
          placeholder="请选择拒绝原因"
          @change="refuseSelect"
        >
          <el-option
            v-for="item in refuseOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div class="refuseTex">
        <el-input
          type="textarea"
          autosize
          placeholder="请输入拒绝原因"
          v-model="refuseTextarea"
        >
        </el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelBtn">取 消</el-button>
        <el-button type="primary" @click="successBtn">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 人才详情的对话框 -->
    <!--
 -->
    <el-dialog
      title="人才详情"
      width="800px"
      :visible.sync="viewShow"
      :close-on-press-escape="false"
      @close="showEdu = false"
    >
      <div class="content">
        <!-- 开始 -->
        <div style="background: #f3f4f6">
          <div class="cell">
            <p class="label">申请类型</p>
            <p class="value">{{ viewDetail.category }}</p>
          </div>
          <div class="cell">
            <p class="label">申请内容</p>
            <p class="value">{{ viewDetail.contentName }}</p>
          </div>
          <div class="cell">
            <p class="label">姓名</p>
            <p class="value">{{ viewDetail.name }}</p>
          </div>
          <div class="cell">
            <p class="label">
              {{ viewDetail.passport === 0 ? "身份证" : "护照" }}
            </p>
            <p class="value">{{ viewDetail.idCard }}</p>
          </div>
          <div class="cell" v-if="viewDetail.socialPremiumLocation !== null">
            <p class="label">工作或社保所在地</p>
            <p class="value">{{ viewDetail.socialPremiumLocation }}</p>
          </div>
          <div class="cell">
            <p class="label">工作单位名称</p>
            <p class="value">{{ viewDetail.unitName }}</p>
          </div>
          <div class="cell" v-if="viewDetail.socialUnit">
            <p class="label">社保缴纳单位</p>
            <p class="value">{{ viewDetail.socialUnit }}</p>
          </div>
          <div class="cell">
            <p class="label">单位统一社会信用代码</p>
            <p class="value">{{ viewDetail.socialCredit }}</p>
          </div>
          <div class="cell">
            <p class="label">个人承诺函</p>
            <el-image
              style="height: 100px; max-width: 150px"
              :src="viewDetail.promise"
              :preview-src-list="[viewDetail.promise]"
              :z-index="1000000"
            />
          </div>
          <div
            class="cell"
            v-for="(item, index) in viewDetail.pictureList"
            :key="index"
          >
            <template v-if="item.pictureType === 1">
              <p class="label">佐证材料(图片)</p>
              <el-image
                style="height: 100px; max-width: 150px"
                :src="item.picture"
                :preview-src-list="[item.picture]"
                :z-index="1000000"
              />
            </template>
            <template v-if="item.pictureType === 2">
              <p class="label">佐证材料(文件)</p>
              <div class="info">
                <p class="item" v-if="item.fileName">
                  文件名称：{{ item.fileName }}
                </p>
                <p class="item" v-if="item.documentNumber">
                  文号：{{ item.documentNumber }}
                </p>
                <p class="item" v-if="item.issuingOrganization">
                  发文机构：{{ item.issuingOrganization }}
                </p>
                <p class="item">
                  <a class="download" target="_blank" :href="item.picture"
                    >下载文件</a
                  >
                </p>
              </div>
            </template>
          </div>
        </div>

        <!-- 结束 -->
        <div class="cell">
          <p class="label">申报人所属</p>
          <p class="value">
            {{ viewDetail.passport === 0 ? "国内" : "港澳台及国外" }}
          </p>
        </div>
        <div class="cell" v-if="viewDetail.socialSecurity">
          <p class="label">申报人分类</p>
          <p class="value">{{ viewDetail.socialSecurity }}</p>
        </div>

        <div class="cell">
          <p class="label">性别</p>
          <p class="value">{{ viewDetail.sex === 0 ? "男" : "女" }}</p>
        </div>
        <div class="cell">
          <p class="label">出生地</p>
          <p class="value">{{ viewDetail.birthPlace }}</p>
        </div>
        <div class="cell" v-if="viewDetail.nation">
          <p class="label">民族</p>
          <p class="value">{{ viewDetail.nation }}</p>
        </div>
        <div class="cell" v-if="viewDetail.politicalFace">
          <p class="label">政治面貌</p>
          <p class="value">{{ viewDetail.politicalFace }}</p>
        </div>
        <div class="cell">
          <p class="label">出生年月</p>
          <p class="value">{{ viewDetail.birthDate }}</p>
        </div>
        <div class="cell">
          <p class="label">手机号</p>
          <p class="value">{{ viewDetail.phone }}</p>
        </div>
        <div class="cell">
          <p class="label">
            学历所在(<span style="color: red">{{
              viewDetail.educationState === 0 ? "校验未通过" : "校验已通过"
            }}</span
            >)
          </p>
          <p class="value">
            {{ viewDetail.educationPassport === 0 ? "国内" : "国外" }}
          </p>
          <el-button
            style="margin-left: 20px"
            size="mini"
            type="success"
            @click="viewEdu"
            >查看</el-button
          >
          <el-button
            style="margin-left: 20px"
            v-if="viewDetail.educationState === 0"
            type="primary"
            size="mini"
            @click="passEducation"
            >审核通过</el-button
          >
        </div>
        <div class="cell" v-show="showEdu">
          <p class="label">学历查验</p>
          <div class="item">
            <p class="value" v-for="(edu, index) in eduList" :key="index">
              {{ edu.cc }}-{{ edu.xxxs }}-{{ edu.yxmc }}-{{ edu.zymc }}
            </p>
          </div>
        </div>
        <div class="cell">
          <p class="label">最高学历</p>
          <p class="value">{{ viewDetail.highestEducation }}</p>
        </div>
        <div class="cell" v-if="viewDetail.major">
          <p class="label">所学专业</p>
          <p class="value">{{ viewDetail.major }}</p>
        </div>
        <div class="cell">
          <p class="label">毕业院校</p>
          <p class="value">{{ viewDetail.graduateSchool }}</p>
        </div>
        <!-- <div class="cell">
            <p class="label">入学时间</p>
            <p class="value">{{ viewDetail.studyTime }}</p>
          </div> -->
        <div class="cell">
          <p class="label">毕业时间</p>
          <p class="value">{{ viewDetail.graduationTime }}</p>
        </div>
        <!-- <div class="cell" v-if="viewDetail.highestDegree">
            <p class="label">最高学位</p>
            <p class="value">{{ viewDetail.highestDegree }}</p>
          </div> -->
        <!-- <div class="cell" v-if="viewDetail.awardingUnit">
            <p class="label">授予单位</p>
            <p class="value">{{ viewDetail.awardingUnit }}</p>
          </div> -->
        <!-- <div class="cell" v-if="viewDetail.timeGrant">
            <p class="label">授予时间</p>
            <p class="value">{{ viewDetail.timeGrant }}</p>
          </div> -->
        <div class="cell">
          <p class="label">职称</p>
          <p class="value">{{ viewDetail.title }}</p>
        </div>

        <div class="cell">
          <p class="label">单位类别</p>
          <p class="value">
            {{
              viewDetail.unitType === "1"
                ? "企业"
                : viewDetail.unitType === "2"
                ? "事业单位(专技人员)"
                : viewDetail.unitType === "3"
                ? "劳务派遣"
                : " "
            }}
          </p>
        </div>

        <div class="cell">
          <p class="label">职务/岗位</p>
          <p class="value">{{ viewDetail.post }}</p>
        </div>
        <div class="cell">
          <p class="label">单位联系人</p>
          <p class="value">{{ viewDetail.contactPerson }}</p>
        </div>
        <div class="cell">
          <p class="label">单位联系电话</p>
          <p class="value">{{ viewDetail.contactNumber }}</p>
        </div>

        <div class="cell">
          <p class="label">个人照片</p>
          <el-image
            style="height: 100px; max-width: 150px"
            :src="viewDetail.headPortrait"
            :preview-src-list="[viewDetail.headPortrait]"
            :z-index="1000000"
          />
        </div>
        <div
          class="cell"
          v-if="viewDetail.payroll && viewDetail.unitType == '2'"
        >
          <p class="label">工资变动审批表</p>
          <a class="download" target="_blank" :href="viewDetail.payroll"
            >下载文件</a
          >
        </div>
        <div
          class="cell"
          v-if="viewDetail.payroll && viewDetail.unitType == '3'"
        >
          <p class="label">劳务派遣合同个人签字和盖章</p>
          <el-image
            style="height: 100px; max-width: 150px"
            :src="viewDetail.payroll"
            :preview-src-list="[viewDetail.payroll]"
            :z-index="7777777"
          />
        </div>
        <!--        <div class="cell" v-if="viewDetail.titleCertificate">-->
        <!--          <p class="label">职称证明</p>-->
        <!--          <el-image-->
        <!--            style="height: 100px; max-width: 150px"-->
        <!--            :src="viewDetail.titleCertificate"-->
        <!--            :preview-src-list="[viewDetail.titleCertificate]"-->
        <!--          />-->
        <!--        </div>-->
        <div class="cell" v-if="viewDetail.education">
          <p class="label">学信网学历证明</p>
          <el-image
            style="height: 100px; max-width: 150px"
            :src="viewDetail.education"
            :preview-src-list="[viewDetail.education]"
            :z-index="7777777"
          />
        </div>
        <div class="cell" v-if="viewDetail.studentStatus">
          <p class="label">学信网学籍证明</p>
          <el-image
            style="height: 100px; max-width: 150px"
            :src="viewDetail.studentStatus"
            :z-index="7777777"
            :preview-src-list="[viewDetail.studentStatus]"
          />
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <!-- 申请的单子有通过拒绝-->
        <el-button
          v-if="viewRow.state === 1"
          type="danger"
          size="mini"
          round
          @click="deny(viewRow)"
          >拒绝
        </el-button>
        <!-- 通过 -->
        <el-button
          v-if="viewRow.state === 1"
          type="success"
          size="mini"
          round
          @click="pass(viewRow)"
          >通过
        </el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="操作记录"
      :visible.sync="recordShow"
      width="800px"
      :close-on-press-escape="false"
    >
      <div class="content">
        <div class="cell" v-for="item in record" :key="item.createTime">
          <p class="label" style="margin-right: 20px">
            {{ item.stateName }}
            <span v-if="item.reason">({{ item.reason }})</span>
          </p>
          <div class="info">
            <p class="item">操作人：{{ item.name }}</p>
            <p class="item">操作时间：{{ item.createTime }}</p>
          </div>
        </div>
        <p v-if="record.length === 0">暂无记录~</p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TableTemplate from "@/components/Table";
// decryptByDES
import { changeList, encryptByDES } from "@/utils";
import {
  getList,
  updateState,
  get,
  getRecord,
  getBranch,
  getType,
  educationState,
  educationQuery,
} from "@/api/talents";
import { Message } from "element-ui";
import docxtemplater from "docxtemplater";
import PizZip from "pizzip";
import JSZipUtils from "jszip-utils";
import { saveAs } from "file-saver";

let stateArr = [
  {
    state: "",
    stateName: "全部",
  },
  {
    state: 1,
    stateName: "待审核",
    type: "warning",
  },
  {
    state: 2,
    stateName: "公示中",
    type: "",
  },
  {
    state: 3,
    stateName: "已发码",
    type: "success",
  },
  {
    state: 4,
    stateName: "公示暂停",
    type: "info",
  },
  {
    state: 5,
    stateName: "审核拒绝",
    type: "danger",
  },
  {
    state: 6,
    stateName: "管理撤销",
    type: "danger",
    effect: "plain",
  },
  {
    state: 7,
    stateName: "强制更新",
    type: "success",
    effect: "plain",
  },
  {
    state: 8,
    stateName: "已逾期",
    type: "warning",
    effect: "plain",
  },
];

export default {
  components: { TableTemplate },
  data() {
    return {
      refuseDialog: false,
      refuseValue: "",
      refuseTextarea: null,
      refuseCode: "",
      refuseOptions: [
        {
          value: 1,
          label: "不符合全日制学历要求",
        },
        {
          value: 2,
          label: "请上传事业单位工资变动审批表",
        },
        {
          value: 3,
          label: "请上传有单位盖章的承诺书",
        },
        {
          value: 4,
          label: "您不属于人才码申报范围",
        },
        {
          value: 5,
          label: "请上传海外境外学历认证书",
        },
        {
          value: 6,
          label: "不符合人才码事业单位专业技术岗和企业全职人员的申报单位要求",
        },
        {
          value: 7,
          label: "请上传有单位盖章、本人签字的承诺书",
        },
      ],
      branchCode: "", // 管理后台给的code
      code: "",
      userName: "",
      searchForm: {
        name: "", // 姓名
        phone: "", // 联系方式
        unitName: "",
        recordName: "",
        state: "", // 状态
        typeCode: "", // 认定类型
        branchCode: "", // 责任部门
        talentClassification: "", // 人才分类
        socialPremiumLocation: "", // 社保缴纳地
        sortType: "desc", // 排序类型
      },
      loading: false,
      // 状态
      stateList: [
        {
          state: "",
          stateName: "全部",
          color: "",
        },
        {
          state: 1,
          stateName: "待审核",
          type: "warning",
        },
        {
          state: 2,
          stateName: "公示中",
          type: "warning",
        },
        {
          state: 3,
          stateName: "已发码",
          type: "success",
        },
        // {
        //   state: 4,
        //   stateName: "公示暂停",
        //   type: "info",
        // },
        // {
        //   state: 5,
        //   stateName: "审核拒绝",
        //   type: "warning",
        // },
        {
          state: 6,
          stateName: "已撤销",
          type: "danger",
        },
        {
          state: 5,
          stateName: "已拒绝",
          type: "danger",
        },
      ],
      // 责任部门
      branchList: [],
      // 认定类型
      typeList: [],
      // 人才类型
      talentsList: [
        {
          id: "",
          label: "全部",
        },
        {
          id: "1",
          label: "乡土或创新人才",
        },
        {
          id: "2",
          label: "学历人才",
        },
        {
          id: "3",
          label: "技能人才",
        },
        {
          id: "4",
          label: "专技人才",
        },
      ],
      tableData: [],
      tableColumns: [
        {
          key: "unitName",
          label: "单位名称",
          width: 250,
        },
        // {
        //   key: "talentCode",
        //   label: "申请编号",
        //   width: 200,
        // },
        {
          key: "name",
          label: "姓名",
          width: 150,
        },
        // {
        //   key: "phone",
        //   label: "手机号",
        // },
        {
          key: "categoryName",
          label: "认定类型",
          width: 100,
        },
        {
          key: "contentName",
          label: "申请内容",
          width: 250,
        },
        {
          key: "updateTime",
          label: "更新时间",
          width: 180,
          type: "slot",
        },
        {
          key: "recordVOS[0].name",
          label: "操作人",
          width: 180,
        },
      ],
      pagination: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      viewShow: false,
      viewDetail: {},
      record: [],
      recordShow: false,
      showEdu: false,
      eduList: [],
      // 查看对话框当前row
      viewRow: {},
    };
  },
  watch: {
    $route() {
      if (this.$route) {
        this.userName = localStorage.getItem("userName");
        this.branchCode = this.$route.query.branchCode
          ? this.$route.query.branchCode
          : "";
        this.code = this.$route.query.code ? this.$route.query.code : "";
        this.searchForm.name = "";
        this.searchForm.phone = "";
        this.searchForm.typeCode = "";
        this.searchForm.state = "";
        this.searchForm.recordName = "";
        this.searchForm.unitName = "";
        this.searchForm.sortType = "desc";
        this.init();
        this.initType();
        if (!this.branchCode) {
          this.initBranch();
        }
      }
    },
  },
  methods: {
    stateFilter(val) {
      let type = "";
      stateArr.forEach((item) => {
        if (item.state === val) {
          type = item.type;
        }
      });
      return type;
    },
    plainFilter(val) {
      let effect = "";
      stateArr.forEach((item) => {
        if (item.state === val) {
          effect = item.effect;
        }
      });
      return effect;
    },

    switechBranch(branchCode) {
      switch (branchCode) {
        case "5":
          return "镇江市区";
        case "17":
          return "丹阳市";
        case "18":
          return "句容市";
        case "19":
          return "扬中市";
      }
    },
    init() {
      this.tableData = [];
      this.loading = true;
      // console.log(1);
      // console.log("this.branchCode---", this.branchCode);
      let params = {
        sortType: this.searchForm.sortType,
        name: this.searchForm.name,
        phone: this.searchForm.phone,
        typeCode: this.searchForm.typeCode,
        state: this.searchForm.state,
        recordName: this.searchForm.recordName,
        unitName: this.searchForm.unitName,
        branchCode: this.branchCode
          ? this.branchCode
          : this.searchForm.branchCode,
        pageNum: this.pagination.currentPage,
        pageSize: this.pagination.pageSize,
        talentClassification: this.searchForm.talentClassification, // 人才分类
        socialPremiumLocation: this.switechBranch(this.code), // 社保缴纳地
      };

      // console.log("params-----", params);
      getList(params).then((res) => {
        this.loading = false;

        if (res.success) {
          this.pagination.total = res.data.total;
          if (res.data.total) {
            this.tableData = res.data.list.map((item) => {
              console.log("人才码列表----", item);
              item.updateTime = item.updateTime?.substring(0, 10);
              item.stateName = this.getSatusArr(item.state).stateName;
              item.type = this.getSatusArr(item.state).type;
              return item;
            });
            var date = new Date();
            var time = date.getTime();
            var oneDay = 1000 * 60 * 60 * 24;
            this.tableData = this.tableData.map((item) => {
              item.overdue = Math.floor(
                (time - new Date(item.updateTime).getTime()) / oneDay
              );
              return item;
            });
            if (localStorage.getItem("userName") == "admin") {
              this.tableData = changeList(this.tableData);
            }
          } else {
            this.tableData = [];
          }
        }
      });
    },
    initType() {
      this.typeList = [
        {
          typeCode: "",
          typeName: "全部",
        },
      ];
      getType().then((res) => {
        console.log(res);
        if (res.code == 200) {
          console.log("initType--->", res);
          this.typeList = this.typeList.concat(res.data);
        }
      });
    },
    initBranch() {
      this.branchList = [
        {
          branchCode: "",
          branchName: "全部",
        },
      ];
      getBranch({}).then((res) => {
        this.branchList = this.branchList.concat(res.data);
        console.log("this.branchList----", this.branchList);
      });
    },
    jumpPage() {
      this.init();
    },
    onSubmit() {
      this.pagination.currentPage = 1;
      this.init();
    },
    view(row) {
      let params = {
        talentCode: row.talentCode,
      };
      get(params).then((res) => {
        this.viewDetail = res.data;
        // this.viewDetail.idCard = decryptByDES(res.data.idCard, "MnuYbhGv");
        this.viewRow = row;
        this.viewShow = true;
      });
    },
    getRecord(row) {
      let params = {
        talentCode: row.talentCode,
      };
      getRecord(params).then((res) => {
        this.record = res.data.map((item) => {
          item.stateName = this.getSatusArr(item.state)
            ? this.getSatusArr(item.state).stateName
            : "未知状态";
          return item;
        });
        this.recordShow = true;
      });
    },

    print(talentCode, row) {
      // console.log("row---", row);
      get({ talentCode }).then((res) => {
        // console.log(res);
        let arr = res.data;
        arr.nation = arr.nation ? arr.nation : "";
        arr.politicalFace = arr.politicalFace ? arr.politicalFace : "";
        arr.major = arr.major ? arr.major : "";
        // arr.highestDegree = arr.highestDegree ? arr.highestDegree : "";
        arr.awardingUnit = arr.awardingUnit ? arr.awardingUnit : "";
        arr.timeGrant = arr.timeGrant ? arr.timeGrant : "";
        arr.unitTypeName = arr.unitType === "1" ? "企业" : "事业单位(专技人员)";
        arr.sexName = arr.sex === 0 ? "男" : "女";
        arr.adoptTime = row.state === 3 ? arr.adoptTime : "";
        arr.promiseDes = arr.promise ? "已上传" : "未上传";
        arr.pictureDes = arr.pictureList.length > 0 ? "已上传" : "未上传";
        arr.educationDes = arr.education ? "已验证" : "未上传";
        arr.studentStatusDes = arr.studentStatus ? "已验证" : "未上传";
        let docxsrc = "./static/talents.docx"; //模板文件的位置
        let docxname = "人才码审核表"; //导出文件的名字
        // 读取并获得模板文件的二进制内容
        JSZipUtils.getBinaryContent(docxsrc, function (error, content) {
          // docxsrc是模板。我们在导出的时候，会根据此模板来导出对应的数据
          // 抛出异常
          if (error) {
            throw error;
          }
          // 创建一个PizZip实例，内容为模板的内容
          // console.log(content);
          // console.log(error);

          let zip = new PizZip(content);
          // 创建并加载docx templater实例对象
          let doc = new docxtemplater().loadZip(zip);
          // 设置模板变量的值
          doc.setData({
            ...arr, // e中的数据可以再模板中直接使用
          });
          try {
            // 用模板变量的值替换所有模板变量
            doc.render();
          } catch (error) {
            // 抛出异常
            let e = {
              message: error.message,
              name: error.name,
              stack: error.stack,
              properties: error.properties,
            };
            console.log(
              JSON.stringify({
                error: e,
              })
            );
            throw error;
          }
          // 生成一个代表docxtemplater对象的zip文件（不是一个真实的文件，而是在内存中的表示）
          let out = doc.getZip().generate({
            type: "blob",
            mimeType:
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
          });
          // 将目标文件对象保存为目标类型的文件，并命名
          saveAs(out, docxname);
        });
      });
    },
    pass(row) {
      if (this.viewDetail.educationState === 0) {
        this.$message.error("学历验证未通过，请先通过学历验证！");
        return;
      }
      this.$confirm("确定通过该人才的申请吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = {
            talentCode: row.talentCode,
            userName: this.userName,
            state: 2,
          };
          updateState(params).then((res) => {
            console.log(res);
            Message.success("审核通过");
            this.viewShow = false;
            this.init();
          });
        })
        .catch(() => {
          // console.log("取消审核");
        });
    },
    passEducation() {
      if (this.viewDetail.educationState !== 0) return;
      educationState({
        educationState: 1,
        talentCode: this.viewDetail.talentCode,
      }).then((res) => {
        // console.log("审核按钮res-----", res);
        if (res.success) {
          this.viewDetail.educationState = 1;
          this.init();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    viewEdu() {
      educationQuery({
        idCard: this.viewDetail.idCard
          ? encryptByDES(this.viewDetail.idCard, "MnuYbhGv")
          : "",
        name: this.viewDetail.name,
      }).then((res) => {
        if (res.success) {
          if (res.data.data && res.data.data.length > 0) {
            this.showEdu = true;
            this.eduList = res.data.data;
          } else {
            this.$message.error(res.data.msg);
          }
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    refuseSelect(val) {
      // console.log("--------", val);
      this.refuseTextarea = val
        ? this.refuseOptions.find((ele) => ele.value === val).label
        : "";
    },
    // 拒绝对话框
    deny(talentCode) {
      this.refuseDialog = true;
      this.refuseCode = talentCode;
    },
    cancelBtn() {
      this.refuseTextarea = null;
      this.refuseValue = "";
      this.refuseDialog = false;
    },
    successBtn() {
      if (this.refuseTextarea === null || this.refuseTextarea == "") {
        this.$message.error("未输入拒绝原因");
      } else {
        // console.log("this.refuseTextarea----", this.refuseTextarea);
        // console.log("this.refuseCode----", this.refuseCode);
        let params = {
          talentCode: this.refuseCode.talentCode,
          userName: this.userName,
          state: 5,
          reason: this.refuseTextarea,
        };
        updateState(params).then((res) => {
          console.log("res---", res);
          Message.success("审核拒绝");
          this.viewShow = false;
          this.init();
        });
        this.refuseDialog = false;
      }
    },
    // deny(talentCode) {
    //   console.log('talentCode----',talentCode);

    //   this.$prompt("确定拒绝该人才的申请吗?确定的话，请输入拒绝原因。", "提示", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     inputPlaceholder: "请输入拒绝原因",
    //     inputType: "textarea",
    //   })
    //     .then(({ value }) => {
    //       if (!value) {
    //         this.$message.error("未输入拒绝原因");
    //       } else {
    //         let params = {
    //           talentCode,
    //           userName: this.userName,
    //           state: 5,
    //           reason: value,
    //         };
    //         updateState(params).then((res) => {
    //           console.log(res);
    //           Message.success("审核拒绝");
    //           this.init();
    //         });
    //       }
    //     })
    //     .catch(() => {
    //       console.log("取消");
    //     });
    // },
    pause(talentCode) {
      this.$confirm("确定暂停该人才的公示吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = {
            talentCode,
            userName: this.userName,
            state: 4,
          };
          updateState(params).then((res) => {
            console.log(res);
            Message.success("暂停成功");
            this.init();
          });
        })
        .catch(() => {
          // console.log("取消暂停");
        });
    },
    recover(talentCode) {
      this.$confirm("确定恢复该人才的公示吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let params = {
            talentCode,
            userName: this.userName,
            state: 2,
          };
          updateState(params).then((res) => {
            console.log(res);
            Message.success("恢复成功");
            this.init();
          });
        })
        .catch(() => {
          // console.log("取消恢复");
        });
    },
    blacklist(talentCode) {
      this.$prompt(
        "确定撤销该申请吗?此操作后去需要重亲提交申请！确定的话，请输入原因。",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          inputPlaceholder: "请输入原因",
          inputType: "textarea",
        }
      )
        .then(({ value }) => {
          if (!value) {
            this.$message.error("未输入拒绝原因");
          } else {
            let params = {
              talentCode,
              userName: this.userName,
              state: 6,
              reason: value,
            };
            updateState(params).then((res) => {
              console.log(res);
              Message.success("撤销成功");
              this.init();
            });
          }
        })
        .catch(() => {
          // console.log("取消");
        });
    },
    getSatusArr(state) {
      return stateArr.filter((item) => {
        return item.state === state;
      })[0];
    },
  },
  created() {
    this.userName = localStorage.getItem("userName");
    this.branchCode = this.$route.query.branchCode
      ? this.$route.query.branchCode
      : "";
    this.code = this.$route.query.code ? this.$route.query.code : "";
    this.init();
    this.initType();
    if (!this.branchCode) {
      this.initBranch();
    }
  },
};
</script>

<style lang="stylus" scoped>
@import '~@/stylus/common';
.table-wrapper1{
    margin-top: 20px;
    padding: 15px;
    background: #fff;
    border-radius: 5px;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);
    max-height: calc(100vh - 320px);
    overflow: auto;
}
.el-form-item {
  margin-right:5px
}
.early, .warning {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-block;
}

.early {
  background: #FFD700;
}

.warning {
  background: red;
}

.content {
  max-height: 60vh;
  overflow-y: auto;

  .cell {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;

    .label {
      width: 150px;
      color: #999;
      text-align: left;

      span {
        color: red;
        font-size: 12px;
      }
    }

    .value {
      color: #000;
      text-align: left;
    }

    .info {
      .item {
        width: 100%;
        text-align: left;
        color: #000;
        margin-bottom: 10px;
      }

      .item:last-child {
        margin-bottom: 0;
      }
    }
  }
}

.refuseDialog {
  /deep/.el-select {
    width: 100%;
    margin: 20px 0;
  }

  /deep/textarea {
    height: 100px !important;
  }
}

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-thumb {
  background-color: #a1a3a9;
  border-radius: 2px;
}
</style>
