调整平昌的党组织选择

This commit is contained in:
aixianling
2023-11-08 11:56:32 +08:00
parent dc45b610cc
commit 1370593dd0
2 changed files with 58 additions and 71 deletions

View File

@@ -15,12 +15,12 @@ import $reg from "./regular"
*/
const addChild = (parent, pending, config) => {
let conf = {
key: 'id',
parent: 'parentId',
children: 'children',
...config
},
doBeforeCount = pending.length
key: 'id',
parent: 'parentId',
children: 'children',
...config
},
doBeforeCount = pending.length
for (let i = pending.length - 1; i >= 0; i--) {
let e = pending[i]
if (e[conf.parent] == parent[conf.key]) {
@@ -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
}
/**
* 封装提示框
@@ -87,7 +58,7 @@ const $decimalCalc = (...arr) => {
return ('' + e).length - index
})
let maxDecimal = Math.max(...decimalLengthes),
precision = Math.pow(10, maxDecimal)
precision = Math.pow(10, maxDecimal)
// 计算
let intArr = arr.map(e => (Number(e) || 0) * precision)
// 返回计算值
@@ -115,10 +86,10 @@ const $colorUtils = {
if (color.length == 4) {
// 检测诸如#FFF简写格式
color =
'#' +
color.charAt(1).repeat(2) +
color.charAt(2).repeat(2) +
color.charAt(3).repeat(2)
'#' +
color.charAt(1).repeat(2) +
color.charAt(2).repeat(2) +
color.charAt(3).repeat(2)
}
hex = parseInt(color.slice(1), 16)
}
@@ -199,8 +170,8 @@ export default {
},
$dateFormat: (time, format) => {
return $moment(time)
.format(format || 'YYYY-MM-DD')
.replace('Invalid Date', '')
.format(format || 'YYYY-MM-DD')
.replace('Invalid Date', '')
},
$copy,
$download: (url, name) => {
@@ -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,

View File

@@ -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))
if (this.selected) {
this.$emit('name', this.selected.map(e => e.name))
this.$emit('origin', this.selected)
}
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
this.searchSysAll();
})
created() {
this.searchSysAll();
}
}
</script>
@@ -220,46 +209,46 @@ export default {
overflow-y: hidden;
}
:deep(.el-dialog__header ){
:deep(.el-dialog__header ) {
line-height: 1;
// padding: 13px 16px;
// border-bottom: 1px solid #eee;
}
:deep( .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content ){
:deep( .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content ) {
background: #eaf5ff !important;
color: #257fff !important;
}
:deep(.el-dialog__body ){
:deep(.el-dialog__body ) {
padding: 16px 16px 0;
}
:deep( .ai-dialog__content--wrapper ){
:deep( .ai-dialog__content--wrapper ) {
padding-right: 0 !important;
}
:deep(.left_cont ){
:deep(.left_cont ) {
height: calc(100% - 40px);
padding-top: 8px;
box-sizing: border-box;
overflow: auto;
}
:deep(.el-tree ){
:deep(.el-tree ) {
background: #fcfcfc;
}
:deep( .el-dialog__body ){
:deep( .el-dialog__body ) {
background: #fcfcfc;
}
:deep(.el-tree-node:focus > .el-tree-node__content ){
:deep(.el-tree-node:focus > .el-tree-node__content ) {
background: #eaf5ff !important;
color: #257fff !important;
}
:deep(.el-tree-node__content:hover ){
:deep(.el-tree-node__content:hover ) {
background: #eaf5ff !important;
color: #257fff !important;
}