<!--
   分局应用授权情况
    @Author:laiyh
    @Date:  2020-09-21
-->


<template>
  <div>
    <dg-table
      row-key="id"
      border
      lazy
      :data="tableData"
      :tree-props="treeProp"
      :load="load"
      :pagination="false"
      v-bind="$attrs"
      v-on="$listeners"
    >
      <template v-for="(item, indexs) in tableHeader">
        <dg-table-column :key="indexs" v-bind="item" align="center"> </dg-table-column>
      </template>
      <slot />
    </dg-table>
    <!-- <new-table :data="tableData" :pagination="false" :tableHeader="tableHeader" :load="load" :tree-props="treeProp" lazy></new-table> -->
    <el-row v-footer>
      <dg-button @click="handleClose">关闭</dg-button>
    </el-row>
  </div>
</template>

<script>
import { roleQuotasTable } from '@/api/statistics-manage';
import newTable from '@/components/new-table';
export default {
  name: 'lTreeTable',
  props: {
    searchForm: {
      type: Object,
      default: () => {}
    }
  },
  components: { newTable },
  data() {
    return {
      tableData: [],
      tableHeader: [
        { label: '单位名称', prop: 'name' },
        { label: '机构代码', prop: 'code' },
        { label: '应分配名额', prop: 'mustQuotas' },
        { label: '实际分配名额', prop: 'quotaed' },
        { label: '待分配名额', prop: 'kfpme' },
        { label: '完成情况', prop: 'overRate' }
      ],
      treeProp: {
        hasChildren: 'isParent',
        children: 'children',
        isLeaf(data) {
          return data.isParent !== true;
        }
      }
    };
  },
  computed: {
    searchFormComputed() {
      return this.searchForm;
    }
  },
  methods: {
    load({ id, isParent, parent }, treeNode, resolve) {
      this.searchFormComputed.isInit = false;
      this.searchFormComputed.orgId = id;
      if (isParent === true || parent === true) {
        roleQuotasTable(this.searchFormComputed)
          .then((res) => {
            resolve(res);
          })
          .catch((err) => {
            resolve([]);
          });
      }
    },
    handleClose() {
      this.$emit('close');
    }
  },
  created() {
    roleQuotasTable(this.searchForm).then((res) => {
      this.tableData = res;
    });
  }
};
</script>

