<template>
  <div class="app-container">
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      class="app-container--search"
    >
      <el-form-item label="考勤日期" prop="strDay">
        <el-date-picker
          type="date"
          v-model="queryParams.strDay"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="resultList">
      <el-table-column label="序号" type="index" width="100"> </el-table-column>
      <el-table-column label="打卡日期" width="120" prop="checkInTime">
        <template slot-scope="scope">
          {{ formatDate(scope.row.checkInTime) }}
        </template>
      </el-table-column>
      <el-table-column label="员工编号" width="120" prop="sysUserName">
      </el-table-column>
      <el-table-column
        label="员工姓名"
        prop="nickName"
        width="120"
      ></el-table-column>
      <el-table-column
        label="考勤组"
        prop="attendanceGroupName"
      ></el-table-column>
      <el-table-column label="上班" width="200">
        <template slot-scope="scope">
          <span style="color: #909399" v-if="scope.row.checkInStatus == '0'">
            <!-- 上班未打卡 -->
            未打卡
          </span>
          <span
            style="color: #409eff"
            v-else-if="scope.row.clockInStatus == '1'"
          >
            <!--上班已打卡-->
            正常 {{ formatTime(scope.row.clockIn) }}</span
          >
          <span
            style="color: #f56c6c"
            v-else-if="scope.row.clockInStatus == '3'"
          >
            迟到 {{ formatTime(scope.row.clockIn) }}
          </span>
          <span v-else>
            {{ scope.row.clockInStatus }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="下班" width="200">
        <template slot-scope="scope">
          <span style="color: #909399" v-if="scope.row.clockOutStatus == '0'">
            <!-- 下班未打卡 -->
            未打卡
          </span>
          <span
            style="color: #409eff"
            v-else-if="scope.row.clockOutStatus == '2'"
          >
            <!--下班已打卡-->
            正常 {{ formatTime(scope.row.clockOut) }}</span
          >
          <span
            style="color: #f56c6c"
            v-else-if="scope.row.clockOutStatus == '4'"
          >
            早退 {{ formatTime(scope.row.clockOut) }}
          </span>
          <span
            style="color: #f56c6c"
            v-else-if="scope.row.clockOutStatus == '5'"
          >
            更新 {{ formatTime(scope.row.clockOut) }}
          </span>
          <span v-else>
            {{ scope.row.clockOutStatus }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="备注" prop="description"></el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { queryList } from "@/api/oa/attendance/history";
import { formatTime, formatDate } from "@/utils/filters";
import { mapGetters } from "vuex";
export default {
  name: "AttendanceHistory",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      resultList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        sysUserName: undefined,
        checkInStatus: undefined,
        strDay: undefined,
        flag: "all",
      },
    };
  },
  computed: {
    ...mapGetters(["userinfo"]),
  },
  created() {
    this.getList();
  },
  methods: {
    formatDate,
    formatTime,
    /** 查询结果列表 */
    getList() {
      this.loading = true;
      this.queryParams.sysUserName = this.userinfo.userName;
      console.log(this.userinfo);
      queryList(this.queryParams).then((response) => {
        this.resultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
