<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, reactive } from "vue";

const router = useRouter();
const pageData = reactive({
  pagination: {
    total: 0,
    size: 20,
    current: 1,
  },
  tableData: [],
  mouduleName: "行政规范性文件",
});
onMounted(() => {
  getTableList();
});

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

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

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