取消自动加载

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 isInited = false;
function initCheckData(zTree) {
if(isInited) {
return;
var isInit = false;
function initSelectNode(zTree) {
var nodes = zTree.transformToArray(zTree.getNodes());
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.length == 0) {
return;
}
var loadLayerIndex;
top.restAjax.post(top.restAjax.path('api/user/listdepartmentuserbyuserdepartmentid', []), {
selectedUsers: selectedUsers
}, null, function(code, data) {
var nodes = zTree.transformToArray(zTree.getNodes());
for(var i = 0, node = nodes[i]; node = nodes[i++];) {
for(var j = 0, item = data[j]; item = data[j++]; ) {
if(node.id == ('u_'+ item.userId) && node.pId == item.departmentId) {
zTree.checkNode(node, true, true);
break;
}
if(!isInit) {
var loadLayerIndex;
top.restAjax.post(top.restAjax.path('api/user/listdepartmentuserbyuserdepartmentid', []), {
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);
}
}
selectUser(zTree.getCheckedNodes(true));
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
}, function() {
top.dialog.close(loadLayerIndex);
});
initSelectNode(zTree);
}, function(code, data) {
top.dialog.msg(data.msg);
}, function() {
loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
}, function() {
top.dialog.close(loadLayerIndex);
});
isInit = true;
} else {
initSelectNode(zTree);
}
}
isInited = true;
}
// 初始化树
function initThree() {
@ -112,7 +119,7 @@
},
async: {
enable: true,
autoLoad: false,
autoLoad: true,
type: 'get',
url: top.restAjax.path('api/department/listztreedepartmentwithuser', []),
autoParam:['id'],
@ -131,18 +138,7 @@
return false;
},
onAsyncSuccess: function(event, treeId, treeNode) {
if(initTimeout != null) {
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);
initCheckData(zTree);
}
},
view: {
@ -150,24 +146,26 @@
}
};
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();
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) {
selectDepartmentUserArray.splice(0, selectDepartmentUserArray.length);
$('#selectUsers').empty();
for(var i = 0, item = checkedNodes[i]; item = checkedNodes[i++];) {
if(item.title && item.title != '') {
selectDepartmentUserArray.push({
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>');
initSelectDepartmentUserArray(item.id.substring(2, item.id.length), item.name, item.title, item.pId);
}
}
top.dialog.dialogData.selectedDepartmentUsers = selectDepartmentUserArray;