<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="员工姓名" prop="employeeName">
        <el-input v-model="queryParams.employeeName" placeholder="员工姓名" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="部门" prop="deptId">
        <treeselect style="width: 250px" :default-expand-level="1" v-model="queryParams.deptId" :options="deptOptions"
          :normalizer="normalizer" placeholder="选择部门" />
      </el-form-item>
      <el-form-item label="手机号" prop="employeeMobile">
        <el-input v-model="queryParams.employeeMobile" placeholder="请输入手机号" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="日期" prop="attendanceMonth">
        <el-date-picker
          value-format="yyyy-MM"
          v-model="queryParams.attendanceMonth"
          type="month"
          placeholder="选择月份">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
          v-hasPermi="['attendance:infoMonthly:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="typeList">
      <el-table-column label="序号" type="index" width="50"align="center"/>
      <el-table-column label="员工姓名" align="center" prop="employeeName" min-width="80" />
      <el-table-column label="部门" align="center" prop="deptName" min-width="100" />
      <el-table-column label="手机号" align="center" prop="employeeMobile" min-width="100" />
      <el-table-column label="出勤天数" align="center" prop="attendanceDays" min-width="100" />
      <el-table-column label="正常打卡次数" align="center" prop="normalClockCount" min-width="100" />
      <el-table-column label="迟到次数" align="center" prop="lateCount" min-width="100" />
      <el-table-column label="旷工次数" align="center" prop="absenteeismCount" min-width="100" />
      <el-table-column label="早退次数" align="center" prop="earlyCount" min-width="100" />
      <el-table-column label="缺卡次数" align="center" prop="missingClockCount" min-width="100" />
      <el-table-column label="请假/出差天数" align="center" prop="leaveCount" min-width="100" />
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listInfoMonthly, exportInfoMonthly } from "@/api/personnel/attendance/info/index";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listDept } from "@/api/system/dept";
export default {
  name: "SystemDictType",
  components: {
    Treeselect,
  },
  data() {
    return {
      postOptions: [],
      // 部门列表
      deptOptions: [], // 部门属性结构
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      typeList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        employeeName: undefined,
        deptId: undefined,
        employeeMobile: undefined,
        attendanceMonth: this.getNowDate(),
      },
    };
  },
  created() {
    this.getList();
    this.getListDept();
  },
  methods: {
    handleAttendanceMonth(e){
      console.log(e)
    },
     //获取当前日期(年月)
     getNowDate() {
      const date = new Date()
      const year = date.getFullYear()
      const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
      return year + '-' + month
    },
    /** 查询部门列表 */
    getListDept() {
      listDept().then(response => {
        this.deptOptions = this.handleTree(response.data, "id");
      });
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      };
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      listInfoMonthly(this.queryParams).then(response => {
        this.typeList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      // 执行导出
      this.$modal.confirm('是否确认导出所有数据项?').then(() => {
        this.exportLoading = true;
        return exportInfoMonthly(params);
      }).then(response => {
        this.$download.excel(response, '月度考勤信息.xls');
        this.exportLoading = false;
      }).catch(() => { });
    }
  }
};
</script>