部门管理
后端返回数据结构
-
[{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] 0: {bcode: "B001", cuicode: null, bname: "全公司", btype: null, pbcode: "B001", bpath: "B001", status: "70"} 1: {bcode: "B002", cuicode: null, bname: "信息部", btype: null, pbcode: "B001", bpath: "B001.B002",…} 2: {bcode: "B003", cuicode: null, bname: "客服部", btype: null, pbcode: "B001", bpath: "B001.B003",…} 3: {bcode: "B004", cuicode: null, bname: "客服一部", btype: null, pbcode: "B003", bpath: "B001.B003.B004",…} 4: {bcode: "B005", cuicode: null, bname: "客服二部", btype: null, pbcode: "B003", bpath: "B001.B003.B005",…} 5: {bcode: "B006", cuicode: null, bname: "信息一部", btype: null, pbcode: "B002", bpath: "B001.B002.B006",…} 6: {bcode: "B007", cuicode: null, bname: "信息二部", btype: null, pbcode: "B002", bpath: "B001.B002.B007",…}
前端处理(树状,符合el-tree)
this.$http(this.$api.CLDBSBB01,{}) .then(res=>{ let data = res.data; let dataMap = new Map() data.forEach(item => { item.children = [] dataMap.set(item.bcode, item) }) data.forEach(item => { let parent = dataMap.get(item.pbcode) if (parent && item.bcode !== item.pbcode) { parent.children.push(item) } else { this.departList.push(item) } }) })