<template>


  <el-container :style="{height: mainHeight + 'px'}">
    <el-aside>
      <el-tree :data="assetStructureList"
               :load="expandTable"
               lazy
               @node-click="(data) => showAssets=data.type"
               :props="defaultProps">
        <div class="custom-tree-node" slot-scope="{ node, data }">
          <div v-if="data.type === 0">{{ data. accessSourceName + '('+data.databaseName + '-' + data.dataSourceSystemName+')' }}</div>
          <div v-if="data.type === 1">{{ 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 === 'dataSource'" :title="title"/>
        <overall-asset-structure v-if="showAssets === 'dataTable'" :title="title"/>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>

import OverallSpecificAssets from "@/views/dataSource/assets/OverallSpecificAssets.vue";
import OverallAssets from "@/views/dataSource/assets/OverallAssets.vue";
import {testList} from "@/api/dataSource/source";

export default {
  name: 'assets',
  components: { OverallSpecificAssets, OverallAssets },
  data() {
    return {
      mainHeight: window.innerHeight - 85,
      defaultProps: {
        children: 'childrenList',
        label: 'name'
      },
      assetStructureList: [],
      childrenList: [],
    showAssets: null,
      title: null
  }
  },
  created() {
    this.findTest();
  },
  methods: {
    expandTable(node, resolve) {
      if (node.level === 0) return resolve(this.assetStructureList);


      const {data} = node;
      this.showAssets = data.type;
      if (data.type === 'dataTable') {
        return resolve([])
      }
      this.title = data.accessSourceName + '('+data.databaseName + '-' + data.dataSourceSystemName+')'
      setTimeout(() => {
        resolve(this.childrenList)
      }, 500);
    },
    findTest(){
      testList().then(
        res=>{
          this.assetStructureList=res.data.assetStructureList;
          this.childrenList=res.data.databaseTableInformationList;
        }
      )
    },
  }
}
</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>
