import httpServer from './httpServer'
let getAreas = function(){
    return new Promise((resolve, reject)=>{
            httpServer({
                method: 'get',
                url: 'organ/getAreaTree'
            }).then(res=>{
                if(res.status != 200){
                    resolve([])
                }else{
                    if(res.data.resultCode == 200){
                        let list = res.data.data
                        let filterList = setChildNull(list)
                        resolve(filterList)
                    }else{
                        resolve([])
                    }
                }
            
            }).catch(err=>{
                resolve([])
            })
        })
}  
function setChildNull(list){
    if (list.length === 0) return []
    list.forEach(v=>{
        fs(v)
    })
    return list
}
function fs(v){
    if(v.children && v.children.length === 0){
        v.children = null
    }else{
        v.children.forEach(s=>{
            fs(s)
        })
    }
    
}
export { getAreas }