<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="企业名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入企业名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="examine_status">
        <el-select
          v-model="queryParams.examine_status"
          placeholder="请选择审核状态"
          clearable
          size="small"
          style="width: 240px"
          @clear="delete queryParams.examine_status"
        >
          <el-option label="审核中" :value="1" />
          <el-option label="审核通过" :value="2" />
          <el-option label="审核拒绝" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="所属站点" prop="tenant_id" v-if="is_super">
        <SiteOptions v-model="queryParams" />
      </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="dataList">
      <el-table-column label="数据编号" align="center" prop="id" />
      <el-table-column label="企业名称" align="center" prop="name" />
      <el-table-column label="统一社会信用代码" align="center" prop="code" />
      <el-table-column
        label="所属领域"
        align="center"
        prop="industrys"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <div>{{ scope.row.industrys[scope.row.industrys.length - 1] }}</div>
        </template>
      </el-table-column>
      <el-table-column label="站点" align="center" prop="area" />
      <el-table-column label="所在地" align="center" prop="address" />
      <el-table-column label="审核状态" align="center" prop="examine_status">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.examine_status == 1"
            >审核中</el-tag
          >
          <el-tag type="success" v-else-if="scope.row.examine_status == 2"
            >审核通过</el-tag
          >
          <el-tag type="danger" v-else>审核拒绝</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="企业类型" align="center" prop="kind">
        <template slot-scope="scope">
          <div>
            {{ enterpriseOptions.find((e) => scope.row.kind == e.key).value }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="created_at">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.created_at) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            :disabled="scope.row.examine_status != 1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row.id)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

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

<script>
import { companyList } from "@/api/dataList/enterprise";

export default {
  data() {
    return {
      is_super: this.$store.getters.is_super,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 企业表格数据
      dataList: null,
      // 查询参数
      queryParams: {
        page_num: 1,
        page_size: 10,
        name: undefined,
        examine_status: undefined,
        tenant_id: undefined,
      },
    };
  },
  methods: {
    /** 查询企业列表 */
    getList() {
      this.loading = true;
      companyList(this.queryParams).then((response) => {
        this.dataList = response.data.data;
        this.total = response.data.count;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page_num = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleDetail(id) {
      console.log(id);
      this.$router.push({
        path: "/examine/enterpriseDetail",
        query: { id },
      });
    },
  },
  created() {
    this.getList();
  },
};
</script>