<script setup>
import Pagination from "@/components/Pagination/index.vue";
import { reactive, ref, toRefs } from "vue";
import { seeLogTypeDict } from "@/constant/dict";
import { useRoute, useRouter } from "vue-router";
import { seeLogList } from "@/api/admin/laboratory/paper";

const route = useRoute();
const router = useRouter();
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    id: null,
  },
});
const { queryParams } = toRefs(data);
if (route.query.id) {
  queryParams.value.id = route.query.id;
} else {
  router.push({ path: "/admin/research/paper" });
}
const queryRef = ref();
const tableData = ref([]);
const loading = ref(false);
const total = ref(0);
const getList = async () => {
  loading.value = true;
  const resp = await seeLogList(queryParams.value);
  tableData.value = resp.rows;
  total.value = resp.total;
  loading.value = false;
};

const resetQuery = () => {
  if (queryRef.value) {
    queryRef.value.resetFields();
  }
  handleQuery();
};

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

/**
 * 删除
 * @param row
 */
const handleDelete = (row) => {
  console.log(row);
};

getList();
</script>

<template>
  <div class="app-container">
    <el-form ref="queryRef" class="mb8" :model="queryParams" inline>
      <!--     企业名称-->
      <el-form-item label="企业名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入企业名称"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--  客户浏览数据列表-->
    <el-table :data="tableData">
      <!--多选-->
      <el-table-column label="企业名称" prop="enterpriseName"></el-table-column>
      <el-table-column label="浏览类别" prop="type">
        <template #default="{ row }">
          <span>{{
            seeLogTypeDict.find((item) => item.value === row.type)?.label
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="名称" prop="typeName"></el-table-column>
      <el-table-column label="联系人" prop="nickname"></el-table-column>
      <el-table-column label="手机" prop="phone"></el-table-column>
      <el-table-column label="浏览次数" prop="seeCount"></el-table-column>
      <el-table-column label="浏览时间" prop="updateTime"></el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-model:limit="queryParams.pageSize"
      v-model:page="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<style lang="scss" scoped></style>
