<template>
  <!-- 弹出框表单 -->
  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <Field
          disabled
          label="请假人"
          prop="leavePerson"
          v-model="form.leavePerson"
          placeholder="请输入请假人"
        />
        <Field
          disabled
          label="所属部门"
          prop="deptName"
          v-model="form.deptName"
          type="textarea"
          placeholder="请输入所属部门"
        />
        <Field
          disabled
          label="电话号码"
          prop="phoneNumber"
          v-model="form.phoneNumber"
          placeholder="请输入电话号码"
        />
        <Field
          disabled
          label="请假类型"
          prop="leaveType"
          v-model="form.leaveType"
          type="select"
          :enumData="dict.leaveType"
          placeholder="请选择请假类型"
        />
        <Field
          disabled
          label="开始时间"
          prop="startTime"
          v-model="form.startTime"
          type="datetime"
        />
        <Field
          label="结束时间"
          prop="endTime"
          v-model="form.endTime"
          type="datetime"
          disabled
        />

        <Field
          disabled
          label="时长,单位秒"
          prop="duration"
          v-model="form.duration"
          placeholder="请输入时长,单位秒"
        />
        <Field
          disabled
          label="请假事由"
          prop="reason"
          v-model="form.reason"
          type="textarea"
          placeholder="请输入请假事由"
        />
        <Field
          disabled
          label="审批负责人"
          prop="approverId"
          v-model="form.approverId"
          placeholder="请输入审批负责人"
        />
        <Field
          disabled
          label="附件"
          prop="attachment"
          v-model="form.attachment"
          type="textarea"
          placeholder="请输入附件"
        />
        <Field
          disabled
          label="附件路径"
          prop="attachmentPath"
          v-model="form.attachmentPath"
          type="textarea"
          placeholder="请输入附件路径"
        />
        <Field
          disabled
          label="备注"
          prop="remark"
          v-model="form.remark"
          type="textarea"
          placeholder="请输入备注"
        />
        <Field
          disabled
          label="申请时间"
          prop="appealTime"
          v-model="form.appealTime"
          type="date"
        />
        <Field
          label="审核结果"
          prop="auditResult"
          v-model="form.auditResult"
          type="radio"
          :enumData="dict.auditResult"
          placeholder="请选择审核结果"
        />
        <Field
          label="审核说明"
          prop="auditDesc"
          v-model="form.auditDesc"
          placeholder="请输入审核说明"
        />
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        v-if="pageInfo.type !== 'view'"
        @click="submitForm"
        >审 核</el-button
      >
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import form from "@/assets/mixins/formdialog";
import dialogShow from "./dialogshow";
export default {
  mixins: [form],
  components: {
    dialogShow,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "请假记录信息",
      // 是否显示弹出层
      open: false,
      // urls: { saveUrl: "/check/attend/record/examine" },
      toString: ["leaveType", "auditResult", "processStatus"],
      toDate: ["startTime", "endTime"],
      // 表单校验
      rules: {},
    };
  },

  methods: {
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      // this.urls.currUrl = "attendance/leave/record/edit";
      // this.getData();
      this.$post("attendance/leave/record/edit", { id: row.id }).then((res) => {
        console.log(res);
      });
      this.pageInfo.type = "edit";
      this.title = "修改请假记录信息";
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "attendance/leave/record/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增请假记录信息";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "attendance/leave/record/view";
      this.getData();
      this.pageInfo.type = "check";
      this.title = "审核请假记录";
    },
    /**取消按钮 */
    cancel() {
      this.open = false;
    },
    /**获取数据后弹框 */
    afterRender(data) {
      this.open = true;
    },

    beforeSubmit(data) {
      data.processStatus = 2;
      return data;
    },

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

    // 表单重置
    reset() {
      this.form = {
        leavePersonId: null,
        leavePerson: "",
        deptId: null,
        deptName: "",
        phoneNumber: "",
        leaveType: null,
        startTime: null,
        endTime: null,
        duration: null,
        reason: "",
        approverId: null,
        approver: "",
        attachment: "",
        attachmentPath: "",
        remark: "",
        appealTime: null,
        auditResult: null,
        auditDesc: "",
        auditTime: null,
        processStatus: 1,
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
