<template>
  <div class="app-container">
    <el-card shadow="never" class="mb16 filter-card">
      <el-form :model="queryParams" ref="queryForm" :inline="true" size="small" label-width="80px">
        <el-form-item label="租户名称" prop="companyName">
          <el-input v-model="queryParams.companyName" placeholder="请输入租户名称" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-table v-loading="loading" :data="numberList" border size="small" style="width:100%">
      <el-table-column label="号码ID" align="center" prop="mobileId" width="80" />
      <el-table-column label="所属租户" align="center" prop="companyName" min-width="140" />
      <el-table-column label="号码/CID" align="center" prop="mobile" min-width="160" />
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === '0' || scope.row.status === 0" type="success" size="small">正常</el-tag>
          <el-tag v-else-if="scope.row.status === '1' || scope.row.status === 1" type="danger" size="small">停用</el-tag>
          <el-tag v-else size="small">{{ scope.row.status }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { listCidNumber } from '@/api/admin/voiceNumber'

export default {
  name: 'AdminVoiceNumber',
  data() {
    return {
      loading: false,
      total: 0,
      numberList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      listCidNumber(this.queryParams).then(res => {
        this.numberList = res.rows || []
        this.total = res.total || 0
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
