<!--
 * @description: 全国稽察报告左侧树
 * @fileName: exportTreeList_jc_group.vue
 * @author:张昀朝
 * @date: 2020-05-28 14:37:39
 * @后台人员: 李海超
 * @version: V0.0.0

 * @modify_description:
 * @modify_content:
 * @modify_author:
 * @modify_date: 2020-05-28 14:37:39
-->
<template>
    <div class="tree" :style="{'height':height + 'px','width':'100%'}">
        <el-tree
            ref="jcTree"
            class="el-treeWhite"
            :data="treeDataLists"
            :props="defaultProps"
            default-expand-all
            :expand-on-click-node="false"
            node-key="id"
            @node-click = 'treeNodeClickHandler'
            @node-expand='treeNodeExpandHandler'
            >
        </el-tree>
    </div>
</template>

<script>
//这里导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//import 《组件名称》 from '《组件路径》';
//import {函数名称1，函数名称2} from '《组件路径》';
import request from '@/utils/gw_ajax_request.js';
import {dateFormat} from "@/utils/gw_date";
import {
    getTree
} from "@api/InspectionReport.js";

    export default {
        components: {},
        props: ['height','width'],
        data() {
            return {
                treeDataLists: [],
                defaultProps: {
                    children: 'children',
                    label: 'pnm'
                },
                defaultExpanded:[],//树默认展开节点数组
                ids:[]
            };
        },
        mounted: function () {
            if(this.width == undefined){
                this.width = '250';
            }
            if(this.height == undefined){
                this.height = '550';
            }

            this.getTreeData();
        },
        computed: {
            userId: function () {
                return localStorage.getItem("userid")
                    ? localStorage.getItem("userid")
                    : "1098101939614724096";
            }
        },
        methods: {
            //获取左侧树数据
            getTreeData:function(){
                let _self = this;
                // getTree('008','1').then((res)=>{
                //     _self.treeDataLists = res.data[0].children;
                //     _self.treeDataLists[0].children.forEach((element) => {
                //         _self.defaultExpanded.push(element.id);
                //     });
                // });
              request.post(`/tac/insp/year/batch/obj/getObjTreeList`,{
                "persId": _self.userId
              }).then(res =>{
                //   //debugger
                _self.treeDataLists = res.data.children;
                if(_self.treeDataLists && _self.treeDataLists.length>0){
                  if(_self.treeDataLists[0].children && _self.treeDataLists[0].children.length>0){
                      if(_self.treeDataLists[0].children[0].children && _self.treeDataLists[0].children[0].children.length>0){
                          if(_self.treeDataLists[0].children[0].children[0].children && _self.treeDataLists[0].children[0].children[0].children.length>0){
                              _self.$nextTick(() => {
                                  _self.$refs.jcTree.setCurrentKey(_self.treeDataLists[0].children[0].children[0].children[0].id);
                                  //_self.$refs.jcTree.setCheckedKeys([_self.treeDataLists[0].children[0].children[0].children[0].id]);
                                  _self.treeNodeClickHandler(_self.treeDataLists[0].children[0].children[0].children[0])
                              })
                          }
                      }
                  }
                }
              })
                // _self.defaultExpanded.unshift("008");
            },
            //树节点点击事件
            treeNodeClickHandler:function(data,node,tree){

                this.ids=[];
                // if(node.childNodes.length == 0){
                //     let currentNodeId = data.id;
                //     let projectName = data.pnm;
                //     let objId = data.objId;
                //     let inspGroupId = data.pid;
                //
                //     this.$emit("provTreeSelectChange", {'id':currentNodeId,'pid':inspGroupId});
                //
                // }else{
                //     return;
                // }
                if(data.pid!=null){
                    if(node!=null && tree!=null){
                        this.eachId(node.data);
                    }else{
                        this.eachId(data);
                    }
                    this.$emit("provTreeSelectChange", {'id':this.ids});
                }
            },
            treeNodeExpandHandler:function(data,node,tree){

                let id = [];
                if(data != null && data.objId!=null){
                    data.children.forEach((element) => {
                        id.push(element.id);
                    });
                    this.$emit("provTreeNodeExpand", {'id':id,'pid':data.id});
                }


            },
            eachId:function (data) {
                if(data.objId!=null){
                    this.ids.push(data.id);
                }else{
                   if(data.children!=null){
                       for(var i = 0;i<data.children.length;i++){
                          this.eachId(data.children[i]);
                       }
                   }
                }
            },


        }
    };
</script>
<style  scoped>
/* @import url(); 引入公共css类 */
.el-tree /deep/ .is-current {
  background: rgb(212, 241, 255) !important;
}
</style>
