123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- 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(
- "<li><div class='tips'>"
- + item.name
- + "</div><div style='text-align:right;' title='"+item.path+"'>"
- + item.spath
- + "<hr class='hr3'/></div></li>");
- $("#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(
- "<div id='gengduo'>查看更多</div>");
- }
- //设置控件节点高度
- $("#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(
- "<li><div>" + item.name
- + "</div><div style='text-align:right;' title='"+item.path+"'>"
- + item.spath
- + "<hr class='hr3'/></div></li>");
- $("#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<nodes.length;i++){
-
- //如果不包含那么添加进去
- if(selectedOrgId.indexValuess(nodes[i].id)==-1){
- selectedOrgId.push(nodes[i].id);
- zTree.addNodes(null,gernerateSimpleNode(nodes[i]));
- //treeObj.removeNode(nodes[i]);
-
-
- }
- treeObj.checkNode(nodes[i],false);
-
- }
- //selectedOrgId.unique3();
- //treeObj.checkAllNodes(false);
-
- $("#hiddenSelIds").val(selectedOrgId);
- getSelectedNum(selectedOrgId);
- }
- //将选中的组织的子节点添加进去
- function getSelectedChildIds(){
-
- var treeObj = orgSel =="INNER" ? $.fn.zTree.getZTreeObj("myTree1"):$.fn.zTree.getZTreeObj("myTree2");
- var selNode = treeObj.getSelectedNodes()[0];
- var childNodes = treeObj.getNodesByParam("parentId",selNode.id,null);
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
-
- for(var i =0;i<childNodes.length;i++){
-
- if(selectedOrgId.indexValuess(childNodes[i].id)==-1){
- selectedOrgId.push(childNodes[i].id);
- zTree.addNodes(null,gernerateSimpleNode(childNodes[i]));
- //treeObj.removeNode(childNodes[i]);
-
- }
-
- }
- $("#hiddenSelIds").val(selectedOrgId);
- getSelectedNum(selectedOrgId);
-
- }
- //清除所有选择的组织
- function backToEver(){
-
- initTree3();
- selectedOrgId=[];
- $("#hiddenSelIds").val("");
- getSelectedNum(selectedOrgId);
-
- }
- //手动生成简易的节点
- function gernerateSimpleNode(treeNode){
-
- var sNode ={id:"",name:"",parentId:"1",icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'};
- sNode.id=treeNode.id;
- sNode.name=treeNode.name;
- return sNode;
-
-
- }
- //更新已选择的数目
- function getSelectedNum(selectedOrgId){
- $("#selectedNum").html(decodeURI(groupName)+" ("+selectedOrgId.length+")");
- }
- //确认是否删除+删除处理
- function beforeRemove1(treeId, treeNode) {
- var zTree = $.fn.zTree.getZTreeObj("myTree3");
- //选中该节点
- zTree.selectNode(treeNode);
- zTree.removeNode(treeNode);
- var index =0;
- for(var i =0;i<selectedOrgId.length;i++){
- if(treeNode.id==selectedOrgId){
- index =i;
- break;
- }
-
- }
- selectedOrgId.splice( 0, index);
- getSelectedNum(selectedOrgId);
- return false;
- }
- function addHoverDom(treeId, treeNode) {
- if (treeNode.editNameFlag || $("#addBtn_" + treeNode.id).length > 0) return;
-
- var sObj = $("#" + treeNode.tId + "_span");
- var addStr = "<span class='zbutton add' id='addBtn_" + treeNode.id
- + "' title='选择到常用联系组' onfocus='this.blur();'></span>";
- 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;
- }
|