Commit 593dbda9 by xinla

扩展SelectWeUser

1 parent fda702be
<script> <script>
import { getDeptTree, getDeptUser } from '@/api/organization' import { getDeptTree, getDeptUser } from '@/api/organization'
export default { export default {
name: 'SelectWeUser', name: 'SelectWeUser',
components: {}, components: {},
props: { props: {
// 添加标签显隐 // 添加标签显隐
visible: { visible: {
type: Boolean, type: Boolean,
default: false default: false,
}, },
title: { title: {
type: String, type: String,
default: '组织架构' default: '组织架构',
}, },
// 是否 只选择叶子节点(人员节点)/禁止选择父节点(部门节点) // 是否 只选择叶子节点(人员节点)/禁止选择父节点(部门节点)
isOnlyLeaf: { isOnlyLeaf: {
type: Boolean, type: Boolean,
default: true default: true,
}, },
// 是否单选 // 是否单选
isSigleSelect: { isSigleSelect: {
type: Boolean, type: Boolean,
default: false default: false,
}, },
// 默认选中的节点 // 默认选中的节点
defaultValues: { defaultValues: {
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
// 必须含有userId和name属性 // 必须含有userId和name属性
validator(val) { validator(val) {
return val.every((e) => e.userId && e.name) return val.every((e) => e.userId && e.name)
} },
}, },
// 禁止选中的节点 // 禁止选中的节点
disabledValues: { disabledValues: {
type: Array, type: Array,
default: () => [] default: () => [],
}, },
destroyOnClose: Boolean destroyOnClose: Boolean,
}, },
data() { data() {
return { return {
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
keywords: '', keywords: '',
searchResult: [], searchResult: [],
searchState: false, searchState: false,
checked: [] checked: [],
} }
}, },
watch: { watch: {
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
this.userList = checkedUserList this.userList = checkedUserList
} }
}, },
immediate: true immediate: true,
}, },
Pvisible(val) { Pvisible(val) {
val && this.$refs.tree && this.$refs.tree.setCheckedKeys(this.defaultValues.map((e) => e.userId || e.id)) val && this.$refs.tree && this.$refs.tree.setCheckedKeys(this.defaultValues.map((e) => e.userId || e.id))
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
this.$refs.tree && this.$refs.tree.setCheckedKeys(this.defaultValues.map((e) => e.userId || e.id)) this.$refs.tree && this.$refs.tree.setCheckedKeys(this.defaultValues.map((e) => e.userId || e.id))
}, 300) }, 300)
} }
} },
}, },
computed: { computed: {
Pvisible: { Pvisible: {
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
}, },
set(val) { set(val) {
this.$emit('update:visible', val) this.$emit('update:visible', val)
} },
}, },
defaultProps() { defaultProps() {
let that = this let that = this
...@@ -97,9 +97,9 @@ ...@@ -97,9 +97,9 @@
}, },
isLeaf(data, node) { isLeaf(data, node) {
return !data.id return !data.id
},
} }
} },
}
}, },
created() {}, created() {},
mounted() {}, mounted() {},
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
}) })
getDeptUser({ getDeptUser({
deptId: this.deptId, deptId: this.deptId,
userName: this.keywords userName: this.keywords,
}).then((res) => { }).then((res) => {
this.searchResult = this.handleName(res.rows) this.searchResult = this.handleName(res.rows)
}) })
...@@ -247,12 +247,17 @@ ...@@ -247,12 +247,17 @@
index > -1 && this.userList.splice(index, 1) index > -1 && this.userList.splice(index, 1)
let order = this.defaultValues.findIndex((i) => i.userId === key) let order = this.defaultValues.findIndex((i) => i.userId === key)
order > -1 && this.defaultValues.slice().splice(order, 1) order > -1 && this.defaultValues.slice().splice(order, 1)
} },
} },
} }
</script> </script>
<template> <template>
<el-dialog :title="title" :visible.sync="Pvisible" :close-on-click-modal="false" :destroy-on-close="destroyOnClose"> <el-dialog
v-bind="$attrs"
:title="title"
:visible.sync="Pvisible"
:close-on-click-modal="false"
:destroy-on-close="destroyOnClose">
<el-row :gutter="20" class="content"> <el-row :gutter="20" class="content">
<el-col :span="12" :xs="24"> <el-col :span="12" :xs="24">
<div class="search-input"> <div class="search-input">
...@@ -262,8 +267,7 @@ ...@@ -262,8 +267,7 @@
@keyup.enter.native="setSearch" @keyup.enter.native="setSearch"
placeholder="请输入员工名称" placeholder="请输入员工名称"
clearable clearable
@change="setChange" @change="setChange">
>
<el-button slot="append" icon="el-icon-search" @click="setSearch"></el-button> <el-button slot="append" icon="el-icon-search" @click="setSearch"></el-button>
</el-input> </el-input>
</div> </div>
...@@ -291,8 +295,7 @@ ...@@ -291,8 +295,7 @@
:load="loadNode" :load="loadNode"
:props="defaultProps" :props="defaultProps"
:check-strictly="isOnlyLeaf" :check-strictly="isOnlyLeaf"
@check-change="handleCheckChange" @check-change="handleCheckChange"></el-tree>
></el-tree>
</div> </div>
</transition> </transition>
</el-col> </el-col>
...@@ -313,32 +316,32 @@ ...@@ -313,32 +316,32 @@
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.content { .content {
min-height: 400px; min-height: 400px;
} }
.search-input { .search-input {
margin-top: 5px; margin-top: 5px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.user-list { .user-list {
.el-row { .el-row {
line-height: 26px; line-height: 26px;
} }
} }
.search-list { .search-list {
margin-top: 20px; margin-top: 20px;
padding: 0 10px; padding: 0 10px;
} }
.fade-enter-active { .fade-enter-active {
transition: opacity 0.5s; transition: opacity 0.5s;
} }
.fade-enter { .fade-enter {
opacity: 0; opacity: 0;
} }
.fade-leave-active { .fade-leave-active {
transition: opacity 0.5s; transition: opacity 0.5s;
} }
.fade-leave-to { .fade-leave-to {
opacity: 0; 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!