<!--
 * @Description: 坐席效能统计
 * @Author: 王晓颖
 * @Date: 2020-04-28 15:08:24
 -->
<template>
  <app-container>
    <div>
      <search-area :need-clear="false" :need-search-more="false" :size="size" type="default" search-more-type="default" @search="search">
        <chart-tools @change="changeTime"/>
        <!--一般查询条件-->
        <search-item>
          <el-date-picker
            v-model="timeRange"
            :size="size"
            type="daterange"
            range-separator="至"
            value-format="yyyy-MM-dd"
            start-placeholder="查询开始日期"
            end-placeholder="查询结束时间"/>
        </search-item>
      </search-area>
      <normal-table
        :data="data"
        :head="tableOption.head"
        :size="size"
        :query="listQuery"
        :need-page="false"
        :total="total"
        :columns="columns"
        :list-loading="listLoading"
        :options="tableOption.options"
        :tools-option="tableOption.toolsOption"
        @change="changePage"/>
      <el-row :gutter="10">
        <el-col :span="12">
          <border-frame title="总话务量统计图">
            <call-total-bar :data="data"/>
          </border-frame>
        </el-col>
        <el-col :span="12">
          <border-frame title="话务时长统计图">
            <call-time-line :data="data"/>
          </border-frame>
        </el-col>
      </el-row>
    </div>
  </app-container>
</template>

<script>
import NormalTable from '@/components/NomalTable/index'
import SearchArea from '../../../components/SearchArea/SearchArea'
import SearchItem from '../../../components/SearchArea/SearchItem'
import AppContainer from '../../../components/layout/AppContainer'
import { seatStatistics } from '@/api/statistics'
import ChartTools from '../components/chartTools'
import CallTotalBar from './components/callTotalBar'
import BorderFrame from '../../../components/frame/borderFrame'
import CallTimeLine from './components/callTimeLine'
import { getToday } from '@/utils/dateutils'

export default {
  name: 'CaseStatisticYear',
  components: { CallTimeLine, BorderFrame, CallTotalBar, ChartTools, AppContainer, SearchItem, SearchArea, NormalTable },
  data() {
    return {
      listQuery: {
        startTime: '',
        endTime: ''
      },
      timeRange: [getToday('yyyy-MM-dd'), getToday('yyyy-MM-dd')], // 查询日期范围
      columns: [
        {
          text: '姓名',
          value: 'userName'
        },
        {
          text: '坐席号',
          value: 'seat'
        },
        {
          text: '接入话务量',
          value: 'callInCount'
        },
        {
          text: '呼出话务量',
          value: 'callOutCount'
        },
        {
          text: '总话务量',
          value: 'callTotalCount'
        },
        {
          text: '受理事件数',
          value: 'acceptCount'
        },
        {
          text: '直接回复数',
          value: 'directReplyCount'
        },
        {
          text: '协同申请数',
          value: 'assignCount'
        },
        {
          text: '暂存数',
          value: 'storagyCount'
        },
        {
          text: '回访重办数',
          value: 'returnDoCount'
        },
        {
          text: '在线呼入时长（分）',
          value: 'onLineInTime'
        },
        {
          text: '在线呼出时长（分）',
          value: 'onLineOutTime'
        },
        {
          text: '在线空闲时长（分）',
          value: 'onLineFreeTime'
        },
        {
          text: '总在线时长（分）',
          value: 'onLineTotalTime'
        },
        {
          text: '总置忙时长（分）',
          value: 'busyTotalTime'
        },
        {
          text: '总签入时长（分）',
          value: 'callInTotalTime'
        },
        {
          text: '平均呼入时长（分）',
          value: 'callInAvgTime'
        },
        {
          text: '平均呼出时长（分）',
          value: 'callOutAvgTime'
        }
      ], // 显示列
      data: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 列表加载动画
      tableOption: {
        head: {
          show: false, // 是否需要标题栏，
          text: '数据列表' // 标题名称
        },
        options: {
          needIndex: false // 是否需要序号列
        },
        toolsOption: {
          selectColumns: false, // 是否需要筛选列
          refresh: false // 是否需要刷新按钮
        }
      }, // 表格属性
      size: 'small',
      userList: [] // 用户列表
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    search() {
      this.fetchData()
    },
    fetchData() {
      this.listLoading = true
      if (this.timeRange.length === 2) {
        this.listQuery.startTime = this.timeRange[0]
        this.listQuery.endTime = this.timeRange[1]
      }
      seatStatistics(this.listQuery).then(response => {
        if (response.code === 200) {
          this.listLoading = false
          this.data = response.data
          // this.data = [
          //   { userName: '坐席1', seat: '001', callInCount: 0, callOutCount: 0, callTotalCount: 20, acceptCount: 0, directReplyCount: 0, assignCount: 0, storagyCount: 0, onLineInTime: 0, onLineFreeTime: 0, redoOneCount: 0, redoTwoCount: 0 },
          //   { userName: '坐席2', seat: '002', callInCount: 0, callOutCount: 0, callTotalCount: 21, acceptCount: 0, directReplyCount: 0, assignCount: 0, storagyCount: 0, onLineInTime: 0, onLineFreeTime: 0, redoOneCount: 0, redoTwoCount: 0 },
          //   { userName: '坐席3', seat: '003', callInCount: 0, callOutCount: 0, callTotalCount: 10, acceptCount: 0, directReplyCount: 0, assignCount: 0, storagyCount: 0, onLineInTime: 0, onLineFreeTime: 0, redoOneCount: 0, redoTwoCount: 0 },
          //   { userName: '坐席4', seat: '004', callInCount: 0, callOutCount: 0, callTotalCount: 5, acceptCount: 0, directReplyCount: 0, assignCount: 0, storagyCount: 0, onLineInTime: 0, onLineFreeTime: 0, redoOneCount: 0, redoTwoCount: 0 }
          // ]
        }
      })
    },
    // 页数发生变化后的操作，可能是页码变化，可能是每页容量变化，此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    },
    changeTime(val) {
      this.timeRange = val
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .table-title{
    text-align: center;
    line-height: 2;
    font-size:18px;
    font-weight: 700;
    background-color: #f0f0f0;

  }
  .level-txt{
    margin-left:20px;
    color: #909399;
    font-size:15px;
    line-height: 32px
  }
</style>
