<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">
          {{ 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 prop="callee" label="被呼叫号码" align="center" min-width=""/>
      <el-table-column label="振铃开始时间" align="center" min-width="">
        <template slot-scope="scope">
          <span>{{ scope.row.time_ring_back | timestampToTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="呼出是否成功" align="center" min-width="">
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.is_call_out_ok === 1 ? 'success' : 'danger'"
            size="mini"
            disable-transitions>
            {{ scope.row.is_call_out_ok | statusFilter }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="time_connected" label="通话建立时间" align="center" min-width="">
        <template slot-scope="scope">
          <span>{{ scope.row.time_hang_up | timestampToTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="录音" align="center" min-width="">
        <template slot-scope="scope">
          <svg-icon v-if="scope.row.rec_file_name.length" class="rec_file" icon-class="bofangluyin" @click.native="playSound(scope.row.rec_file_name, scope.row.caller_agent_id)"/>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="挂断时间" align="center" min-width="">
        <template slot-scope="scope">
          <span>{{ scope.row.time_hang_up | timestampToTime }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="period_talking" label="通话时长" align="center" min-width=""/>
    </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 { getCallOutList } from '@/api/trafficData/trafficData'
import { timestampToTime } from '@/utils'
import audioPlayer from '@/components/audioPlayer'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装

export default {
  name: 'OutcryData',
  components: {
    Pagination
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: '成功',
        0: '不成功'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      loading: false,
      keyword: '',
      recordpath: '', // 录音的路径
      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	模糊查询（呼叫号码）
        }
        getCallOutList(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.recordpath = response.data.recordpath
            this.pageParams.total = response.data.total
            this.dataLists = response.data.rows
          }
        })
        resolve()
      })
    },
    btn_search() {
      this.getList()
    },
    // 播放录音
    playSound(rec_file, artist) {
      this.$layer.iframe({
        content: {
          content: audioPlayer, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'recFiles': this.recordpath + rec_file, 'artists': artist.toString() }// props//该方法会自动添加一个key为layerid的值， 该值为创建层的id， 可以直接使用
        },
        area: ['600px', '230px'],
        shadeClose: true,
        title: '录音详情'
      })
    }
  }
}
</script>

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

</style>
