import { getOrgTree } from '@/api/org';

export const orgMixin = {
    data () {
        return {
            orgOptions: [],
            orgProps: {
                checkStrictly: true,
                value: 'enforce_org_id',
                label: 'enforce_org_name',
                children: 'sub_orgs',
            },
        }
    },
    methods: {
        checkOrgLeaf(list) {
            if (list) {
                list.map(item => {
                    if (item.sub_orgs && item.sub_orgs.length > 0) {
                        this.checkOrgLeaf(item.sub_orgs);
                    }
                    else {
                        delete item.sub_orgs;
                    }
                });
            }
        },
        loadOrgTree() {
            getOrgTree().then(res => {
                if (res && res.data) {
                    let list = res.data;
                    this.checkOrgLeaf(list);
                    this.orgOptions = list;
                }
            });
        },
    }
}
