<template>
  <div class="content-main">
    <div class="content-body-wrap">
     <div class="content-body">
         <Row :gutter="8" style="width:100%;height: 100%">
          <i-col span="4" style="height:100%">
            <div class="station-tree">
              <div class="station-tree-body">
                <tree-filter :defaultData="stationData" :clickAllNode="false" v-if="stationData && stationData.length>0" @treeChange="treeChange" ref="tree"></tree-filter>
              </div>
            </div>
          </i-col>
          <i-col span="20" style="height:100%">
            <div class="right-main">
              <resource-management-index :stationData="stationData" :levelNum="levelNum" :currentMenuId="currentMenuId" @changeTree="changeTree" ref="treeManage"></resource-management-index>
            </div>
          </i-col>
        </Row>
     </div>
    </div>
  </div>
</template>
<script>
import ResourceManagementIndex from './ResourceManagementIndex.vue'
export default {
  name: "ResourceManagement",
   components:{
    ResourceManagementIndex
  },
  data() {
    return {
		  stationData: [],
      levelNum: 0,
      currentMenuId: '',
    };
  }, 
  created () {
    this.getMetroLevel('init')
  },
  mounted() {
  },
  methods: {
     // 获取树形数据
    getMetroLevel (text,currentMenuId,editText) {
      this.$get('metroapi/menu/sysMenuTree').then(res => {
				if (res.httpCode == 1) {
          this.stationData = res.data
          if (text == 'update') {
            this.stationData = this.getParentIdList(this.stationData,currentMenuId,editText)
          } else {
            this.stationData = this.getTree(this.stationData)
          }
				}
		  })
    },
    getTree(arr) {
      return arr.map((v,index) => {
        if (index==0) {
          v.expand = true
        } else {
          v.expand = false
        }
        if (v.level== 1) {
          v.disabled = true
        }
        if (index==0 && v.level== 2) {
          this.levelNum = v.level
          v.selected = true
          v.disabled = true
          this.currentMenuId = v.nodeId
          this.$refs.treeManage.getMenuData(v.nodeId)
        }
        if (v.children) v.children = this.getTree(v.children);
        return v;
      });
    },
    // 根据搜索框的值查到当前nodeId
    // filterNodeId(list,val){
    //   let _this=this
    //   for (let i = 0; i < list.length; i++) {
    //     let a=list[i]
    //     if(a.title=== val){
    //       return a.nodeId
    //     }else{
    //       if(a.children && a.children.length>0){
    //         let res=_this.filterNodeId(a.children,val)
    //         if(res){
    //           return res
    //         }
    //       }
    //     }
    //   }
    // },
    getParentIdList(list, id,editText) {
        if (!list || !id) {
            return ''
        }
        let findParent = (data, currentdId, nodeId) => {
            for (var i = 0, length = data.length; i < length; i++) {
                let node = data[i];
                node.expand = false
                node.selected = false
                node.disabled = false
                if (node.level== 1) {
                  node.disabled = true
                }
                if (node.nodeId === currentdId) {
                    node.expand = true
                    if (node.nodeId == id) {     
                      node.expand = true
                      this.currentOrgId = node.nodeId
                      node.selected = true
                      node.disabled = true
                      this.showTree = true
                      this.$refs.treeManage.getMenuData(node.nodeId,editText)
                      if(node.children) {
                        findParent(node.children, currentdId, node.nodeId);
                      }       
                    }
                    if (!node.nodeId) {
                      break
                    }
                    findParent(list, nodeId);
                    // break
                } else {
                    if (node.children) {
                      findParent(node.children, currentdId, node.nodeId);
                    }
                    continue
                }
            }
            return list;
        }
        return findParent(list, id);
    },
    treeChange(arr,level,currentNodeId) {
      this.levelNum = level
      this.$refs.treeManage.getMenuData(currentNodeId)
		},
    // inputChange (nodeId) {
    //  this.getMetroLevel('init')
    //  this.$refs.treeManage.getOrgData(nodeId)
    // },
    changeTree (currentOrgId,editText) {
      this.getMetroLevel('update',currentOrgId,editText)
    }
  }
};
</script>
<style scoped lang="stylus">
.content-main {
  width: 100%;
  height: calc(100% - 50px);
  overflow: hidden;
}
.content-body-wrap {
  width: 100%;
  height: 100%;
  background: #06214D;
}
.content-body {
  width: 100%;
  height: 100%;
  background: #06214D;
}
.common-search {
  width: 100%;
}
>>> .common-search .ivu-input {
  background-color: #06214D;
  border: 1px solid #2355A6;
  border-radius: 15px;
  color: #fff;
  height: 32px;
}
>>> .common-search .ivu-input:focus {
    border-color: #0185ea;
}
.station-tree {
  height: 100%;
  padding: 10px;
}
.station-tree-body {
  border: 1px solid #204384;
  height: 100%;
  padding: 10px;
}
.station-tree-center {
  height: calc(100% - 32px);
  padding-top: 10px;
}
.station-tree-left {
  height: 100%;
  overflow: auto;
}
.station-tree-left-notree {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  fon-size: 14px;
}
.right-main {
  height: 100%;
  padding: 10px 0;
}
/* 对话框里的input里的placeholder样式修改 */
/deep/ .ivu-input::-webkit-input-placeholder , /deep/ .ivu-input-number-input::-webkit-input-placeholder{
  color: #718EBD;
}
/deep/ .ivu-input::-moz-placeholder, /deep/ .ivu-input-number-input::-webkit-input-placeholder{   /* Mozilla Firefox 19+ */
  color: #718EBD;
}
/deep/ .ivu-input::-moz-placeholde, /deep/ .ivu-input-number-input::-webkit-input-placeholderr{    /* Mozilla Firefox 4 to 18 */
 color: #718EBD;
}
/deep/ .ivu-input::-ms-input-placeholder, /deep/ .ivu-input-number-input::-webkit-input-placeholder{  /* Internet Explorer 10-11 */
  color: #718EBD;
}
</style>