提交一点地区组件功能

This commit is contained in:
aixianling
2021-12-30 18:26:18 +08:00
parent b69852d4af
commit 4097778003

View File

@@ -5,7 +5,7 @@
<slot v-if="$slots.default"/>
<div v-else class="areaSelector">
<image :src="locationIcon" class="location"/>
<div v-text="currentArea.name"/>
<div v-text="selected.name"/>
</div>
</div>
<div class="areaSelector">
@@ -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()
}
}
</script>