<template>
    <div class="section-team-node">
        <TreeNode 
            @handleExpand="handleExpand"
            @handleChecked="handleChecked"
            :showExpand="withMembers ? !!data.memberCount : false"
            :showExpandIcon="withMembers ? !!data.memberCount : false"
            :showChecked="withMembers ? !!data.memberCount && root.limit > 1 : true"
            :loading="data.loading"
            :expand="data.expand"
            :checked="checked">
            <template slot="content">{{data.name}}</template>
            <template 
                slot="children" 
                v-if="data.children">
                <div v-for="(item, index) in data.children" :key="index">
                    <MemberNode 
                        :data="item"
                        :parent="data"
                        @handleChecked="handleChecked" />
                </div>
                <Load 
                    :showNoMoreTip="false"
                    :hasData="!!data.children.length"
                    :hasMore="data.hasMore"
                    :loading="data.loading" 
                    @on-load="getMemberList(data.classId, data)"/>
            </template>
        </TreeNode>
    </div>
</template>
<script>
    /**
     * 外部人员节点
     *  */
    import MemberNode from './section-member-node'
    import Node from '../mixins/node'
    import Load from '../../../base/page/'

    export default {
        name: 'YYTeamNode',
        mixins: [Node],
        components: {
            MemberNode,
            Load
        },
        inject: ['root'],
        props: {
            data: {
                type: Object,
                default () {
                    return {}
                }
            },
            withMembers: {
                type: Boolean
            }
        },
        computed: {
            checked() {
                if(this.withMembers) {
                    const even = this.data.children.every(item => {
                        return item.checked
                    })
                    return this.data.children.length ? even : false
                }
                const data = this.root.selected.out['m' + this.data.classId] || null
                return !!data
            }
        },
        methods: {
            getMemberList(classId, data) {
                this.$emit('getMemberList', classId, data)
            }
        }
    }
</script>

