1. Query the content of the cascade selector department interface
queryDeptTree() {
varuserId=this.$store.getters.accountId
enterpriseDeptTree({ 'user_id':userId }).then(response=> {
this.deptOptions=response.data.data
this . makeDeptMap ( this . deptOptions ) //Make the obtained department structure id into a map
})
}
2. Make a map
//Store recursively into deptMap
makeDeptMap(currentDept) {
var dept
if (currentDept.length===1) {
dept=currentDept[0]
this . deptMap [ dept . deptId + '' ] = dept . pid //pid is the parent node id
if (dept.childEnterpriseDeptList!==undefined&&dept.childEnterpriseDeptList.length>0) {
this.makeDeptMap(dept.childEnterpriseDeptList)
}
} else {
currentDept.forEach(curDept=> {
dept=curDept
this.deptMap[dept.deptId+''] =dept.pid
if (dept.childEnterpriseDeptList!==undefined&&dept.childEnterpriseDeptList.length>0) {
this.makeDeptMap(dept.childEnterpriseDeptList)
}
})
}
}
3. Find the parent id of the current id to make an id string:
this.findAncestorById(this.oldDeptId)
findAncestorById ( deptId ) {
this.contentDept.unshift(deptId)
varcurDeptId=this.deptMap[deptId]
while (curDeptId!==undefined&&curDeptId!==0) {
this.contentDept.unshift(curDeptId)
curDeptId=this.deptMap[curDeptId]
}
}