提交一点地区组件功能
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<slot v-if="$slots.default"/>
|
<slot v-if="$slots.default"/>
|
||||||
<div v-else class="areaSelector">
|
<div v-else class="areaSelector">
|
||||||
<image :src="locationIcon" class="location"/>
|
<image :src="locationIcon" class="location"/>
|
||||||
<div v-text="currentArea.name"/>
|
<div v-text="selected.name"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="areaSelector">
|
<div class="areaSelector">
|
||||||
@@ -75,7 +75,7 @@ export default {
|
|||||||
})
|
})
|
||||||
return level
|
return level
|
||||||
},
|
},
|
||||||
currentArea() {
|
currentSelector() {
|
||||||
return this.fullArea?.slice(-1)?.[0] || {}
|
return this.fullArea?.slice(-1)?.[0] || {}
|
||||||
},
|
},
|
||||||
locationIcon() {
|
locationIcon() {
|
||||||
@@ -98,16 +98,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
areaId(v) {
|
|
||||||
v && this.getFullArea()
|
|
||||||
},
|
|
||||||
value(v) {
|
value(v) {
|
||||||
v && this.handleInit()
|
v && this.handleInit()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getFullArea() {
|
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, {
|
return areaId && this.$http.post('/admin/area/getAllParentAreaId', null, {
|
||||||
withoutToken: true,
|
withoutToken: true,
|
||||||
params: {areaId},
|
params: {areaId},
|
||||||
@@ -116,8 +113,14 @@ export default {
|
|||||||
res.data.forEach(e => {
|
res.data.forEach(e => {
|
||||||
e.levelLabel = this.levelLabels[e.type]
|
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) {
|
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 {
|
} else {
|
||||||
this.fullArea = res.data
|
this.fullArea = res.data
|
||||||
}
|
}
|
||||||
@@ -132,8 +135,8 @@ export default {
|
|||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res?.data) {
|
if (res?.data) {
|
||||||
this.list = res.data
|
this.list = res.data
|
||||||
let self = this.fullArea.find((e) => e.id == this.index)
|
let self = this.fullArea.find((e) => e.id == id)
|
||||||
this.list.unshift(self)
|
self && this.list.unshift(self)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -172,13 +175,16 @@ export default {
|
|||||||
handleInit() {
|
handleInit() {
|
||||||
this.index = this.value || this.areaId
|
this.index = this.value || this.areaId
|
||||||
this.getFullArea().then(() => {
|
this.getFullArea().then(() => {
|
||||||
if (this.all && !this.currentArea.id) this.getProvinces()
|
if (this.all && !this.currentSelector.id) this.getProvinces()
|
||||||
else this.getChildAreas(this.currentArea.id)
|
else this.getChildAreas(this.currentSelector.id)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
closePopup() {
|
closePopup() {
|
||||||
this.$refs.areaSelector?.handleSelect()
|
this.$refs.areaSelector?.handleSelect()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
!!this.value && this.handleInit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user