2019-04-14 16:20:04 +08:00
|
|
|
<template>
|
|
|
|
<a-modal
|
|
|
|
:width="modalWidth"
|
|
|
|
:visible="visible"
|
|
|
|
:title="title"
|
|
|
|
@ok="handleSubmit"
|
|
|
|
@cancel="close"
|
|
|
|
cancelText="关闭"
|
|
|
|
style="margin-top: -70px"
|
|
|
|
wrapClassName="ant-modal-cust-warp"
|
|
|
|
>
|
|
|
|
<a-row :gutter="10" style="background-color: #ececec; padding: 10px; margin: -10px">
|
|
|
|
<a-col :md="6" :sm="24">
|
|
|
|
<a-card :bordered="false">
|
|
|
|
<!--组织机构-->
|
|
|
|
<a-directory-tree
|
|
|
|
selectable
|
2019-10-18 18:37:41 +08:00
|
|
|
:selectedKeys="selectedDepIds"
|
2019-04-14 16:20:04 +08:00
|
|
|
:checkStrictly="true"
|
2019-10-18 18:37:41 +08:00
|
|
|
@select="onDepSelect"
|
2019-04-14 16:20:04 +08:00
|
|
|
:dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
|
|
|
|
:treeData="departTree"
|
|
|
|
/>
|
|
|
|
</a-card>
|
|
|
|
</a-col>
|
|
|
|
<a-col :md="18" :sm="24">
|
|
|
|
<a-card :bordered="false">
|
|
|
|
用户账号:
|
|
|
|
<a-input-search
|
|
|
|
:style="{width:'150px',marginBottom:'15px'}"
|
2019-05-19 18:54:09 +08:00
|
|
|
placeholder="请输入用户账号"
|
2019-04-14 16:20:04 +08:00
|
|
|
v-model="queryParam.username"
|
|
|
|
@search="onSearch"
|
2019-05-19 18:54:09 +08:00
|
|
|
></a-input-search>
|
|
|
|
<a-button @click="searchReset(1)" style="margin-left: 20px" icon="redo">重置</a-button>
|
2019-04-14 16:20:04 +08:00
|
|
|
<!--用户列表-->
|
|
|
|
<a-table
|
|
|
|
ref="table"
|
|
|
|
:scroll="scrollTrigger"
|
|
|
|
size="middle"
|
|
|
|
rowKey="id"
|
|
|
|
:columns="columns"
|
|
|
|
:dataSource="dataSource"
|
|
|
|
:pagination="ipagination"
|
2019-10-18 18:37:41 +08:00
|
|
|
:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: getType}"
|
2019-04-14 16:20:04 +08:00
|
|
|
@change="handleTableChange">
|
|
|
|
</a-table>
|
|
|
|
</a-card>
|
|
|
|
</a-col>
|
|
|
|
</a-row>
|
|
|
|
</a-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-10-18 18:37:41 +08:00
|
|
|
import {filterObj} from '@/utils/util'
|
|
|
|
import {queryDepartTreeList, getUserList, queryUserByDepId} from '@/api/api'
|
|
|
|
|
2019-04-14 16:20:04 +08:00
|
|
|
export default {
|
2019-05-19 18:54:09 +08:00
|
|
|
name: 'JSelectUserByDepModal',
|
2019-04-14 16:20:04 +08:00
|
|
|
components: {},
|
2019-10-18 18:37:41 +08:00
|
|
|
props: ['modalWidth', 'multi', 'userIds'],
|
2019-04-14 16:20:04 +08:00
|
|
|
data() {
|
|
|
|
return {
|
2019-05-19 18:54:09 +08:00
|
|
|
queryParam: {
|
2019-10-18 18:37:41 +08:00
|
|
|
username: "",
|
2019-05-19 18:54:09 +08:00
|
|
|
},
|
2019-04-14 16:20:04 +08:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: '用户账号',
|
|
|
|
align: 'center',
|
|
|
|
dataIndex: 'username'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '真实姓名',
|
|
|
|
align: 'center',
|
|
|
|
dataIndex: 'realname'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '性别',
|
|
|
|
align: 'center',
|
|
|
|
dataIndex: 'sex',
|
2019-10-18 18:37:41 +08:00
|
|
|
customRender: function (text) {
|
2019-04-14 16:20:04 +08:00
|
|
|
if (text === 1) {
|
|
|
|
return '男'
|
|
|
|
} else if (text === 2) {
|
|
|
|
return '女'
|
|
|
|
} else {
|
|
|
|
return text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '手机号码',
|
|
|
|
align: 'center',
|
|
|
|
dataIndex: 'phone'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '邮箱',
|
|
|
|
align: 'center',
|
|
|
|
dataIndex: 'email'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
scrollTrigger: {},
|
|
|
|
dataSource: [],
|
2019-10-18 18:37:41 +08:00
|
|
|
selectedRowKeys: [],
|
|
|
|
selectUserRows: [],
|
|
|
|
selectUserIds: [],
|
2019-05-19 18:54:09 +08:00
|
|
|
title: '根据部门选择用户',
|
2019-04-14 16:20:04 +08:00
|
|
|
ipagination: {
|
|
|
|
current: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
pageSizeOptions: ['10', '20', '30'],
|
|
|
|
showTotal: (total, range) => {
|
|
|
|
return range[0] + '-' + range[1] + ' 共' + total + '条'
|
|
|
|
},
|
|
|
|
showQuickJumper: true,
|
|
|
|
showSizeChanger: true,
|
|
|
|
total: 0
|
|
|
|
},
|
|
|
|
isorter: {
|
|
|
|
column: 'createTime',
|
|
|
|
order: 'desc'
|
|
|
|
},
|
2019-10-18 18:37:41 +08:00
|
|
|
selectedDepIds: [],
|
2019-04-14 16:20:04 +08:00
|
|
|
departTree: [],
|
|
|
|
visible: false,
|
|
|
|
form: this.$form.createForm(this)
|
|
|
|
}
|
|
|
|
},
|
2019-10-18 18:37:41 +08:00
|
|
|
computed: {
|
|
|
|
// 计算属性的 getter
|
|
|
|
getType: function () {
|
|
|
|
console.log("multi: ", this.multi);
|
|
|
|
return this.multi == true ? 'checkbox' : 'radio';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
userIds() {
|
|
|
|
this.initUserNames()
|
|
|
|
}
|
|
|
|
},
|
2019-04-14 16:20:04 +08:00
|
|
|
created() {
|
|
|
|
// 该方法触发屏幕自适应
|
|
|
|
this.resetScreenSize();
|
2019-10-18 18:37:41 +08:00
|
|
|
this.loadData().then((res) => {
|
|
|
|
this.initUserNames();
|
|
|
|
})
|
2019-04-14 16:20:04 +08:00
|
|
|
},
|
|
|
|
methods: {
|
2019-10-18 18:37:41 +08:00
|
|
|
initUserNames() {
|
|
|
|
let names = ''
|
|
|
|
console.log("props userIds: ", this.userIds)
|
|
|
|
if (this.userIds) {
|
|
|
|
let currUserIds = this.userIds
|
2019-11-21 18:17:25 +08:00
|
|
|
let userIdsArr = currUserIds.split(',');
|
2019-10-18 18:37:41 +08:00
|
|
|
for (let item of this.dataSource) {
|
2019-11-21 18:17:25 +08:00
|
|
|
if (userIdsArr.includes(item.username)) {
|
2019-10-18 18:37:41 +08:00
|
|
|
names += "," + item.realname
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (names) {
|
|
|
|
names = names.substring(1)
|
|
|
|
}
|
|
|
|
this.$emit("initComp", names)
|
2019-12-25 13:25:10 +08:00
|
|
|
}else{
|
|
|
|
// JSelectUserByDep组件bug issues/I16634
|
|
|
|
this.$emit("initComp", "")
|
2019-10-18 18:37:41 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
async loadData(arg) {
|
2019-04-14 16:20:04 +08:00
|
|
|
if (arg === 1) {
|
|
|
|
this.ipagination.current = 1;
|
|
|
|
}
|
|
|
|
let params = this.getQueryParams();//查询条件
|
2019-10-18 18:37:41 +08:00
|
|
|
await getUserList(params).then((res) => {
|
2019-04-14 16:20:04 +08:00
|
|
|
if (res.success) {
|
|
|
|
this.dataSource = res.result.records;
|
|
|
|
this.ipagination.total = res.result.total;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 触发屏幕自适应
|
|
|
|
resetScreenSize() {
|
|
|
|
let screenWidth = document.body.clientWidth;
|
|
|
|
if (screenWidth < 500) {
|
2019-10-18 18:37:41 +08:00
|
|
|
this.scrollTrigger = {x: 800};
|
2019-04-14 16:20:04 +08:00
|
|
|
} else {
|
|
|
|
this.scrollTrigger = {};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
showModal() {
|
|
|
|
this.visible = true;
|
|
|
|
this.queryDepartTree();
|
2019-10-18 18:37:41 +08:00
|
|
|
this.loadData();
|
2019-04-14 16:20:04 +08:00
|
|
|
this.form.resetFields();
|
|
|
|
},
|
|
|
|
getQueryParams() {
|
|
|
|
let param = Object.assign({}, this.queryParam, this.isorter);
|
|
|
|
param.field = this.getQueryField();
|
|
|
|
param.pageNo = this.ipagination.current;
|
|
|
|
param.pageSize = this.ipagination.pageSize;
|
|
|
|
return filterObj(param);
|
|
|
|
},
|
|
|
|
getQueryField() {
|
|
|
|
let str = 'id,';
|
|
|
|
for (let a = 0; a < this.columns.length; a++) {
|
|
|
|
str += ',' + this.columns[a].dataIndex;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
},
|
|
|
|
searchReset(num) {
|
|
|
|
let that = this;
|
2019-10-18 18:37:41 +08:00
|
|
|
if (num !== 0) {
|
2019-05-19 18:54:09 +08:00
|
|
|
that.queryParam = {};
|
|
|
|
that.loadData(1);
|
2019-04-14 16:20:04 +08:00
|
|
|
}
|
|
|
|
that.selectedRowKeys = [];
|
2019-10-18 18:37:41 +08:00
|
|
|
that.selectUserIds = [];
|
|
|
|
that.selectedDepIds = [];
|
2019-04-14 16:20:04 +08:00
|
|
|
},
|
|
|
|
close() {
|
|
|
|
this.searchReset(0);
|
|
|
|
this.visible = false;
|
|
|
|
},
|
|
|
|
handleTableChange(pagination, filters, sorter) {
|
|
|
|
//TODO 筛选
|
|
|
|
if (Object.keys(sorter).length > 0) {
|
|
|
|
this.isorter.column = sorter.field;
|
|
|
|
this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc';
|
|
|
|
}
|
|
|
|
this.ipagination = pagination;
|
|
|
|
this.loadData();
|
|
|
|
},
|
|
|
|
handleSubmit() {
|
|
|
|
let that = this;
|
2019-10-18 18:37:41 +08:00
|
|
|
this.getSelectUserRows();
|
|
|
|
console.log(that.selectUserRows)
|
|
|
|
that.$emit('ok', that.selectUserRows, that.selectUserIds);
|
|
|
|
that.searchReset(0)
|
2019-04-14 16:20:04 +08:00
|
|
|
that.close();
|
|
|
|
},
|
2019-10-18 18:37:41 +08:00
|
|
|
//获取选择用户信息
|
|
|
|
getSelectUserRows(rowId) {
|
2019-04-14 16:20:04 +08:00
|
|
|
let dataSource = this.dataSource;
|
2019-10-18 18:37:41 +08:00
|
|
|
let userIds = "";
|
|
|
|
this.selectUserRows = [];
|
2019-04-14 16:20:04 +08:00
|
|
|
for (let i = 0, len = dataSource.length; i < len; i++) {
|
2019-10-18 18:37:41 +08:00
|
|
|
if (this.selectedRowKeys.includes(dataSource[i].id)) {
|
|
|
|
this.selectUserRows.push(dataSource[i]);
|
|
|
|
userIds = userIds + "," + dataSource[i].username
|
2019-04-14 16:20:04 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-18 18:37:41 +08:00
|
|
|
this.selectUserIds = userIds.substring(1);
|
2019-04-14 16:20:04 +08:00
|
|
|
},
|
|
|
|
// 点击树节点,筛选出对应的用户
|
2019-10-18 18:37:41 +08:00
|
|
|
onDepSelect(selectedDepIds) {
|
|
|
|
if (selectedDepIds[0] != null) {
|
|
|
|
this.initQueryUserByDepId(selectedDepIds); // 调用方法根据选选择的id查询用户信息
|
|
|
|
if (this.selectedDepIds[0] !== selectedDepIds[0]) {
|
|
|
|
this.selectedDepIds = [selectedDepIds[0]];
|
2019-04-14 16:20:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onSelectChange(selectedRowKeys, selectionRows) {
|
|
|
|
this.selectedRowKeys = selectedRowKeys;
|
|
|
|
this.selectionRows = selectionRows;
|
|
|
|
},
|
|
|
|
onSearch() {
|
|
|
|
this.loadData(1);
|
|
|
|
},
|
|
|
|
// 根据选择的id来查询用户信息
|
2019-10-18 18:37:41 +08:00
|
|
|
initQueryUserByDepId(selectedDepIds) {
|
|
|
|
queryUserByDepId({id: selectedDepIds.toString()}).then((res) => {
|
2019-04-14 16:20:04 +08:00
|
|
|
if (res.success) {
|
|
|
|
this.dataSource = res.result;
|
|
|
|
this.ipagination.total = res.result.length;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
queryDepartTree() {
|
|
|
|
queryDepartTreeList().then((res) => {
|
|
|
|
if (res.success) {
|
|
|
|
this.departTree = res.result;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
modalFormOk() {
|
|
|
|
this.loadData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.ant-table-tbody .ant-table-row td {
|
|
|
|
padding-top: 10px;
|
|
|
|
padding-bottom: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#components-layout-demo-custom-trigger .trigger {
|
|
|
|
font-size: 18px;
|
|
|
|
line-height: 64px;
|
|
|
|
padding: 0 24px;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: color .3s;
|
|
|
|
}
|
|
|
|
</style>
|