<template>
  <div class="page">
    <LayoutTable :data="tableData" :config="tableConfig" notDel notAdd>
      <el-button
        slot="table-head-left2"
        style="margin-left: 10px"
        size="mini"
        type="primary"
        @click="morehandle"
        >批量处理</el-button
      >
    </LayoutTable>
    <drawer-show ref="drawerShow" @ok="getData" />
    <!-- 撤销提示 -->
    <el-dialog :visible.sync="dialogVisible" title="提示" width="40%">
      <div>
        撤销异常处理结果后，当天的考勤结果将会重新计算，系统需要花费一点时间。
      </div>
      <div class="flex flex_end">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="resetError">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
/** 表单弹出框模式需引入 */
import drawerShow from "./drawershow";
import table from "@/assets/mixins/table";
export default {
  name: "AttendanceRecordErrorList",
  components: {
    drawerShow,
  },
  mixins: [table],
  created() {},
  methods: {
    /** 重写新增方法 */
    // toAdd(row) {
    //     this.$refs.dialogform.add(row);
    // },
    // /** 重写编辑方法 */
    // toEdit(row) {
    //     this.$refs.dialogform.edit(row);
    // },
    // /** 重写查看方法 */
    // toView(row) {
    //     this.$refs.dialogform.view(row);
    // },

    morehandle() {
      let arr = this.tableData.data.filter((item) => {
        if (this.selection.includes(item.id) && item.processStatus == 0) {
          return item;
        }
      });
      this.$nextTick(() => {
        this.selection = arr.map((item) => item.id);
      });
      if (arr.length < 1) {
        this.$message.error("请至少选择一条处理");
        return;
      }

      this.$refs.drawerShow.edit(arr[0], arr);
    },
    // 处理
    handle(err) {
      console.log(err);
      this.$refs.drawerShow.edit(err, []);
    },
    // 撤销
    reCancle(err) {
      console.log(err);
      this.currentParams = err;
      this.dialogVisible = true;
    },
    resetError() {
      this.$post("attendance/record/error/revokeError", {
        ...this.currentParams,
      }).then((res) => {
        if (res.code == 1) {
          this.dialogVisible = false;
          this.getData();
        }
      });
    },
  },
  data() {
    return {
      config: {
        isshowTabPane: true,
        search: [
          {
            name: "deptId",
            type: "select",
            label: "全部部门",
          },
          {
            name: "groupId",
            type: "select",
            label: "全部考勤组",
          },
          /*                        {
                            name: "classId",
                            type: "select",
                            label: "全部班次",
                            fuzzy: false
                        },*/
          {
            name: "errorStatus",
            type: "select",
            label: "全部异常状态",
          },
          {
            name: "processStatus",
            type: "select",
            label: "全部处理状态",
          },
          {
            name: "errorDateTimeStart",
            type: "date",
            label: "异常开始时间",
          },
          {
            name: "errorDateTimeEnd",
            type: "date",
            label: "异常结束时间",
          },
          {
            name: "staffName",
            type: "text",
            label: "员工姓名",
            fuzzy: true,
          },
          {
            name: "phoneNumber",
            type: "text",
            label: "手机号",
            fuzzy: true,
          },
        ],
        columns: [
          { type: "selection", width: 60, fixed: "left" },
          { type: "index", label: "序号", width: 50, fixed: "left" },
          { label: "员工姓名", prop: "staffName", fixed: "left", width: 100 },
          { label: "工号", prop: "workNum" },
          { label: "部门", prop: "deptName" },
          { label: "考勤组", prop: "attendanceGroupName" },
          /*  {label: "班次", prop: "shiftsName"},*/
          {
            label: "异常状态",
            prop: "errorStatus",
            formatter: this.formattereErrorStatus,
          },
          {
            label: "异常时间",
            prop: "errorDateTime",
            formatter: this.formatterDate,
          },
          {
            label: "处理结果",
            prop: "processResult",
            formatter: this.formatters,
          },
          {
            label: "上下班时间",
            prop: "goOffDateTime",
            formatter: (row) => {
              return row.goOrOff + " " + row.goOffDateTime;
            },
          },
          {
            label: "实际打卡时间",
            prop: "actualAttendanceDateTime",
            formatter: this.formatterDate,
          },
          {
            label: "处理时间",
            prop: "operDateTime",
            formatter: this.formatterDate,
          },
          {
            label: "处理状态",
            prop: "processStatus",
            formatter: this.formattereDealStatus,
          },
          { label: "处理人", prop: "opertor", formatter: this.formatters },
          { label: "备注", prop: "remark", formatter: this.formatters },
          {
            label: "操作",
            width: 240,
            formatter: (row) => {
              if (row.processStatus == 0 || !row.processStatus) {
                return (
                  <el-button
                    type="text"
                    size="mini"
                    onClick={() => {
                      this.handle(row);
                    }}
                  >
                    处理
                  </el-button>
                );
              } else {
                return (
                  <span>
                    <el-button
                      type="text"
                      size="mini"
                      onClick={() => {
                        this.reCancle(row);
                      }}
                    >
                      撤销
                    </el-button>
                  </span>
                );
              }
            },
          },
        ],
      },
      dialogVisible: false,
      currentParams: {},
    };
  },
};
</script>
