<template>
  <div class="page">
    <LayoutTable :data="tableData" notDel :config="tableConfig">
      <!-- <el-button
        slot="table-head-left2"
        style="margin-left: 10px"
        icon="el-icon-tickets"
        size="mini"
        @click="handleImport"
        >导入</el-button
      > -->
      <el-button
        slot="table-head-left2"
        style="margin-left: 10px"
        icon="el-icon-tickets"
        size="mini"
        @click="doExport"
        :disabled="isExport"
        >导出</el-button
      >
    </LayoutTable>

    <!-- 考勤绩效记录信息导入对话框 -->
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的数据
          <el-link
            type="primary"
            style="font-size: 14px"
            @click="downloadTemplate"
            >下载模板</el-link
          >
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <drawer-show ref="drawerform" @ok="getData" />
  </div>
</template>

<script>
/** 表单弹出框模式需引入 */
import drawerShow from "./drawershow";
import table from "@/assets/mixins/table";
import { downloadFile } from "@/assets/utils/index";

export default {
  name: "PerformAttendRecordList",
  components: {
    drawerShow,
  },
  mixins: [table],
  created() {},
  methods: {
    handleCellClick(row, column, event, cell) {
      if (column.label == "图片凭证") {
        const suffix = `(bmp|jpg|png|tif|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF|webp|jpeg)`;
        const regular = new RegExp(`.*\.${suffix}`);
        regular.test(row.filePaths);
        if (!regular.test(row.filePaths)) {
          downloadFile(row.filePaths, row.fileName);
        }
      }
    },
    /** 导入 */
    handleImport() {
      this.upload.title = "考勤绩效记录信息导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    downloadTemplate() {
      this.isExport = true;
      this.$download(
        "/perform/attend/record/downloadTemplate",
        {},
        { type: "excel" }
      )
        .then(() => (this.isExport = false))
        .catch((error) => {
          this.isExport = false;
          this.$message.error(error.message);
        });
    },
    /** 文件上传中处理 */
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    /** 文件上传成功处理 */
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getData();
    },
    /** 提交上传文件 */
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 导出Excel */
    doExport() {
      this.isExport = true;
      this.$download(
        "/perform/attend/record/exportExcel",
        {
          page: 1,
          size: -1,
        },
        { type: "excel" }
      )
        .then(() => (this.isExport = false))
        .catch((error) => {
          this.isExport = false;
          this.$message.error(error.message);
        });
    },
    /** 重写新增方法 */
    toAdd(row) {
      this.$refs.drawerform.add(row);
    },
    /** 重写编辑方法 */
    toEdit(row) {
      row.view = "核查";
      this.$refs.drawerform.edit(row);
    },
    /** 重写查看方法 */
    toView(row) {
      row.view = "查看";
      this.$refs.drawerform.view(row);
    },
  },
  data() {
    return {
      // 用户导入参数
      upload: {
        // 是否显示弹出层（考勤绩效记录信息导入）
        open: false,
        // 弹出层标题（考勤绩效记录信息导入）
        title: "导入考勤绩效记录信息数据",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 上传的地址
        url: "/attendance/perform/attend/record/importData",
      },
      isExport: false,
      config: {
        isshowTabPane: true,
        search: [
          {
            name: "processStatus",
            type: "select",
            label: "处理状态",
            fuzzy: false,
          },
          {
            name: "salaId",
            type: "selectSalaId",
            label: "大厅",
            fuzzy: false,
          },
          {
            name: "deptId",
            type: "selectDeptId",
            label: "部门",
            fuzzy: false,
          },
          {
            name: "createTimeMonth",
            type: "month",
            label: "请选择异常时间",
            fuzzy: false,
          },
          {
            name: "staffName",
            type: "text",
            label: "员工姓名搜索",
            fuzzy: false,
          },
        ],
        columns: [
          { type: "selection", width: 50 },
          { type: "index", label: "序号", width: 50 },

          { label: "姓名", prop: "staffName", formatter: this.formatter },

          { label: "窗口编号", prop: "windowNum", formatter: this.formatter },
          { label: "所属大厅", prop: "salaName", formatter: this.formatter },

          { label: "所属部门", prop: "deptName", formatter: this.formatter },

          {
            label: "考勤组",
            prop: "attendanceGroupName",
            formatter: this.formatter,
          },

          {
            label: "异常时间",
            prop: "errorTime",
            formatter: this.formatterDate,
          },

          {
            label: "上下班时间",
            width: 100,
            prop: "goOffTimeStr",
          },

          {
            label: "实际打卡时间",
            prop: "actualAttendTime",
            formatter: this.formatterDate,
          },

          { label: "异常结果", prop: "errorResult", formatter: this.formatter },

          /*
         {
            label: "图片凭证",
            prop: "filePaths",
            width: 150,
            formatter: this.formatterPic,
          },
*/

          {
            label: "图片凭证",
            prop: "filePaths",
            width: 150,
            formatter: this.formatterPic,
          },

          { label: "绩效规则", prop: "ruleName", formatter: this.formatter },

          {
            label: "加分/扣分方式",
            prop: "subMethod",
            formatter: this.formatter,
          },

          {
            label: "加分/扣分时间",
            prop: "deductTime",
            formatter: this.formatterDate,
          },

          {
            label: "加分/扣分人员",
            prop: "deductPerson",
            formatter: this.formatter,
          },

          { label: "分值", prop: "score", formatter: this.formatter },

          {
            label: "处理状态",
            prop: "processStatus",
            formatter: this.formatter,
          },

          {
            label: "操作",
            width: 200,
            fixed: "right",
            formatter: (row) => {
              return row.processStatus == 1 ? (
                <table-buttons
                  noAdd
                  row={row}
                  onEdit={this.toEdit}
                  onView={this.toView}
                  onDel={this.toDel}
                />
              ) : (
                <table-buttons
                  noAdd
                  noEdit
                  noDel
                  row={row}
                  onEdit={this.toEdit}
                  onView={this.toView}
                  onDel={this.toDel}
                />
              );
            },
          },
        ],
      },
    };
  },
};
</script>
