<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select v-model="seatId" class="filter-item" filterable clearable placeholder="请选择坐席">
        <el-option
          v-for="item in seatOptions"
          :key="item.agentid"
          :label="item.agentid"
          :value="item.agentid"/>
      </el-select>
      <el-date-picker
        v-model="searchDate"
        :picker-options="pickerOptions"
        class="filter-item"
        type="daterange"
        format="yyyy年MM月dd日"
        value-format="yyyy-MM-dd"
        align="left"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"/>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="btn_search">搜索</el-button>
    </div>

    <el-table v-loading="loading" :data="dataLists" border stripe>
      <el-table-column type="index" label="编号" align="center" fixed width="80"/>
      <el-table-column label="坐席工号" align="center" min-width="">
        <template slot-scope="scope">
          {{ scope.row.agent_id = scope.row.agent_id === 0 ? '-' : scope.row.agent_id }}
        </template>
      </el-table-column>
      <el-table-column label="小休开始时间" align="center" min-width="110">
        <template slot-scope="scope">
          <span>{{ scope.row.time_begin | timestampToTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="小休结束时间" align="center" min-width="110">
        <template slot-scope="scope">
          <span>{{ scope.row.time_end | timestampToTime }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="repose_times" label="本次小休的时长(s)" align="center" min-width="110"/>
    </el-table>
    <pagination
      v-show="pageParams.total > 0"
      :total="pageParams.total"
      :pageindex.sync="pageParams.pageindex"
      :pagesize.sync="pageParams.pagesize"
      class="pagination"
      @pagination="getList" />

  </div>
</template>

<script>

import { getSeatSelect } from '@/api/commonAPI'
import { getSeatRestList } from '@/api/trafficData/trafficData'
import { timestampToTime, pickerOptions } from '@/utils'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装
export default {
  name: 'SeatVacationette',
  components: {
    Pagination
  },
  filters: {

  },
  data() {
    return {
      loading: false,
      seatId: '',
      seatOptions: [],
      searchDate: '',
      pickerOptions,
      recordpath: '', // 录音的路径
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [] // 列表数据
    }
  },
  created() {
    this.getSeatSelects()
    this.getList()
    document.onkeyup = (e) => {
      if (e.keyCode === 13) {
        this.getList()
      }
    }
  },
  methods: {
    getList() {
      this.loading = true
      return new Promise(resolve => {
        const params = {
          pageindex: this.pageParams.pageindex, // 第几页
          pagesize: this.pageParams.pagesize, // 每页几条信息
          keyword: this.seatId, //	否	string	坐席id
          stime: this.searchDate && this.searchDate[0],
          etime: this.searchDate && this.searchDate[1]
        }
        getSeatRestList(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.pageParams.total = response.data.total
            this.dataLists = response.data.rows
          }
        })
        resolve()
      })
    },
    btn_search() {
      this.getList()
    },
    getSeatSelects() {
      getSeatSelect().then(response => {
        if (response.state.toLowerCase() === 'success') {
          this.seatOptions = response.data
        }
      })
    }
  }
}
</script>

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

</style>
