This commit is contained in:
yanran200730
2022-01-18 17:16:18 +08:00
parent a3948329f3
commit 8218448c60
2 changed files with 22 additions and 5 deletions

View File

@@ -5,7 +5,7 @@
<slot v-if="$slots.default"/>
<div v-else class="areaSelector">
<image :src="locationIcon" class="location"/>
<div v-text="selected.name || currentArea.name"/>
<div v-text="areaName"/>
</div>
</div>
<div class="areaSelector">
@@ -90,6 +90,7 @@ export default {
return {
fullArea: [],
index: '',
areaName: '',
list: [],
levelLabels: ["省", "市", "县/区", "镇/街道", "村/社区"],
selected: {},
@@ -101,6 +102,12 @@ export default {
v && (this.getFullArea())
},
value (v) {
if (this.list.length && v) {
this.areaName = this.list.find((e) => e.id == this.value).name
}
},
fullArea: {
handler(v) {
this.$nextTick(() => {
@@ -134,8 +141,8 @@ export default {
this.fullArea = res.data.reverse().slice(this.dataRange)
} else {
this.fullArea = res.data
}
return this.fullArea
}
})
@@ -148,6 +155,14 @@ export default {
if (res.data.length) {
this.list = res.data
let self = this.fullArea.find((e) => e.id == this.areaId)
if (this.value && !this.areaName && this.value !== this.areaId) {
this.areaName = this.list.find((e) => e.id == this.value).name
}
if (!this.areaName && this.value === this.areaId) {
this.areaName = self.name
}
if (self.id) {
this.list.unshift(self)
}
@@ -173,6 +188,7 @@ export default {
if (this.selected.type == 5) {
fullName = fullName + this.selected.name
}
this.areaName = this.selected.name
this.$emit('update:fullName', fullName)
this.$emit('update:name', this.selected.name)
this.closePopup()
@@ -210,7 +226,6 @@ export default {
return false
}
console.log(this.index)
this.getFullArea().then(() => {
this.getChildAreas(this.currentArea.id || this.areaId)
})