异步树异步处理
---恢复内容开始---
//初始化树
init: function () {
_group_tree = _group_tree || $("#designer-group").createSyncTree({
check: {enable: false}, //是否启用复选框
view:{
addHoverDom:function (treeId,treeNode) {
// alert(treeNode.tId + "===" + treeNode.id)
var operateWarpper = $('#operate_' + treeNode.tId);
if ( operateWarpper.length > 0 ) {
operateWarpper.fadeIn();
return;
}
operateWarpper = $("<span id='operate_" + treeNode.tId + "' style='padding-left: 5px;'></span>")
var addBtn = $("<i id='addBtn_" + treeNode.tId + "' title='添加' class='fa fa-plus fa-ceec' ></i>")
.bind("click",function () {
updateGroup=treeNode;
parentNode = treeNode; //保存当前节点
$("#groupSubject_form", _groupSubjectModal).find("#parentId").val(treeNode.id != '-1' ? treeNode.id:"");
if("cdata" in treeNode) {
if (treeNode.cdata.state == "2") {
//新建指标
//根据groupid查询同一主体分组下的主体
$("#field_form").find("#groupId").html("");
$.get(CEEC.contextPath + '/report/subject/selectSubjectList', {groupId: treeNode.cdata.group_id}, function (res) {
Field.subject(res, treeNode)
}, "json");
} else if (treeNode.cdata.state == "1") {
//新建主体
$.get(CEEC.contextPath + '/report/subject/selectSubjectGroupByParentId', {parentId: treeNode.cdata.parentId}, function (res) {
$("#subject_form").find("#groupId").html("");
if (res && res.success) {
$.each(res.data, function (index, value) {
var sel = "";
if (treeNode.name == value.groupName) {
sel = "selected";
}
$("#subject_form").find("#groupId").append("<option value='" + value.groupId + "' " + sel + " >" + value.groupName + "</option>");
})
}
}, "json");
_subjectModel.modal("show");
} else if (treeNode.cdata.state == "3") {
//新建指标
//查询同级的指标分组
selFieldGroup = treeNode.cdata.parentId;
Field.fieldGroup(treeNode, selFieldGroup);
//根据指标分组的parent_id查询主体
$.get(CEEC.contextPath + '/report/subject/selectSubjectList', {subjectId: treeNode.cdata.parentId}, function (res) {
Field.subject(res, treeNode);
}, "json");
}
return false;
}else if (treeNode.id == "-1") {
//全部 添加主体分组
_groupSubjectModal.modal('show');
}
}).appendTo(operateWarpper);
//顶层节点不允许修改
if(treeNode.id != '-1'){
var editBtn = $("<i id='editBtn_" + treeNode.tId + "' title='编辑' class='fa fa-edit fa-ceec' ></i>")
.bind("click",function () {
parentNode = treeNode; //保存当前节点
Field.group.editMultiplex(treeNode);
return false;
}).appendTo(operateWarpper);
}
$("#" + treeNode.tId + "_span").after(operateWarpper);
},
removeHoverDom:function (treeId,treeNode) {
$("#operate_"+treeNode.tId).fadeOut();
// $("#addBtn_"+treeNode.tId).unbind().remove();
},
// showLine:true,
selectedMulti:false
},
callback: {
onClick: function (event, treeId, treeNode) {
updateGroup=treeNode;
var strSubjectId = "";
$("#createRelease").addClass('disabled');
if("cdata" in treeNode){
if(treeNode.cdata.state=="2"){
strSubjectId=treeNode.id;
$("#createRelease").removeClass('disabled');
//如果主体状态已发布 发布主体隐藏
if(treeNode.cdata.status==true){
$("#createRelease").addClass('disabled');
}
}
if(treeNode.cdata.state=="2"||treeNode.cdata.state=="3"){
var groupIdss="";
if(treeNode.cdata.state=="3"){
//当前树
groupIdss=treeNode.id;
strSubjectId=treeNode.cdata.parentId;
}
tbl_fieldDefine_list = $("#tbl_fieldDefine_list").createTable({
url: CEEC.contextPath + '/report/fieldDefine/list?subjectId=' + strSubjectId+'&state='+treeNode.cdata.state+'&groupId='+groupIdss,
pagination: true,
singleSelect: false,
clickToSelect: false, //是否启用点击选中行
classes: 'table-hover table-mail',
height: 700,
columns:[
{field: 'fieldIds', checkbox: 'fieldId'},
// {field:'fieldId', title:'指标'},
{field:'fieldName', title:'指标名称'},
{field:'fieldCode', title:'主体标识'},
{field:'applyType', title:'应用类型',
formatter:function (value, row, index) {
return applyTypes[value] && applyTypes[value].name;
}
},
{field: 'sumType', title: '汇总方式',
formatter:function (value, row, index) {
return sumTypes[value] && sumTypes[value].name;
}
}
]
});
}
else{
tbl_fieldDefine_list = $("#tbl_fieldDefine_list").createTable("");
}
//所属位置
create11 = treeNode.cdata.state;
//上级分组Id
parentId=treeNode.cdata.parentId;
}else{
//默认全部
$("#subjectGrop11").attr("onclick","Field.group.createSubject();");
//$("#subject11").attr("onclick","Field.fieldManage.createSubject();");
//指标和指标分组不可用 新建主体不可用
$("#subject1").addClass('disabled');
$("#field1").addClass('disabled');
$("#fieldGrop1").addClass('disabled');
$("#oneCreate").addClass('disabled');
$("#batchCreate").addClass('disabled');
}
},
onCheck: function (event, treeId, checkNode) {
updateGroup = checkNode;
},
onExpand: Field.group.zTreeOnCollapse
},
async: {
autoParam: ["id", "checked","cdata"],
enable: true,
url: CEEC.contextPath + '/report/designer/subject/fileIdGroups',
type: 'get',
dataType: 'json',
dataFilter: function (treeId, parentNode, respons) {
// console.log(JSON.stringify(respons))
if (respons.success) {
return respons.data.nodes || respons.data.treeNodes
} else {
CEEC.MessageBox && CEEC.MessageBox.danger(respons.code || respons.msg);
}
}
}
});
},
async为重点 其他是自己的业务逻辑
//Controller层
/**
* 查询指标分组
* @return
*/
@ResponseBody
@RequestMapping(value = "/{category}/fileIdGroups", method = RequestMethod.GET)
public Result fileIdGroups(String id){
HttpServletRequest request = WebUtils.getRequest();
String state = request.getParameter("cdata[state]");
if(StringUtil.isNotEmpty(state)&&state.equals("3")){
return Result.Success();
}
return Result.Success("nodes", this.designerService.queryfileIdGroups(id,state));
}
//serviceImpl
@Override
public List<TreeNode> queryfileIdGroups(String nodeid, String state) {
List<TreeNode> nodes = new ArrayList<>();
TreeNode root = new TreeNode("-1", "全部", "", true, true);
if (StringUtil.isEmpty(nodeid)) {
// nodes = schemaGroupMapper.getSubjectGroupById(null).stream().map(g -> {
// String parentId = (g.getParentId().toString() != null) ? g.getParentId().toString() : "0";
// return new TreeNode(g.getGroupId().toString(),
// g.getGroupName().toString(), parentId,
// true, false, g);
// }).collect(Collectors.toList());
nodes.add(root);
return nodes;
}
long id = Long.valueOf(nodeid).longValue();
if (id == -1) {
nodes = schemaGroupMapper.getSubjectGroupById(id).stream().map(g -> {
String parentId = (g.getParentId().toString() != null) ? g.getParentId().toString() : "0";
return new TreeNode(g.getGroupId().toString(),
g.getGroupName().toString(), parentId,
true, false, g);
}).collect(Collectors.toList());
}
if (StringUtil.isNotEmpty(state)) {
switch (Integer.parseInt(state)) {
case 1:
nodes = schemaGroupMapper.getSubjectById(id).stream().map(g -> {
String parentId = (g.getGroupId().toString() != null) ? g.getGroupId().toString() : "0";
return new TreeNode(g.getSubjectId().toString(),
g.getSubjectName().toString(), parentId,
true, false, g);
}).collect(Collectors.toList());
break;
case 2:
nodes = schemaGroupMapper.getFileIdGroupById(id).stream().map(g -> {
String parentId = (g.getParentId().toString() != null) ? g.getParentId().toString() : "0";
return new TreeNode(g.getGroupId().toString(),
g.getGroupName().toString(), parentId, Long.valueOf(g.getState().toString()) ==3L,false, g);
}).collect(Collectors.toList());
break;
case 3:
nodes = schemaGroupMapper.getFieldDefineById(id).stream().map(g -> {
String parentId = (g.getGroupId().toString() != null) ? g.getGroupId().toString() : "0";
return new TreeNode(g.getFieldId().toString(),
g.getFieldName().toString(), parentId,
false, false, g);
}).collect(Collectors.toList());
break;
case 4:
break;
}
}
return nodes;
}
---恢复内容结束---