<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryFormRef"
      :inline="true"
      :model="queryParams"
      label-width="68px"
    >
      <el-form-item label="企业名称" prop="name">
        <el-input
          v-model="queryParams.name"
          clearable
          placeholder="请输入企业名称"
          size="default"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <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-row v-if="false" :gutter="10" class="mb8">
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="dataList"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column align="center" label="机构名称" prop="name" />
      <el-table-column align="center" label="统一社会信用代码" prop="code" />
      <el-table-column align="center" label="主要研究方向" prop="research" />
      <el-table-column align="center" label="所在地" prop="address" />
      <el-table-column align="center" label="申请时间">
        <template #default="{ row }">
          <span>{{ 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="edit"
            size="small"
            type="text"
            @click="handleApproval(row.id)"
            >审核
          </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 name="ResearchApproval" setup>
import { reactive, ref, toRefs } from "vue";
import { useRouter } from "vue-router";
import { researchList } from "@/api/dataList/research";
import DictTag from "@/components/DictTag/index.vue";
import { auditStatusDict } from "@/constant/dict";

const router = useRouter();
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: undefined,
  },
});

const { queryParams } = toRefs(data);
const showSearch = ref(true);
const loading = ref(true);
const total = ref(0);
const dataList = ref([]);
const ids = ref([]);

const handleSelectionChange = (selection) => {
  ids.value = selection.map((el) => el.id);
};

/** 研究机构列表 */
const getList = async () => {
  loading.value = true;
  const resp = await researchList(queryParams.value);
  dataList.value = resp.rows;
  total.value = resp.total;
  loading.value = false;
};

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

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

const handleApproval = (id) => {
  router.push({
    path: "/approval/research/approval",
    query: { id },
  });
};

getList();
</script>
