修改人员逻辑

This commit is contained in:
wenc000 2020-05-07 17:54:05 +08:00
parent e6819f975b
commit eaad8bf31e

View File

@ -10,6 +10,7 @@
<link rel="stylesheet" type="text/css" href="assets/js/vendor/zTree3/css/metroStyle/metroStyle.css"/> <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/layui/css/layui.css" media="all">
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all"> <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
<style>.remove-selected-user {color: #FFF;}</style>
</head> </head>
<body> <body>
<div class="layui-fluid layui-anim layui-anim-fadein" style="padding: 0;"> <div class="layui-fluid layui-anim layui-anim-fadein" style="padding: 0;">
@ -69,6 +70,35 @@
border: '1px dotted silver' 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 initTimeout = null;
var isInit = false; var isInit = false;
@ -82,7 +112,6 @@
} }
} }
} }
// selectUser(zTree.getCheckedNodes(true));
} }
function initCheckData(zTree) { function initCheckData(zTree) {
if(selectedUsers) { if(selectedUsers) {
@ -95,7 +124,7 @@
selectedUsers: selectedUsers selectedUsers: selectedUsers
}, null, function(code, data) { }, null, function(code, data) {
for(var i = 0, item; item = data[i++];) { 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); initSelectNode(zTree);
}, function(code, data) { }, function(code, data) {
@ -134,7 +163,9 @@
}, },
callback: { callback: {
onCheck: function(event, treeId, treeNode) { onCheck: function(event, treeId, treeNode) {
selectUser(zTree.getCheckedNodes(true)); var checkedNodes = zTree.getCheckedNodes(true);
var unCheckNodes = zTree.getCheckedNodes(false);
selectUser(checkedNodes, unCheckNodes);
return false; return false;
}, },
onAsyncSuccess: function(event, treeId, treeNode) { onAsyncSuccess: function(event, treeId, treeNode) {
@ -150,26 +181,31 @@
initFrame(); initFrame();
initThree(); initThree();
// 选择人员 // 选择人员
function initSelectDepartmentUserArray(id, name, title, departmentId) { function selectUser(checkedNodes, unCheckNodes) {
console.log(title); // 清空未选中的列表
selectDepartmentUserArray.push({ for(var i = 0, item; item = unCheckNodes[i++];) {
userId: id, if(item.title) {
userName: name, removeSelectDepartmentUserArray(item.id.substring(2, item.id.length), item.pId);
userTitle: title, }
departmentId: departmentId, }
}); for(var i = 0, item; item = checkedNodes[i++];) {
$('#selectUsers').append('<span id="selected_user_'+ id +'" class="layui-btn layui-btn-xs">'+ title +' </span>'); if(item.title) {
} var userId = item.id.substring(2, item.id.length);
function selectUser(checkedNodes) { if(!isNodeChecked(userId, item.pId)) {
selectDepartmentUserArray.splice(0, selectDepartmentUserArray.length); addSelectDepartmentUserArray(userId, item.name, item.title, item.pId);
$('#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; 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() { $('.confirm').on('click', function() {
closeBox(); closeBox();
}); });