<template>
  <!-- 弹出框表单 -->
  <el-drawer
    :title="title"
    :visible.sync="open"
    :direction="direction"
    :destroy-on-close="true"
    size="50%"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <Field
          label="核查记录Id"
          prop="checkRecordId"
          v-model="form.checkRecordId"
          placeholder="请输入核查记录Id"
        />
        <Field
          label="员工ID"
          prop="staffId"
          v-model="form.staffId"
          placeholder="请输入员工ID"
        />
        <Field
          label="员工姓名"
          prop="staffName"
          v-model="form.staffName"
          placeholder="请输入员工姓名"
        />
        <Field
          label="工号"
          prop="workNum"
          v-model="form.workNum"
          placeholder="请输入工号"
        />
        <Field
          label="所属部门"
          prop="deptId"
          v-model="form.deptId"
          placeholder="请输入所属部门"
        />
        <Field
          label="所属部门名称"
          prop="deptName"
          v-model="form.deptName"
          placeholder="请输入所属部门名称"
        />
        <Field
          label="所属考勤组ID"
          prop="attendanceGroupId"
          v-model="form.attendanceGroupId"
          placeholder="请输入所属考勤组ID"
        />
        <Field
          label="所属考勤组名称"
          prop="attendanceGroupName"
          v-model="form.attendanceGroupName"
          placeholder="请输入所属考勤组名称"
        />
        <Field
          label="考勤时间"
          prop="attendanceDate"
          v-model="form.attendanceDate"
          type="date"
        />
        <Field
          label="绩效规则id"
          prop="ruleId"
          v-model="form.ruleId"
          placeholder="请输入绩效规则id"
        />
        <Field
          label="规则名称"
          prop="ruleName"
          v-model="form.ruleName"
          placeholder="请输入规则名称"
        />
        <Field
          label="扣分方式"
          prop="subMethod"
          v-model="form.subMethod"
          type="select"
          :enumData="dict.subMethod"
          placeholder="请选择扣分方式"
        />
        <Field
          label="增减类型"
          prop="subAddType"
          v-model="form.subAddType"
          type="select"
          :enumData="dict.subAddType"
          placeholder="请选择增减类型"
        />
        <Field
          label="扣分或增加分值"
          prop="score"
          v-model="form.score"
          placeholder="请输入扣分或增加分值"
        />
        <Field
          label="上下班时间"
          prop="goOffTimeStr"
          v-model="form.goOffTimeStr"
          placeholder="请输入上下班时间"
        />
        <Field
          label="异常时间"
          prop="errorTime"
          v-model="form.errorTime"
          type="date"
        />
        <Field
          label="实际打卡时间"
          prop="actualAttendTime"
          v-model="form.actualAttendTime"
          type="date"
        />
        <Field
          label="异常处理结果"
          prop="errorResult"
          v-model="form.errorResult"
          placeholder="请输入异常处理结果"
        />
        <Field
          label="核查人员"
          prop="checkPerson"
          v-model="form.checkPerson"
          placeholder="请输入核查人员"
        />
        <Field
          label="核查时间"
          prop="checkTime"
          v-model="form.checkTime"
          type="date"
        />
        <Field
          label="核查说明"
          prop="checkDesc"
          v-model="form.checkDesc"
          type="textarea"
          placeholder="请输入核查说明"
        />
        <Field
          label="核查结果"
          prop="checkResult"
          v-model="form.checkResult"
          placeholder="请输入核查结果"
        />
        <Field
          label="处理状态"
          prop="processStatus"
          v-model="form.processStatus"
          type="select"
          :enumData="dict.processStatus"
          placeholder="请选择处理状态"
        />
        <Field
          label="申诉说明"
          prop="appealDesc"
          v-model="form.appealDesc"
          placeholder="请输入申诉说明"
        />
        <Field
          label="申诉时间"
          prop="appealTime"
          v-model="form.appealTime"
          type="date"
        />
        <Field
          label="申诉结果"
          prop="appealResult"
          v-model="form.appealResult"
          type="select"
          :enumData="dict.appealResult"
          placeholder="请选择申诉结果"
        />
        <Field
          label="说明"
          prop="remark"
          v-model="form.remark"
          type="textarea"
          placeholder="请输入说明"
        />
      </el-row>
      <el-divider content-position="center"
        >绩效记录申诉附件信息信息</el-divider
      >
      <br />
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAddPerformAttendAppealFiles"
            >添加</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            @click="handleDeletePerformAttendAppealFiles"
            >删除</el-button
          >
        </el-col>
      </el-row>

      <el-table
        :data="performAttendAppealFilesList"
        :row-class-name="rowPerformAttendAppealFilesIndex"
        @selection-change="handlePerformAttendAppealFilesSelectionChange"
        ref="performAttendAppealFiles"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="序号" align="center" prop="index" width="50" />
        <el-table-column label="文件名称" prop="fileName">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.fileName"
              placeholder="请输入文件名称"
            />
          </template>
        </el-table-column>
        <el-table-column label="文件地址" prop="filePath">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.filePath"
              placeholder="请输入文件地址"
            />
          </template>
        </el-table-column>
        <el-table-column label="创建用户" prop="createUserId">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.createUserId"
              placeholder="请输入创建用户"
            />
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="createTime">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.createTime"
              placeholder="请输入创建时间"
            />
          </template>
        </el-table-column>
        <el-table-column label="更新用户" prop="updateUserId">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.updateUserId"
              placeholder="请输入更新用户"
            />
          </template>
        </el-table-column>
        <el-table-column label="更新时间" prop="updateTime">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.updateTime"
              placeholder="请输入更新时间"
            />
          </template>
        </el-table-column>
      </el-table>

      <form-buttons
        @submit="submitForm"
        v-if="pageInfo.type != 'view'"
        noCancelBtn
      />
    </el-form>
  </el-drawer>
