This commit is contained in:
aixianling
2023-03-24 15:24:18 +08:00
parent da27eaee98
commit 0dda0201ba
3 changed files with 33 additions and 32 deletions

View File

@@ -64,7 +64,8 @@ export default {
separator: {type: String, default: ""},
showBadge: {type: Boolean, default: true},
value: String,
valueLevel: {type: [Number, String], default: -1}
valueLevel: {type: [Number, String], default: -1},
root: String
},
data() {
return {
@@ -76,13 +77,14 @@ export default {
}
},
computed: {
rootArea: v => new Area(v.root),
currentArea: v => v.selected || v.value,
selectedArea: v => new Area(v.currentArea, v.hashMap),
startLevel: v => Number(v.hideLevel) || 0,//地区最高可选行政地区等级
startLevel: v => Math.max(Number(v.hideLevel), 0, v.rootArea.level),//地区最高可选行政地区等级
endLevel: v => Number(v.areaLevel) || 0,//地区最低可选行政地区等级
selectedArea: v => new Area(v.currentArea, v.hashMap),
selectedName: v => v.selectedArea.name || "无",
validateState: v => ['', 'success'].includes(v.elFormItem?.validateState),
selectedMap: v => v.selectedArea.areaMap,
validateState: v => ['', 'success'].includes(v.elFormItem?.validateState),
hashMap() {
//地区数据缓存器,用于快速获取数据
const hash = {}
@@ -98,10 +100,18 @@ export default {
4: "村/社区"
}
let ops = this.areaOps.map((list, i) => ({
header: levelLabels[i], list
header: levelLabels[i], i, list
})).slice(Math.max(0, this.startLevel), this.endLevel)
if (this.startLevel > 0 && ops.length > 0) {
ops[0].list = ops[0].list.filter(e => e.id == this.selectedMap[this.startLevel])
const tmp = this.$copy(ops[0]?.list?.[0] || {})
if (this.startLevel >= ops[0].i) {
const opsMap = this.selectedMap.length > 0 ? this.selectedMap : this.rootArea.areaMap
ops[0].list = [this.hashMap[opsMap[ops[0].i]]].filter(Boolean) || []
} else {
const prev = +tmp.type - 1
const prevId = tmp.parentId
prev > -1 && ops.unshift({header: levelLabels[prev], list: [this.hashMap[prevId]]})
}
}
return ops
}
@@ -113,7 +123,7 @@ export default {
this.dispatch('ElFormItem', 'el.form.change', [v]);
this.initAreaName()
}
},
}
},
methods: {
dispatch(componentName, eventName, params) {
@@ -206,8 +216,9 @@ export default {
},
initOptions() {
this.areaOps = []
const opsMap = this.selectedMap.length > 0 ? this.selectedMap : this.rootArea.areaMap
let map = {};
return Promise.all([null, ...this.selectedMap].map((id, i) => this.getAreasByParentId(id).then(list => map[i] = list))).then(() => {
return Promise.all([null, ...opsMap].map((id, i) => this.getAreasByParentId(id).then(list => map[i] = list))).then(() => {
this.areaOps = Object.values(map)
})
},