<template>
  <!-- 首页 -->
  <div class="dashboard-container">
    <div>
      <orgTree ref="tree" style="float:left" @selectItem="selectItem" @defaultSite="defaultSite" @dblClick="dblClick"/>
      <div class="ml300">
        <type v-loading="loading" :type="type" :curInfo="curInfo" :selectId="selectId" :curId="curId" />
      </div>
    </div>
  </div>
</template>

<script>
import { treeBaseInfo } from './api'
import orgTree from '@/components/orgTree.vue'
import Type from './components/index.vue'

export default {
  name: 'Dashboard',
  data() {
    return {
      type: 1,
      curInfo: {},
      loading: false,
      curId: null,
      selectId: null
    }
  },
  components: {
    orgTree,
    Type,
  },
  methods: {
    // 初始化选中第一条数据
    defaultSite(data){
      this.getDetailNode(data);
    },
    // 单击树
    selectItem(data) {
      this.selectId = data.id;
      this.curId = data.code;
      this.type = data.type;
      this.getDetailNode(data.id);
    },
    // 双击树
    dblClick(data, node) {
      this.changeTreeNodeStatus(node);
    },
    // 双击树，收起节点
    changeTreeNodeStatus (node) {
      node.expanded = true;
      for (let i = 0; i < node.childNodes.length; i++) {
        // 改变节点的自身expanded状态
        node.childNodes[i].expanded = true;
        // 遍历子节点
        if (node.childNodes[i].childNodes.length > 0) {
          this.changeTreeNodeStatus(node.childNodes[i]);
        }
      }
    },
    // 获取节点的详情
    getDetailNode(data) {
      let param = {
        type: this.type,
        id: data
      }
      this.loading = true;
      treeBaseInfo(param).then(res => {
        let controlLimit = res.controlLimit || [];
        if(controlLimit) {
          controlLimit.map(item => {
            res[`type${item.type}`]= item.sum;
          })
        }
        this.curInfo = res;
        this.loading = false;
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.header_title {
  font-size: 23px;
  font-family: Source Han Sans CN;
  font-weight: 500;
  line-height: 40px;
  text-align: center;
  color: #0058ff;
  letter-spacing: 5px;
  opacity: 1;
  margin-bottom: 20px;
}
::v-deep.el-card {
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  min-height: 243px;
  .el-card__header {
    font-size: 18px;
    color: #333333;
    font-weight: 500;
    text-align: center;
    background: rgba(226, 235, 255, 0.39);
    opacity: 1;
  }
  .el-card__body {
    padding: 0px;
  }
}
.posa {
  position: relative;
}
.savebtn {
  position: absolute;
  right: 2%;
}
.text {
  padding: 10px 20px 10px 20px;
  border-bottom: 1px solid #e3e3e3;
  &:last-child {
    border-bottom: none;
  }
  .item_name,
  .item_data,
  .value_handle {
    height: 16px;
    line-height: 16px;
    margin-top: 12px;
    margin-bottom: 12px;
  }
  .item_name {
    width: 262px;
    height: 16px;
    line-height: 16px;
    color: #7e7e7e;
    margin-top: 12px;
    margin-bottom: 12px;
  }

  .value_handle {
    color: red;
    margin-right: 10px;
  }
  .alarmbtn {
    margin-top: 6px;
    margin-bottom: 6px;
  }
  .el-card:last-child .text {
    border-bottom: none !important;
  }
}
.text2 {
  padding: 10px 20px 10px 20px;
  border-bottom: 1px solid #e3e3e3;
  .item_name,
  .item_data,
  .value_handle {
    height: 16px;
    line-height: 16px;
    margin-top: 12px;
    margin-bottom: 12px;
  }
  .item_name {
    width: 262px;
    height: 16px;
    line-height: 16px;
    color: #7e7e7e;
    margin-top: 12px;
    margin-bottom: 12px;
  }
  .value_handle {
    color: red;
    margin-right: 10px;
    min-width: 52px;
  }
  .alarmbtn {
    margin-top: 6px;
    margin-bottom: 6px;
  }
  .el-card:last-child .text {
    border-bottom: none !important;
  }
}
</style>
