var setting1, setting2,setting3; //判定是选择外部还是内部单位 var orgSel; //记录选中的组织id var selectedOrgId=[]; //记录选中组的名称 var groupName="已选择常用组"; //记录要添加的常用组id var groupId=""; var targetOrg; var userId =top.com.sinosoft.lz.system.user.LoginInfo.getUser_id(); var addTreeNodes=[ ]; function initTree1() { $.fn.zTree.init($("#myTree1"), setting1); } function initTree2() { var url = $.pathname()+ "/ws/OrganizationsService/OrganizationsService/loadSysOrgOuterInfo"; $.post(url, { "id" : outOrgId }, function(data) { $.fn.zTree.init($("#myTree2"), setting2, data.treeNodes); }, "json"); } function initTree3(){ $.fn.zTree.init($("#myTree3"),setting3,addTreeNodes); } var inOrgId,outOrgId; $(function() { var iframeUrl = window.location.href; if (iframeUrl.indexOf('?') > -1) { orgSel = (iframeUrl).split('?')[1]; groupId=(iframeUrl).split('?')[2]; inOrgId=(iframeUrl).split('?')[3]; outOrgId=(iframeUrl).split('?')[4]; groupName=(iframeUrl).split('?')[5]; } $("#hiddenSelGroup").val(groupId); $("#selectedNum").append(decodeURI(groupName)+"(0)"); setting1 = { view : { addHoverDom: addHoverDom, removeHoverDom: removeHoverDom, selectedMulti: false }, async : { enable : true, dataType : 'JSON', dataName : 'treeNodes', aysnc : false, url :getAsyncUrl, autoParam : [ "id", "name", "orgLevel" ], otherParam : [ "deptId", inOrgId ] }, check:{ enable: true, chkboxType:{ "Y": "", "N": "" } } }; setting2 = { view : { addHoverDom: addHoverDom, removeHoverDom: removeHoverDom, selectedMulti: false }, async : { enable : true, dataType : 'JSON', dataName : 'treeNodes', url : getAsyncUrl, autoParam : [ "id", "name" ], otherParam : [ "deptId", outOrgId ] }, check:{ enable: true, chkboxType:{ "Y": "", "N": "" } } }; setting3={ edit: { enable: true, removeTitle:"删除", showRemoveBtn : setRemoveBtn, // 显示编辑按钮 showRenameBtn : setRenameBtn }, callback:{ //禁止拖拽 beforeRemove: beforeRemove1, }, }; initTree3(); //判定是外部机构还是内部机构然后进行页面加载 if(orgSel=="INNER"){ initTree1(); $("#org_outer2").hide(); $("#queryInput2").hide(); $("#showTitle").html("中国南方电网"); } if(orgSel=="OUTER"){ initTree2(); $("#org_inner1").hide(); $("#queryInput1").hide(); $("#showTitle").html("外部单位"); } //绑定查询框事件 $("#queryInput1").on("keyup", function(event) { getValue = $("#queryInput1").val().trim(); if(getValue!=""){ inputTips(getValue,orgSel); } }); $("#queryInput2").on("keyup", function(event) { getValue = $("#queryInput2").val().trim(); if(getValue!=""){ inputTips(getValue,orgSel); } }); //绑定添加到常用组事件 $("#chooseOne").bind( "click", function() { getCheckedIds(); }); //绑定添加子节点 $("#chooseChildren").bind( "click", function() { getSelectedChildIds(); }); //绑定清除事件 $("#clearChosen").bind("click",function(){ backToEver(); }); //绑定确定事件 $("#confirmChosen").bind("click", function() { var zTree = $.fn.zTree.getZTreeObj("myTree3"); var n = zTree.getNodes(); $.post($.pathname()+ "/ws/OrganizationsService/OrganizationsService/addCommonOrgInfoById", { 'id' : selectedOrgId.join(""), 'group_id' : groupId }, function(data) { if (data > 0) { } }, "json"); }); //绑定点击查询显示框的其他位置隐藏div方法 $("body:eq(0)").bind("click" ,function (event){ var e = event || window.event; var elem = e.srcElement || e.target; while(elem) { if(elem.id == "queryContent1") { return; } elem = elem.parentNode; } //隐藏div的方法 $("#queryContent1").hide(); }); }); function doSome(data, mid) { var parentIds = data.parentIds; var childOrg = data.childOrg; var isOuter = $("#queryInput1").is(":hidden"); //var orgType= isOuter ? "OUTER":"INNER"; var zTree = isOuter ? $.fn.zTree.getZTreeObj("myTree2") : $.fn.zTree .getZTreeObj("myTree1"); if (canFind(mid)) { zTree.selectNode(zTree.getNodesByParam("id", mid, null)[0]); return; } isAdd = true; for (var i = 0; i < parentIds.length; i++) { var treeNodes = zTree.getNodesByParam("id", parentIds[i], null)[0]; var p = i - 1; if (treeNodes == null) { //找不到那么久找他的父节点 然后加载 var pnode = zTree.getNodesByParam("id", parentIds[p], null)[0]; targetOrg = mid; zTree.reAsyncChildNodes(pnode, "refresh", true); break; } } isAdd = false; setTimeout(function() { zTree.selectNode(zTree.getNodesByParam("id", mid, null)[0]); }, 200); } function canFind(mid) { var treeObj = orgSel=="INNER" ? $.fn.zTree.getZTreeObj("myTree1"):$.fn.zTree.getZTreeObj("myTree2"); var treeNodes = treeObj.getNodesByParam("id", mid, null)[0]; return treeNodes != null; } var getValue; var moreresult; function inputTips(getValue,orgType) { var params = { 'name' : getValue, 'type' : orgType, 'role' : inOrgId }; //清空ul $("#queryContent1").find("ul").empty(); //查询字段 $ .ajax({ url : $.pathname() + '/ws/OrganizationsService/OrganizationsService/queryOrgByName', data : params, dataType : 'json', type : 'post', success : function(result) { moreresult = result; if (result.length > 0) { $("#queryContent1").show(); } ; for (var i = 0; i < result.length; i++) { var item = result[i]; if (i < 3) { //遍历加载字段 $("#queryContent1") .find("ul") .append( "
  • " + item.name + "
    " + item.spath + "
  • "); $("#queryContent1").find("ul").find("li") .last().data("id", item.id) .on("click", function() { findById($(this).data("id")); }); } if (i == 3) { if ($("#queryContent1").find("#gengduo").size() == 0) { $("#queryContent1") .find("ul") /* .find("li") .last() */ .append( "
    查看更多
    "); } //设置控件节点高度 $("#gengduo").css({ "font-size" : "12px", "line-height" : "1.4em", "text-align" : "center" }); //绑定点击事件, $("#gengduo").on("click", function() { $("#gengduo").hide(); moreOptions(moreresult); }); } } } }); } var isAdd = false; function getAsyncUrl(treeId, treeNode) { return isAdd ? $.pathname() + "/ws/OrganizationsService/OrganizationsService/addOrgInfoById?targetOrg=" + targetOrg : $.pathname() + "/ws/OrganizationsService/OrganizationsService/getOrgInfoById"; }; function moreOptions(moreresult) { for (var i = 3; i < moreresult.length; i++) { var item = moreresult[i]; $("#queryContent1").find("ul").append( "
  • " + item.name + "
    " + item.spath + "
  • "); $("#queryContent1").find("ul").find("li").last() .data("id", item.id).on("click", function() { findById($(this).data("id")); }); //$("#queryContent1").find("ul").find("li:gt").addClass("tips"); } } function findById(id) { $ .ajax({ url : $.pathname() + '/ws/OrganizationsService/OrganizationsService/queryOrgInfo', data : { 'id' : id }, type : 'post', dataType : 'json', success : function(data) { doSome(data, id); } }); $("#queryContent1").hide(); } //单个选中 function getHoverNode(treeNode){ var treeObj = orgSel =="INNER" ? $.fn.zTree.getZTreeObj("myTree1") : $.fn.zTree.getZTreeObj("myTree2"); treeObj.checkNode(treeNode,true); var zTree = $.fn.zTree.getZTreeObj("myTree3"); if(selectedOrgId.indexValuess(treeNode.id)==-1){ selectedOrgId.push(treeNode.id); zTree.addNodes(null,gernerateSimpleNode(treeNode)); } treeObj.checkNode(treeNode,false); $("#hiddenSelIds").val(selectedOrgId); getSelectedNum(selectedOrgId); } //获取勾选的组织id function getCheckedIds(){ var treeObj = orgSel =="INNER" ? $.fn.zTree.getZTreeObj("myTree1") : $.fn.zTree.getZTreeObj("myTree2"); var nodes = treeObj.getCheckedNodes(true); var zTree = $.fn.zTree.getZTreeObj("myTree3"); for(var i =0; i 0) return; var sObj = $("#" + treeNode.tId + "_span"); var addStr = ""; sObj.append(addStr); var btn = $("#addBtn_" + treeNode.id); if (btn){ btn.bind("click", function(){ getHoverNode(treeNode); }); } }; function setRemoveBtn(treeId, treeNode) { return true; } function setRenameBtn(treeId, treeNode) { return false; } function removeHoverDom(treeId, treeNode) { $("#addBtn_" + treeNode.id).unbind().remove(); }; function beforeRemove1(treeId, treeNode) { var zTree = $.fn.zTree.getZTreeObj("myTree3"); zTree.removeNode(treeNode); selectedOrgId.removeGetInfo(treeNode.id); $("#hiddenSelIds").val(""); getSelectedNum(selectedOrgId); return false; }