<template>
  <table-module
    :pageData="pageData"
    @columnEvent="columnEvent"
    @paginationEvent="paginationEvent"
  />
</template>
<script setup name="zwgkzd">
import api from "@/api/zwgk.js";
import { useRouter } from "vue-router";
import tableModule from "@/components/tableModule/publicInfo.vue";
import { onMounted, ref } from "vue";

const router = useRouter();
const pageData = ref({
  pagination: {
    total: 0,
    size: 20,
    current: 1,
  },
  tableData: [],
  mouduleName: "政府信息公开年报",
});
onMounted(() => {
  getTableList();
});

function getTableList() {
  api.annualReport(pageData.pagination).then((res) => {
    if (res.code == 200) {
      pageData.value.pagination.size = res.data.size;
      pageData.value.pagination.total = res.data.total;
      pageData.value.pagination.current = res.data.pages;
      res.data.records.map((item) => {
        item.documentName = item.title;
        item.publishDate = item.publishTime.substring(0, 10);
        pageData.value.tableData.push(item);
      });
    }
  });
}

// 分页
function paginationEvent(val) {
  pageData.pagination.current = val;
  getTableList();
}

// 查看详情
function columnEvent(data) {
  //定义一个路径
  let href = router.resolve({
    path: "/articleDetails",
    query: { type: "gknb", id: data.id },
  }).href;
  //打开新的页面 到 href 这个页面
  window.open(href, "_blank");
}
</script>
