<template>
  <div>
    <el-card :body-style="{ padding: '5px' }" style="margin-bottom:5px">
      <header-box :search="search" />
    </el-card>
    <el-card :body-style="{ padding: '5px' }">
      <div style="text-align:right;padding:5px 10px ">
        <el-button @click="diaBox('新增')" v-if="showButtons.add" size="mini" type="primary">新建</el-button>
      </div>
      <content-box :tableData='tableData' :showButtons="showButtons" :tableLoading='tableLoading' :pagination='pagination' @getData='getData'
        @edit='diaBox' />
    </el-card>
    <dia-box ref="diaBox" @cancel='cancel' :title='title' :isDiaBox='isDiaBox' @getData='getData' />
  </div>
</template>
<script>
  import {
    mapState
  } from "vuex";
  import diaBox from "./components/diaBox.vue"
  import headerBox from "./components/header.vue"
  import contentBox from "./components/content.vue"
  export default {
    data() {
      return {
        search: {
          frameName: ""
        },
        title: "",
        params: {},
        isDiaBox: false
      }
    },
    computed: {
      ...mapState({
        tableData: (state) => state.denseFrameParameters.tableData,
        pagination: (state) => state.denseFrameParameters.pagination,
        showButtons: (state) => state.denseFrameParameters.showButtons,
      }),
      tableLoading: {
        get() {
          return this.$store.state.denseFrameParameters.tableLoading;
        },
        set(val) {
          this.$store.state.denseFrameParameters.tableLoading = val;
        },
      },
    },
    components: {
      headerBox,
      contentBox,
      diaBox
    },
    methods: {
      getData() {
        this.params = {
          frameName: this.search.frameName,
          page: this.pagination.pageNum,
          limit: this.pagination.pageSize,
        }
        this.tableLoading = true
        this.$store.dispatch('denseFrameParameters/getData', this.params).catch(err => {
          this.tableLoading = false
        })
      },
      diaBox(str, val) {
        this.title = str
        this.isDiaBox = true
        if (str != '新增') {
          for (let key in this.$refs.diaBox.form) {
            for (let index in val) {
              if (key === index) {
                this.$refs.diaBox.form[key] = val[index]
              }
            }
          }
        }
      },
      cancel() {
        this.isDiaBox = false
      }
    },
    created() {
      let btnData = {
        menuid: this.$getMenuId(sessionStorage.getItem("routerIdList"), this.$route.path),
        roleid: sessionStorage.getItem("roleid")
      }
      this.$store.dispatch("denseFrameParameters/getButtonList", btnData);
      this.getData()
    }
  }

</script>
