提交 311cc483 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

feat: 组织机构按名称检索

上级 a708919f
...@@ -162,7 +162,7 @@ public class DeptService { ...@@ -162,7 +162,7 @@ public class DeptService {
* @return * @return
*/ */
private List<Long> upTree(List<SimpleTreeNode> allNodes, List<SimpleTreeNode> targetNodes){ private List<Long> upTree(List<SimpleTreeNode> allNodes, List<SimpleTreeNode> targetNodes){
final Map<Long, SimpleTreeNode> map = targetNodes.stream().collect(Collectors.toMap(SimpleTreeNode::getId, node -> node)); final Map<Long, SimpleTreeNode> map = allNodes.stream().collect(Collectors.toMap(SimpleTreeNode::getId, node -> node));
List<Long> results = targetNodes.parallelStream().flatMap(targetNode -> { List<Long> results = targetNodes.parallelStream().flatMap(targetNode -> {
//向上逐级找爹 //向上逐级找爹
List<Long> ids = new ArrayList<>(); List<Long> ids = new ArrayList<>();
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<complex-table <complex-table
ref="table" ref="table"
:data="tableData" :data="tableData"
lazy :lazy="isLazy"
:load="loadExpandDatas" :load="loadExpandDatas"
:columns="columns" :columns="columns"
:buttons="buttons" :buttons="buttons"
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
:search-config="searchConfig" :search-config="searchConfig"
:pagination-config="paginationConfig" :pagination-config="paginationConfig"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
:default-expand-all="isTableExpand"
row-key="deptId" row-key="deptId"
@search="search" @search="search"
> >
...@@ -22,7 +23,7 @@ ...@@ -22,7 +23,7 @@
<!-- <el-table-column type="selection" fix /> --> <!-- <el-table-column type="selection" fix /> -->
<el-table-column label="名称" prop="name" /> <el-table-column label="名称" prop="name" />
<el-table-column label="下属组织数" prop="subCount" /> <el-table-column label="下属组织数" prop="subCount" />
<el-table-column label="状态" align="center" prop="enabled"> <!-- <el-table-column label="状态" align="center" prop="enabled">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
v-model="scope.row.enabled" v-model="scope.row.enabled"
...@@ -32,7 +33,7 @@ ...@@ -32,7 +33,7 @@
@change="changeEnabled(scope.row, scope.row.enabled,)" @change="changeEnabled(scope.row, scope.row.enabled,)"
/> />
</template> </template>
</el-table-column> </el-table-column> -->
<el-table-column prop="createTime" label="创建日期"> <el-table-column prop="createTime" label="创建日期">
<template v-slot:default="scope"> <template v-slot:default="scope">
<span>{{ scope.row.createTime | timestampFormatDate }}</span> <span>{{ scope.row.createTime | timestampFormatDate }}</span>
...@@ -47,7 +48,7 @@ ...@@ -47,7 +48,7 @@
:close-on-click-modal="false" :close-on-click-modal="false"
:title="formType=='add' ? $t('organization.create') : $t('organization.modify')" :title="formType=='add' ? $t('organization.create') : $t('organization.modify')"
:visible.sync="dialogOrgAddVisible" :visible.sync="dialogOrgAddVisible"
width="30%" width="500px"
:destroy-on-close="true" :destroy-on-close="true"
@closed="closeFunc" @closed="closeFunc"
> >
...@@ -74,7 +75,7 @@ ...@@ -74,7 +75,7 @@
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="enabled"> <el-form-item label="状态" prop="enabled">
<el-radio-group v-model="form.enabled" style="width: 140px"> <el-radio-group v-model="form.enabled" style="width: 140px" disabled>
<el-radio :label="true">启用</el-radio> <el-radio :label="true">启用</el-radio>
<el-radio :label="false">停用</el-radio> <el-radio :label="false">停用</el-radio>
</el-radio-group> </el-radio-group>
...@@ -176,15 +177,19 @@ export default { ...@@ -176,15 +177,19 @@ export default {
field: 'pid', field: 'pid',
operator: 'eq', operator: 'eq',
value: 0 value: 0
} },
defaultForm: { deptId: null, top: true, enabled: true, pid: null },
isTableExpand: false,
isLazy: true
} }
}, },
activated() { activated() {
this.form = Object.assign({}, this.defaultForm)
this.search() this.search()
}, },
methods: { methods: {
create() { create() {
this.form = Object.assign({}, this.defaultForm)
this.dialogOrgAddVisible = true this.dialogOrgAddVisible = true
this.formType = 'add' this.formType = 'add'
}, },
...@@ -254,8 +259,20 @@ export default { ...@@ -254,8 +259,20 @@ export default {
} }
return Object.assign({}, condition) return Object.assign({}, condition)
}, },
setTableAttr(isSearch) {
if (isSearch) {
this.lazy = false
this.isTableExpand = true
} else {
this.lazy = true
this.isTableExpand = false
}
},
// 加载表格数据 // 加载表格数据
search(condition) { search(condition) {
this.setTableAttr()
this.tableData = []
let param = {} let param = {}
if (condition && condition.quick) { if (condition && condition.quick) {
const con = this.quick_condition(condition) const con = this.quick_condition(condition)
...@@ -273,11 +290,36 @@ export default { ...@@ -273,11 +290,36 @@ export default {
} }
return obj return obj
}) })
if (condition && condition.quick) {
data = this.buildTree(data)
this.setTableAttr(true)
}
this.tableData = data this.tableData = data
this.depts = null this.depts = null
}) })
}, },
buildTree(arrs) {
const idMapping = arrs.reduce((acc, el, i) => {
acc[el.deptId] = i
return acc
}, {})
const roots = []
arrs.forEach(el => {
// 判断根节点
if (el.pid === null || el.pid === 0) {
roots.push(el)
return
}
// 用映射表找到父元素
const parentEl = arrs[idMapping[el.pid]]
// 把当前元素添加到父元素的`children`数组中
parentEl.children = [...(parentEl.children || []), el]
})
return roots
},
// 加载下一级子节点数据 // 加载下一级子节点数据
loadExpandDatas(row, treeNode, resolve) { loadExpandDatas(row, treeNode, resolve) {
getDeptTree(row.deptId).then(res => { getDeptTree(row.deptId).then(res => {
...@@ -359,7 +401,7 @@ export default { ...@@ -359,7 +401,7 @@ export default {
id: node.deptId, id: node.deptId,
pid: node.pid, pid: node.pid,
label: node.name, label: node.name,
children: node.children children: node.children || null
} }
}, },
// 改变状态 // 改变状态
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论