From 40977780039c6cccad8dab0951d818f9297176e6 Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 30 Dec 2021 18:26:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=B8=80=E7=82=B9=E5=9C=B0?= =?UTF-8?q?=E5=8C=BA=E7=BB=84=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AiAreaPicker.vue | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/components/AiAreaPicker.vue b/src/components/AiAreaPicker.vue index 77c25890..db6b96fb 100644 --- a/src/components/AiAreaPicker.vue +++ b/src/components/AiAreaPicker.vue @@ -5,7 +5,7 @@
-
+
@@ -75,7 +75,7 @@ export default { }) return level }, - currentArea() { + currentSelector() { return this.fullArea?.slice(-1)?.[0] || {} }, locationIcon() { @@ -98,16 +98,13 @@ export default { } }, watch: { - areaId(v) { - v && this.getFullArea() - }, value(v) { v && this.handleInit() } }, methods: { getFullArea() { - let areaId = this.areaId || (this.all ? '' : this.$areaId) + let areaId = this.index || (this.all ? '' : this.$areaId) return areaId && this.$http.post('/admin/area/getAllParentAreaId', null, { withoutToken: true, params: {areaId}, @@ -116,8 +113,14 @@ export default { res.data.forEach(e => { e.levelLabel = this.levelLabels[e.type] }) + if (!/0{3}$/g.test(areaId)) {//如果是村需要特殊处理 + this.selected = res.data.shift() + } else { + this.selected = res.data?.[0] + } + this.$emit('update:name', this.selected.name) if (res.data.length > 1) { - this.fullArea = res.data.reverse().slice(this.dataRange) + this.fullArea = res.data.filter(e => !!e.levelLabel).reverse().slice(this.dataRange) } else { this.fullArea = res.data } @@ -132,8 +135,8 @@ export default { }).then((res) => { if (res?.data) { this.list = res.data - let self = this.fullArea.find((e) => e.id == this.index) - this.list.unshift(self) + let self = this.fullArea.find((e) => e.id == id) + self && this.list.unshift(self) } }) }, @@ -172,13 +175,16 @@ export default { handleInit() { this.index = this.value || this.areaId this.getFullArea().then(() => { - if (this.all && !this.currentArea.id) this.getProvinces() - else this.getChildAreas(this.currentArea.id) + if (this.all && !this.currentSelector.id) this.getProvinces() + else this.getChildAreas(this.currentSelector.id) }) }, closePopup() { this.$refs.areaSelector?.handleSelect() } + }, + created() { + !!this.value && this.handleInit() } }