<template>
  <el-container :style="{height: mainHeight + 'px'}">
    <el-aside>

      <el-tree :data="assetStructureList"
               :expand-on-click-node="false"
               :load="expandTable"
               lazy
               @node-click="showAssetsFun"
               :props="defaultProps">
        <div class="custom-tree-node"  slot-scope="{ node, data }">
          <div v-if="data.type == 1" >{{ data.name + '('+data.databaseName + '-' + data.systemName+')' }}</div>
          <div v-if="data.type == 2" >{{ data.name + '-'+data.as + '(' + data.dataTotal+'条)' }}</div>
        </div>
      </el-tree>
    </el-aside>
    <el-container>
      <el-main>
        <OverallAssets v-if="showAssets == null"/>
        <overall-specific-assets v-if="showAssets == 1" v-bind:bb="aa" v-bind:dictName="dictAddName" v-bind:selectAll="chir" v-bind:childrenMess="childr" v-bind:shu="DataStructure"  v-bind:selectData="dataStructure"  :title="title"/>
        <overall-asset-structure v-if="showAssets == 2" v-bind:bb="aa" v-bind:dictName="dictAddName" v-bind:selectAll="chir" v-bind:childrenMess="childr" v-bind:shu="DataStructure"  v-bind:selectData="dataStructure" :title="title"/>
      </el-main>
    </el-container>

  </el-container>
</template>
<script>
import OverallAssets from './dashboard/OverallAssets.vue'
import OverallSpecificAssets from './dashboard/OverallSpecificAssets.vue'
import OverallAssetStructure from './dashboard/OverallAssetStructure.vue'
import {
  overallDataStructure,
  selectChild,
  selectChildAll,
  selectDataSource,
  selectDataStur,
  selectDepartmen,
  selectDictionaryy
} from '@/api/kvt/kvt'

export default {
  name: 'assetStructure',
  components: { OverallAssetStructure, OverallSpecificAssets, OverallAssets },
  data() {
    return {
      mainHeight: window.innerHeight - 85,
      defaultProps: {
        children: 'childrenList',
        label: 'name'
      },
      assetStructureList: [
        // {
        //   name: "测试4",
        //   systemName: "传媒系统",
        //   databaseName: "chuanmei",
        //   type: "dataSource"
        // }
      ],
      childrenList: [
        // {
        //   name: "sys_notice",
        //   as: "通知公告",
        //   dataTotal: 6347,
        //   type: "dataTable",
        //   childrenList: []
        // }
      ],
      childrenMess:[
        // {
        //   name: "",
        //   as: "",
        //   dataTotal: 0
        // }
      ],
      showAssets: null,
      title: null,
      dataname: null,
      databaseNam: null,
      dataStructure:[],
      childr:[],
      chir: [],
      dictAddName: [],
      aa: 0,
      DataStructure: {}
    }
  },
  created() {
    this.selectDataSource()
  },
  methods: {
    // selctChild(tableName){
    //   // console.log("table",tableName)
    //   // selectChild(tableName).then(res =>{
    //   //   console.log("childrenList",res)
    //   //   this.childr=res.data
    //   // })
    // },
    // selectDepartment(selectDepartment){
    //   // selectDepartmen(selectDepartment).then(res=>{
    //   //   console.log("res",res)
    //   //   this.childrenList = res.data
    //   // })
    // },
    selectDataSource(){
      selectDataSource().then(res=>{

        this.assetStructureList = res.data
        console.log("assetStructureList",res)
      })
    },
    expandTable(node, resolve){
      if (node.level === 0) return resolve(this.assetStructureList);
      const {data} = node;
      this.showAssets = data.type;
      selectChildAll().then(res=>{
        console.log("wwwwwwww",res)
        this.chir = res.data
      })
      selectDepartmen(node.data.databaseName).then(res=>{
        console.log("childrenList",res)
        this.childrenList = res.data
      })
   if (node.level==1){
     overallDataStructure().then(res =>{
       console.log("rrrr",res)
       this.DataStructure = res.data
     })
   }
      if (data.type == 1){
        this.aa=data.id
        console.log("55555555555555555",data)
        selectDictionaryy(data.id).then(res => {
          console.log("selectDictionaryy",res.data)
          this.dictAddName = res.data
        })
      }
      if (data.type == 2) {
        return resolve([])
      }
      setTimeout(() => {
        resolve(this.childrenList)
      }, 500);
    },

    showAssetsFun(data){
      this.title = data.name + '('+data.databaseName + '-' + data.systemName+')'
      this.showAssets = data.type;
      this.dataname= data.name,
        this.databaseNam= data.databaseName
      selectChild(data.name).then(res =>{
        this.childr=res.data
      })
      selectDataStur(data.name).then(res=>{
        this.dataStructure= res.data
      })


    }
  }
}
</script>
<style scoped lang="scss">
.el-aside {
  margin: 0;
  padding: 0;
  width: 400px;
  background-color: white;
}
.el-main {
  background-color: #f1f1f1;
}
.custom-tree-node{
  height: 30px;
}
</style>
