<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="78px">
      <el-form-item label="操作类别" prop="LeiBie">
        <el-select v-model="queryParams.LeiBie" placeholder="请选择操作类别" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.caozuo_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="操作内容" prop="CaoZuo">
        <el-input v-model="queryParams.CaoZuo" placeholder="请输入操作内容" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="操作日期">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"></el-date-picker>
      </el-form-item>
      <el-form-item label="证书变更状态" label-width="110px" prop="isSuccess">
        <el-select v-model="queryParams.isSuccess" placeholder="请选择证书变更状态" clearable>
          <el-option v-for="dict in dict.type.zsbg_type" :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-table v-loading="loading" :data="RenCaiZSYxqLogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="">
        <template slot-scope="scope">
          {{ getXvhao(scope.$index, queryParams) }}
        </template>
      </el-table-column>
      <el-table-column label="操作类别" align="center" prop="LeiBie" />
      <el-table-column label="人员表ID" align="center" prop="RenCaiID" />
      <el-table-column label="人员姓名" align="center" prop="RenCaiName" />
      <el-table-column label="操作内容" align="center" prop="CaoZuo" />
      <el-table-column label="变更前日期" align="center" prop="oldJLYxq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.oldJLYxq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="变更后日期" align="center" prop="newJLYxq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.newJLYxq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="变更时间" align="center" prop="WriteTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.WriteTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="状态" align="center" prop="isSuccess">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.jxjy_bgsfcg" :value="scope.row.isSuccess" />
        </template>
      </el-table-column>
      <el-table-column label="考试通过时间" align="center" prop="WriteTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.WriteTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['jlry:RenCaiZSYxqLog:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['jlry:RenCaiZSYxqLog: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="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="操作类别" prop="LeiBie">
          <el-input v-model="form.LeiBie" placeholder="请输入操作类别" />
        </el-form-item>
        <el-form-item label="人员id" prop="RenCaiID">
          <el-input v-model="form.RenCaiID" placeholder="请输入人员id" />
        </el-form-item>
        <el-form-item label="人才姓名" prop="RenCaiName">
          <el-input v-model="form.RenCaiName" placeholder="请输入人才姓名" />
        </el-form-item>
        <el-form-item label="操作说明" prop="CaoZuo">
          <el-input v-model="form.CaoZuo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="变更前监理工程师有效期" prop="oldJLYxq">
          <el-date-picker clearable v-model="form.oldJLYxq" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择变更前监理工程师有效期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="变更后监理工程师有效期" prop="newJLYxq">
          <el-date-picker clearable v-model="form.newJLYxq" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择变更后监理工程师有效期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="变更时间" prop="WriteTime">
          <el-date-picker clearable v-model="form.WriteTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择变更时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否成功更新证书有效期，1：成功，0：未成功" prop="isSuccess">
          <el-select v-model="form.isSuccess" placeholder="请选择是否成功更新证书有效期，1：成功，0：未成功">
            <el-option v-for="dict in dict.type.jxjy_bgsfcg" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
      </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>
  </div>
</template>

<script>
import { listRenCaiZSYxqLog, getRenCaiZSYxqLog, delRenCaiZSYxqLog, addRenCaiZSYxqLog, updateRenCaiZSYxqLog } from "@/api/jlry/RenCaiZSYxqLog";

export default {
  name: "RenCaiZSYxqLog",
  dicts: ['jxjy_bgsfcg', 'caozuo_type', 'zsbg_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 证书有效期变更日志表格数据
      RenCaiZSYxqLogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        LeiBie: null,
        RenCaiID: null,
        RenCaiName: null,
        CaoZuo: null,
        oldJLYxq: null,
        newJLYxq: null,
        WriteTime: null,
        isSuccess: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询证书有效期变更日志列表 */
    getList() {
      this.loading = true;
      listRenCaiZSYxqLog(this.queryParams).then(response => {
        this.RenCaiZSYxqLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: null,
        LeiBie: null,
        RenCaiID: null,
        RenCaiName: null,
        CaoZuo: null,
        oldJLYxq: null,
        newJLYxq: null,
        WriteTime: null,
        isSuccess: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      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
      getRenCaiZSYxqLog(ID).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改证书有效期变更日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ID != null) {
            updateRenCaiZSYxqLog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRenCaiZSYxqLog(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.ID || this.ids;
      this.$modal.confirm('是否确认删除证书有效期变更日志编号为"' + IDs + '"的数据项？').then(function () {
        return delRenCaiZSYxqLog(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('jlry/RenCaiZSYxqLog/export', {
        ...this.queryParams
      }, `RenCaiZSYxqLog_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
