import React from 'react';
import ReactDom from 'react-dom';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import {
Form, Icon, Button, Input, Select, AutoComplete, Spin, Table,
message, DatePicker, Modal, TreeSelect, Popconfirm, Tabs
} from 'antd';
import Newuser from "./newUser.jsx"
import './userMangagement.less'
import { techAuditStatusList, station, post } from '../../../dataDic.js';
import { getPost, getStation, getRole } from '../../../tools.js';
import { ChooseList } from "../../order/orderNew/chooseList";
const { TabPane } = Tabs
const User = Form.create()(React.createClass({
loadData(pageNo) {
this.state.data = [];
this.setState({
userDetaile: false,
loading: true,
page: pageNo
});
var admin = window.adminData.isSuperAdmin || '';
var departmentId = window.adminData.departmentId || '';
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + '/api/admin/superviser/adminList',
data: {
pageNo: pageNo || 1,
pageSize: this.state.pagination.pageSize,
name: this.state.userNameSearch,
departmentId: admin ? this.state.organizationSearch : departmentId,
rid: this.state.rolesSearch,
duty: this.state.postSearch,
position: this.state.stationSearch,
status: this.state.statusSeach,
mobile: this.state.signNameSearch,
superiorId: this.state.theTypes,
ambManage: this.state.ambManage,
ambId: this.state.amb == 1 ? this.state.ambId : undefined,
ancestors: this.state.amb == 2 ? this.state.ambId : undefined,
seniorStaff: this.state.seniorStaff,
publicPurview: this.state.publicPurview,
},
success: function (data) {
let theArr = [];
if (!data.data || !data.data.list) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
} else {
for (let i = 0; i < data.data.list.length; i++) {
let thisdata = data.data.list[i];
theArr.push({
key: i,
id: thisdata.id,
mobile: thisdata.mobile,
name: thisdata.name,
email: thisdata.email,
createTime: thisdata.createTime,
province: thisdata.province,
position: thisdata.position,
seniorStaff: thisdata.seniorStaff,
publicPurview: thisdata.publicPurview,
superior: thisdata.superior, //上级名称
superiorId: thisdata.superiorId, //上级Id
duty: thisdata.duty, //职务
status: thisdata.status,
userNo: thisdata.userNo,
departmentName: thisdata.departmentName, //部门名称
departmentId: thisdata.departmentId, //部门id
roles: thisdata.roles,
rolesId: thisdata.rolesId,
lastLoginTime: thisdata.lastLoginTime,
rolesName: thisdata.rolesName,
ancestorsNames: thisdata.ancestorsNames, //分巴
ambName: thisdata.ambName,
ambRole: thisdata.ambRole,
});
};
this.state.pagination.current = data.data.pageNo ? data.data.pageNo : '0';
this.state.pagination.total = data.data.totalCount ? data.data.totalCount : '0';
};
if (!data.data.list.length) {
this.state.pagination.current = 0
this.state.pagination.total = 0
}
this.setState({
dataSource: theArr,
pagination: this.state.pagination,
selectedRowKeys: []
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
loadDatas(pageNo) {
this.state.data = [];
this.setState({
userDetaile: false,
loading: true,
});
var admin = window.adminData.isSuperAdmin || '';
var departmentId = window.adminData.departmentId || '';
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + '/api/admin/superviser/adminList',
data: {
pageNo: pageNo || 1,
pageSize: this.state.paginations.pageSize,
name: this.state.userNameSearchs,
status: 0
// departmentId: admin?this.state.organizationSearch:departmentId,
// rid: this.state.rolesSearch,
// duty: this.state.postSearch,
// position: this.state.stationSearch,
// status: this.state.statusSeach,
// mobile: this.state.signNameSearch,
// superiorId: this.state.theTypes
},
success: function (data) {
let theArr = [];
if (!data.data || !data.data.list) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
} else {
for (let i = 0; i < data.data.list.length; i++) {
let thisdata = data.data.list[i];
theArr.push({
key: i,
id: thisdata.id,
mobile: thisdata.mobile,
name: thisdata.name,
email: thisdata.email,
createTime: thisdata.createTime,
province: thisdata.province,
position: thisdata.position,
superior: thisdata.superior, //上级名称
superiorId: thisdata.superiorId, //上级Id
duty: thisdata.duty, //职务
status: thisdata.status,
userNo: thisdata.userNo,
departmentName: thisdata.departmentName, //部门名称
departmentId: thisdata.departmentId, //部门id
roles: thisdata.roles,
rolesId: thisdata.rolesId,
lastLoginTime: thisdata.lastLoginTime,
rolesName: thisdata.rolesName,
ancestorsNames: thisdata.ancestorsNames, //分巴
ambName: thisdata.ambName,
ambRole: thisdata.ambRole,
});
};
this.state.paginations.current = data.data.pageNo ? data.data.pageNo : '0';
this.state.paginations.total = data.data.totalCount ? data.data.totalCount : '0';
};
if (!data.data.list.length) {
this.state.paginations.current = 0
this.state.paginations.total = 0
}
this.setState({
dataSourceData: theArr,
paginations: this.state.paginations,
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
getInitialState() {
return {
amb: 1,
datauser: {},
searchMore: true,
selectedRowKeys: [],
selectedRows: [],
userDetaile: false,
departmentArr: [],
loading: false,
roleArr: [],
pagination: {
defaultCurrent: 1,
defaultPageSize: 10,
showQuickJumper: true,
pageSize: 10,
onChange: function (page) {
this.loadData(page);
}.bind(this),
showTotal: function (total) {
return '共' + total + '条数据';
}
},
paginations: {
defaultCurrent: 1,
defaultPageSize: 10,
showQuickJumper: true,
pageSize: 10,
onChange: function (page) {
this.loadDatas(page);
}.bind(this),
showTotal: function (total) {
return '共' + total + '条数据';
}
},
columns: [{
title: '用户编号',
dataIndex: 'userNo',
key: 'userNo',
isNoD: true,
}, {
title: '登录用户名',
dataIndex: 'mobile',
key: 'mobile',
width: "140px",
}, {
title: '角色',
dataIndex: 'rolesName',
key: 'rolesName',
render: (text, record) =>
{text + (getRole(record.ambRole) ? ("(" + getRole(record.ambRole) + ")") : "")}
}, {
title: '用户姓名',
dataIndex: 'name',
key: 'name',
width: "140px",
}, {
title: '部门',
dataIndex: 'departmentName',
key: 'departmentName',
}, {
title: '分巴',
dataIndex: 'ancestorsNames',
key: 'ancestorsNames',
render: (text, record) =>
{!!text && text.replace(/,/g, "-")}
{!!record.ambName && "-" + record.ambName}
}, {
title: '职务',
dataIndex: 'duty',
key: 'duty',
isNoD: true,
render: text => { return getPost(text) }
},
{
title: '岗位',
dataIndex: 'position',
key: 'position',
isNoD: true,
render: text => { return getStation(text) }
},
{
title: '员工',
dataIndex: 'seniorStaff',
key: 'seniorStaff',
render: text => {["新员工", "老员工"][text]}
},
{
title: '上级主管姓名',
dataIndex: 'superior',
key: 'superior',
width: "140px",
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
render: (text) =>
{text == 0
? "正常" : text == 1
? "停用" : "-"}
},
{
title: '最后登录时间',
dataIndex: 'lastLoginTime',
key: 'lastLoginTime',
}
],
column: [{
title: '用户编号',
dataIndex: 'userNo',
key: 'userNo',
}, {
title: '登录用户名',
dataIndex: 'mobile',
key: 'mobile',
}, {
title: '角色',
dataIndex: 'rolesName',
key: 'rolesName',
render: (text, record) =>
{text + (getRole(record.ambRole) ? ("(" + getRole(record.ambRole) + ")") : "")}
}, {
title: '用户姓名',
dataIndex: 'name',
key: 'name',
}, {
title: '转交',
dataIndex: 'ee',
key: 'ee',
render: (text, record, index) => {
return
{ this.examineOK(record) }} okText="确认" cancelText="取消">
}
},
],
dataSourceData: [],
};
},
//点击离职一键转交
resources() {
this.loadDatas();
let deletedIds;
let rowItem;
for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
rowItem = this.state.selectedRows[idx];
// console.log(rowItem.id);
if (rowItem.id) {
deletedIds = rowItem.id;
};
};
this.setState({
visible: true,
aid: deletedIds
});
},
//关闭离职一键转交
handleCancel() {
this.setState({
visible: false,
selectedRowKeys: []
}, () => {
this.loadData(this.state.page);
});
},
//一键离职
examineOK(record) {
// console.log(record);
this.setState({
loading: true
});
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/role/dimission",
data: {
aid: this.state.aid,
transferId: record.id,
}
}).done(function (data) {
if (!data.error.length) {
message.success('转交成功!');
this.handleCancel()
} else {
message.warning(data.error[0].message);
};
this.setState({
loading: false,
visible2: false
});
}.bind(this));
},
// 设置默认table(用来默认不显示某列数据 isNoD:true)
defaultcolumns() {
const newArr = [];
this.state.columns.forEach((item) => {
if (item.isNoD) {
return
} else {
newArr.push(item);
}
});
this.setState({
changeList: newArr,
}, () => {
this.loadData();
});
},
componentWillMount() {
this.defaultcolumns();
this.loadData();
this.departmentList();
this.rolesList();
this.getList();
},
tableRowClick(record, index) {
this.rolesArrS(record)
},
//新建获取id
addIdS() {
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + '/api/admin/superviser/newId',
data: {},
success: function (data) {
this.setState({
addId: data.data
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
//部门
departmentList() {
this.setState({
loading: true
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/organization/selectSuperId",
data: {
},
success: function (data) {
let thedata = data.data;
let theArr = [];
if (!thedata) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
thedata = {};
} else {
thedata.map(function (item, index) {
theArr.push({
key: index,
name: item.name,
id: item.id,
depNo: item.depNo
})
})
}
this.setState({
departmentArr: theArr,
})
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
//修改时获取角色数组
rolesArrS(e) {
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/role",
data: {
uid: e.id
},
success: function (data) {
let thedata = data.data;
let theArr = [];
let theId = []
if (!thedata) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
thedata = {};
} else {
}
this.setState({
role: thedata,
userDetaile: true,
showDesc: true,
datauser: e
})
}.bind(this),
}).always(function () {
}.bind(this));
},
//角色
rolesList() {
this.setState({
loading: true
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/roles",
data: {
},
success: function (data) {
let thedata = data.data;
let theArr = [];
if (!thedata) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
thedata = {};
} else {
thedata.map(function (item, index) {
theArr.push({
key: index,
roleName: item.roleName,
id: item.id,
})
})
}
this.setState({
roleArr: theArr,
})
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
//锁定
locking() {
let deletedIds;
let statust;
let mobiles;
let names;
let rolesId = [];
for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
let rowItem = this.state.selectedRows[idx];
if (rowItem.id) {
deletedIds = rowItem.id;
statust = rowItem.status;
names = rowItem.name;
mobiles = rowItem.mobile;
rolesId = rowItem.rolesId
};
};
this.setState({
selectedRowKeys: [],
loading: true
});
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/superviser/updateAdmin",
data: {
roles: rolesId,
data: JSON.stringify({
id: deletedIds,
status: '锁定',
name: names,
mobile: mobiles,
}),
}
}).done(function (data) {
if (!data.error.length) {
message.success('锁定成功!');
this.setState({
loading: false,
});
} else {
message.warning(data.error[0].message);
};
this.loadData();
}.bind(this));
},
//激活
activation() {
let deletedIds;
let statust;
let mobiles;
let names;
let rolesId = []
for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
let rowItem = this.state.selectedRows[idx];
if (rowItem.id) {
deletedIds = rowItem.id;
statust = rowItem.status;
names = rowItem.name;
mobiles = rowItem.mobile;
rolesId = rowItem.rolesId
};
};
this.setState({
selectedRowKeys: [],
loading: true
});
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/superviser/updateAdmin",
data: {
roles: rolesId,
data: JSON.stringify({
id: deletedIds,
status: 0,
name: names,
mobile: mobiles,
})
}
}).done(function (data) {
if (!data.error.length) {
message.success('激活成功!');
this.setState({
loading: false,
});
} else {
message.warning(data.error[0].message);
};
this.loadData();
}.bind(this));
},
//删除
delectRow() {
let deletedIds;
for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
let rowItem = this.state.selectedRows[idx];
if (rowItem.id) {
deletedIds = rowItem.id;
};
};
this.setState({
selectedRowKeys: [],
loading: true
});
$.ajax({
method: "POST",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/superviser/deleteById",
data: {
id: deletedIds,
}
}).done(function (data) {
if (!data.error.length) {
message.success('删除成功!');
this.setState({
loading: false,
});
} else {
message.warning(data.error[0].message);
};
this.loadData(this.state.page);
}.bind(this));
},
addClick() {
this.addIdS()
this.setState({
datauser: {},
showDesc: true,
userDetaile: false,
});
},
closeDesc(e, s) {
this.setState({
userDetaile: false,
showDesc: e
})
if (s) {
this.loadData(this.state.page);
};
},
search() {
this.state.userDetaile = false
this.loadData();
},
searchs() {
this.state.userDetaile = false
this.loadDatas();
},
reset() {
this.state.ambManage = undefined
this.state.ambId = undefined;
this.state.amb = 1;
this.state.userNameSearch = undefined;
this.state.organizationSearch = undefined;
this.state.rolesSearch = undefined;
this.state.postSearch = undefined;
this.state.stationSearch = undefined;
this.state.statusSeach = undefined;
this.state.signNameSearch = undefined;
this.state.mobileSearch = undefined;
this.state.auto = undefined;
this.state.theTypes = undefined;
this.state.seniorStaff = undefined;
this.state.publicPurview = undefined;
this.loadData();
},
resets() {
this.state.userNameSearchs = '';
this.state.organizationSearch = undefined;
this.state.rolesSearch = undefined;
this.state.postSearch = undefined;
this.state.stationSearch = undefined;
this.state.statusSeach = undefined;
this.state.signNameSearch = '';
this.state.mobileSearch = '';
this.state.auto = '';
this.state.theTypes = '';
this.loadDatas();
},
searchSwitch() {
this.setState({
searchMore: !this.state.searchMore
});
},
//主管初始加载(自动补全)
supervisor(e) {
$.ajax({
method: "post",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/organization/selectName",
data: {
name: e
},
success: function (data) {
let thedata = data.data;
if (!thedata) {
if (data.error && data.error.length) {
message.warning(data.error[0].message);
};
thedata = {};
};
this.setState({
customerArr: thedata,
});
}.bind(this),
}).always(function () {
this.setState({
loading: false
});
}.bind(this));
},
//上级主管输入框失去焦点是判断客户是否存在
selectAuto(value, options) {
this.setState({
auto: value
})
},
blurChange(e) {
let theType = '';
let contactLists = this.state.customerArr || [];
if (e) {
contactLists.map(function (item) {
if (item.name == e.toString()) {
theType = item.id;
}
});
}
this.setState({
theTypes: theType
})
},
//值改变时请求客户名称
httpChange(e) {
if (e.length >= 1) {
this.supervisor(e);
}
this.setState({
auto: e
})
},
changeList(arr) {
const newArr = [];
this.state.columns.forEach(item => {
arr.forEach(val => {
if (val === item.title) {
newArr.push(item);
}
});
});
this.setState({
changeList: newArr
});
},
// 筛选数据
getList() {
this.setState({
loading: true,
});
$.ajax({
method: "get",
dataType: "json",
crossDomain: false,
url: globalConfig.context + "/api/admin/amb/selectAll",
success: function (data) {
this.setState({
loading: false,
});
if (data.error && data.error.length === 0) {
let menuList = data.data
this.setState({
level1Data: menuList ? this.handleTreeData(menuList) : []
});
} else {
message.warning(data.error[0].message);
}
}.bind(this),
}).always(
function () {
this.setState({
loading: false,
});
}.bind(this)
);
},
// 树状默认数据处理
handleTreeData(treeData) {
let nodeDta = [];
treeData.map(item => {
let treeObj = {};
treeObj.key = item.id
treeObj.id = item.id
treeObj.value = item.id
treeObj.label = item.name
treeObj.title = item.name
treeObj.lvl = item.lvl
treeObj.parentId = item.parentId
item.list ? treeObj.children = this.handleTreeData(item.list) : null;
nodeDta.push(treeObj)
})
return nodeDta
},
render() {
const rowSelection = {
selectedRowKeys: this.state.selectedRowKeys,
onChange: (selectedRowKeys, selectedRows) => {
this.setState({
selectedRows: selectedRows.slice(-1),
selectedRowKeys: selectedRowKeys.slice(-1)
});
},
onSelectAll: (selected, selectedRows, changeRows) => {
this.setState({
selectedRowKeys: []
})
},
};
const dataSources = this.state.customerArr || [];
const options = dataSources.map((group, index) =>
{group.name}
)
const hasSelected = this.state.selectedRowKeys.length > 0;
const { RangePicker } = DatePicker;
let departmentArr = this.state.departmentArr || [];
let roleArr = this.state.roleArr || [];
return (
{/*
*/}
{/*
*/}
{this.state.showDesc &&
}
);
}
}));
export default User;