Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f2aae68e
authored
Jun 20, 2023
by
怪兽?别跑
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
组织架构搜索调整
1 parent
7c47ae09
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
294 additions
and
291 deletions
vue3-lw-pc/src/components/SelectUser.vue
vue3-lw-pc/src/components/SelectUser.vue
View file @
f2aae68
<
script
>
<
script
>
import
{
getDeptTree
,
getDeptUser
}
from
'@/api/organization'
import
{
getDeptTree
,
getDeptUser
}
from
'@/api/organization'
export
default
{
export
default
{
name
:
'SelectUser'
,
name
:
'SelectUser'
,
components
:
{},
components
:
{},
props
:
{
props
:
{
isWechat
:
{
isWechat
:
{
type
:
Boolean
,
type
:
Boolean
,
default
:
true
,
default
:
true
},
// 添加标签显隐
visible
:
{
type
:
Boolean
,
default
:
false
,
},
title
:
{
type
:
String
,
default
:
'组织架构'
,
},
// 是否 只选择叶子节点(人员节点)/禁止选择父节点(部门节点)
isOnlyLeaf
:
{
type
:
Boolean
,
default
:
true
,
},
// 是否单选
isSigleSelect
:
{
type
:
Boolean
,
default
:
false
,
},
// 默认选中的节点
defaultValues
:
{
type
:
Array
,
default
:
()
=>
[],
// 必须含有userId和name属性
validator
(
val
)
{
return
val
.
every
((
e
)
=>
e
.
userId
&&
e
.
name
)
},
},
},
// 添加标签显隐
// 禁止选中的节点
visible
:
{
disabledValues
:
{
type
:
Boolean
,
type
:
Array
,
default
:
false
default
:
()
=>
[],
},
destroyOnClose
:
Boolean
,
// 选中部门时,是否用部门代替显示该部门下所有人员
departReplaceUser
:
{
type
:
Boolean
,
default
:
false
,
},
},
data
()
{
return
{
treeData
:
[],
userList
:
[],
defaultKeys
:
[],
deptId
:
''
,
//根部门Id
keywords
:
''
,
searchResult
:
[],
searchState
:
false
,
checked
:
[],
}
},
watch
:
{
defaultValues
:
{
handler
(
value
)
{
const
checkedUserList
=
[]
if
(
!
Array
.
isArray
(
value
)
||
value
.
length
==
0
)
{
this
.
userList
=
[]
}
else
{
value
.
forEach
((
i
)
=>
{
const
id
=
i
.
userId
||
i
.
id
if
(
id
)
{
checkedUserList
.
push
(
i
)
}
})
this
.
userList
=
checkedUserList
}
},
},
immediate
:
true
,
title
:
{
deep
:
true
,
type
:
String
,
},
default
:
'组织架构'
Pvisible
(
val
)
{
},
val
&&
this
.
$refs
.
tree
&&
this
.
$refs
.
tree
.
setCheckedKeys
(
this
.
defaultValues
.
map
((
e
)
=>
e
.
userId
||
e
.
id
))
// 是否 只选择叶子节点(人员节点)/禁止选择父节点(部门节点)
if
(
!
this
.
$refs
.
tree
)
{
isOnlyLeaf
:
{
setTimeout
(()
=>
{
type
:
Boolean
,
this
.
$refs
.
tree
&&
this
.
$refs
.
tree
.
setCheckedKeys
(
this
.
defaultValues
.
map
((
e
)
=>
e
.
userId
||
e
.
id
))
default
:
true
},
300
)
},
}
// 是否单选
},
isSigleSelect
:
{
},
type
:
Boolean
,
computed
:
{
default
:
false
Pvisible
:
{
get
()
{
return
this
.
visible
},
},
set
(
val
)
{
// 默认选中的节点
this
.
$emit
(
'update:visible'
,
val
)
defaultValues
:
{
type
:
Array
,
default
:
()
=>
[],
// 必须含有userId和name属性
validator
(
val
)
{
return
val
.
every
((
e
)
=>
e
.
userId
&&
e
.
name
)
}
},
// 禁止选中的节点
disabledValues
:
{
type
:
Array
,
default
:
()
=>
[]
},
},
destroyOnClose
:
Boolean
,
// 选中部门时,是否用部门代替显示该部门下所有人员
departReplaceUser
:
{
type
:
Boolean
,
default
:
false
}
},
},
defaultProps
()
{
data
()
{
let
that
=
this
return
{
return
{
label
:
'name'
,
treeData
:
[]
,
children
:
'children'
,
userList
:
[]
,
d
isabled
(
data
,
node
)
{
d
efaultKeys
:
[],
return
(
that
.
isOnlyLeaf
&&
data
.
isParty
)
||
that
.
disabledValues
.
some
((
e
)
=>
e
==
(
data
.
userId
||
data
.
id
))
deptId
:
''
,
//根部门Id
}
,
keywords
:
''
,
isLeaf
(
data
,
node
)
{
searchResult
:
[],
return
!
data
.
id
searchState
:
false
,
},
checked
:
[]
}
}
},
},
dealedUserList
()
{
watch
:
{
if
(
!
this
.
departReplaceUser
)
{
defaultValues
:
{
return
this
.
userList
handler
(
value
)
{
const
checkedUserList
=
[]
if
(
!
Array
.
isArray
(
value
)
||
value
.
length
==
0
)
{
this
.
userList
=
[]
}
else
{
value
.
forEach
((
i
)
=>
{
const
id
=
i
.
userId
||
i
.
id
if
(
id
)
{
checkedUserList
.
push
(
i
)
}
})
this
.
userList
=
checkedUserList
}
},
immediate
:
true
,
deep
:
true
},
Pvisible
(
val
)
{
val
&&
this
.
$refs
.
tree
&&
this
.
$refs
.
tree
.
setCheckedKeys
(
this
.
defaultValues
.
map
((
e
)
=>
e
.
userId
||
e
.
id
))
if
(
!
this
.
$refs
.
tree
)
{
setTimeout
(()
=>
{
this
.
$refs
.
tree
&&
this
.
$refs
.
tree
.
setCheckedKeys
(
this
.
defaultValues
.
map
((
e
)
=>
e
.
userId
||
e
.
id
))
},
300
)
}
}
}
// 提取所有部门
let
arr
=
this
.
userList
.
filter
((
e
)
=>
e
.
isParty
)
// 提取所有非选中部门的人员
let
userList
=
this
.
userList
.
filter
((
e
)
=>
!
e
.
isParty
&&
!
arr
.
some
((
e2
)
=>
e
.
userDepts
[
0
]?.
deptId
==
e2
.
deptId
))
// 提取无父级部门
arr
=
arr
.
filter
((
e
)
=>
!
arr
.
some
((
e2
)
=>
e
.
parentId
==
e2
.
id
))
arr
.
push
(...
userList
)
return
arr
},
},
},
computed
:
{
created
()
{},
Pvisible
:
{
mounted
()
{},
get
()
{
methods
:
{
return
this
.
visible
setChange
(
e
)
{
},
if
(
!
e
)
{
set
(
val
)
{
this
.
searchState
=
false
this
.
$emit
(
'update:visible'
,
val
)
this
.
$refs
.
tree
.
setCheckedKeys
(
this
.
userList
.
map
((
e
)
=>
e
.
userId
||
e
.
id
))
}
},
defaultProps
()
{
let
that
=
this
return
{
label
:
'name'
,
children
:
'children'
,
disabled
(
data
,
node
)
{
return
(
that
.
isOnlyLeaf
&&
data
.
isParty
)
||
that
.
disabledValues
.
some
((
e
)
=>
e
==
(
data
.
userId
||
data
.
id
))
},
isLeaf
(
data
,
node
)
{
return
!
data
.
id
}
}
},
dealedUserList
()
{
if
(
!
this
.
departReplaceUser
)
{
return
this
.
userList
}
// 提取所有部门
let
arr
=
this
.
userList
.
filter
((
e
)
=>
e
.
isParty
)
// 提取所有非选中部门的人员
let
userList
=
this
.
userList
.
filter
((
e
)
=>
!
e
.
isParty
&&
!
arr
.
some
((
e2
)
=>
e
.
userDepts
[
0
]?.
deptId
==
e2
.
deptId
))
// 提取无父级部门
arr
=
arr
.
filter
((
e
)
=>
!
arr
.
some
((
e2
)
=>
e
.
parentId
==
e2
.
id
))
arr
.
push
(...
userList
)
return
arr
}
}
},
},
setSearch
()
{
created
()
{},
if
(
!
this
.
keywords
)
return
mounted
()
{},
this
.
searchResult
=
[]
methods
:
{
this
.
searchState
=
true
setChange
(
e
)
{
this
.
checked
=
this
.
userList
.
map
((
dd
)
=>
{
if
(
!
e
)
{
return
dd
.
userId
this
.
searchState
=
false
})
this
.
$refs
.
tree
.
setCheckedKeys
(
this
.
userList
.
map
((
e
)
=>
e
.
userId
||
e
.
id
))
getDeptUser
({
deptId
:
this
.
deptId
,
userName
:
this
.
keywords
,
}).
then
((
res
)
=>
{
this
.
searchResult
=
this
.
handleUser
(
res
.
rows
)
})
},
setSelectChange
(
e
,
index
)
{
if
(
e
)
{
if
(
this
.
isSigleSelect
)
{
this
.
userList
[
0
]
=
this
.
searchResult
[
index
]
}
else
{
this
.
userList
.
push
(
this
.
searchResult
[
index
])
}
}
},
setSearch
()
{
if
(
!
this
.
keywords
)
return
this
.
searchResult
=
[]
this
.
searchState
=
true
this
.
checked
=
this
.
userList
.
map
((
dd
)
=>
{
this
.
checked
=
this
.
userList
.
map
((
dd
)
=>
{
return
dd
.
userId
return
dd
.
userId
})
})
// this.$forceUpdate()
getDeptUser
({
}
else
{
// deptId: this.deptId,
this
.
cancle
(
this
.
searchResult
[
index
].
userId
)
userName
:
this
.
keywords
}
}).
then
((
res
)
=>
{
// setTimeout(() => {
this
.
searchResult
=
this
.
handleUser
(
res
.
rows
)
// this.keywords = ''
// this.setChange()
// }, 500)
},
treeFormat
(
list
)
{
let
dealOptions
=
[]
list
.
forEach
((
one
)
=>
{
let
findIndex
=
list
.
findIndex
((
item
)
=>
{
return
item
.
id
===
one
.
parentId
})
})
if
((
!
one
.
parentId
&&
one
.
parentId
!==
0
&&
one
.
parentId
!==
false
)
||
findIndex
===
-
1
)
{
},
dealOptions
.
push
(
one
)
setSelectChange
(
e
,
index
)
{
}
else
{
if
(
e
)
{
if
(
!
list
[
findIndex
].
children
)
{
if
(
this
.
isSigleSelect
)
{
list
[
findIndex
].
children
=
[]
this
.
userList
[
0
]
=
this
.
searchResult
[
index
]
list
[
findIndex
].
children
.
push
(
one
)
}
else
{
}
else
{
list
[
findIndex
].
children
.
push
(
one
)
this
.
userList
.
push
(
this
.
searchResult
[
index
]
)
}
}
this
.
checked
=
this
.
userList
.
map
((
dd
)
=>
{
return
dd
.
userId
})
// this.$forceUpdate()
}
else
{
this
.
cancle
(
this
.
searchResult
[
index
].
userId
)
}
}
})
// setTimeout(() => {
return
dealOptions
// this.keywords = ''
},
// this.setChange()
loadNode
(
node
,
resolve
)
{
// }, 500)
if
(
node
.
level
===
0
)
{
},
if
(
!
Array
.
isArray
(
this
.
defaultValues
)
||
this
.
defaultValues
.
length
==
0
)
{
treeFormat
(
list
)
{
this
.
userList
=
[]
let
dealOptions
=
[]
list
.
forEach
((
one
)
=>
{
let
findIndex
=
list
.
findIndex
((
item
)
=>
{
return
item
.
id
===
one
.
parentId
})
if
((
!
one
.
parentId
&&
one
.
parentId
!==
0
&&
one
.
parentId
!==
false
)
||
findIndex
===
-
1
)
{
dealOptions
.
push
(
one
)
}
else
{
if
(
!
list
[
findIndex
].
children
)
{
list
[
findIndex
].
children
=
[]
list
[
findIndex
].
children
.
push
(
one
)
}
else
{
list
[
findIndex
].
children
.
push
(
one
)
}
}
})
return
dealOptions
},
loadNode
(
node
,
resolve
)
{
if
(
node
.
level
===
0
)
{
if
(
!
Array
.
isArray
(
this
.
defaultValues
)
||
this
.
defaultValues
.
length
==
0
)
{
this
.
userList
=
[]
}
getDeptTree
().
then
(({
data
})
=>
{
let
_data
=
this
.
handleDepart
(
data
)
let
value
=
this
.
treeFormat
(
_data
)
if
(
value
.
length
)
{
this
.
deptId
=
value
[
0
].
deptId
}
resolve
(
value
)
})
}
else
{
getDeptUser
({
deptId
:
node
.
data
.
id
}).
then
(({
rows
})
=>
{
let
arr
=
this
.
handleUser
(
rows
)
node
.
data
.
children
&&
arr
.
push
(...
node
.
data
.
children
)
// 懒加载选中状态的子节点不会触发子节点的选中事件,需要手动触发
if
(
node
.
checked
)
{
setTimeout
(()
=>
{
arr
.
forEach
((
e
)
=>
{
this
.
handleCheckChange
(
e
,
true
)
})
},
200
)
}
resolve
(
arr
)
})
}
}
getDeptTree
().
then
(({
data
})
=>
{
},
let
_data
=
this
.
handleDepart
(
data
)
handleDepart
(
data
)
{
let
value
=
this
.
treeFormat
(
_data
)
return
data
.
map
((
i
)
=>
{
if
(
value
.
length
)
{
if
(
i
.
deptId
)
{
this
.
deptId
=
value
[
0
].
deptId
i
.
userId
=
i
.
deptId
i
.
name
=
i
.
deptName
i
.
id
=
i
.
deptId
i
.
isParty
=
true
}
}
re
solve
(
value
)
re
turn
i
})
})
}
else
{
},
getDeptUser
({
deptId
:
node
.
data
.
id
}).
then
(({
rows
})
=>
{
handleUser
(
data
)
{
let
arr
=
this
.
handleUser
(
rows
)
return
data
.
map
((
i
)
=>
{
node
.
data
.
children
&&
arr
.
push
(...
node
.
data
.
children
)
if
(
i
.
userName
)
{
// 懒加载选中状态的子节点不会触发子节点的选中事件,需要手动触发
i
.
userId
=
this
.
isWechat
?
i
.
weUserId
:
i
.
userId
if
(
node
.
checked
)
{
i
.
name
=
i
.
userName
setTimeout
(()
=>
{
arr
.
forEach
((
e
)
=>
{
this
.
handleCheckChange
(
e
,
true
)
})
},
200
)
}
}
re
solve
(
arr
)
re
turn
i
})
})
}
},
},
// 选择变化
handleDepart
(
data
)
{
handleCheckChange
(
data
,
checked
,
indeterminate
)
{
return
data
.
map
((
i
)
=>
{
if
(
checked
)
{
if
(
i
.
deptId
)
{
if
(
this
.
isSigleSelect
)
{
i
.
userId
=
i
.
deptId
// 单选情况
i
.
name
=
i
.
deptName
this
.
$refs
.
tree
.
setCheckedKeys
([
data
.
userId
])
i
.
id
=
i
.
deptId
}
i
.
isParty
=
true
if
(
this
.
isOnlyLeaf
)
{
}
if
(
data
.
userId
&&
!
data
.
isParty
)
{
return
i
this
.
userList
.
push
(
data
)
})
}
},
}
else
{
handleUser
(
data
)
{
const
isExist
=
this
.
userList
.
findIndex
((
i
)
=>
i
.
userId
===
data
.
userId
)
>
-
1
return
data
.
map
((
i
)
=>
{
!
isExist
&&
this
.
userList
.
push
(
data
)
if
(
i
.
userName
)
{
i
.
userId
=
this
.
isWechat
?
i
.
weUserId
:
i
.
userId
i
.
name
=
i
.
userName
}
return
i
})
},
// 选择变化
handleCheckChange
(
data
,
checked
,
indeterminate
)
{
if
(
checked
)
{
if
(
this
.
isSigleSelect
)
{
// 单选情况
this
.
$refs
.
tree
.
setCheckedKeys
([
data
.
userId
])
}
if
(
this
.
isOnlyLeaf
)
{
if
(
data
.
userId
&&
!
data
.
isParty
)
{
this
.
userList
.
push
(
data
)
}
}
}
else
{
}
else
{
const
isExist
=
this
.
userList
.
findIndex
((
i
)
=>
i
.
userId
===
data
.
userId
)
>
-
1
let
index
=
this
.
userList
.
findIndex
((
i
)
=>
i
.
userId
===
data
.
userId
)
!
isExist
&&
this
.
userList
.
push
(
data
)
index
>
-
1
&&
this
.
userList
.
splice
(
index
,
1
)
}
}
}
else
{
this
.
userList
=
this
.
unique
(
this
.
userList
)
let
index
=
this
.
userList
.
findIndex
((
i
)
=>
i
.
userId
===
data
.
userId
)
},
index
>
-
1
&&
this
.
userList
.
splice
(
index
,
1
)
unique
(
arr
)
{
}
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
this
.
userList
=
this
.
unique
(
this
.
userList
)
for
(
var
j
=
i
+
1
;
j
<
arr
.
length
;
j
++
)
{
},
if
(
arr
[
i
].
userId
.
split
(
'_'
)[
0
]
==
arr
[
j
].
userId
.
split
(
'_'
)[
0
])
{
unique
(
arr
)
{
arr
.
splice
(
j
,
1
)
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
j
--
for
(
var
j
=
i
+
1
;
j
<
arr
.
length
;
j
++
)
{
}
if
(
arr
[
i
].
userId
.
split
(
'_'
)[
0
]
==
arr
[
j
].
userId
.
split
(
'_'
)[
0
])
{
arr
.
splice
(
j
,
1
)
j
--
}
}
}
}
return
arr
},
// 确 定
submit
()
{
this
.
Pvisible
=
false
this
.
$emit
(
'success'
,
[...
this
.
dealedUserList
])
},
// 取消选择
cancle
(
key
)
{
this
.
$refs
.
tree
.
setChecked
(
key
,
false
)
let
index
=
this
.
userList
.
findIndex
((
i
)
=>
i
.
userId
===
key
)
index
>
-
1
&&
this
.
userList
.
splice
(
index
,
1
)
let
order
=
this
.
defaultValues
.
findIndex
((
i
)
=>
i
.
userId
===
key
)
order
>
-
1
&&
this
.
defaultValues
.
slice
().
splice
(
order
,
1
)
}
}
return
arr
}
},
}
// 确 定
submit
()
{
this
.
Pvisible
=
false
this
.
$emit
(
'success'
,
[...
this
.
dealedUserList
])
},
// 取消选择
cancle
(
key
)
{
this
.
$refs
.
tree
.
setChecked
(
key
,
false
)
let
index
=
this
.
userList
.
findIndex
((
i
)
=>
i
.
userId
===
key
)
index
>
-
1
&&
this
.
userList
.
splice
(
index
,
1
)
let
order
=
this
.
defaultValues
.
findIndex
((
i
)
=>
i
.
userId
===
key
)
order
>
-
1
&&
this
.
defaultValues
.
slice
().
splice
(
order
,
1
)
},
},
}
</
script
>
</
script
>
<
template
>
<
template
>
<el-dialog
<el-dialog
...
@@ -288,7 +288,8 @@ export default {
...
@@ -288,7 +288,8 @@ export default {
:title=
"title"
:title=
"title"
v-model=
"Pvisible"
v-model=
"Pvisible"
:close-on-click-modal=
"false"
:close-on-click-modal=
"false"
:destroy-on-close=
"destroyOnClose"
>
:destroy-on-close=
"destroyOnClose"
>
<div
class=
"content"
>
<div
class=
"content"
>
<div
class=
"left"
>
<div
class=
"left"
>
<div
class=
"search-input"
>
<div
class=
"search-input"
>
...
@@ -297,7 +298,8 @@ export default {
...
@@ -297,7 +298,8 @@ export default {
@
keyup
.
enter=
"setSearch"
@
keyup
.
enter=
"setSearch"
placeholder=
"请输入员工名称"
placeholder=
"请输入员工名称"
clearable
clearable
@
change=
"setChange"
>
@
change=
"setChange"
>
<template
#
append
><el-button
icon=
"el-icon-search"
@
click=
"setSearch"
></el-button></
template
>
<template
#
append
><el-button
icon=
"el-icon-search"
@
click=
"setSearch"
></el-button></
template
>
</el-input>
</el-input>
</div>
</div>
...
@@ -324,7 +326,8 @@ export default {
...
@@ -324,7 +326,8 @@ export default {
:load=
"loadNode"
:load=
"loadNode"
:props=
"defaultProps"
:props=
"defaultProps"
:check-strictly=
"isOnlyLeaf"
:check-strictly=
"isOnlyLeaf"
@
check-change=
"handleCheckChange"
></el-tree>
@
check-change=
"handleCheckChange"
></el-tree>
</div>
</div>
</transition>
</transition>
</div>
</div>
...
@@ -345,42 +348,42 @@ export default {
...
@@ -345,42 +348,42 @@ export default {
</template>
</template>
<
style
lang=
"scss"
scoped
>
<
style
lang=
"scss"
scoped
>
.content
{
.content
{
display
:
flex
;
display
:
flex
;
justify-content
:
space-between
;
justify-content
:
space-between
;
}
}
.left
,
.left
,
.right
{
.right
{
width
:
49%
;
width
:
49%
;
max-height
:
calc
(
100vh
-
170px
);
max-height
:
calc
(
100vh
-
170px
);
overflow
:
auto
;
overflow
:
auto
;
}
}
.search-input
{
.search-input
{
margin-top
:
5px
;
margin-top
:
5px
;
margin-bottom
:
10px
;
margin-bottom
:
10px
;
}
}
.user-list
{
.user-list
{
line-height
:
26px
;
line-height
:
26px
;
padding-right
:
10px
;
padding-right
:
10px
;
.user-name
{
.user-name
{
margin
:
0
5px
;
margin
:
0
5px
;
flex
:
auto
;
flex
:
auto
;
}
}
.search-list
{
line-height
:
26px
;
padding
:
0
10px
;
}
.fade-enter-active
{
transition
:
opacity
0.5s
;
}
.fade-enter
{
opacity
:
0
;
}
.fade-leave-active
{
transition
:
opacity
0.5s
;
}
.fade-leave-to
{
opacity
:
0
;
}
}
}
.search-list
{
line-height
:
26px
;
padding
:
0
10px
;
}
.fade-enter-active
{
transition
:
opacity
0.5s
;
}
.fade-enter
{
opacity
:
0
;
}
.fade-leave-active
{
transition
:
opacity
0.5s
;
}
.fade-leave-to
{
opacity
:
0
;
}
</
style
>
</
style
>
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment