<template>
  <div class="page">
    <header-box :headerForm="headerForm" @searchClick="getData" @resetClick="resetClick">
    </header-box>
    <content-box :loading="loading" :showButtons="showButtons" :tableData="tableData" :pagination="pagination" :ruleForm="ruleForm"
      @refreshTable="getData">
    </content-box>
  </div>
</template>

<script>
  import {
    getData,
  } from "@/api/archiveUtilize/compilationResearch/editingTopics"
  import {
    message,
    clearObjValue
  } from "@/utils/common";
  import { getButtonList } from "@/api/user"
  import headerBox from "./components/header";
  import contentBox from "./components/content";
  export default {
    data() {
      return {
        headerForm: {
          title: "",
        },
        params: {},
        loading: false,
        tableData: [],
        pagination: {
          pageSize: 10,
          pageNum: 1,
          total: 0,
        },
        ruleForm: {
          title: "",
          class: "",
        },
        showButtons: {
          look: false,
          submit: false,
        },
      };
    },
    components: {
      headerBox,
      contentBox,
    },
    methods: {
      getData() {
        this.loading = true;
        this.params = {
          page: this.pagination.pageNum,
          limit: this.pagination.pageSize,
          title: this.headerForm.title,
          state: 5
        };
        let params = this.params;
        getData(params).then((res) => {
          this.tableData = res.body.list;
          this.pagination.total = res.body.total;
          this.loading = false;
        });
      },
      //重置
      resetClick() {
        clearObjValue(this.headerForm);
      },
      async getButtonList(){
        let params = {
          menuid: this.$getMenuId(sessionStorage.getItem("routerIdList"), this.$route.path),
          roleid: sessionStorage.getItem("roleid")
        }
        let res =  await getButtonList(params);
        if(res.code === '100'){
          let data = res.body.list;
          data.forEach(item=>{
            this.showButtons[item.key] = true;
          })
        }
      },
    },
    created() {
      this.getButtonList()
      this.getData();
    },
  };

</script>

<style lang="scss" scoped>
  .page {
    width: 100%;
  }

</style>
