<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="perName">
        <el-input
          v-model="queryParams.perName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="cardNumber">
        <el-select v-model="queryParams.cardNumber" placeholder="请选择卡号" clearable>
          <el-option
            v-for="dict in cardNoList"
            :key="dict.value"
            :label="dict.name"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
     
      <el-form-item label="" prop="departId">
        <el-select v-model="queryParams.departId" placeholder="请选择部门" clearable>
          <el-option
            v-for="dict in DepartmentList"
            :key="dict.value"
            :label="dict.name"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="positionId">
        <el-select v-model="queryParams.positionId" placeholder="请选择职务" clearable>
          <el-option
            v-for="dict in InfoPositionList"
            :key="dict.value"
            :label="dict.name"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="jobTypeId">
        <el-select v-model="queryParams.jobTypeId" placeholder="请选择工种" clearable>
          <el-option
            v-for="dict in WorkTypeList"
            :key="dict.value"
            :label="dict.name"
            :value="dict.value"
          />
        </el-select>
        
      </el-form-item>
      <el-form-item label="日期查询">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-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="attendanceList" >
      <el-table-column label="姓名" align="center" prop="perName" />
      <el-table-column label="卡号" align="center" prop="cardNumber" />
      <el-table-column label="部门" align="center" prop="departName" />
      <el-table-column label="职务" align="center" prop="positionName" />
      <el-table-column label="工种" align="center" prop="workTypeName" />
      <el-table-column label="时间" align="center" prop="entryTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出/入井" align="center" prop="action"/>
     
      
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    
  </div>
</template>

<script>
import { listAttendance } from "@/api/tyler/attendance";
import { baseInfoDepartment, baseInfoArea, baseInfoStation, baseInfoWorkType, baseInfoPosition, baseInfoCardNumber } from "@/api/tyler/common";

export default {
  name: "attendance",
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      
      // 考勤管理数据表格数据
      attendanceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        perName:null,
        cardNumber: null,
        departId: null,
        positionId: null,
        jobTypeId: null,
      },
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // common
      //卡号列表
      cardNoList: [],
      //部门列表
      DepartmentList: [],
      //分站列表
      StationList: [],
      //区域列表
      AreaList: [],
      //职务列表
      InfoPositionList: [],
      //工种列表
      WorkTypeList: [],
     
    };
  },
  created() {
    this.getCommon();
    this.getList();
  
  },
  methods: {
    // common
    
    getCommon(){
      //卡号
      baseInfoCardNumber().then(res=>{
        this.cardNoList = res.data;
      })
      //部门
      baseInfoDepartment().then(res=>{
        this.DepartmentList = res.data;
      })
      //分站
      baseInfoStation().then(res=>{
        this.StationList = res.data;
      })
      //区域
      baseInfoArea().then(res=>{
        this.AreaList = res.data;
      })
      //职务
      baseInfoPosition().then(res=>{
        this.InfoPositionList = res.data;
      })
      
      //工种
      baseInfoWorkType().then(res=>{
        this.WorkTypeList = res.data;
      })
    },
    /** 查询人员定位实时数据列表 */
    getList() {
      this.loading = true;
      listAttendance(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.attendanceList = response.rows;
        this.leaderList = response.remark;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        perName: null,
        departId: null,
        addressId: null,
        areaId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.dateRange = [];
    },
 

    /** 导出按钮操作 */
    handleExport() {
      this.download('business/per/export', {
        ...this.queryParams
      }, `per_${new Date().getTime()}.xlsx`)
    }
  },


};
</script>
<style lang="scss" scoped>
.now-leader{
  display: flex;
  justify-content: space-between;
}
</style>