</template>

<script>
import form from "@/assets/mixins/formdialog";
export default {
  name: "PerformAttendAppealDetail",
  mixins: [form],
  components: {},
  created() {
    this.changePath("perform/attend/appeal");
  },
  data() {
    return {
      // 子表选中数据
      checkedPerformAttendAppealFiles: [],
      // 绩效记录申诉附件信息表格数据
      performAttendAppealFilesList: [],
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "绩效记录申诉信息",
      // 是否显示弹出层
      open: false,
      direction: "rtl",
      toString: ["subMethod", "subAddType", "processStatus", "appealResult"],
      toDate: [
        "attendanceDate",
        "errorTime",
        "actualAttendTime",
        "checkTime",
        "appealTime",
      ],
      // 表单校验
      rules: {
        staffName: [
          { required: true, message: "请输入员工姓名", trigger: "blur" },
          { max: 64, message: "最多只能录入64个字符", trigger: "blur" },
        ],
        createTime: [{ required: true, message: "请选择创建时间" }],
      },
    };
  },

  methods: {
    /** 绩效记录申诉附件信息序号 */
    rowPerformAttendAppealFilesIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 绩效记录申诉附件信息添加按钮操作 */
    handleAddPerformAttendAppealFiles() {
      let obj = {};
      obj.fileName = "";
      obj.filePath = "";
      obj.createUserId = "";
      obj.createTime = "";
      obj.updateUserId = "";
      obj.updateTime = "";
      this.performAttendAppealFilesList.push(obj);
    },
    /** 绩效记录申诉附件信息删除按钮操作 */
    handleDeletePerformAttendAppealFiles() {
      if (this.checkedPerformAttendAppealFiles.length == 0) {
        this.$alert("请先选择要删除的绩效记录申诉附件信息数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.performAttendAppealFilesList.splice(
          this.checkedPerformAttendAppealFiles[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handlePerformAttendAppealFilesSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.performAttendAppealFiles.clearSelection();
        this.$refs.performAttendAppealFiles.toggleRowSelection(selection.pop());
      } else {
        this.checkedPerformAttendAppealFiles = selection;
      }
    },
    // 渲染前置处理
    beforeRender(data) {
      if (data.entity.performAttendAppealFilesList) {
        this.performAttendAppealFilesList =
          data.entity.performAttendAppealFilesList;
      }
      return data;
    },
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "perform/attend/appeal/edit";
      this.getData();
      this.pageInfo.type = "edit";
      this.title = "修改绩效记录申诉信息";
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "perform/attend/appeal/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增绩效记录申诉信息";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "perform/attend/appeal/view";
      this.getData();
      this.pageInfo.type = "view";
      this.title = "绩效记录申诉信息详细";
    },
    /**取消按钮 */
    cancel() {
      this.open = false;
    },
    /**获取数据后弹框 */
    afterRender(data) {
      this.open = true;
    },

    afterSubmit(data) {
      this.open = false;
      this.$emit("ok");
    },

    // 表单重置
    reset() {
      this.form = {
        checkRecordId: null,
        staffId: null,
        staffName: "",
        workNum: "",
        deptId: null,
        deptName: "",
        attendanceGroupId: null,
        attendanceGroupName: "",
        attendanceDate: null,
        ruleId: null,
        ruleName: "",
        subMethod: 1,
        subAddType: 1,
        score: 0.0,
        goOffTimeStr: "",
        errorTime: null,
        actualAttendTime: null,
        errorResult: "",
        checkPerson: "",
        checkTime: null,
        checkDesc: "",
        checkResult: "",
        processStatus: 1,
        appealDesc: "",
        appealTime: null,
        appealResult: 2,
        remark: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
