<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="tree-card">
        <!-- 用了行列布局 -->
        <!-- 1. 第一行 公司信息-->
        <tree-tools :tree-node="company" :is-root="true" />
        <!-- 2. 树型控件 -->
        <el-tree :data="departs" :props="defaultProps" :default-expand-all="true">
          <!-- 作用域插槽 -->
          <tree-tools slot-scope="{data}" :tree-node="data" /><!-- 父传子-->
        </el-tree>
      </el-card>
    </div>
  </div>
</template>

<script>
import treeTools from './componets/tree-tools.vue'
import { getDepartments } from '@/api/departments'
import { listToTreeData } from '@/utils/list-to-treedata'
export default {
  components: { treeTools },
  data() {
    return {
      company: {},
      departs: [],
      defaultProps: {
        label: 'name',
        children: 'children'
      }
    }
  },
  async created() {
    const res = await getDepartments()
    console.log(res)
    this.departs = [...listToTreeData(res.depts, '')]
    console.log(this.departs)
    this.company = {
      name: 'xx股份有限公司' || res.companyName,
      manager: '负责人'
    }
  }

}
</script>

<style>
.tree-card {
  padding: 30px  140px;
  font-size:14px;
}
.is-leaf{
  visibility:hidden;
}
.el-icon-arrow-down{
  display: none;
}
</style>
