//部门管理 hook
import { ref, reactive } from 'vue'

export function useDepart(){
    //选择的部门
    let defaultDepart = ref('')
    //选择的分组
    let defaultGroup = ref('')
    let groupTeamId = 0
    let tablePrams = reactive({
        pageNo:1,
    })
    //获取对应部门/分组下的用户数据
    function getTableUser(){}
    //树结构事件
    function useTreeEvent(){
        let act_node = ref('')
        function clickNode(node,data){
            console.log('node',node)
            console.log('data',data)
            act_node.value = data.unicodeKey
            /* 部门节点 */
            if(data.IsDepartment) {
                defaultDepart.value = data.DepartmentId;
                defaultGroup.value = '';
                groupTeamId = 0
            }else if(data.IsGroup){
                /* 分组节点 */
                defaultGroup.value = data.DepartmentId;
                defaultDepart.value = ''
                groupTeamId = 0
            } else {
                defaultGroup.value = data.GroupId;
                groupTeamId = data.DepartmentId
                defaultDepart.value = ''
            }
            tablePrams.pageNo = 1;
            getTableUser();
        }

        //原项目中的addNode editNode addDepart合成一个
        function openNodeDialog(type,data,{level}){
            console.log('type',type)
            console.log('data',data)
            console.log('level',level)
            //level为0 增加部门
            //level为1 编辑部门&增加分组
            //level为2 编辑分组&增加分组
            //level为3 编辑分组
        }
        function removeNode(){}
        return {
            act_node,
            clickNode,
            openNodeDialog,
            removeNode
        }

    }
    //树结构移动
    function useTreeMove(){
        function checkAllowDrag(){}
        function checkAllowDrop(){}
        function handleDropOver(){}
        return {
            checkAllowDrag,
            checkAllowDrop,
            handleDropOver
        }
    }


    return {
        groupTeamId,
        defaultDepart,defaultGroup,tablePrams,
        getTableUser,
        useTreeMove,
        useTreeEvent
    }
}

