<template>
  <div class="app-container">
    <!-- 顶部搜索区域 -->
    <el-form :inline="true" :model="queryData">
      <el-form-item label="企业名称">
        <el-input
          v-model="queryData.name"
          placeholder="请输入关键字"
          style="width: 150px"
        ></el-input>
      </el-form-item>
      <el-form-item label="审核状态">
        <el-select
          v-model="queryData.examineStatus"
          class="m-2"
          placeholder="请选择"
          style="width: 100px"
        >
          <el-option :value="1" label="已审核" />
          <el-option :value="2" label="已拒绝" />
        </el-select>
      </el-form-item>
      <el-form-item label="企业类型">
        <el-select
          v-model="queryData.kind"
          class="m-2"
          placeholder="请选择"
          style="width: 100px"
        >
          <el-option :value="101" label="上市企业" />
          <el-option :value="102" label="优质企业" />
          <el-option :value="103" label="普通企业" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="站点">
        <site-options
          v-model="queryData.tenantId"
          :site-list="siteList"
          style="width: 160px"
        />
      </el-form-item> -->

      <el-form-item style="float: right">
        <el-button
          icon="search"
          size="default"
          type="primary"
          @click="handleQuery"
          >搜索
        </el-button>
        <el-button icon="refresh" size="default" @click="resetQuery"
          >重置
        </el-button>
      </el-form-item>
    </el-form>

    <!--表格区域-->
    <el-table :data="dataList" border style="width: 100%">
      <el-table-column align="center" label="企业名称" prop="name" />
      <!-- <el-table-column prop="code" label="统一社会信用代码" align="center" /> -->
      <el-table-column align="center" label="所属领域">
        <template #default="{ row }">
          <div>{{ row.industrys[row.industrys.length - 1] }}</div>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="" label="站点" align="center">
        <template #default="{ row }">
          {{ siteList.find((el) => el.id === row.tenantId)?.name ?? "无" }}
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="所在地" prop="address" />
      <el-table-column align="center" label="审核状态" prop="examineStatus">
        <template #default="{ row }">
          <dict-tag :options="auditStatusDict" :value="row.examineStatus" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="企业类型" prop="kind">
        <template #default="{ row }">
          <div>
            {{ enterpriseOptions.find((e) => row.kind == e.key).value }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="申请时间" prop="createdAt" />
      <el-table-column align="center" label="操作" prop="" width="200px">
        <template #default="{ row }">
          <el-button size="small" type="text" @click="handleDetail(row.id)"
            >审核
          </el-button>
          <el-button size="small" type="text" @click="delList(row.id)"
            >删除
          </el-button>
          <el-button size="small" type="text" @click="setType(row)"
            >设置企业类型
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页器 -->
    <pagination
      v-show="total > 0"
      v-model:limit="queryData.page_size"
      v-model:page="queryData.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 设置企业类型弹框 -->
    <el-dialog v-model="isShow" title="设置企业类型">
      <el-row justify="center" style="height: 100px" type="flex">
        <el-radio-group v-model="setTypeRow.kind">
          <el-radio
            v-for="{ key, value } in enterpriseOptions"
            :key="key"
            :label="key"
            >{{ value }}
          </el-radio>
          <!-- <el-radio label="101">上市企业</el-radio> -->
          <!-- <el-radio label="102">优质企业</el-radio> -->
          <!-- <el-radio label="103">普通企业</el-radio> -->
        </el-radio-group>
      </el-row>
      <el-row justify="end" type="flex">
        <el-button type="" @click="isShow = false">取消</el-button>
        <el-button type="primary" @click="btnType">确认</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script setup>
import { delItem, editType, enterpriseList } from "@/api/dataList/list";
import { enterpriseOptions } from "@/utils/parameter";
import { reactive, ref } from "vue";
import { ElMessageBox } from "element-plus";
import { cloneDeep } from "lodash";
import { useRouter } from "vue-router";
import useUserStore from "@/store/modules/user";
import { auditStatusDict } from "@/constant/dict";
import DictTag from "@/components/DictTag/index.vue";

const data = reactive({
  queryData: {
    pageNum: 1,
    pageSize: 10,
    examineStatus: "",
  },
  setTypeRow: {},
});
const router = useRouter();
const total = ref(0);
const dataList = ref([]);
const { queryData, setTypeRow } = toRefs(data);
// const siteList = ref([]);
const isShow = ref(false);
const radioList = ref("");

// 临时id
const id = ref("");
// 获取企业列表
const getList = async () => {
  const res = await enterpriseList(queryData.value);
  dataList.value = res.rows;
  total.value = res.total;
};
// // 获取站点列表
// const getSiteList = async () => {
//   const resp = await tenantSelect();
//   siteList.value = resp.rows;
// };
// 搜索查询
const handleQuery = () => {
  getList(queryData.value);
};
// 重置按钮
const resetQuery = () => {
  queryData.value = {
    pageNum: 1,
    pageSize: 10,
    examineStatus: "",
  };
  getList();
};
// 企业类型弹框
const setType = (row) => {
  // radioList.value = row.kind;
  isShow.value = true;
  // id.value = row.id;
  setTypeRow.value = cloneDeep(row);
};
// 发送修改类型请求

const btnType = async () => {
  await editType({ id: setTypeRow.value.id, kind: setTypeRow.value.kind });
  getList();
  isShow.value = false;
};
// 删除按钮
const delList = async (id) => {
  ElMessageBox.confirm(`是否确认删除编号为${id}的数据项？`)
    .then(async () => {
      await delItem(id);
      getList();
      ElMessage.success("删除成功");
    })
    .catch(() => {});
  getList();
};
// 跳转详情页
const handleDetail = (id) => {
  router.push({
    path: "/approval/dataList/add",
    query: { id },
  });
};
getList();
// getSiteList();
useUserStore().getUnApprovedBusiness();
</script>
<style></style>
