取消自动加载

This commit is contained in:
wenc000 2020-05-07 14:31:08 +08:00
parent b97099405a
commit 82ded29737

View File

@ -71,38 +71,45 @@
} }
// 初始化数据 // 初始化数据
var initTimeout = null; var initTimeout = null;
var isInited = false; var isInit = false;
function initCheckData(zTree) { function initSelectNode(zTree) {
if(isInited) { var nodes = zTree.transformToArray(zTree.getNodes());
return; for(var i = 0, node = nodes[i]; node = nodes[i++];) {
for(var j = 0; item = selectDepartmentUserArray[j++]; ) {
if(node.id == ('u_'+ item.userId) && node.pId == item.departmentId) {
zTree.checkNode(node, true, true);
break;
}
}
} }
// selectUser(zTree.getCheckedNodes(true));
}
function initCheckData(zTree) {
if(selectedUsers) { if(selectedUsers) {
if(selectedUsers.length == 0) { if(selectedUsers.length == 0) {
return; return;
} }
var loadLayerIndex; if(!isInit) {
top.restAjax.post(top.restAjax.path('api/user/listdepartmentuserbyuserdepartmentid', []), { var loadLayerIndex;
selectedUsers: selectedUsers top.restAjax.post(top.restAjax.path('api/user/listdepartmentuserbyuserdepartmentid', []), {
}, null, function(code, data) { selectedUsers: selectedUsers
var nodes = zTree.transformToArray(zTree.getNodes()); }, null, function(code, data) {
for(var i = 0, node = nodes[i]; node = nodes[i++];) { for(var i = 0, item; item = data[i++];) {
for(var j = 0, item = data[j]; item = data[j++]; ) { initSelectDepartmentUserArray(item.userId, item.userName, ('【'+ item.departmentName +'】'+ item.userName), item.departmentId);
if(node.id == ('u_'+ item.userId) && node.pId == item.departmentId) {
zTree.checkNode(node, true, true);
break;
}
} }
} initSelectNode(zTree);
selectUser(zTree.getCheckedNodes(true)); }, function(code, data) {
}, function(code, data) { top.dialog.msg(data.msg);
top.dialog.msg(data.msg); }, function() {
}, function() { loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3}); }, function() {
}, function() { top.dialog.close(loadLayerIndex);
top.dialog.close(loadLayerIndex); });
}); isInit = true;
} else {
initSelectNode(zTree);
}
} }
isInited = true;
} }
// 初始化树 // 初始化树
function initThree() { function initThree() {
@ -112,7 +119,7 @@
}, },
async: { async: {
enable: true, enable: true,
autoLoad: false, autoLoad: true,
type: 'get', type: 'get',
url: top.restAjax.path('api/department/listztreedepartmentwithuser', []), url: top.restAjax.path('api/department/listztreedepartmentwithuser', []),
autoParam:['id'], autoParam:['id'],
@ -131,18 +138,7 @@
return false; return false;
}, },
onAsyncSuccess: function(event, treeId, treeNode) { onAsyncSuccess: function(event, treeId, treeNode) {
if(initTimeout != null) { initCheckData(zTree);
clearTimeout(initTimeout)
}
var subNodes = zTree.getNodesByParam('pId', treeNode.id, null);
for(var i = 0, item = subNodes[i]; item = subNodes[i++];) {
if(item.id.indexOf('u_') < 0) {
zTree.expandNode(item, true, false, false);
}
}
initTimeout = setTimeout(function() {
initCheckData(zTree);
}, 500);
} }
}, },
view: { view: {
@ -150,24 +146,26 @@
} }
}; };
var zTree = $.fn.zTree.init($('#leftTree'), setting); var zTree = $.fn.zTree.init($('#leftTree'), setting);
zTree.addNodes(null, {id: '0', pId: '-1', name: '根节点', url: 'javascript:void(0);', icon: 'assets/images/tree/tree-department.png', isParent: 'true'});
common.refreshTree('leftTree');
} }
initFrame(); initFrame();
initThree(); 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) { function selectUser(checkedNodes) {
selectDepartmentUserArray.splice(0, selectDepartmentUserArray.length); selectDepartmentUserArray.splice(0, selectDepartmentUserArray.length);
$('#selectUsers').empty(); $('#selectUsers').empty();
for(var i = 0, item = checkedNodes[i]; item = checkedNodes[i++];) { for(var i = 0, item = checkedNodes[i]; item = checkedNodes[i++];) {
if(item.title && item.title != '') { if(item.title && item.title != '') {
selectDepartmentUserArray.push({ initSelectDepartmentUserArray(item.id.substring(2, item.id.length), item.name, item.title, item.pId);
userId: item.id.substring(2, item.id.length),
userName: item.name,
userTitle: item.title,
departmentId: item.pId,
});
$('#selectUsers').append('<span id="selected_user_'+ item.id +'" class="layui-btn layui-btn-xs">'+ item.title +' </span>');
} }
} }
top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserArray; top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserArray;