<template>
  <!-- 弹出框表单 -->
  <el-drawer
    :title="title"
    :visible.sync="open"
    :direction="direction"
    size="50%"
  >
    <div class="dra_content">
      <div class="dra_top box">
        <div class="title">异常情况</div>
        <div class="content">
          <el-row>
            <el-col :span="12"
              >员工：{{ form.staffName ? form.staffName : "--" }}</el-col
            >
            <el-col :span="12"
              >所属部门：{{ form.deptName ? form.deptName : "--" }}</el-col
            >
          </el-row>
          <el-row>
            <el-col :span="12"
              >窗口编号：{{ form.windowNum ? form.windowNum : "--" }}</el-col
            >
            <el-col :span="12"
              >考勤组：{{
                form.attendanceGroupName ? form.attendanceGroupName : "--"
              }}</el-col
            >
          </el-row>
          <el-row>
            <el-col :span="12"
              >实际打卡时间：{{
                form.actualAttendTime ? form.actualAttendTime : "--"
              }}</el-col
            >
            <el-col :span="12"
              >上下班时间：{{
                form.goOffTimeStr ? form.goOffTimeStr : "--"
              }}</el-col
            >
          </el-row>
          <el-row>
            <el-col :span="12"
              >异常时间：{{ form.errorTime ? form.errorTime : "--" }}</el-col
            >
            <el-col :span="12"
              >异常结果：{{ form.errorTime ? form.errorTime : "--" }}</el-col
            >
          </el-row>
          <el-row>
            <el-col :span="12"
              >扣分方式：{{ form.subMethod ? form.subMethod : "--" }}</el-col
            >
            <el-col :span="12"
              >扣分时间：{{ form.deductTime ? form.deductTime : "--" }}</el-col
            >
          </el-row>
          <el-row>
            <el-col :span="12"
              >扣分人员：{{
                form.deductPerson ? form.deductPerson : "--"
              }}</el-col
            >
            <el-col :span="12"
              >图片凭证：{{
                form.snapPath ? picMatter(form.snapPath) : "--"
              }}</el-col
            >
          </el-row>
        </div>
      </div>
      <div class="dra_down box">
        <div class="title">核查情况</div>
        <div class="content">
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
              <el-form-item label="核查结果：">
                <p v-if="form.view == '查看'">
                  {{
                    form.checkResult == 1
                      ? "加分/扣分"
                      : form.checkResult == 2
                      ? "不加分/不扣分"
                      : "--"
                  }}
                </p>
                <el-radio-group
                  v-model="form.checkResult"
                  @input="radioChange"
                  v-else
                >
                  <el-radio :label="1">加分/扣分</el-radio>
                  <el-radio :label="2">不加分/不扣分</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-row>
            <div v-if="form.checkResult == 1">
              <el-row>
                <el-form-item
                  :label="form.view == '查看' ? '绩效规则：' : '修改规则：'"
                >
                  <p v-if="form.view == '查看'">{{ form.ruleName }}</p>
                  <div v-else>
                    <el-col :span="22">
                      <el-select
                        v-model="form.categoryId"
                        style="width: 100%;"
                        @change="cateChange"
                      >
                        <el-option
                          v-for="item in kaoqinCateArr"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id"
                        >
                        </el-option
                      ></el-select>
                    </el-col>
                    <el-col :span="22">
                      <el-select
                        v-model="form.ruleId"
                        style="width: 100%;margin-top: 10px;"
                        @change="ruleChange"
                      >
                        <el-option
                          v-for="item in kaoqinArr"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id"
                        >
                        </el-option></el-select
                    ></el-col>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="加分/扣除分值：">
                  <p v-if="form.view == '查看'">
                    {{form.subAddType==1?'+':'-'}} {{ form.score ? form.score : "--" }}
                  </p>
                  <p v-else>{{form.subAddType==1?'+':'-'}}{{ form.score }}</p>
                </el-form-item>
              </el-row>
            </div>
            <el-row>
              <el-form-item label="说明：">
                <p v-if="form.view == '查看'">
                  {{ form.checkDesc ? form.checkDesc : "--" }}
                </p>
                <el-input
                  v-else
                  v-model="form.checkDesc"
                  type="textarea"
                ></el-input>
              </el-form-item>
            </el-row>
            <el-row v-if="form.view == '查看'">
              <el-form-item label="核查人员：">
                <p>{{ form.checkPerson ? form.checkPerson : "--" }}</p>
              </el-form-item>
            </el-row>
            <el-row v-if="form.view == '查看'">
              <el-form-item label="核查时间：">
                <p>{{ form.checkTime ? form.checkTime : "--" }}</p>
              </el-form-item>
            </el-row>
            <form-buttons
              v-show="form.view == '核查'"
              @submit="submitForm"
              v-if="pageInfo.type != 'view'"
              noCancelBtn
            />
          </el-form>
        </div>
      </div>
    </div>
    <!-- <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <Field
          label="记录ID"
          prop="recordId"
          v-model="form.recordId"
          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="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="checkStatus"
          v-model="form.checkStatus"
          type="select"
          :enumData="dict.checkStatus"
          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";
