<template>
    <div class="section-group-node">
        <TreeNode 
            @handleExpand="handleExpand"
            @handleChecked="handleChecked"
            :showExpandIcon="!!(withMembers && data.groupMemberCount)"
            :showExpand="!!(withMembers && data.groupMemberCount)"
            :showChecked="withMembers ? !!data.groupMemberCount && root.limit > 1 : true"
            :loading="data.loading"
            :expand="data.expand"
            :checked="checked">
            <template slot="content">{{data.groupName}}</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>
            </template>
        </TreeNode>
    </div>
</template>
<script>
    /**
     * 内部群节点
     *  */
    import MemberNode from './section-member-node'
    import Node from '../mixins/node'
    export default {
        name: 'YYGroupNode',
        mixins: [Node],
        components: {
            MemberNode
        },
        inject: ['root'],
        props: {
            data: {
                type: Object,
                default () {
                    return {}
                }
            },
            withMembers: {
                type: Boolean
            }
        },
        computed: {
            checked() {
                if(this.withMembers) {
                    return !!(this.data.children && this.data.children.length &&  this.data.children.every(item => item.checked))

                    // const even = this.data.children.every(item => {
                    //     return item.checked
                    // })
                    // return this.data.children.length ? even : false
                }
                const data = this.root.selected.group['m' + this.data.gid] || null
                return !!data
            }
        }
    }
</script>

