566 lines
18 KiB
Vue
566 lines
18 KiB
Vue
<template>
|
|
<j-modal
|
|
:title="$t('userSelect.selectUser')"
|
|
:maskClosable="false"
|
|
:width="1200"
|
|
:closable="true"
|
|
centered
|
|
@ok="handleOk"
|
|
@cancel="handleCancel"
|
|
switchFullscreen
|
|
:visible="visible">
|
|
<div class="modal-top-wrapper">
|
|
<div class="modal-left-wrapper">
|
|
<a-spin :spinning="treeLoading">
|
|
<a-tree
|
|
:show-line="true"
|
|
:show-icon="true"
|
|
:tree-data="treeData"
|
|
:selectedKeys="currentTreeNode"
|
|
:replaceFields="{children: 'subset', title: 'name', key: 'id'}"
|
|
:default-expand-all="defaultExpandAll"
|
|
@select="treeSelect">
|
|
<template #custom="record">
|
|
<div class="tree-operate-node">
|
|
<a-icon class="parent-node-icon" type="folder" v-if="record.subset && record.subset.length > 0" />
|
|
<a-tooltip>
|
|
<template #title>
|
|
{{ record.name }}
|
|
</template>
|
|
<span class="tree-node-custom-title">{{ record.name }}</span>
|
|
</a-tooltip>
|
|
</div>
|
|
</template>
|
|
</a-tree>
|
|
</a-spin>
|
|
</div>
|
|
<div class="modal-right-wrapper">
|
|
<div class="modal-search-wrapper table-page-search-wrapper search-wrap">
|
|
<a-form layout="inline" @keyup.enter.native="searchQuery">
|
|
<a-row :gutter="24">
|
|
<a-col :span="6">
|
|
<a-form-item :label="$t('system.internalWorkGroup.name')" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
|
<a-input :placeholder="$t('pleaseEnter')+$t('system.internalWorkGroup.name')" v-model="queryParam.realname"></a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="6">
|
|
<a-form-item :label="$t('system.internalWorkGroup.workNo')" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
|
<a-input :placeholder="$t('pleaseEnter')+$t('system.internalWorkGroup.workNo')" v-model="queryParam.username"></a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="6">
|
|
<a-form-item :label="$t('system.internalWorkGroup.role')" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
|
<a-input :placeholder="$t('pleaseEnter')+$t('system.internalWorkGroup.role')" v-model="queryParam.userRoleName"></a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="6">
|
|
<a-form-item :label="$t('system.internalWorkGroup.post')" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
|
<a-input :placeholder="$t('pleaseEnter')+$t('system.internalWorkGroup.post')" v-model="queryParam.userPostName"></a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<!--<a-col :span="6">-->
|
|
<!-- <a-form-item :label="$t('userSelect.workGroup')" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
|
|
<!-- <a-tree-select-->
|
|
<!-- tree-node-filter-prop="title"-->
|
|
<!-- v-model="queryParam.workingGroupId"-->
|
|
<!-- :maxTagCount="1"-->
|
|
<!-- :show-search="true"-->
|
|
<!-- :getPopupContainer="triggerNode=> triggerNode.parentNode"-->
|
|
<!-- style="width: 100%"-->
|
|
<!-- :tree-data="workingGroupTreeList"-->
|
|
<!-- :placeholder="$t('pleaseSelect')"-->
|
|
<!-- />-->
|
|
<!-- </a-form-item>-->
|
|
<!--</a-col>-->
|
|
<span style="float: right;overflow: hidden;margin-right: 11px" class="table-page-search-submitButtons">
|
|
<a-button style="margin-left: 8px" type="primary" icon="search" @click="searchQuery">{{$t('query')}}</a-button>
|
|
<a-button style="margin-left: 8px" type="primary" ghost icon="reload" @click="searchReset">{{$t('reset')}}</a-button>
|
|
</span>
|
|
</a-row>
|
|
</a-form>
|
|
<!-- 全选所有 -->
|
|
<a-checkbox v-if="type === 'checkbox'" v-model="isCheckedAll" class="modal-title-check" @change="checkedAllChange">{{ $t('checkedAll') }}</a-checkbox>
|
|
</div>
|
|
<div class="modal-content">
|
|
<a-table
|
|
:columns="columns"
|
|
rowKey="userId"
|
|
bordered
|
|
:scroll="{x: '100%', y: '280px'}"
|
|
:data-source="dataSource"
|
|
:pagination="ipagination"
|
|
:row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: type }"
|
|
:loading="loadingLeft"
|
|
@change="leftTableChange">
|
|
<template slot="text" slot-scope="text">
|
|
<a-tooltip overlay-class-name="tooltip-style">
|
|
<template slot="title">{{ text || text === 0 ? text : global.emptyLine }}</template>
|
|
<div class="table-text">{{ text || text === 0 ? text : global.emptyLine }}</div>
|
|
</a-tooltip>
|
|
</template>
|
|
</a-table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<p class="modal-content-title">{{ $t('userSelect.selectedPersonnel') }}</p>
|
|
<div v-if="dataSourceRight && dataSourceRight.length > 0" class="name-content">
|
|
<div v-for="(item, index) in dataSourceRight" :key="item.userId" class="name-div">
|
|
{{ item.realname + '(' + item.username + ')' }}
|
|
<a-icon type="close" @click="handleDelete(item, index)" />
|
|
</div>
|
|
</div>
|
|
<a-empty v-else/>
|
|
</j-modal>
|
|
</template>
|
|
|
|
<script>
|
|
import { getAction, postAction } from '@/api/manage'
|
|
import { getWorkGroupTreeList } from '@/api/api'
|
|
|
|
export default {
|
|
name: 'UserSelectByWorkGroupModal',
|
|
props: {
|
|
type: { // 是单选还是多选
|
|
type: String,
|
|
default: 'radio'
|
|
},
|
|
value: {
|
|
type: String,
|
|
default: () => {
|
|
return ''
|
|
}
|
|
},
|
|
// 是否校验必选
|
|
checkRequired: {
|
|
type: Boolean,
|
|
required: false,
|
|
default: true
|
|
}
|
|
},
|
|
watch: {
|
|
value: {
|
|
immediate: true,
|
|
handler (val) {
|
|
console.log(val)
|
|
if (val) {
|
|
this.selectedRowKeys = val ? val.split(',') : []
|
|
this.getUserListByIds(val)
|
|
}
|
|
}
|
|
},
|
|
dataSourceRight: {
|
|
immediate: true,
|
|
deep: true,
|
|
handler (val) {
|
|
console.log(this.currentQueryAllData)
|
|
const arrOne = this.currentQueryAllData.map(item => item.userId)
|
|
const arrTwo = this.dataSourceRight.map(item => item.userId)
|
|
const temp = []
|
|
for (const item of arrTwo) {
|
|
arrOne.includes(item) ? temp.push(item) : ''
|
|
}
|
|
if (val.length !== 0 && this.dataSourceRight.length >= this.ipagination.total && temp.length === this.currentQueryAllData.length) {
|
|
// 选中数据长度等于当前表格总长度
|
|
this.isCheckedAll = true
|
|
} else {
|
|
this.isCheckedAll = false
|
|
}
|
|
}
|
|
},
|
|
currentQueryAllData: {
|
|
immediate: true,
|
|
deep: true,
|
|
handler (val) {
|
|
console.log(this.currentQueryAllData)
|
|
const arrOne = this.currentQueryAllData.map(item => item.userId)
|
|
const arrTwo = this.dataSourceRight.map(item => item.userId)
|
|
const temp = []
|
|
for (const item of arrTwo) {
|
|
arrOne.includes(item) ? temp.push(item) : ''
|
|
}
|
|
if (this.dataSourceRight.length !== 0 && this.dataSourceRight.length >= this.ipagination.total && temp.length === this.currentQueryAllData.length) {
|
|
// 选中数据长度等于当前表格总长度
|
|
this.isCheckedAll = true
|
|
} else {
|
|
this.isCheckedAll = false
|
|
}
|
|
}
|
|
},
|
|
queryParam: {
|
|
deep: true,
|
|
handler (val) {
|
|
this.isClickedSearch = false
|
|
}
|
|
}
|
|
},
|
|
data () {
|
|
return {
|
|
visible: false,
|
|
queryParam: {},
|
|
labelCol: {
|
|
span: 6
|
|
},
|
|
wrapperCol: {
|
|
span: 18
|
|
},
|
|
treeLoading: false,
|
|
currentTreeNode: null, // 当前选中的树节点
|
|
defaultExpandAll: false, // 左侧树默认展开所有
|
|
treeData: [],
|
|
columns: [
|
|
{
|
|
title: this.$t('user.workNo'),
|
|
dataIndex: 'username',
|
|
align: 'center',
|
|
scopedSlots: { customRender: 'text' }
|
|
},
|
|
{
|
|
title: this.$t('userSelect.name'),
|
|
dataIndex: 'realname',
|
|
align: 'center',
|
|
scopedSlots: { customRender: 'text' }
|
|
},
|
|
{
|
|
title: this.$t('role'),
|
|
dataIndex: 'userRoleName',
|
|
align: 'center',
|
|
scopedSlots: { customRender: 'text' }
|
|
},
|
|
{
|
|
title: this.$t('userSelect.post'),
|
|
dataIndex: 'userPostName',
|
|
align: 'center',
|
|
scopedSlots: { customRender: 'text' }
|
|
}
|
|
],
|
|
dataSource: [],
|
|
ipagination: {
|
|
current: 1,
|
|
pageSize: 5,
|
|
pageSizeOptions: ['5', '10', '20', '30', '100', '200'],
|
|
showTotal: (total, range) => {
|
|
return range[0] + '-' + range[1] + ' ' + this.$t('total') + ' ' + total + ' ' + this.$t('strip')
|
|
},
|
|
showQuickJumper: true,
|
|
showSizeChanger: true,
|
|
total: 0
|
|
},
|
|
selectedRowKeys: [],
|
|
loadingLeft: false,
|
|
dataSourceRight: [],
|
|
workingGroupTreeList: [], // 内部工作组下拉框数据
|
|
isCheckedAll: false, // 是否选中所有
|
|
url: {
|
|
userList: '/act/user/workGroupPage',
|
|
userListByIds: '/sys/user/queryByIds'
|
|
},
|
|
isClickedSearch: false, // 改完搜索条件是否点击过搜索
|
|
oldQueryParam: {}, // 上一次的搜索条件,用于从一个搜索条件改成另一个搜索条件,但是没有点搜索,这时候全选时传旧的搜索条件
|
|
oldTotal: 0,
|
|
currentQueryAllData: [] // 当前查询条件下的所有数据
|
|
}
|
|
},
|
|
mounted () {
|
|
this.initTreeData()
|
|
this.getWorkGroupTree()
|
|
this.loadData()
|
|
},
|
|
methods: {
|
|
open (value) {
|
|
this.visible = true
|
|
this.loadData()
|
|
if (value) {
|
|
this.selectedRowKeys = value.split(',')
|
|
this.getUserListByIds(value)
|
|
}
|
|
},
|
|
// 获取内部工作组树
|
|
getWorkGroupTree () {
|
|
getWorkGroupTreeList().then((res) => {
|
|
if (res.success) {
|
|
this.workingGroupTreeList = this.dealTreeData(res.result)
|
|
} else {
|
|
this.workingGroupTreeList = []
|
|
}
|
|
})
|
|
},
|
|
// 左侧树点击选中
|
|
treeSelect (selectedKeys) {
|
|
console.log(selectedKeys)
|
|
this.currentTreeNode = selectedKeys
|
|
this.queryParam.workingGroupId = selectedKeys[0]
|
|
this.loadData()
|
|
},
|
|
// 获取左侧树数据
|
|
initTreeData (params) {
|
|
this.treeLoading = true
|
|
getWorkGroupTreeList(params).then(res => {
|
|
if (res.success) {
|
|
this.treeData = this.dealTreeData(res.result)
|
|
this.treeData[0].scopedSlots = { title: 'oneCustom' }
|
|
} else {
|
|
this.treeData = []
|
|
}
|
|
}).finally(() => {
|
|
this.$nextTick(() => {
|
|
this.defaultExpandAll = true
|
|
})
|
|
this.treeLoading = false
|
|
})
|
|
},
|
|
// 处理左侧树数据结构
|
|
dealTreeData (treeData) {
|
|
return treeData.map(item => {
|
|
item.label = item.name
|
|
item.value = item.id
|
|
item.children = this.dealTreeData(item.subset)
|
|
return item
|
|
})
|
|
},
|
|
// 全选所有
|
|
checkedAllChange (e) {
|
|
console.log(e.target.checked)
|
|
if (e.target.checked) {
|
|
this.checkCurrentAll()
|
|
} else {
|
|
this.dataSourceRight = []
|
|
this.selectedRowKeys = []
|
|
}
|
|
},
|
|
checkCurrentAll () {
|
|
this.loadingLeft = true
|
|
let params
|
|
if (this.isClickedSearch) {
|
|
// 点击过搜索了,传搜索条件
|
|
params = Object.assign({}, this.queryParam)
|
|
} else {
|
|
// 没点击过搜索,传旧的搜索条件
|
|
params = Object.assign({}, this.oldQueryParam)
|
|
}
|
|
params.pageNo = 1
|
|
params.pageSize = this.ipagination.total + 10
|
|
getAction(this.url.userList, params).then(res => {
|
|
if (res.success) {
|
|
this.dataSourceRight = res.result.records || []
|
|
this.selectedRowKeys = (res.result.records || []).map(item => item.userId)
|
|
}
|
|
}).finally(() => {
|
|
this.loadingLeft = false
|
|
})
|
|
},
|
|
// 获取当前查询条件的所有数据
|
|
async getCurrentAllData () {
|
|
const params = Object.assign({}, this.queryParam)
|
|
params.pageNo = 1
|
|
params.pageSize = 100000000
|
|
await getAction(this.url.userList, params).then(res => {
|
|
if (res.success) {
|
|
this.currentQueryAllData = res.result.records || []
|
|
}
|
|
})
|
|
},
|
|
searchReset () {
|
|
this.queryParam = {}
|
|
this.loadData()
|
|
},
|
|
searchQuery () {
|
|
this.isClickedSearch = true
|
|
this.loadData()
|
|
},
|
|
// 获取用户左侧树列表
|
|
async loadData () {
|
|
this.loadingLeft = true
|
|
if (this.type === 'checkbox') {
|
|
await this.getCurrentAllData()
|
|
}
|
|
const params = Object.assign({}, this.queryParam)
|
|
params.pageNo = this.ipagination.current
|
|
params.pageSize = this.ipagination.pageSize
|
|
getAction(this.url.userList, params).then((res) => {
|
|
if (res.success) {
|
|
if (res.result.current > 1 && res.result.records.length === 0) {
|
|
this.ipagination.current = res.result.current - 1
|
|
this.loadData()
|
|
return
|
|
}
|
|
this.oldQueryParam = Object.assign({}, this.queryParam)
|
|
this.dataSource = res.result.records || []
|
|
this.ipagination.total = res.result.total
|
|
} else {
|
|
this.$message.warn(res.message)
|
|
}
|
|
}).finally(() => {
|
|
this.loadingLeft = false
|
|
})
|
|
},
|
|
// 表格选择
|
|
onSelectChange (selectedRowKeys, selectedRows) {
|
|
this.selectedRowKeys = selectedRowKeys
|
|
if (this.type === 'checkbox') {
|
|
if (selectedRowKeys.length > this.dataSourceRight.length) {
|
|
// 说明是增加了数据
|
|
for (const rowIndex in selectedRows) {
|
|
if (!this.dataSourceRight.find(item => item.userId === selectedRows[rowIndex].userId)) {
|
|
// 右侧不存在,追加到右侧表格
|
|
this.dataSourceRight.push(selectedRows[rowIndex])
|
|
}
|
|
}
|
|
} else {
|
|
// 说明是删除了数据
|
|
if (selectedRowKeys && selectedRowKeys.length > 0) {
|
|
// 没有选中数据,说明这一页没有选中数据了
|
|
for (let i = 0; i < this.dataSourceRight.length; i++) {
|
|
if (!selectedRowKeys.find(item => item === this.dataSourceRight[i].userId)) {
|
|
// 表格选中中没有找到这一条数据,说明已经被删了
|
|
this.dataSourceRight.splice(i, 1)
|
|
i--
|
|
}
|
|
}
|
|
} else {
|
|
this.dataSourceRight = []
|
|
}
|
|
}
|
|
console.log(this.dataSourceRight)
|
|
} else {
|
|
this.dataSourceRight = selectedRows
|
|
}
|
|
},
|
|
// 左侧表格改变
|
|
leftTableChange (pagination) {
|
|
this.ipagination = pagination
|
|
this.loadData()
|
|
},
|
|
// 根据ids获取用户列表
|
|
getUserListByIds (ids) {
|
|
const params = {}
|
|
params.userIds = ids
|
|
this.loadingRight = true
|
|
postAction(this.url.userListByIds, params).then((res) => {
|
|
if (res.success) {
|
|
this.dataSourceRight = res.result.map(item => { return { ...item, userId: item.id } }) || []
|
|
} else {
|
|
this.$message.warn(res.message)
|
|
}
|
|
}).finally(() => {
|
|
this.loadingRight = false
|
|
})
|
|
},
|
|
// 名字列表的删除
|
|
handleDelete (record, index) {
|
|
this.dataSourceRight.splice(index, 1)
|
|
this.selectedRowKeys = this.selectedRowKeys.filter(item => item !== record.userId)
|
|
},
|
|
handleOk () {
|
|
if (this.checkRequired && (!this.selectedRowKeys || this.selectedRowKeys.length === 0)) {
|
|
if (this.type === 'radio') {
|
|
this.$message.warning(this.$t('docTool.split.pleaseSelectUser'))
|
|
} else {
|
|
this.$message.warning(this.$t('pleaseAtLeastSelectOneUser'))
|
|
}
|
|
return
|
|
}
|
|
this.$emit('change', this.selectedRowKeys.join(','))
|
|
this.$emit('nameChange', this.dataSourceRight.map(item => item.realname + '(' + item.username + ')').join(','))
|
|
this.close()
|
|
},
|
|
handleCancel () {
|
|
this.close()
|
|
},
|
|
close () {
|
|
this.visible = false
|
|
this.dataSourceRight = []
|
|
this.selectedRowKeys = []
|
|
this.queryParam = {}
|
|
this.ipagination = {
|
|
current: 1,
|
|
pageSize: 5,
|
|
pageSizeOptions: ['5', '10', '20', '30', '100', '200'],
|
|
showTotal: (total, range) => {
|
|
return range[0] + '-' + range[1] + ' ' + this.$t('total') + ' ' + total + ' ' + this.$t('strip')
|
|
},
|
|
showQuickJumper: true,
|
|
showSizeChanger: true,
|
|
total: 0
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
@import '~@assets/less/common.less';
|
|
.search-wrap {
|
|
position: relative;
|
|
}
|
|
.modal-title-check {
|
|
position: absolute;
|
|
left: 25px;
|
|
bottom: 10px;
|
|
}
|
|
.modal-top-wrapper {
|
|
display: flex;
|
|
height: 480px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.modal-left-wrapper {
|
|
width: 200px;
|
|
margin-right: 20px;
|
|
height: 100%;
|
|
overflow-y: scroll;
|
|
}
|
|
.modal-right-wrapper {
|
|
flex: 1;
|
|
}
|
|
.modal-content {
|
|
width: 100%;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
&-left {
|
|
width: 58%;
|
|
}
|
|
&-right {
|
|
width: 40%;
|
|
}
|
|
&-title-div {
|
|
display: flex;
|
|
align-items: center;
|
|
height: 28px;
|
|
margin: 20px 0;
|
|
.modal-content-title {
|
|
color: #1D2129;
|
|
font-weight: 500;
|
|
margin-right: 12px;
|
|
margin-bottom: 0;
|
|
}
|
|
}
|
|
}
|
|
.name-content {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
max-height: 200px;
|
|
overflow-y: auto;
|
|
.name-div {
|
|
width: auto;
|
|
padding: 5px 16px;
|
|
margin-right: 12px;
|
|
margin-top: 8px;
|
|
background: rgba(213, 44, 38, 0.08);
|
|
border-radius: 4px 4px 4px 4px;
|
|
opacity: 1;
|
|
color: @primary-color;
|
|
white-space: nowrap;
|
|
/deep/ .anticon {
|
|
margin-left: 4px;
|
|
}
|
|
}
|
|
}
|
|
|
|
/deep/ .ant-table-content .ant-table-body{
|
|
overflow: scroll !important;
|
|
}
|
|
|
|
/deep/ .ant-form-item-label{
|
|
min-width: 70px !important;
|
|
}
|
|
</style>
|