import { timestampToTime } from "@/assets/utils/dateFormat.js";

export default {
  name: "CheckAttendRecordDetail",
  mixins: [form],
  components: {},
  created() {
    this.changePath("check/attend/record");
    this.$post("/perform/rules/category/list", { page: 1, size: -1 }).then(
      (res) => {
        if (res.code == 1) {
          this.kaoqinCateArr = res.data.data;
        } else {
          this.kaoqinCateArr = [];
        }
      }
    );
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "考勤绩效记录核查信息",
      // 是否显示弹出层
      open: false,
      direction: "rtl",
      toString: ["subAddType", "checkStatus"],
      toDate: ["attendanceDate", "errorTime", "actualAttendTime", "checkTime"],
      // 表单校验
      rules: {
        staffName: [
          { required: true, message: "请输入员工姓名", trigger: "blur" },
          { max: 64, message: "最多只能录入64个字符", trigger: "blur" },
        ],
        createTime: [{ required: true, message: "请选择创建时间" }],
      },
      form: {},
      kaoqinCateArr: [],
      kaoqinArr: [],
      baseUrl: process.env.VUE_APP_API_BASE_URL + "/",
      urls:{saveUrl:'/check/attend/record/examine'}//重写核查地址
    };
  },
  computed: {},
  methods: {
    // 审核
    radioChange(val) {
      console.log(val);
      this.form.checkResult = val;
      this.$forceUpdate(this.form);
    },
    picMatter(val) {
      if (val || val !== "--") {
        return (
          <el-image
            src={val.indexOf("http") == -1 ? this.baseUrl + val : val}
            preview-src-list={val.indexOf("http") == -1 ? this.baseUrl + val : val}
            style="width: 100px"
          ></el-image>
        );
      } else {
        return val;
      }
    },
    ruleChange(val) {
      console.log(val);
      let arr = this.kaoqinArr.filter((v) => v.id == val);
      this.form.score = arr && arr[0].score;
      this.form.checkStatus == 1 ? (this.form.checkStatus = 2) : "";
    },
    cateChange() {
      this.$post("/perform/rules/list", {
        page: 1,
        size: -1,
        categoryId: this.form.categoryId,
      }).then((res) => {
        this.kaoqinArr = res.data.data;
        this.form.ruleId = "";
      });
    },
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      // this.urls.currUrl = "check/attend/record/edit";
      // this.getData();

      this.$get("/check/attend/record/info", { id: row.id }).then((res) => {
        console.log(res.data);
        if (res.code == 1) {
          this.form = res.data;
        } else {
          this.form = row;
        }
        for (let key in this.form) {
          key == "actualAttendTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "attendanceDate"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "createTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "errorTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "updateTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "checkTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : "";
        }
        this.form.checkResult = 1;
        this.form.view = "核查";
        this.open = true;
      });
      this.pageInfo.type = "edit";
      row.view == "核查"
        ? (this.title = "考勤绩效记录核查")
        : (this.title = "修改考勤绩效记录核查信息");
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "check/attend/record/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增考勤绩效记录核查信息";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      // this.urls.currUrl = "check/attend/record/view";
      // this.getData();
      this.$get("/check/attend/record/info", { id: row.id }).then((res) => {
        if (res.code == 1) {
          this.form = res.data;
        } else {
          this.form = row;
        }
        for (let key in this.form) {
          key == "actualAttendTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "attendanceDate"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "createTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "errorTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "updateTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : key == "checkTime"
            ? (this.form[key] = timestampToTime(this.form[key], 6))
            : "";
        }
        this.form.view = "查看";
        console.log(this.form);
        this.open = true;
      });
      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 = {
        recordId: null,
        staffId: null,
        staffName: "",
        workNum: "",
        deptId: null,
        deptName: "",
        attendanceGroupId: null,
        attendanceGroupName: "",
        attendanceDate: null,
        ruleId: null,
        ruleName: "",
        subAddType: 1,
        score: 0.0,
        goOffTimeStr: "",
        errorTime: null,
        actualAttendTime: null,
        errorResult: "",
        checkPerson: "",
        checkTime: null,
        checkDesc: "",
        checkResult: "",
        checkStatus: 1,
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
<style lang="less" scoped>
.dra_content {
  width: 100%;
  height: 100%;
  padding: 20px;
  .box {
    width: 100%;
    height: auto;
    .title {
      color: #1890ff;
      font-size: 16px;
      padding-left: 10px;
      position: relative;
      margin-bottom: 30px;
      &::after {
        content: "";
        display: block;
        border-left: 3px solid #1890ff;
        left: 0;
        top: 0;
        bottom: 0;
        position: absolute;
      }
    }
    .content {
      width: 100%;
      padding: 10px;
      font-family: "微软雅黑", sans-serif;
      font-weight: 400;
      font-style: normal;
      font-size: 14px;
      margin-left: 0 auto;
      margin-bottom: 30px;
      /deep/.el-row {
        margin-bottom: 20px;
      }
    }
  }
}
</style>
