1.查询级联选择器部门接口的内容this
queryDeptTree() {spa
var userId = this.$store.getters.accountId递归
enterpriseDeptTree({ 'user_id': userId }).then(response => {接口
this.deptOptions = response.data.dataget
this.makeDeptMap(this.deptOptions) //将拿到的部门结构id作成一张mapio
})List
}map
2.制做map查询
//递归存储到deptMapmake
makeDeptMap(currentDept) {
var dept
if (currentDept.length === 1) {
dept = currentDept[0]
this.deptMap[dept.deptId + ''] = dept.pid //pid为父节点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.找当前id的父id制做id串:
this.findAncestorById(this.oldDeptId)
findAncestorById(deptId) {
this.contentDept.unshift(deptId)
var curDeptId = this.deptMap[deptId]
while (curDeptId !== undefined && curDeptId !== 0) {
this.contentDept.unshift(curDeptId)
curDeptId = this.deptMap[curDeptId]
}
}