<template>
    <div class="section-member section-recent">
        <Scroller>
            <div ref="scrollerContent">
                <MemberNode 
                    v-for="(item, index) in list"
                    :key="index"
                    :data="item"
                    @handleChecked="handleChecked" />
                    <Load :hasData="true" :hasMore="hasMore" :loading="loading" @on-load="getMemberList" />
                <!-- <Empty v-if="!loading && !hasMore && !list.length"/> -->
            </div>
        </Scroller>
    </div>
</template>
<script>
    import MemberNode from './section-member-node'
    import Section from '../mixins/section'
    import Load from '../../../base/page/'
    import Empty from '../../../base/empty/'
    import Locale from '../../../../mixins/locale'
    import { getRecentContact } from '../utils'

    export default {
        name: 'YYSectionMember',
        mixins: [Section, Locale],
        components: {
            MemberNode,
            Load,
            Empty
        },
        inject: ['root'],
        data() {
            return {
                hasMore: true,
                loading: false
            }
        },
        methods: {
            getMemberList() { // 拉取当前组织树
                this.loading = true
                const { host, qzId, chooseDeptType, language, security, token } = this.root;
                getRecentContact(host, qzId, {
                    token: token,
                    language: language,
                    security: security,
                    includeDuty: true,
                    type: chooseDeptType,
                }).then(res => {
                    let data = res && res.data || []
                    data.forEach(item => {
                        item.checked = false
                    })
                    // this.hasMore = !(data.length < this.size)
                    // this.page++
                    this.loading = false
                    this.hasMore = false;
                    return this.list = (this.list || []).concat(data)
                }).catch(error => {
                    this.loading = false
                    this.handleError()
                })
            }
        },
        created() {
            this.getMemberList()
        }
    }
</script>
