BUG 28292

This commit is contained in:
aixianling
2022-03-16 20:10:17 +08:00
parent 8dfcf23684
commit fe3fe256ec
5 changed files with 88 additions and 89 deletions

View File

@@ -1,6 +1,6 @@
<template>
<section class="AiAreaPicker">
<ai-search-popup mode="bottom" ref="areaSelector" length="85%">
<ai-search-popup mode="bottom" ref="areaSelector" length="85%" :disabled="disabled">
<div slot="btn" @tap="handleInit">
<slot v-if="$slots.default"/>
<div v-else-if="isForm">
@@ -21,8 +21,8 @@
</div>
<div/>
<span v-if="all" v-text="`省`" @click="selectNode({}, -1)"/>
<span v-for="(area,i) in fullArea" :key="area.id" v-text="area.levelLabel || '村/社区'"
@click="selectNode(area, i)"/>
<span v-for="(area,i) in fullArea.filter(e=>e.type<valueLevel)" :key="area.id"
v-text="area.levelLabel || '村/社区'" @click="selectNode(area, i)"/>
</div>
<!--用来作为占位的-->
<div class="fixedPlaceholder" style="line-height: 60px;" v-if="false">
@@ -63,7 +63,9 @@ export default {
icon: {default: "location.svg"},
isForm: Boolean,
valueLevel: {default: 5},
fullName: {default: ''}
fullName: {default: ''},
disabled: Boolean,
selectRoot: Boolean
},
computed: {
...mapState(['user']),
@@ -73,14 +75,14 @@ export default {
if (this.all) return (level = 0)
rules.some((e, i) => {
let reg = new RegExp(`0{${e}}`, 'g')
if (reg.test(this.areaId || this.user.areaId || this.$areaId)) {
if (reg.test(this.root)) {
return (level = i)
}
})
return level
},
currentArea() {
return this.fullArea?.slice(-1)?.[0] || {}
root() {
return this.areaId || this.user.areaId || this.$areaId
},
locationIcon() {
return this.$cdn + this.icon
@@ -105,15 +107,15 @@ export default {
},
watch: {
areaId(v) {
v && (this.getFullArea())
v && (this.getFullArea(v))
},
value(v) {
if (this.list.length && v) {
this.areaName = this.list.find((e) => e.id == this.value).name
if (v) {
this.getFullArea(v).then(list => {
this.areaName = list?.reverse()?.[0]?.name
})
}
},
fullArea: {
handler(v) {
this.$nextTick(() => {
@@ -135,9 +137,8 @@ export default {
scrollHeight() {
this.height = document.querySelector('.areaSelector') && `calc(100% - ${document.querySelector('.areaSelector').offsetHeight}px)`
},
getFullArea() {
let areaId = this.areaId || (this.all ? '' : this.$areaId)
return this.$http.post('/admin/area/getAllParentAreaId', null, {
getFullArea(areaId) {
return areaId && this.$http.post('/admin/area/getAllParentAreaId', null, {
withoutToken: true,
params: {areaId},
}).then((res) => {
@@ -149,7 +150,6 @@ export default {
this.fullArea = res.data.reverse().slice(this.dataRange)
} else {
this.fullArea = res.data
}
return this.fullArea
}
@@ -160,32 +160,16 @@ export default {
withoutToken: true,
params: {id},
}).then((res) => {
if (res.data.length) {
if (res?.data) {
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)
if (this.selectRoot) {
let root = JSON.parse(JSON.stringify(this.fullArea?.[0]))
this.list.unshift(root)
}
this.scrollHeight()
} else {
if (this.areaId.substr(this.areaId.length - 3, 3) !== '000') {
this.list = [{
id: this.areaId,
name: this.fullArea[0].name
}]
this.areaName = this.fullArea[0].name
}
}
})
},
getProvinces() {
this.$http.post('/admin/area/queryProvinceList', null, {withoutToken: true}).then((res) => {
if (res?.data) {
@@ -234,16 +218,23 @@ export default {
}
},
handleInit() {
this.index = this.value || this.areaId
if (this.all && !this.areaId && !this.currentArea.id) {
this.getProvinces()
return false
this.index = this.value || this.root
if (!this.disabled) {
if (this.all) {
this.getProvinces()
return false
} else if (this.value) {
this.getFullArea(this.value).then(() => {
let area = this.fullArea?.[0]
if (area.type == this.valueLevel) this.getChildAreas(area.parentId)
else this.getChildAreas(area.id)
})
} else {
this.getFullArea(this.root).then(() => {
this.getChildAreas(this.root)
})
}
}
this.getFullArea().then(() => {
this.getChildAreas(this.currentArea.id || this.areaId)
})
},
closePopup() {
this.$refs.areaSelector?.handleSelect()