<template>
    <div class="office-tree">
        <tree
            v-if="zTreeNodes"
            :height="height"
            :nodes="zTreeNodes"
            :parent="parent"
            :triggerNodeId="triggerNodeId"
            :layerid="layerid"
            @click="triggerNodeClick(triggerNodeId)"
            :checkEnable="checkEnable"
            ref="tree"></tree>
    </div>
</template>

<script>
 import { getMeneData } from '@/api/operation/gei/dataMenu'
import Tree from '@/components/Tree'

export default {
    components: {
        Tree  
    },
    data () {
        return {
            parent: this.tparent,
            zTreeNodes: null,
        }
    },
    props: ["params", "nodes", "height", "level", "parentId", "tparent", "triggerNodeId", "layerid","checkEnable"],
    mounted () {
        this.parent = this.tparent || this.$parent;
        var level = this.level;
        getMeneData().then(result => {
            console.log(result)
            let zTreeNodes =[]
            for(let k=0;k<20;k++){
                zTreeNodes.push(result.data[k])
            }
            for(var i =0 ;i<20;i++) {
               zTreeNodes[i].pid = zTreeNodes[i].levelIndex;
               zTreeNodes[i].name = zTreeNodes[i].indexName;
               zTreeNodes[i].open = true;
           }
            this.zTreeNodes = zTreeNodes;
            console.log(this.zTreeNodes)
            this.$nextTick(() => {
                this.$emit('initTreeDataAfter');
            });
        });
    },
    methods: {
        getTree: function() {
            return this.$refs.tree;
        },
        triggerNodeClick: function (id) {
            console.log(id);
            var tree = this.getTree();
            tree.triggerNodeClick(id);
        },
        getFilePath(nodeId){
            let ztree = this.getTree().zTree;
            var treeNode = ztree.getNodeByParam("id", nodeId);
            if (treeNode == null) return "";
            var name = treeNode.name;
            var pNode = treeNode.getParentNode();
            if (pNode != null) {
                name = this.getFilePath(pNode.id) + " / " + name;
                name = this.getFilePath(pNode.id) + " / " + name;
            }
            return name;
        },

    }
}
</script>

<style scoped>

</style>