<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker
        v-model="searchDate"
        :picker-options="pickerOptions"
        class="filter-item"
        type="daterange"
        format="yyyy年MM月dd日"
        value-format="yyyy-MM-dd"
        align="left"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      />
      <el-input v-model="keyword" placeholder="请输入主叫号码" class="filter-item" />
      <el-select v-model="roleId" class="filter-item" filterable clearable placeholder="请选择坐席">
        <el-option
          v-for="item in roleOptions"
          :key="item.F_UserCode"
          :label="item.F_UserCode"
          :value="item.F_UserCode"
        />
      </el-select>
      <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 @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="45" />
      <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="UserCode" 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">
          <svg-icon
            v-if="scope.row.FilePath"
            class="rec_file"
            icon-class="bofangluyin"
            @click.native="playSound(scope.row.FilePath, scope.row.UserCode)"
          />
          <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.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>
    <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 { getOutboundCallRecordsList } from "@/api/outbound/automaticOutbound";
import { getUserAccountLists } from '@/api/systemSetup/roleSetting/userManage'
import { getCallRecords } from '@/api/trafficData/trafficData'
import audioPlayer from '@/components/audioPlayer'
import { pickerOptions } from '@/utils'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装
export default {
  name: 'OutboundCallRecords',
  components: {
    Pagination
  },
  filters: {
    // 呼叫类型
    calltypeFilter (status) {
      const statusMap = {
        0: '呼入',
        1: '呼出'
      }
      return statusMap[status]
    },
    // 呼叫状态
    statusFilter (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
      }
    }
  },
  data () {
    return {
      loading: false,
      keyword: '',
      roleId: '',
      roleOptions: [],
      searchDate: '',
      pickerOptions,
      recordpath: '', // 录音的路径
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      multipleSelection: [], //选中数据
    }
  },
  created () {
    this.getRoleSelects()
    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, // 每页几条信息
          CallNumber: this.keyword.replace(/\s*/g, ""), //	否	string	模糊查询（呼叫号码）
          UserCode: this.roleId, //	否	string	模糊查询（呼叫号码） CallNumber
          SearchStartTime: this.searchDate && this.searchDate[0],
          SearchEndTime: this.searchDate && this.searchDate[1]
        }
        getOutboundCallRecordsList(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()
      })
    },
    btn_search () {
      this.getList()
    },
    // 获取角色下拉
    getRoleSelects () {
      getUserAccountLists().then(response => {
        if (response.state.toLowerCase() === 'success') {
          this.roleOptions = response.data.Rows
        }
      })
    },
    // 播放录音
    playSound (rec_file, artist) {
      this.$layer.iframe({
        content: {
          content: audioPlayer, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { 'recFiles': rec_file, 'artists': artist.toString() }// props//该方法会自动添加一个key为layerid的值， 该值为创建层的id， 可以直接使用
        },
        area: ['600px', '230px'],
        shadeClose: true,
        title: '录音详情'
      })
    },
    handleSelectionChange (selection) {
      this.multipleSelection = selection
    },
  }
}
</script>

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