调整平昌的党组织选择
This commit is contained in:
@@ -34,35 +34,6 @@ const addChild = (parent, pending, config) => {
|
||||
parent[conf.children].map(c => addChild(c, pending, conf))
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 数组转tree
|
||||
* @param list 待转化的数组
|
||||
* @param config 配置
|
||||
*/
|
||||
const $arr2tree = (list, config = {}) => {
|
||||
const {key = 'id', parent = 'parentId', children = 'children'} = config, result = [], itemMap = {},
|
||||
ids = list?.map(e => `#${e[key]}#`)?.toString()
|
||||
for (const e of list) {
|
||||
const id = e[key], pid = e[parent]
|
||||
itemMap[id] = {...e, [children]: [itemMap[id]?.[children]].flat().filter(Boolean)}
|
||||
const treeItem = itemMap[id]
|
||||
if (!!pid && ids.indexOf(`#${pid}#`) > -1) {
|
||||
if (!itemMap[pid]) {
|
||||
itemMap[pid] = {
|
||||
children: []
|
||||
}
|
||||
}
|
||||
itemMap[pid].children.push(treeItem)
|
||||
} else result.push(treeItem)
|
||||
}
|
||||
const removeNullChildren = node => {
|
||||
if (node[children] && node[children].length > 0) {
|
||||
node[children].map(c => removeNullChildren(c))
|
||||
} else delete node[children]
|
||||
}
|
||||
result.forEach(removeNullChildren)
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装提示框
|
||||
@@ -216,7 +187,34 @@ export default {
|
||||
},
|
||||
$debounce,
|
||||
$checkJson,
|
||||
$arr2tree,
|
||||
$arr2tree: (list, config = {}) => {
|
||||
let result = []
|
||||
const {key = 'id', parent = 'parentId', children = 'children'} = config, itemMap = {},
|
||||
ids = list?.map(e => `#${e[key]}#`)?.toString()
|
||||
for (const e of list) {
|
||||
const id = e[key], pid = e[parent]
|
||||
itemMap[id] = {...e, [children]: [itemMap[id]?.[children]].flat().filter(Boolean)}
|
||||
const treeItem = itemMap[id]
|
||||
if (!!pid && ids.indexOf(`#${pid}#`) > -1) {
|
||||
if (!itemMap[pid]) {
|
||||
itemMap[pid] = {
|
||||
children: []
|
||||
}
|
||||
}
|
||||
itemMap[pid].children.push(treeItem)
|
||||
} else result.push(treeItem)
|
||||
}
|
||||
const removeNullChildren = node => {
|
||||
if (node[children] && node[children].length > 0) {
|
||||
node[children].map(c => removeNullChildren(c))
|
||||
} else delete node[children]
|
||||
}
|
||||
if (!!config.root) {
|
||||
result = itemMap[config.root]
|
||||
}
|
||||
result.forEach(removeNullChildren)
|
||||
return result
|
||||
},
|
||||
$load,
|
||||
$reg,
|
||||
Area,
|
||||
|
||||
@@ -113,7 +113,6 @@ export default {
|
||||
selected: [],
|
||||
selectedTemp: [],
|
||||
selectParty: [],
|
||||
valueType: "",
|
||||
defaultChecked: [],
|
||||
defaultExpanded: [],
|
||||
childCount: 0
|
||||
@@ -164,18 +163,12 @@ export default {
|
||||
if (this.type === '2') {
|
||||
this.treeData = res.data
|
||||
} else {
|
||||
res.data = res.data.map(a => {
|
||||
return {...a, name: a.name}
|
||||
});
|
||||
if (this.valueType) {
|
||||
this.selected = res.data.filter(e => (this.valueType == "string" && e.id == this.value) || this.value?.includes(e.id))
|
||||
this.selected = res.data.filter(e => [this.value].flat().includes(e.id))
|
||||
if (this.selected) {
|
||||
this.$emit('name', this.selected.map(e => e.name))
|
||||
this.$emit('origin', this.selected)
|
||||
}
|
||||
}
|
||||
this.treeData = res.data.filter(e => !e.parentId || e.id === this.topOrgId);
|
||||
this.treeData.map(t => this.addChild(t, res.data));
|
||||
this.treeData = this.$arr2tree(res.data, {root: this.topOrgId})
|
||||
}
|
||||
} else {
|
||||
this.treeData = [res.data]
|
||||
@@ -187,14 +180,13 @@ export default {
|
||||
if (!this.selectedTemp.length && !this.isEmpty) {
|
||||
return this.$message.error(this.type === '0' ? '党组织不能为空' : '小区不能为空')
|
||||
}
|
||||
|
||||
this.selected = this.selectedTemp;
|
||||
this.selectParty.length && (this.selected = JSON.parse(JSON.stringify(this.selectParty)))
|
||||
if (this.type === '1' && this.selected[0].isVan === '0') {
|
||||
return this.$message.error('请选择小区')
|
||||
}
|
||||
this.dialog = false
|
||||
this.$emit('change', this.valueType == "string" ? this.selected.map(e => e.id)[0] : this.selected.map(e => e.id))
|
||||
this.$emit('change', typeof this.value == "string" ? this.selected.map(e => e.id)[0] : this.selected.map(e => e.id))
|
||||
this.$emit('name', this.selected.map(e => e.name))
|
||||
this.$emit('origin', this.selected)
|
||||
},
|
||||
@@ -205,11 +197,8 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$nextTick(() => {
|
||||
this.valueType = typeof this.value
|
||||
created() {
|
||||
this.searchSysAll();
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user