<template>
    <div class="treebox">
        <el-tree ref="tree" @node-click="handleCheckChange" :data="treeList" node-key="o"
            :default-checked-keys="defaultListc" :default-expanded-keys="defaultList"></el-tree>
    </div>
</template>

<script>
    export default {
        props: ["defaultList","type"],
        data() {
            return {
                treeList: [],
                opt: [],
                defaultProps: {
                    children: 'children',
                    label: 'label'
                },
                defaultListc:[]
            };
        },
        methods: {
            getTree(v) {
                this.$http({
                    url: "/sysmgr/csysdept/queryAllList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        parentorgid: v
                    },
                }).then((res) => {
                    this.treeList = res.data;
                });
            },
            handleCheckChange(v) {
                let opt = [{
					id:v.id,
					o:v.o,
					ou:v.ou,
					displayname:v.displayname
				}];
                this.$emit("treeCheck",opt)
            },
        },
        mounted() {},
        created() {
            this.getTree();
            this.defaultListc = this.defaultList;
        },
        watch:{
            type(){
                this.defaultListc = this.defaultList;
            }
        }
    };
</script>

<style scoped lang="scss">
    .treebox {
        border: 1px solid #ddd;
    }
</style>
