<template>
  <!-- 弹出框表单 -->
  <el-drawer
    :title="title"
    :visible.sync="open"
    :direction="direction"
    size="50%"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <el-col :span="22">
          <el-form-item label="姓名：">
            <el-select v-model="form.staffId" style="width: 100%;">
              <el-option
                v-for="item in staffArr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option
            ></el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="所属部门：">
            <el-select v-model="form.deptId" style="width: 100%;">
              <el-option
                v-for="item in deptArr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option
            ></el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="窗口编号：">
            <el-input
              v-model="form.windowNum"
              placeholder="请输入窗口编号"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="考勤组：">
            <el-select v-model="form.attendanceGroupId" style="width: 100%;">
              <el-option
                v-for="item in kaoqinArr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option
            ></el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="异常时间：">
            <el-date-picker
              v-model="form.errorTime"
              type="date"
              placeholder="选择日期"
              style="width: 100%;"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="实际打卡时间：">
            <el-time-select
              v-model="form.actualAttendTime"
              :picker-options="{
                start: '06:00',
                step: '00:15',
                end: '18:30',
              }"
              placeholder="选择时间"
              style="width: 100%;"
            >
            </el-time-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="图片凭证：">
            <el-upload
              class="upload-demo"
              action="https://jsonplaceholder.typicode.com/posts/"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              multiple
              :limit="3"
              :on-exceed="handleExceed"
              :file-list="fileList"
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">
                只能上传jpg/png等图片文件
              </div>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="22">
          <el-form-item label="绩效规则：">
            <el-col :span="22">
              <el-select v-model="form.attendanceGroupId" style="width: 100%;">
                <el-option
                  v-for="item in kaoqinArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option
              ></el-select>
            </el-col>
            <el-col :span="22">
              <el-select
                v-model="form.attendanceGroupId"
                style="width: 100%;margin-top: 10px;"
              >
                <el-option
                  v-for="item in kaoqinArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option></el-select
            ></el-col>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22">
          <el-form-item label="扣分分值：">
            <p>{{ form.score }}</p>
          </el-form-item>
        </el-col>
      </el-row>

      <form-buttons
        @submit="submitForm"
        v-if="pageInfo.type != 'view'"
        noCancelBtn
      />
    </el-form>
    <!-- <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <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="ruleNme"
          v-model="form.ruleNme"
          placeholder="请输入规则名称"
        />
        <Field
          label="异常时间"
          prop="errorTime"
          v-model="form.errorTime"
          type="date"
        />
        <Field
          label="上下班时间"
          prop="goOffTimeStr"
          v-model="form.goOffTimeStr"
          placeholder="请输入上下班时间"
        />
        <Field
          label="实际打卡时间"
          prop="actualAttendTime"
          v-model="form.actualAttendTime"
          type="date"
        />
        <Field
          label="异常处理结果"
          prop="errorResult"
          v-model="form.errorResult"
          placeholder="请输入异常处理结果"
        />
        <Field
          label="扣分方式"
          prop="subMethod"
          v-model="form.subMethod"
          type="select"
          :enumData="dict.subMethod"
          placeholder="请选择扣分方式"
        />
        <Field
          label="扣分人员"
          prop="deductPerson"
          v-model="form.deductPerson"
          placeholder="请输入扣分人员"
        />
        <Field
          label="扣分时间"
          prop="deductTime"
          v-model="form.deductTime"
          type="date"
        />
        <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="processStatus"
          v-model="form.processStatus"
          type="select"
          :enumData="dict.processStatus"
          placeholder="请选择处理状态"
        />
        <Field
          label="备注"
          prop="remark"
          v-model="form.remark"
          type="textarea"
          placeholder="请输入备注"
        />
      </el-row>

      <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: "PerformAttendRecordDetail",
  mixins: [form],
  components: {},
  created() {
    this.changePath("perform/attend/record");
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "考勤绩效记录信息",
      // 是否显示弹出层
      open: false,
      direction: "rtl",
      toString: ["subMethod", "subAddType", "processStatus"],
      toDate: ["attendanceDate", "errorTime", "actualAttendTime", "deductTime"],
      // 表单校验
      rules: {
        staffName: [
          { required: true, message: "请输入员工姓名", trigger: "blur" },
          { max: 64, message: "最多只能录入64个字符", trigger: "blur" },
        ],
        createTime: [{ required: true, message: "请选择创建时间" }],
      },
      staffArr: [
        {
          label: "员工1",
          value: "1",
        },
      ],
      deptArr: [],
      kaoqinArr: [],
      fileList: [],
    };
  },

  methods: {
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "perform/attend/record/edit";
      this.getData();
      this.pageInfo.type = "edit";
      this.title = "修改考勤绩效记录信息";
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "perform/attend/record/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增考勤绩效记录信息";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "perform/attend/record/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 = {
        staffId: null,
        staffName: "",
        workNum: "",
        deptId: null,
        deptName: "",
        attendanceGroupId: null,
        attendanceGroupName: "",
        attendanceDate: null,
        ruleId: null,
        ruleNme: "",
        errorTime: null,
        goOffTimeStr: "",
        actualAttendTime: null,
        errorResult: "",
        subMethod: 1,
        deductPerson: "",
        deductTime: null,
        subAddType: 1,
        score: 0.0,
        processStatus: 1,
        remark: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${
          files.length
        } 个文件，共选择了 ${files.length + fileList.length} 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
  },
};
</script>
