<template>
  <div>
    <el-card style="margin-bottom:5px" :body-style="{ padding: '8px' }">
      <header-box :headerForm="search" @searchClick="getData">
      </header-box>
    </el-card>
    <el-card :body-style="{ padding: '5px' }">
      <content-box :loading="loading" :showButtons="showButtons" :tableData="tableData" :pagination="pagination" :ruleForm="ruleForm"
        @refreshTable="getData" />
    </el-card>
  </div>
</template>
<script>
  import headerBox from "./components/header";
  import contentBox from "./components/content";
  import {
    mapState
  } from "vuex";
  export default {
    data() {
      return {
        search: {
          title: "",
        },
        params: {},
        ruleForm: {
          title: "",
          class: "",
        },
      }
    },
    computed: {
      ...mapState({
        tableData: (state) => state.documentView.tableData,
        pagination: (state) => state.documentView.pagination,
        showButtons: (state) => state.documentView.showButtons,
      }),
      loading: {
        get() {
          return this.$store.state.documentView.loading;
        },
        set(val) {
          this.$store.state.documentView.loading = val;
        },
      },
    },
    components: {
      headerBox,
      contentBox
    },
    methods: {
      getData() {
        this.loading = true;
        this.params = {
          page: this.pagination.pageNum,
          limit: this.pagination.pageSize,
          title: this.search.title,
        };
        this.$store.dispatch('documentView/getData', this.params).catch(err => {
          this.loading = false
        })
      },

    },
    created() {
      let btnData = {
        menuid: this.$getMenuId(sessionStorage.getItem("routerIdList"), this.$route.path),
        roleid: sessionStorage.getItem("roleid")
      }
      this.$store.dispatch("documentView/getButtonList", btnData);
      this.getData()
    }
  }

</script>
