diff --git a/pages/tabBar/xjPage/xj.vue b/pages/tabBar/xjPage/xj.vue index 7c704a1..a394f7b 100644 --- a/pages/tabBar/xjPage/xj.vue +++ b/pages/tabBar/xjPage/xj.vue @@ -175,8 +175,32 @@ export default { }) }); }, + + getArea(arr) { + let newArr = []; + if (arr != undefined && arr.length > 0) { + newArr = arr.map(item => { + if (item.children != undefined && item.children.length > 0) { + this.getArea(item.children); + } + return item; + }); + } + return newArr; + }, + getCommunity(arr) { + if (arr != undefined && arr.length > 0) { + arr.forEach(async (item) => { + let communityList = await this.getListByParentId("1", item.deptId); + this.apartmentList = [...this.apartmentList,...communityList] + if (item.children != undefined && item.children.length > 0) { + this.getCommunity(item.children); + } + }); + } + }, getTree(){ - getdeptList().then(async (res) => { + getdeptList().then((res) => { this.deptOptions = this.handleTree( res.data, "deptId", @@ -184,15 +208,8 @@ export default { "children", 2 ); - console.log(this.deptOptions,'this.deptOptions'); - - const deptInfo = this.deptOptions[0].children[0] - const newArr = this.deptOptions.map(item => ({ - name: item.deptName, - })) - this.apartmentList = newArr - // this.deptOptions = await this.getListByParentId("1", deptInfo.deptId); - // console.log(this.deptOptions); + const areaLst = this.getArea(this.deptOptions[0].children) + this.getCommunity(areaLst) }); }, // 三级联动通用接口