<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <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>
        <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="RenCaiLogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column width="100" label="序号" align="center" prop="">
        <template slot-scope="scope">
          {{ getXvhao(scope.$index, queryParams) }}
        </template>
      </el-table-column>
      <el-table-column width="160" label="操作类别" align="center" prop="LeiBie" />
      <el-table-column label="操作内容" align="center" prop="CaoZuo" />
      <el-table-column width="220" label="操作人" align="center" prop="LoginName" />
      <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>

    <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" type="textarea" 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="操作人id" prop="LoginID">
          <el-input v-model="form.LoginID" placeholder="请输入操作人id" />
        </el-form-item>
        <el-form-item label="操作人账号" prop="LoginUser">
          <el-input v-model="form.LoginUser" placeholder="请输入操作人账号" />
        </el-form-item>
        <el-form-item label="操作人姓名" prop="LoginName">
          <el-input v-model="form.LoginName" placeholder="请输入操作人姓名" />
        </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>
      <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 { listRenCaiLog, getRenCaiLog, delRenCaiLog, addRenCaiLog, updateRenCaiLog } from "@/api/system/RenCaiLog";

export default {
  name: "RenCaiLog",
  dicts: ['caozuo_type',],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人才操作日志表格数据
      RenCaiLogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        LeiBie: null,
        RenCaiID: null,
        CaoZuo: null,
        LoginID: null,
        LoginUser: null,
        LoginName: null,
        WriteTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询人才操作日志列表 */
    getList() {
      this.loading = true;
      listRenCaiLog(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.RenCaiLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: null,
        LeiBie: null,
        RenCaiID: null,
        CaoZuo: null,
        LoginID: null,
        LoginUser: null,
        LoginName: null,
        WriteTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.pageNum = 1;
      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
      getRenCaiLog(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) {
            updateRenCaiLog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRenCaiLog(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 delRenCaiLog(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/RenCaiLog/export', {
        ...this.queryParams
      }, `RenCaiLog_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
