<template>
  <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="CusCode" 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">{{ scope.row.CallType | calltypeFilter }}</template>
      </el-table-column>
      <el-table-column label="呼叫状态" align="center" min-width>
        <template slot-scope="scope">
          <el-tag
            :type="scope.row.CallState === 1 ? 'success' : 'danger'"
            size="mini"
            disable-transitions
          >{{ scope.row.CallState | statusFilter }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="处理方式" align="center" min-width>
        <template slot-scope="scope">{{ scope.row.DealType | dealtypeFilter }}</template>
      </el-table-column>
      <el-table-column label="满意度" align="center" min-width>
        <template slot-scope="scope">{{ scope.row.MYD | evaluationFilter }}</template>
      </el-table-column>
      <el-table-column label="录音" align="center" min-width>
        <template slot-scope="scope">
          <svg-icon
            v-if="scope.row.FilePath"
            class="rec_file"
            icon-class="bofangluyin"
            @click.native="playSound(scope.row.FilePath, scope.row.agent_code)"
          />
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="呼叫开始时间" align="center" min-width="110">
        <template slot-scope="scope">
          <span>{{ scope.row.BeginTime | timesFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column label="通话开始时间" align="center" min-width="110">
        <template slot-scope="scope">
          <span>{{ scope.row.TalkStartTime | timesFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column label="通话结束时间" align="center" min-width="110">
        <template slot-scope="scope">
          <span>{{ scope.row.TalkEndTime | timesFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column label="挂机时间" align="center" min-width="110">
        <template slot-scope="scope">
          <span>{{ scope.row.EndTime | timesFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="TalkLongTime" label="通话时长" align="center" min-width />
      <el-table-column prop="RelayNumber" label="中继号码" align="center" min-width />
      <el-table-column label="外呼类型" align="center" min-width>
        <template slot-scope="scope">{{ scope.row.callopttype | callopttypeFilter }}</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="getCallRecord"
    />
  </div>
</template>

<script>
import {
  getCallRecords
} from '@/api/trafficData/trafficData'
import audioPlayer from '@/components/audioPlayer'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装

export default {
  name: 'CallRecord',
  components: {
    Pagination
  },
  filters: {
    // 呼叫类型
    calltypeFilter (status) {
      const statusMap = {
        0: '呼入',
        1: '呼出'
      }
      return statusMap[status]
    },
    // 呼叫状态
    statusFilter (status) {
      const statusMap = {
        0: '未接通',
        1: '已接通'
      }
      return statusMap[status]
    },
    // 外呼类型
    callopttypeFilter (status) {
      const statusMap = {
        0: '拨号外呼',
        1: '回访外呼'
      }
      return statusMap[status]
    },
    // 处理方式
    dealtypeFilter (status) {
      const statusMap = {
        0: 'IVR处理',
        1: '骚扰电话',
        2: '自助服务',
        3: '转值班电话',
        4: '留言',
        5: '呼损',
        6: '人工处理'
      }
      return statusMap[status]
    },
    // 满意度
    evaluationFilter (status) {
      const statusMap = {
        0: '-',
        1: '非常满意',
        2: '基本满意',
        3: '不满意'
      }
      return statusMap[status]
    },
    // 时间格式化
    timesFilter (tm) {
      if (tm === '1970-01-01 08:00:00') {
        return '-'
      } else {
        return tm
      }
    }
  },
  props: {
    callinNum: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      loading: false,
      recordpath: '', // 录音的路径
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0, // 总共多少数据
        prevText: '上一页',
        nextText: '下一页'
      },
      dataLists: [] // 通话记录列表数据
    }
  },
  created () {

  },
  methods: {
    // 获取通话记录
    getCallRecord () {
      this.loading = true
      return new Promise(resolve => {
        const params = {
          pageindex: this.pageParams.pageindex, // 第几页
          pagesize: this.pageParams.pagesize, // 每页几条信息
          CallType:'',
          keyword: this.callinNum //	否	string	模糊查询（呼叫号码）
        }
        getCallRecords(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.recordpath = response.data.recordpath
            this.pageParams.total = response.data.Totals
            this.dataLists = response.data.Rows
          }
        })
        resolve()
      })
    },
    // 播放录音
    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>
