<template>
    <a-tree-select
        :value="value"
        show-search
        style="width: 100%"
        :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
        placeholder="Please select"
        :tree-data="treeData"
        allow-clear
        tree-default-expand-all
        :replaceFields="replaceFields"
        v-on="$listeners"
    />
</template>

<script>
import api from '@/api/organization';
import { arrayToTree } from '@/utils';
export default {
    model: {
        prop: 'value',
        event: 'change',
    },
    props: {
        value: Number,
        showMenu: Boolean,
    },
    data() {
        return {
            treeData: [],
            replaceFields: {
                title: 'orgName',
                key: 'orgId',
                value: 'orgId',
            },
        };
    },
    async mounted() {
        this.rawData = await api.getOrganizationList();
        const newArr = new arrayToTree({
            data: this.rawData,
            rootValue: 0,
            parentKey: 'parentOrgId',
            key: 'orgId',
        }).treeData;
        this.treeData = [...newArr];
    },
};
</script>
