<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="keyword" placeholder="请输入呼叫号码" class="filter-item"/>
      <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">
          <span>{{ scope.row.peer_line_type | peerLineTypeFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column label="主叫坐席" align="center" min-width="">
        <template slot-scope="scope">
          {{ scope.row.caller_agent_id = scope.row.caller_agent_id === 0 ? '-' : scope.row.caller_agent_id }}
        </template>
      </el-table-column>
      <el-table-column prop="caller" label="呼叫号码" align="center" min-width=""/>
      <el-table-column label="被叫坐席" align="center" min-width="">
        <template slot-scope="scope">
          {{ scope.row.callee_agent_id = scope.row.callee_agent_id === 0 ? '-' : scope.row.callee_agent_id }}
        </template>
      </el-table-column>
      <el-table-column prop="callee" label="被呼叫号码" align="center" min-width=""/>
      <el-table-column label="三方是否成功" align="center" min-width="">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.is_conference_ok === 1 ? 'success' : 'danger'"
            size="mini"
            disable-transitions>
            {{ scope.row.is_conference_ok | statusFilter }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="转三方时间" align="center" min-width="">
        <template slot-scope="scope">
          <span>{{ scope.row.time_connected | timestampToTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="转三方结束时间" align="center" min-width="">
        <template slot-scope="scope">
          <span>{{ scope.row.time_conference_end | timestampToTime }}</span>
        </template>
      </el-table-column>
    </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 { getThreeCallList } from '@/api/trafficData/trafficData'
import { timestampToTime } from '@/utils'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装

export default {
  name: 'ThreePartyTelCalls',
  components: {
    Pagination
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: '成功',
        0: '不成功'
      }
      return statusMap[status]
    },
    peerLineTypeFilter(type) {
      // 0-未知设备,1-内线分机，2-中继外线,7-VOIP资源
      const typeMap = {
        0: '未知设备',
        1: '内线分机',
        2: '中继外线',
        7: 'VOIP资源'
      }
      return typeMap[type]
    }
  },
  data() {
    return {
      loading: false,
      keyword: '',
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [] // 列表数据
    }
  },
  created() {
    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.keyword //	否	string	模糊查询（呼叫号码）
        }
        getThreeCallList(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()
    }
  }
}
</script>

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

</style>
