<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="关键词" prop="keyword">
        <el-input v-model="queryParams.keyword" placeholder="请输入关键词" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="租户">
        <inline-tenant-selector @change="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-table v-loading="loading" :data="list" border>
      <el-table-column label="ID" prop="id" width="80" align="center" />
      <el-table-column label="租户ID" prop="companyId" width="100" align="center" v-if="showCompanyId" />
      <el-table-column label="创建时间" prop="createTime" width="160" align="center" />
      <el-table-column label="操作" width="120" fixed="right" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

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

<script>
import { getRequest } from "@/api/common";
import InlineTenantSelector from "@/components/InlineTenantSelector";

export default {
  name: "CompanyVoiceRoboticController",
  components: { InlineTenantSelector },
  data() {
    return {
      loading: false,
      showSearch: true,
      list: [],
      total: 0,
      showCompanyId: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      getRequest("/company/companyVoiceRobotic/list", this.$withTenant(this.queryParams)).then(response => {
        this.list = response.rows || response.data || [];
        this.total = response.total || 0;
        this.loading = false;
      }).catch(() => {
        this.list = [];
        this.total = 0;
        this.loading = false;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.queryParams = { pageNum: 1, pageSize: 10, keyword: undefined };
      this.handleQuery();
    },
    handleView(row) {
      this.$message.info("查看详情: ID=" + row.id);
    },
  },
};
</script>
