<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="employeePhone">
        <el-input v-model="queryParams.employeePhone" placeholder="请输入手机号" clearable style="width: 250px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="日期" prop="attendanceDate">
        <el-date-picker v-model="queryParams.attendanceDate" style="width: 250px" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" />
      </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="['relations:renew: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="员工姓名" 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="employeePhone" min-width="100" />
      <el-table-column label="日期" align="center" prop="attendanceDate" min-width="100" />
      <el-table-column label="上班时间" align="center" prop="workStartTime" min-width="100" />
      <el-table-column label="下班下班" align="center" prop="workEndTime" min-width="100" />
      <el-table-column label="迟到时间(min)" align="center" prop="lateMinute" min-width="100" />
      <el-table-column label="早退时间(min)" align="center" prop="earlyMinute" min-width="100" />
      <el-table-column label="总工作时间(min)" align="center" prop="totalWorkingMinute" 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 { listInfoDaily, exportInfo } 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 {
      posOptions: [],
      // 部门列表
      deptOptions: [], // 部门属性结构
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      typeList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        employeeName: undefined,
        deptId: undefined,
        position: undefined,
        employeePhone: undefined,
        attendanceDate: [],
      },
    };
  },
  created() {
    this.getList();
    this.getListDept();
  },
  methods: {
    /** 查询部门列表 */
    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;
      // 执行查询
      listInfoDaily(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 exportInfo(params);
      }).then(response => {
        this.$download.excel(response, '.xls');
        this.exportLoading = false;
      }).catch(() => { });
    }
  }
};
</script>