<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 prop="caller" label="呼叫号码" align="center" min-width=""/>
      <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_call_ok === 1 ? 'success' : 'danger'"
            size="mini"
            disable-transitions>
            {{ scope.row.is_call_ok | statusFilter }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="转移开始时间" align="center" min-width="">
        <template slot-scope="scope">
          <span>{{ scope.row.time_call_begin | timestampToTime }}</span>
        </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_call_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 { getIVRCalloutRecord } from '@/api/trafficData/trafficData'
import { timestampToTime } from '@/utils'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装

export default {
  name: 'IVRCallOut',
  components: {
    Pagination
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: '不成功',
        1: '成功'
      }
      return statusMap[status]
    }
  },
  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	模糊查询（呼叫号码）
        }
        getIVRCalloutRecord(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>
