<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="班次：" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="班次类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="shiftList" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="班制" align="center" fixed="left"  prop="name" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="detailOpen(scope.row)"
          >{{scope.row.name}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="工作时长" align="center" fixed="left"    prop="workHour" />
      <el-table-column label="上班打卡时间" align="center"    prop="onDutyCheckTime" />
      <el-table-column label="下班打卡时间" align="center"  prop="offDutyCheckTime"/>
    </el-table>

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

    <el-drawer :title="detail.leaveTitle"  :visible.sync="detail.leaveDrawer" direction="rtl" size="50%"  :before-close="detailClose">
        <el-table :data="detail.detailList">
          <el-table-column label="考勤组名称" align="center" prop="groupName" />
          <el-table-column label="班制名称" align="center" prop="shiftName" />
          <el-table-column label="类型" align="center" prop="type" >
            <template slot-scope="scope">
              <span v-if="scope.row.type == 'OnDuty'">上班卡</span>
              <span v-else-if="scope.row.type == 'OffDuty'">下班卡</span>
              <span v-else>未知</span>
            </template>
          </el-table-column>
          <el-table-column label="考勤基准时间" align="center" prop="checkTime" />
        </el-table>
    </el-drawer>
  </div>
</template>


<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 137px;
    line-height: 137px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 137px;
    display: block;
  }
</style>


<script>
import { listShift } from '@/api/system/shift'
import { listGroupDetail } from '@/api/system/shiftGroup'
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "shift",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工管理表格数据
      shiftList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
      },
      detail:{
        row:{},
        leaveTitle:"考勤组详情",
        // 请假管理详情表格数据
        detailList: [],
        leaveDrawer:false,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询员工管理列表 */
    getList() {
      this.loading = true;
      listShift(this.queryParams).then(response => {
        this.shiftList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
       /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

        //查询详情
    detailOpen(row) {
      this.detail.leaveTitle = row.name+" 的考勤组信息"
      this.detail.row = row;
      listGroupDetail({shiftId:row.dingId}).then(response => {
        console.log(response)
        this.detail.detailList = response.rows;
        this.detail.leaveDrawer = true;
      });
    },

      //关闭详情
      detailClose(done) {
      done();
      this.handleQuery();
    },
  }
};
</script>
