修改人员逻辑
This commit is contained in:
parent
e6819f975b
commit
eaad8bf31e
@ -10,6 +10,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="assets/js/vendor/zTree3/css/metroStyle/metroStyle.css"/>
|
||||
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
||||
<style>.remove-selected-user {color: #FFF;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid layui-anim layui-anim-fadein" style="padding: 0;">
|
||||
@ -69,6 +70,35 @@
|
||||
border: '1px dotted silver'
|
||||
});
|
||||
}
|
||||
// 节点是否已经选择
|
||||
function isNodeChecked(userId, departmentId) {
|
||||
for(var i = 0, item; item = selectDepartmentUserArray[i++];) {
|
||||
if(departmentId == item.departmentId && userId == item.userId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// 选择人员
|
||||
function addSelectDepartmentUserArray(id, name, title, departmentId) {
|
||||
selectDepartmentUserArray.push({
|
||||
userId: id,
|
||||
userName: name,
|
||||
userTitle: title,
|
||||
departmentId: departmentId,
|
||||
});
|
||||
$('#selectUsers').append('<span id="selected_user_'+ id +'" class="layui-btn layui-btn-xs">'+ title +' <a href="javascript:void(0);" class="remove-selected-user" data-userid="'+ id +'" data-departmentid="'+ departmentId +'"><i class="fa fa-times"></i></a></span>');
|
||||
}
|
||||
// 删除人员
|
||||
function removeSelectDepartmentUserArray(userId, departmentId) {
|
||||
for(var i = 0, item; item = selectDepartmentUserArray[i++];) {
|
||||
if(departmentId == item.departmentId && userId == item.userId) {
|
||||
selectDepartmentUserArray.splice(--i, 1);
|
||||
$('#selected_user_'+ userId).remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 初始化数据
|
||||
var initTimeout = null;
|
||||
var isInit = false;
|
||||
@ -82,7 +112,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
// selectUser(zTree.getCheckedNodes(true));
|
||||
}
|
||||
function initCheckData(zTree) {
|
||||
if(selectedUsers) {
|
||||
@ -95,7 +124,7 @@
|
||||
selectedUsers: selectedUsers
|
||||
}, null, function(code, data) {
|
||||
for(var i = 0, item; item = data[i++];) {
|
||||
initSelectDepartmentUserArray(item.userId, item.userName, ('【'+ item.departmentName +'】'+ item.userName), item.departmentId);
|
||||
addSelectDepartmentUserArray(item.userId, item.userName, ('【'+ item.departmentName +'】'+ item.userName), item.departmentId);
|
||||
}
|
||||
initSelectNode(zTree);
|
||||
}, function(code, data) {
|
||||
@ -134,7 +163,9 @@
|
||||
},
|
||||
callback: {
|
||||
onCheck: function(event, treeId, treeNode) {
|
||||
selectUser(zTree.getCheckedNodes(true));
|
||||
var checkedNodes = zTree.getCheckedNodes(true);
|
||||
var unCheckNodes = zTree.getCheckedNodes(false);
|
||||
selectUser(checkedNodes, unCheckNodes);
|
||||
return false;
|
||||
},
|
||||
onAsyncSuccess: function(event, treeId, treeNode) {
|
||||
@ -150,26 +181,31 @@
|
||||
initFrame();
|
||||
initThree();
|
||||
// 选择人员
|
||||
function initSelectDepartmentUserArray(id, name, title, departmentId) {
|
||||
console.log(title);
|
||||
selectDepartmentUserArray.push({
|
||||
userId: id,
|
||||
userName: name,
|
||||
userTitle: title,
|
||||
departmentId: departmentId,
|
||||
});
|
||||
$('#selectUsers').append('<span id="selected_user_'+ id +'" class="layui-btn layui-btn-xs">'+ title +' </span>');
|
||||
function selectUser(checkedNodes, unCheckNodes) {
|
||||
// 清空未选中的列表
|
||||
for(var i = 0, item; item = unCheckNodes[i++];) {
|
||||
if(item.title) {
|
||||
removeSelectDepartmentUserArray(item.id.substring(2, item.id.length), item.pId);
|
||||
}
|
||||
}
|
||||
for(var i = 0, item; item = checkedNodes[i++];) {
|
||||
if(item.title) {
|
||||
var userId = item.id.substring(2, item.id.length);
|
||||
if(!isNodeChecked(userId, item.pId)) {
|
||||
addSelectDepartmentUserArray(userId, item.name, item.title, item.pId);
|
||||
}
|
||||
function selectUser(checkedNodes) {
|
||||
selectDepartmentUserArray.splice(0, selectDepartmentUserArray.length);
|
||||
$('#selectUsers').empty();
|
||||
for(var i = 0, item = checkedNodes[i]; item = checkedNodes[i++];) {
|
||||
if(item.title && item.title != '') {
|
||||
initSelectDepartmentUserArray(item.id.substring(2, item.id.length), item.name, item.title, item.pId);
|
||||
}
|
||||
}
|
||||
top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserArray;
|
||||
}
|
||||
$(document).on('click', '.remove-selected-user', function() {
|
||||
var zTree = $.fn.zTree.getZTreeObj('leftTree');
|
||||
removeSelectDepartmentUserArray(this.dataset.userid, this.dataset.departmentid);
|
||||
// 删除选中状态
|
||||
var node = zTree.getNodeByParam('id', 'u_'+ this.dataset.userid, null);
|
||||
zTree.checkNode(node, false, true);
|
||||
top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserArray;
|
||||
});
|
||||
$('.confirm').on('click', function() {
|
||||
closeBox();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user