diff --git a/src/views/components/resiSearch.vue b/src/views/components/resiSearch.vue index 9c9887eb7..5a9aa1396 100644 --- a/src/views/components/resiSearch.vue +++ b/src/views/components/resiSearch.vue @@ -931,17 +931,20 @@ export default { if (this.columnName) this.handleChangeForm(this.columnName) }, mounted(){ - this.$EventBus.$on('handleClickResiTree', (val) => { + this.$EventBus.$on('handleClickResiTree', async (val) => { if(val.type === 'agency'){ this.form.agencyId = val.id; this.optionsV = []; - this.getValiheList(); + this.form.villageId = ''; + this.form.buildId = ''; + await this.getValiheList(); }else if(val.type === 'neighborHood'){ this.form.villageId = val.id; - this.handleChangeV(val.id) + await this.handleChangeV(val.id) + this.form.buildId = ''; }else if(val.type === 'building'){ this.form.buildId = val.id; - this.handleChangeB(val.id) + await this.handleChangeB(val.id) } }) }, diff --git a/src/views/modules/base/resi.vue b/src/views/modules/base/resi.vue index f24cff36a..da46c37f8 100644 --- a/src/views/modules/base/resi.vue +++ b/src/views/modules/base/resi.vue @@ -1300,13 +1300,52 @@ export default { if (!value) return true; return data.label.indexOf(value) !== -1; }, - async handleNodeClick(obj) { + extractData(node) { + const result = []; + let currentNode = node; + while (currentNode) { + result.push({ id: currentNode.data.id, level: currentNode.data.level }); + currentNode = currentNode.parent; + } + return result; + }, + + traverseTree(tree) { + const results = []; + tree.forEach(node => { + results.push(...this.extractData(node)); + if (node.children && node.children.length > 0) { + results.push(...this.traverseTree(node.children)); + } + }); + return results; + }, + async handleNodeClick(obj,node) { this.selObj = JSON.parse(JSON.stringify(obj)); this.selTreeObj = obj; await nextTick(1000); - this.$nextTick(()=>{ + this.$nextTick(async ()=>{ if(obj.level === "building" || obj.level === "neighborHood"){ - this.$EventBus.$emit('handleClickResiTree',{type:obj.level,id:obj.id}) + const gridNode = this.traverseTree([node]); + const gridResult = gridNode.find(item => item.level === 'grid'); + const neighborHoodResult = gridNode.find(item => item.level === "neighborHood"); + const buildingResult = gridNode.find(item => item.level === "building"); + + const gridId = gridResult ? gridResult.id : null; + const neighborHoodId = neighborHoodResult ? neighborHoodResult.id : null; + const buildingId = buildingResult ? buildingResult.id : null; + if (gridId) { + await this.$EventBus.$emit('handleClickResiTree', { type: 'agency', id: gridId }); + } + await nextTick(500); + if (neighborHoodId) { + await this.$EventBus.$emit('handleClickResiTree', { type: 'neighborHood', id: neighborHoodId }); + } + await nextTick(500); + if (buildingId) { + await this.$EventBus.$emit('handleClickResiTree', { type: 'building', id: buildingId }); + } + }else{ this.$EventBus.$emit('handleClickResiTree',{type:'agency',id:obj.id}) }