Commit e5ee7947 by 姜鹏凯

Merge branch 'test'

2 parents 55e1c679 0fd86343
<script> <script>
import { getDeptTree, getDeptUser } from '@/api/organization' import { getDeptTree, getDeptUser } from '@/api/organization'
import { createUniqueString } from '@/utils'
export default { export default {
name: 'SelectUser', name: 'SelectUser',
components: {}, components: {},
...@@ -49,7 +47,12 @@ ...@@ -49,7 +47,12 @@
return { return {
treeData: [], treeData: [],
userList: [], userList: [],
defaultKeys: [] defaultKeys: [],
deptId: '', //根部门Id
keywords: '',
searchResult: [],
searchState: false,
checked: []
} }
}, },
watch: { watch: {
...@@ -86,11 +89,7 @@ ...@@ -86,11 +89,7 @@
label: 'name', label: 'name',
children: 'children', children: 'children',
disabled(data, node) { disabled(data, node) {
return ( return (that.isOnlyLeaf && data.isParty) || that.disabledValues.some((e) => e == (data.userId || data.id))
(that.isOnlyLeaf && data.isParty) ||
that.disabledValues.some((e) => e == (data.userId || data.id)) ||
data.userId === ''
)
}, },
isLeaf(data, node) { isLeaf(data, node) {
return !data.id return !data.id
...@@ -101,6 +100,45 @@ ...@@ -101,6 +100,45 @@
created() {}, created() {},
mounted() {}, mounted() {},
methods: { methods: {
setChange(e) {
if (!e) {
this.searchState = false
this.$refs.tree.setCheckedKeys(this.userList.map((e) => e.userId || e.id))
}
},
setSearch() {
if (!this.keywords) return
this.searchResult = []
this.searchState = true
this.checked = this.userList.map((dd) => {
return dd.userId
})
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])
}
this.checked = this.userList.map((dd) => {
return dd.userId
})
this.$forceUpdate()
} else {
this.cancle(this.searchResult[index].userId)
}
setTimeout(() => {
this.keywords = ''
this.setChange()
}, 500)
},
treeFormat(list) { treeFormat(list) {
let dealOptions = [] let dealOptions = []
list.forEach((one) => { list.forEach((one) => {
...@@ -126,21 +164,15 @@ ...@@ -126,21 +164,15 @@
this.userList = [] this.userList = []
} }
getDeptTree().then(({ data }) => { getDeptTree().then(({ data }) => {
// data.forEach((element) => {
// element.key = createUniqueString()
// })
let _data = this.handleDepart(data) let _data = this.handleDepart(data)
resolve(this.treeFormat(_data)) let value = this.treeFormat(_data)
// api.getList({ department: _data[0].id }).then(({ rows, total }) => { if (value.length) {
// _data && rows.unshift(..._data); this.deptId = value[0].deptId
// resolve(rows); }
// }); resolve(value)
}) })
} else { } else {
getDeptUser({ deptId: node.data.id }).then(({ rows }) => { getDeptUser({ deptId: node.data.id }).then(({ rows }) => {
// rows.forEach((element) => {
// element.key = createUniqueString()
// })
let arr = this.handleUser(rows) let arr = this.handleUser(rows)
node.data.children && arr.push(...node.data.children) node.data.children && arr.push(...node.data.children)
resolve(arr) resolve(arr)
...@@ -223,22 +255,46 @@ ...@@ -223,22 +255,46 @@
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="12" :xs="24"> <el-col :span="12" :xs="24">
<div class="head-container"> <div class="head-container">
<el-tree <div class="search-input">
node-key="nodeKey" <el-input
ref="tree" size="mini"
lazy v-model="keywords"
accordion @keyup.enter.native="setSearch"
show-checkbox placeholder="请输入员工名称"
:check-on-click-node="false" clearable
:expand-on-click-node="true" @change="setChange"
:load="loadNode" >
:props="defaultProps" <el-button slot="append" icon="el-icon-search" @click="setSearch"></el-button>
:check-strictly="isOnlyLeaf" </el-input>
@check-change="handleCheckChange" </div>
></el-tree> <div class="search-list user-list" v-show="searchState">
<!-- :default-checked-keys=" <el-checkbox-group v-model="checked">
defaultValues.map((e) => (isOnlyLeaf ? e.userId : e.userId || e.id)) <el-row v-for="(item, index) in searchResult" :key="index">
" --> <el-checkbox :label="item.userId" :key="index" @change="setSelectChange($event, index)">
<div>
{{ item.name }}
</div>
</el-checkbox>
</el-row>
</el-checkbox-group>
</div>
<transition name="fade">
<div class="head-container" v-show="!searchState">
<el-tree
node-key="nodeKey"
ref="tree"
lazy
accordion
show-checkbox
:check-on-click-node="false"
:expand-on-click-node="true"
:load="loadNode"
:props="defaultProps"
:check-strictly="isOnlyLeaf"
@check-change="handleCheckChange"
></el-tree>
</div>
</transition>
</div> </div>
</el-col> </el-col>
<el-col :span="12" :xs="24" class="user-list"> <el-col :span="12" :xs="24" class="user-list">
...@@ -258,9 +314,32 @@ ...@@ -258,9 +314,32 @@
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.content {
min-height: 400px;
}
.search-input {
margin-top: 5px;
margin-bottom: 10px;
}
.user-list { .user-list {
.el-row { .el-row {
line-height: 26px; line-height: 26px;
} }
} }
.search-list {
margin-top: 20px;
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>
<script> <script>
import { getDeptTree, getDeptUser } from '@/api/organization' import { getDeptTree, getDeptUser } from '@/api/organization'
import { createUniqueString } from '@/utils'
export default { export default {
name: 'SelectWeUser', name: 'SelectWeUser',
components: {}, components: {},
...@@ -45,7 +43,12 @@ ...@@ -45,7 +43,12 @@
return { return {
treeData: [], treeData: [],
userList: [], userList: [],
defaultKeys: [] defaultKeys: [],
deptId: '', //根部门Id
keywords: '',
searchResult: [],
searchState: false,
checked: []
} }
}, },
watch: { watch: {
...@@ -90,11 +93,7 @@ ...@@ -90,11 +93,7 @@
label: 'name', label: 'name',
children: 'children', children: 'children',
disabled(data, node) { disabled(data, node) {
return ( return (that.isOnlyLeaf && data.isParty) || that.disabledValues.some((e) => e == (data.userId || data.id))
(that.isOnlyLeaf && data.isParty) ||
that.disabledValues.some((e) => e == (data.userId || data.id)) ||
data.userId === ''
)
}, },
isLeaf(data, node) { isLeaf(data, node) {
return !data.id return !data.id
...@@ -105,6 +104,45 @@ ...@@ -105,6 +104,45 @@
created() {}, created() {},
mounted() {}, mounted() {},
methods: { methods: {
setChange(e) {
if (!e) {
this.searchState = false
this.$refs.tree.setCheckedKeys(this.userList.map((e) => e.userId || e.id))
}
},
setSearch() {
if (!this.keywords) return
this.searchResult = []
this.searchState = true
this.checked = this.userList.map((dd) => {
return dd.userId
})
getDeptUser({
deptId: this.deptId,
userName: this.keywords
}).then((res) => {
this.searchResult = this.handleName(res.rows)
})
},
setSelectChange(e, index) {
if (e) {
if (this.isSigleSelect) {
this.userList[0] = this.searchResult[index]
} else {
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(() => {
this.keywords = ''
this.setChange()
}, 500)
},
treeFormat(list) { treeFormat(list) {
let dealOptions = [] let dealOptions = []
list.forEach((one) => { list.forEach((one) => {
...@@ -129,23 +167,16 @@ ...@@ -129,23 +167,16 @@
if (!Array.isArray(this.defaultValues) || this.defaultValues.length == 0) { if (!Array.isArray(this.defaultValues) || this.defaultValues.length == 0) {
this.userList = [] this.userList = []
} }
console.log(this.defaultValues)
getDeptTree().then(({ data }) => { getDeptTree().then(({ data }) => {
// data.forEach((element) => {
// element.key = createUniqueString()
// })
let _data = this.handleTree(data) let _data = this.handleTree(data)
resolve(this.treeFormat(_data)) let value = this.treeFormat(_data)
// api.getList({ department: _data[0].id }).then(({ rows, total }) => { if (value.length) {
// _data && rows.unshift(..._data); this.deptId = value[0].deptId
// resolve(rows); }
// }); resolve(value)
}) })
} else { } else {
getDeptUser({ deptId: node.data.id }).then(({ rows }) => { getDeptUser({ deptId: node.data.id }).then(({ rows }) => {
// rows.forEach((element) => {
// element.key = createUniqueString()
// })
let arr = this.handleName(rows) let arr = this.handleName(rows)
node.data.children && arr.push(...node.data.children) node.data.children && arr.push(...node.data.children)
resolve(arr) resolve(arr)
...@@ -166,7 +197,7 @@ ...@@ -166,7 +197,7 @@
handleName(data) { handleName(data) {
return data.map((i) => { return data.map((i) => {
if (i.userName) { if (i.userName) {
i.userId = i.weUserId ? i.weUserId : '' i.userId = i.weUserId
i.name = i.userName i.name = i.userName
} }
return i return i
...@@ -174,7 +205,6 @@ ...@@ -174,7 +205,6 @@
}, },
// 选择变化 // 选择变化
handleCheckChange(data, checked, indeterminate) { handleCheckChange(data, checked, indeterminate) {
// console.log(arguments)
if (checked) { if (checked) {
if (this.isSigleSelect) { if (this.isSigleSelect) {
// 单选情况 // 单选情况
...@@ -189,11 +219,9 @@ ...@@ -189,11 +219,9 @@
!isExist && this.userList.push(data) !isExist && this.userList.push(data)
} }
} else { } else {
// let index = this.userList.indexOf(data)
let index = this.userList.findIndex((i) => i.userId === data.userId) let index = this.userList.findIndex((i) => i.userId === data.userId)
index > -1 && this.userList.splice(index, 1) index > -1 && this.userList.splice(index, 1)
} }
// console.log(data, checked, indeterminate);
this.userList = this.unique(this.userList) this.userList = this.unique(this.userList)
}, },
unique(arr) { unique(arr) {
...@@ -225,26 +253,48 @@ ...@@ -225,26 +253,48 @@
</script> </script>
<template> <template>
<el-dialog :title="title" :visible.sync="Pvisible" :close-on-click-modal="false" :destroy-on-close="destroyOnClose"> <el-dialog :title="title" :visible.sync="Pvisible" :close-on-click-modal="false" :destroy-on-close="destroyOnClose">
<el-row :gutter="20"> <el-row :gutter="20" class="content">
<el-col :span="12" :xs="24"> <el-col :span="12" :xs="24">
<div class="head-container"> <div class="search-input">
<el-tree <el-input
node-key="userId" size="mini"
ref="tree" v-model="keywords"
lazy @keyup.enter.native="setSearch"
accordion placeholder="请输入员工名称"
show-checkbox clearable
:check-on-click-node="false" @change="setChange"
:expand-on-click-node="true" >
:load="loadNode" <el-button slot="append" icon="el-icon-search" @click="setSearch"></el-button>
:props="defaultProps" </el-input>
:check-strictly="isOnlyLeaf"
@check-change="handleCheckChange"
></el-tree>
<!-- :default-checked-keys="
defaultValues.map((e) => (isOnlyLeaf ? e.userId : e.userId || e.id))
" -->
</div> </div>
<div class="search-list user-list" v-show="searchState">
<el-checkbox-group v-model="checked">
<el-row v-for="(item, index) in searchResult" :key="index">
<el-checkbox :label="item.userId" :key="index" @change="setSelectChange($event, index)">
<div>
{{ item.name }}
</div>
</el-checkbox>
</el-row>
</el-checkbox-group>
</div>
<transition name="fade">
<div class="head-container" v-show="!searchState">
<el-tree
node-key="userId"
ref="tree"
lazy
accordion
show-checkbox
:check-on-click-node="false"
:expand-on-click-node="true"
:load="loadNode"
:props="defaultProps"
:check-strictly="isOnlyLeaf"
@check-change="handleCheckChange"
></el-tree>
</div>
</transition>
</el-col> </el-col>
<el-col :span="12" :xs="24" class="user-list"> <el-col :span="12" :xs="24" class="user-list">
<el-row :gutter="10">选择人员列表</el-row> <el-row :gutter="10">选择人员列表</el-row>
...@@ -263,9 +313,32 @@ ...@@ -263,9 +313,32 @@
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.content {
min-height: 400px;
}
.search-input {
margin-top: 5px;
margin-bottom: 10px;
}
.user-list { .user-list {
.el-row { .el-row {
line-height: 26px; line-height: 26px;
} }
} }
.search-list {
margin-top: 20px;
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>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!