<template>
  <div class="app-container">
    <el-form
      ref="queryFormRef"
      :inline="true"
      :model="queryParams"
      label-width="85px"
    >
      <el-form-item label="实验室名称" prop="name">
        <el-input
          v-model="queryParams.name"
          clearable
          placeholder="请输入实验室名称"
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--      <el-form-item v-if="isSuper" label="所属站点" prop="tenant_id">-->
      <!--        <SiteOptions v-model="queryParams" :site-list="[]"/>-->
      <!--      </el-form-item>-->

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

    <el-table v-loading="loading" :data="dataList" border>
      <el-table-column align="center" label="姓名" prop="name" />
      <!--      <el-table-column align="center" label="手机号" prop="mobile" />-->
      <el-table-column align="center" label="资格证书缩略图">
        <template #default="{ row }">
          <el-image
            :src="row.certificatePics?.split(',')?.[0] ?? ''"
            style="width: 120px; height: 120px"
          ></el-image>
        </template>
      </el-table-column>
      <!--      <el-table-column align="center" label="站点" prop="area" />-->
      <el-table-column align="center" label="所在地" prop="wordAddress" />
      <el-table-column align="center" label="申请时间" prop="createTime">
        <template #default="{ row }">
          <span>{{ parseTime(row.createTime) }}</span>
        </template>
      </el-table-column>
      <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="操作">
        <template #default="{ row }">
          <el-button
            icon="el-icon-edit"
            size="small"
            type="text"
            @click="handleDetail(row.brokerId)"
            >审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      v-model:limit="queryParams.pageSize"
      v-model:page="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>
<script setup>
import { reactive, ref, toRefs } from "vue";
import { useRouter } from "vue-router";
import { agentList } from "@/api/dataList/agent";
import { parseTime } from "@/utils/ruoyi";
import DictTag from "@/components/DictTag/index.vue";
import { auditStatusDict } from "@/constant/dict";
/* TODO: is_super: this.$store.getters.is_super,  */

const router = useRouter();
const showSearch = ref(true);
const loading = ref(true);
const total = ref(0); /*总条数*/
const dataList = ref(null); /*实验室表格数据*/
const queryFormRef = ref();
const isSuper = ref(false);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: undefined,
  },
});

const { queryParams } = toRefs(data);

/*查询实验室列表*/
const getList = () => {
  loading.value = true;
  agentList(queryParams.value).then((response) => {
    dataList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
};

/**
 * 搜索按钮操作
 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/**
 * 重置按钮操作
 */
const resetQuery = () => {
  // dateRange.value = [];
  queryFormRef.value?.resetFields();
  handleQuery();
};

/**
 * 详情
 * @param id
 */
const handleDetail = (id) => {
  router.push({
    path: "/approval/agent-approval-detail",
    query: { id },
  });
};

getList();
</script>
