let depts=[{id:1,name:"集团",pid:null},{id:2,name:'子公司',pid:1},{id:3,name:'财务部门',pid:2
}]
function deep(data,pid){
let array=[]
data.forEach(item=>{
if(item.pid==pid){
array.push(item)
item.children=deep(data,item.id)
}
})
return array
}
let one=deep(depts,null)
console.log(one);