<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="keyword" placeholder="请输入关键字" class="filter-item" />
      <el-select v-model="ZXZCode" class="filter-item" filterable clearable placeholder="请选择坐席组">
        <el-option
          v-for="item in agentGroupDataLists"
          :key="item.F_ZXZCode"
          :label="item.F_ZXZName"
          :value="item.F_ZXZCode"
        />
      </el-select>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="btn_search">搜索</el-button>
      <el-button type="primary" v-permission="'HY_add'" class="filter-item" @click="btn_add">添加</el-button>
    </div>
    <el-table v-loading="loading" :data="dataLists" border stripe>
      <!-- <el-table-column type="selection" width="45" /> -->
      <el-table-column type="index" label="编号" align="center" fixed width="80" />
      <el-table-column prop="F_Name" label="名称" align="center" min-width />
      <el-table-column prop="F_ZXZCode" label="坐席组" align="center" min-width />
      <el-table-column prop="F_Tel" label="底号" align="center" min-width />
      <el-table-column prop="F_CreateOn" label="创建时间" align="center" min-width />
      <el-table-column prop="F_CreateBy" label="创建人" align="center" min-width />
      <el-table-column label="操作" width="160" align="center" class-name="oparate_btn" fixed="right">
        <template slot-scope="scope">
          <el-button v-permission="'HY_edit'" size="mini" type="text" @click="btn_edit(scope.row.F_ID)">编辑</el-button>
          <el-button v-permission="'HY_delete'" size="mini" type="text" @click="btn_delete(scope.row.F_ID)">删除</el-button>
        </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 { getBaseNumberList, deleteBaseNumberList } from "@/api/systemSetup/roleSetting/baseNumberManagement"
import { getCallRecords } from '@/api/trafficData/trafficData'
import { getSeatGroupLists } from '@/api/systemSetup/roleSetting/seatGroup'
import addOrEdit from './addOrEdit'
import Pagination from '@/components/Pagination' // 对el-pagination 二次封装
export default {
  name: 'BaseNumberManagement',
  components: {
    Pagination
  },
  filters: {
  },
  data () {
    return {
      loading: false,
      keyword: '',
      ZXZCode: '',
      agentGroupDataLists: '', //坐席组数据
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      multipleSelection: [], //选中数据
    }
  },
  created () {
    this.getList()
    this.getAgentGroup()
    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.replace(/\s*/g, ""), //	关键字
          code: this.ZXZCode, //坐席组code
        }
        getBaseNumberList(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.pageParams.total = response.rows.Totals
            this.dataLists = response.rows.Rows
          }
        })
        resolve()
      })
    },
    btn_search () {
      this.getList()
    },
    btn_add () {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: '' } // props//该方法会自动添加一个key为layerid的值， 该值为创建层的id， 可以直接使用
        },
        area: ['80%', '90%'],
        shadeClose: false,
        title: '添加底号管理'
      })
    },
    btn_edit (id) {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: id } // props//该方法会自动添加一个key为layerid的值， 该值为创建层的id， 可以直接使用
        },
        area: ['80%', '90%'],
        shadeClose: false,
        title: '编辑底号管理'
      })
    },
    btn_delete (id) {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = {
          ids: id,
        }
        deleteBaseNumberList(params).then(response => {
          if (response.state.toLowerCase() === 'success') {
            this.getList()
            this.$message.success('删除成功!')
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },
    //获取坐席组
    getAgentGroup() {
      this.loading = true
      return new Promise(resolve => {
        const params = {
          pageindex: 1, // 第几页
          pagesize: 100, // 每页几条信息
          key: '',
        }
        getSeatGroupLists(params).then(response => {
          this.loading = false
          if (response.state.toLowerCase() === 'success') {
            this.agentGroupDataLists = response.data.Rows
          }
        })
        resolve()
      })
    },
  }
}
</script>

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