<template>
  <div class="app-container">
    <el-form v-show="showSearch" :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="工程名称" prop="proName">
        <el-input
          v-model="queryParams.proName"
          placeholder="请输入工程名称"
          clearable v-no-whitespace
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考勤时间" prop="time">
        <el-date-picker
          v-model="queryParams.time"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择考勤时间"
          :clearable="false"
        />
      </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="handleReset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="tableData" fit highlight-current-row style="width: 100%">
      <!-- 多选 -->
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column
        type="index"
        width="55"
        label="序号"
        align="center"
        :index="indexContinuous(queryParams.pageNum, queryParams.pageSize)"
      />
      <el-table-column
        v-for="(column, index) in tableColumns"
        show-overflow-tooltip
        :key="column.prop"
        :label="column.label"
        :prop="column.prop"
        align="center"
      ></el-table-column>
      <!-- 操作 -->
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleDetail(scope.row)">查看详情</el-button>
        </template>
      </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 { getAttendancePersonList } from '@/api/checkInAdmin'
import { indexContinuous } from '@/utils/bonus'

export default {
  data() {
    return {
      showSearch: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proName: '', // 工程名称
        time: new Date().toLocaleDateString().replace(/\//g, '-'), // 考勤时间
      },
      total: 0, // 总条数
      // 表头
      tableColumns: [
        { label: '工程名称', prop: 'proName' },
        { label: '承包商名称', prop: 'contName' },
        { label: '入场总人数', prop: 'entryNum' },
        { label: '今日上班人数', prop: 'onWorkNum' },
        { label: '特殊工种人数', prop: 'specialNum' },
        { label: '今日上班时间', prop: 'upperWorkTime' },
        { label: '今日下班时间', prop: 'belowWorkTime' },
      ],
      // 表格数据
      tableData: [],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    indexContinuous,
    // 查询
    handleQuery() {
      console.log('查询')
      this.getList()
    },
    // 重置
    handleReset() {
      console.log('重置')
      this.$refs.queryForm.resetFields()
      this.getList()
    },
    // 获取列表
    async getList() {
      try {
        const params = {
          ...this.queryParams,
        }
        console.log('🚀 ~ getList ~ params:', params)
        const res = await getAttendancePersonList(params)
        console.log('🚀 ~ 获取列表 ~ res:', res)
        this.tableData = res.rows
        this.total = res.total
      } catch (error) {
        console.log(error)
      }
    },
    // 查看详情
    handleDetail(row) {
      console.log('查看详情', row)
      this.$router.push({
        path: '/checkingIn/activeCheckingInRecord/personCheckingInList/personList',
        query: {
          proId: row.proId,
          time: this.queryParams.time,
        },
      })
    },
  },
}
</script>

<style lang="scss" scoped></style>
