<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="期次" prop="qi">
        <el-cascader v-model="queryParams.qi" placeholder="请选择期次" :props="prop" :options="options" @change="handleChange">
          <template :slot-scope="{ node, data }">
            <span v-if="data.children != null">{{ data.year + '年' }}</span>
            <span v-else> {{ '第 ' + data.year + ' 期' }} </span>
          </template>
        </el-cascader>
      </el-form-item>
      <el-form-item label="姓名" prop="UserName">
        <el-input v-model="queryParams.UserName" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证" prop="UserCord">
        <el-input v-model="queryParams.UserCord" placeholder="请输入身份证" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>


      <el-form-item label="地点" prop="City" v-hasRole="['xiehui']">
        <el-select v-model="queryParams.City" placeholder="请选择地点" clearable>
          <el-option v-for="dict in dict.type.zgks_address" :key="dict.label" :label="dict.label" :value="dict.label" />
        </el-select>
      </el-form-item>
      <el-form-item label="培训类别" prop="ZYIdList">
        <el-select v-model="queryParams.ZYIdList" placeholder="请选择培训类别" clearable>
          <el-option v-for="dict in dict.type.jxjy_zhuanye" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" 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" plain icon="el-icon-unlock" size="mini" :disabled="multiple"
          @click="handleUnlock">批量解锁</el-button>
      </el-col></el-row> -->
    <el-table v-loading="loading" :data="ZigePersonList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="80" prop="PersonId">
        <template slot-scope="scope">
          {{ getXvhao(scope.$index, queryParams) }}
        </template>
      </el-table-column>
      <el-table-column label="期次" width="130" align="center" prop="ZYIdList">
        <template slot-scope="scope">
          <span>{{
            scope.row.QiciYear + "年 第" + scope.row.QiCi + "期"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="地点" align="center" prop="ZYIdList">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zgks_address" :value="scope.row.City" />
        </template>
      </el-table-column>
      <el-table-column width="130" label="姓名" align="center" prop="UserName">
        <template slot-scope="scope">
          <el-button type="text" @click="handleUpdate(scope.row, false)">
            <span style="">
              {{
                scope.row.UserName
              }}
            </span>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="UserSex" />
      <el-table-column label="身份证" width="170" align="center" prop="UserCord" />
      <el-table-column label="手机号码" width="110" align="center" prop="UserPhone" />
      <el-table-column width="110" label="培训类别" align="center">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.jxjy_zhuanye" :value="scope.row.ZYIdList" />
        </template>
      </el-table-column>
      <el-table-column width="260" label="执业单位" align="center" prop="DeptName" />
      <el-table-column width="150" label="报名时间" align="center" prop="UserPwd">
        <template slot-scope="scope">
          {{ parseTime(scope.row.AddDate, "{y}-{m}-{d} {h}:{i}:{s}") }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="是否通过" align="center" prop="pxshenhe">
        <template slot-scope="scope">
          {{
            scope.row.pxshenhe == null
            ? "" : scope.row.pxshenhe == 0 ? '待审核'
              : scope.row.pxshenhe == 2
                ? "不通过"
                : scope.row.pxshenhe == 1
                  ? "审核通过"
                  : "材料补正"
          }}
        </template>
      </el-table-column> -->
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-unlock" @click="handleUnlock(scope.row)">恢复资格考试报名</el-button>
          <!-- <el-button size="mini" type="text" icon="el-icon-view" @click="handleUpdate(scope.row, false)">详细</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="报名信息" top="3vh" :visible.sync="open" width="75%" :close-on-click-modal="false">
      <div style="
          height: 74vh;
          overflow-y: auto;
          overflow-x: hidden;
          padding-top: 0;
        " class="pd-10">
        <component ref="zgks" :is="zgks" :info="zgksInfo" :type="1" :xiugai="xiugaiType" @submitSuccess="submitSuccess">
        </component>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="xiugaiType == true">修 改</el-button>
        <!-- <el-button @click="cancel">取 消</el-button> -->
        <el-button @click="cancel">{{ xiugaiType == true ? '取 消' : '关 闭' }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listZigePerson,
  getZigePerson,
  delZigePerson,
  addZigePerson,
  updateZigePerson,
  unlockZigePerson,
  zsyxqxqList
} from "@/api/xiehui/zgks/ZigePerson";
import { searchZgksQici } from "@/api/xiehui/zgks/ZigeTraining"
import jly from "../../../components/baoming/jly.vue";
import zj from "../../../components/baoming/zj.vue";
import jlgcs from "../../../components/baoming/jlgcs.vue";
export default {
  name: "ZigePerson",
  dicts: ["jxjy_shenhe", "jxjy_zhuanye", "zgks_address"],
  components: {
    jly,
    zj,
    jlgcs,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资格考试报名表格数据
      ZigePersonList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      xuqiNow: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lockStatus: 1,
        UserName: null,
        UserCord: null,
        QiciYear: null,
        QiCi: null,
        // DeptName: null,
        City: null,
        ZYIdList: null,
        orderByColumn: "adddate",
        isAsc: "desc",
        qi: null,
        BMdept: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      zgks: null,
      zgksInfo: null,
      xiugaiType: false,
      options: [],
      prop: {
        label: "year",
        value: "year"
      }
    };
  },
  created() {
    this.queryParams.BMdept = this.$store.getters.userInfo.id
    this.qiciSearch()
    this.getList();
  },
  methods: {

    // getListXuQi() {

    // },
    qiciSearch() {
      searchZgksQici().then(res => {
        this.options = res.data
      })
    },
    //选择期次
    handleChange(e) {
      this.queryParams.QiciYear = e[0]
      this.queryParams.QiCi = e[1]
    },
    handleUnlock(row) {
      let ids = this.ids.join(',')
      const PersonId = row.PersonId || ids;
      this.$confirm("是否恢复资格考试报名?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(function () {
        return unlockZigePerson({ personIdsStr: PersonId, TrainId: row.TrainId });
      })
        .then(() => {
          // this.$modal.msgSuccess("解锁成功");
          this.getList()
          this.$modal.msgSuccess("恢复成功")
        });
    },
    /** 查询资格考试报名列表 */
    getList() {
      this.loading = true;
      listZigePerson(this.queryParams).then((response) => {
        this.ZigePersonList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        PersonId: null,
        TrainId: null,
        ZYIdList: null,
        UserName: null,
        UserPwd: null,
        UserSex: null,
        UserCord: null,
        UserDate: null,
        UserPhone: null,
        UserEmail: null,
        City: null,
        ZcsZhuanYe: null,
        ZhuanYeType: null,
        Zsbh: null,
        Yxqz: null,
        BMdept: null,
        DeptName: null,
        DeptTel: null,
        DeptLxr: null,
        DeptLxrPhone: null,
        DeptEmail: null,
        DeptAddress: null,
        DeptZipcode: null,
        FeeFlg: null,
        Bzq: null,
        AddDate: null,
        OverFlg: null,
        QianFaDate: null,
        BeiZhu: null,
        ShenHe: null,
        PeiXunFlg: null,
        Undef1: null,
        Undef2: null,
        Undef3: null,
        Undef4: null,
        Undef5: null,
        wanchengflg: null,
        zongxueshi: null,
        BYschool: null,
        xueli: null,
        zhicheng: null,
        ZCpizhunDept: null,
        minzu: null,
        zygznx: null,
        jlgznx: null,
        zcpdsj: null,
        sxzy: null,
        zhiwu: null,
        bmfs: null,
        grshenhe: null,
        pxshenhe: null,
        pxshyj: null,
        zhichengZhuanYe: null,
        BYTime: null,
        KplxFlg: null,
        KpGRName: null,
        kpzcdz: null,
        kpzcdh: null,
        kpkhyh: null,
        kpyhzh: null,
        kpGRemail: null,
        dzfpyx: null,
        sjr: null,
        sjrsj: null,
        yjdz: null,
        yjbm: null,
        kplx: null,
        kpfs: null,
        kpdw: null,
        nsrsbh: null,
        zsyxq: null,
        zgzsh: null,
        sfsgz: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.QiciYear = null
      this.queryParams.QiCi = null
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.PersonId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加资格考试报名";
    },
    /** 修改按钮操作 */
    handleUpdate(row, type) {
      this.reset();
      const PersonId = row.PersonId || this.ids;
      this.xiugaiType = type == undefined ? true : false;
      this.loading = true;
      getZigePerson(PersonId).then((response) => {
        this.form = response.data;

        if (response.data.ZcsZhuanYe == "8" || response.data.ZcsZhuanYe == "监理工程师") {
          this.zgks = "jlgcs";
        } else if (response.data.ZcsZhuanYe == "28" || response.data.ZcsZhuanYe == '监理员') {
          this.zgks = "jly";
        } else {
          this.zgks = "zj";
        }
        this.zgksInfo = response.data;
        this.loading = false;
        this.open = true;
      });
    },
    //审核
    shenhe(row) {
      this.reset();
      const PersonId = row.PersonId || this.ids;
      getZigePerson(PersonId).then((response) => {
        this.form = response.data;
        this.$msgbox({
          title: "提示",
          message: "审核通过？",
          showCancelButton: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          beforeClose: (action, instance, done) => {
            if (action === "confirm") {
              instance.confirmButtonLoading = true;
              instance.confirmButtonText = "执行中...";
              this.form.grshenhe = 1;
              updateZigePerson(this.form).then((response) => {
                done();
                setTimeout(() => {
                  instance.confirmButtonLoading = false;
                  this.$modal.msgSuccess("审核成功");
                }, 300);
                this.getList();
              });
            } else {
              done();
            }
          },
        });
      });
    },
    changeYear() {
      if (this.queryParams.QiciYear == null) {
        this.queryParams.QiCi = null
      }
    },
    //撤回
    chehui(row) {
      this.reset();
      const PersonId = row.PersonId || this.ids;
      getZigePerson(PersonId).then((response) => {
        this.form = response.data;
        this.$msgbox({
          title: "提示",
          message: "确认撤回吗？",
          showCancelButton: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          beforeClose: (action, instance, done) => {
            if (action === "confirm") {
              instance.confirmButtonLoading = true;
              instance.confirmButtonText = "执行中...";
              this.form.grshenhe = 2;
              updateZigePerson(this.form).then((response) => {
                done();
                setTimeout(() => {
                  instance.confirmButtonLoading = false;
                  this.$modal.msgSuccess("撤回成功");
                }, 300);
                this.getList();
              });
            } else {
              done();
            }
          },
        });
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs.zgks.submit();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const PersonIds = row.PersonId || this.ids;
      this.$modal
        .confirm('是否确认删除资格考试报名编号为"' + PersonIds + '"的数据项？')
        .then(function () {
          return delZigePerson(PersonIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "zgks/ZigePerson/export",
        {
          ...this.queryParams,
        },
        `ZigePerson_${new Date().getTime()}.xlsx`
      );
    },
    //修改提交成功回调
    submitSuccess(e) {
      this.$refs.zgks.reset();
      this.open = false;
      this.getList();
    },
    // 取消按钮
    cancel() {
      this.$refs.zgks.reset();
      this.open = false;
    },
  },
};
</script>
<style scoped>
.el-form-item--small.el-form-item {
  margin-bottom: 6px;
}
</style>
