ec79657c66e7ded3524d1e16e01595d973a95559.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. var setting1, setting2,setting3;
  2. //判定是选择外部还是内部单位
  3. var orgSel;
  4. //记录选中的组织id
  5. var selectedOrgId=[];
  6. //记录选中组的名称
  7. var groupName="已选择常用组";
  8. //记录要添加的常用组id
  9. var groupId="";
  10. var targetOrg;
  11. var userId =top.com.sinosoft.lz.system.user.LoginInfo.getUser_id();
  12. var addTreeNodes=[
  13. ];
  14. function initTree1() {
  15. $.fn.zTree.init($("#myTree1"), setting1);
  16. }
  17. function initTree2() {
  18. var url = $.pathname()+ "/ws/OrganizationsService/OrganizationsService/loadSysOrgOuterInfo";
  19. $.post(url, {
  20. "id" : outOrgId
  21. }, function(data) {
  22. $.fn.zTree.init($("#myTree2"), setting2, data.treeNodes);
  23. }, "json");
  24. }
  25. function initTree3(){
  26. $.fn.zTree.init($("#myTree3"),setting3,addTreeNodes);
  27. }
  28. var inOrgId,outOrgId;
  29. $(function() {
  30. var iframeUrl = window.location.href;
  31. if (iframeUrl.indexOf('?') > -1) {
  32. orgSel = (iframeUrl).split('?')[1];
  33. groupId=(iframeUrl).split('?')[2];
  34. inOrgId=(iframeUrl).split('?')[3];
  35. outOrgId=(iframeUrl).split('?')[4];
  36. groupName=(iframeUrl).split('?')[5];
  37. }
  38. $("#hiddenSelGroup").val(groupId);
  39. $("#selectedNum").append(decodeURI(groupName)+"(0)");
  40. setting1 = {
  41. view : {
  42. addHoverDom: addHoverDom,
  43. removeHoverDom: removeHoverDom,
  44. selectedMulti: false
  45. },
  46. async : {
  47. enable : true,
  48. dataType : 'JSON',
  49. dataName : 'treeNodes',
  50. aysnc : false,
  51. url :getAsyncUrl,
  52. autoParam : [ "id", "name", "orgLevel" ],
  53. otherParam : [ "deptId", inOrgId ]
  54. },
  55. check:{
  56. enable: true,
  57. chkboxType:{ "Y": "", "N": "" }
  58. }
  59. };
  60. setting2 = {
  61. view : {
  62. addHoverDom: addHoverDom,
  63. removeHoverDom: removeHoverDom,
  64. selectedMulti: false
  65. },
  66. async : {
  67. enable : true,
  68. dataType : 'JSON',
  69. dataName : 'treeNodes',
  70. url : getAsyncUrl,
  71. autoParam : [ "id", "name" ],
  72. otherParam : [ "deptId", outOrgId ]
  73. },
  74. check:{
  75. enable: true,
  76. chkboxType:{ "Y": "", "N": "" }
  77. }
  78. };
  79. setting3={
  80. edit: {
  81. enable: true,
  82. removeTitle:"删除",
  83. showRemoveBtn : setRemoveBtn,
  84. // 显示编辑按钮
  85. showRenameBtn : setRenameBtn
  86. },
  87. callback:{
  88. //禁止拖拽
  89. beforeRemove: beforeRemove1,
  90. },
  91. };
  92. initTree3();
  93. //判定是外部机构还是内部机构然后进行页面加载
  94. if(orgSel=="INNER"){
  95. initTree1();
  96. $("#org_outer2").hide();
  97. $("#queryInput2").hide();
  98. $("#showTitle").html("中国南方电网");
  99. }
  100. if(orgSel=="OUTER"){
  101. initTree2();
  102. $("#org_inner1").hide();
  103. $("#queryInput1").hide();
  104. $("#showTitle").html("外部单位");
  105. }
  106. //绑定查询框事件
  107. $("#queryInput1").on("keyup", function(event) {
  108. getValue = $("#queryInput1").val().trim();
  109. if(getValue!=""){
  110. inputTips(getValue,orgSel);
  111. }
  112. });
  113. $("#queryInput2").on("keyup", function(event) {
  114. getValue = $("#queryInput2").val().trim();
  115. if(getValue!=""){
  116. inputTips(getValue,orgSel);
  117. }
  118. });
  119. //绑定添加到常用组事件
  120. $("#chooseOne").bind(
  121. "click",
  122. function() {
  123. getCheckedIds();
  124. });
  125. //绑定添加子节点
  126. $("#chooseChildren").bind(
  127. "click",
  128. function() {
  129. getSelectedChildIds();
  130. });
  131. //绑定清除事件
  132. $("#clearChosen").bind("click",function(){
  133. backToEver();
  134. });
  135. //绑定确定事件
  136. $("#confirmChosen").bind("click", function() {
  137. var zTree = $.fn.zTree.getZTreeObj("myTree3");
  138. var n = zTree.getNodes();
  139. $.post($.pathname()+ "/ws/OrganizationsService/OrganizationsService/addCommonOrgInfoById",
  140. {
  141. 'id' : selectedOrgId.join(""),
  142. 'group_id' : groupId
  143. },
  144. function(data) {
  145. if (data > 0) {
  146. }
  147. }, "json");
  148. });
  149. //绑定点击查询显示框的其他位置隐藏div方法
  150. $("body:eq(0)").bind("click" ,function (event){
  151. var e = event || window.event;
  152. var elem = e.srcElement || e.target;
  153. while(elem)
  154. {
  155. if(elem.id == "queryContent1")
  156. {
  157. return;
  158. }
  159. elem = elem.parentNode;
  160. }
  161. //隐藏div的方法
  162. $("#queryContent1").hide();
  163. });
  164. });
  165. function doSome(data, mid) {
  166. var parentIds = data.parentIds;
  167. var childOrg = data.childOrg;
  168. var isOuter = $("#queryInput1").is(":hidden");
  169. //var orgType= isOuter ? "OUTER":"INNER";
  170. var zTree = isOuter ? $.fn.zTree.getZTreeObj("myTree2") : $.fn.zTree
  171. .getZTreeObj("myTree1");
  172. if (canFind(mid)) {
  173. zTree.selectNode(zTree.getNodesByParam("id", mid, null)[0]);
  174. return;
  175. }
  176. isAdd = true;
  177. for (var i = 0; i < parentIds.length; i++) {
  178. var treeNodes = zTree.getNodesByParam("id", parentIds[i], null)[0];
  179. var p = i - 1;
  180. if (treeNodes == null) {
  181. //找不到那么久找他的父节点 然后加载
  182. var pnode = zTree.getNodesByParam("id", parentIds[p], null)[0];
  183. targetOrg = mid;
  184. zTree.reAsyncChildNodes(pnode, "refresh", true);
  185. break;
  186. }
  187. }
  188. isAdd = false;
  189. setTimeout(function() {
  190. zTree.selectNode(zTree.getNodesByParam("id", mid, null)[0]);
  191. }, 200);
  192. }
  193. function canFind(mid) {
  194. var treeObj = orgSel=="INNER" ? $.fn.zTree.getZTreeObj("myTree1"):$.fn.zTree.getZTreeObj("myTree2");
  195. var treeNodes = treeObj.getNodesByParam("id", mid, null)[0];
  196. return treeNodes != null;
  197. }
  198. var getValue;
  199. var moreresult;
  200. function inputTips(getValue,orgType) {
  201. var params = {
  202. 'name' : getValue,
  203. 'type' : orgType,
  204. 'role' : inOrgId
  205. };
  206. //清空ul
  207. $("#queryContent1").find("ul").empty();
  208. //查询字段
  209. $
  210. .ajax({
  211. url : $.pathname()
  212. + '/ws/OrganizationsService/OrganizationsService/queryOrgByName',
  213. data : params,
  214. dataType : 'json',
  215. type : 'post',
  216. success : function(result) {
  217. moreresult = result;
  218. if (result.length > 0) {
  219. $("#queryContent1").show();
  220. }
  221. ;
  222. for (var i = 0; i < result.length; i++) {
  223. var item = result[i];
  224. if (i < 3) {
  225. //遍历加载字段
  226. $("#queryContent1")
  227. .find("ul")
  228. .append(
  229. "<li><div class='tips'>"
  230. + item.name
  231. + "</div><div style='text-align:right;' title='"+item.path+"'>"
  232. + item.spath
  233. + "<hr class='hr3'/></div></li>");
  234. $("#queryContent1").find("ul").find("li")
  235. .last().data("id", item.id)
  236. .on("click", function() {
  237. findById($(this).data("id"));
  238. });
  239. }
  240. if (i == 3) {
  241. if ($("#queryContent1").find("#gengduo").size() == 0) {
  242. $("#queryContent1")
  243. .find("ul")
  244. /* .find("li")
  245. .last() */
  246. .append(
  247. "<div id='gengduo'>查看更多</div>");
  248. }
  249. //设置控件节点高度
  250. $("#gengduo").css({
  251. "font-size" : "12px",
  252. "line-height" : "1.4em",
  253. "text-align" : "center"
  254. });
  255. //绑定点击事件,
  256. $("#gengduo").on("click", function() {
  257. $("#gengduo").hide();
  258. moreOptions(moreresult);
  259. });
  260. }
  261. }
  262. }
  263. });
  264. }
  265. var isAdd = false;
  266. function getAsyncUrl(treeId, treeNode) {
  267. return isAdd ? $.pathname()
  268. + "/ws/OrganizationsService/OrganizationsService/addOrgInfoById?targetOrg="
  269. + targetOrg
  270. : $.pathname()
  271. + "/ws/OrganizationsService/OrganizationsService/getOrgInfoById";
  272. };
  273. function moreOptions(moreresult) {
  274. for (var i = 3; i < moreresult.length; i++) {
  275. var item = moreresult[i];
  276. $("#queryContent1").find("ul").append(
  277. "<li><div>" + item.name
  278. + "</div><div style='text-align:right;' title='"+item.path+"'>"
  279. + item.spath
  280. + "<hr class='hr3'/></div></li>");
  281. $("#queryContent1").find("ul").find("li").last()
  282. .data("id", item.id).on("click", function() {
  283. findById($(this).data("id"));
  284. });
  285. //$("#queryContent1").find("ul").find("li:gt").addClass("tips");
  286. }
  287. }
  288. function findById(id) {
  289. $
  290. .ajax({
  291. url : $.pathname()
  292. + '/ws/OrganizationsService/OrganizationsService/queryOrgInfo',
  293. data : {
  294. 'id' : id
  295. },
  296. type : 'post',
  297. dataType : 'json',
  298. success : function(data) {
  299. doSome(data, id);
  300. }
  301. });
  302. $("#queryContent1").hide();
  303. }
  304. //单个选中
  305. function getHoverNode(treeNode){
  306. var treeObj = orgSel =="INNER" ? $.fn.zTree.getZTreeObj("myTree1") : $.fn.zTree.getZTreeObj("myTree2");
  307. treeObj.checkNode(treeNode,true);
  308. var zTree = $.fn.zTree.getZTreeObj("myTree3");
  309. if(selectedOrgId.indexValuess(treeNode.id)==-1){
  310. selectedOrgId.push(treeNode.id);
  311. zTree.addNodes(null,gernerateSimpleNode(treeNode));
  312. }
  313. treeObj.checkNode(treeNode,false);
  314. $("#hiddenSelIds").val(selectedOrgId);
  315. getSelectedNum(selectedOrgId);
  316. }
  317. //获取勾选的组织id
  318. function getCheckedIds(){
  319. var treeObj = orgSel =="INNER" ? $.fn.zTree.getZTreeObj("myTree1") : $.fn.zTree.getZTreeObj("myTree2");
  320. var nodes = treeObj.getCheckedNodes(true);
  321. var zTree = $.fn.zTree.getZTreeObj("myTree3");
  322. for(var i =0; i<nodes.length;i++){
  323. //如果不包含那么添加进去
  324. if(selectedOrgId.indexValuess(nodes[i].id)==-1){
  325. selectedOrgId.push(nodes[i].id);
  326. zTree.addNodes(null,gernerateSimpleNode(nodes[i]));
  327. //treeObj.removeNode(nodes[i]);
  328. }
  329. treeObj.checkNode(nodes[i],false);
  330. }
  331. //selectedOrgId.unique3();
  332. //treeObj.checkAllNodes(false);
  333. $("#hiddenSelIds").val(selectedOrgId);
  334. getSelectedNum(selectedOrgId);
  335. }
  336. //将选中的组织的子节点添加进去
  337. function getSelectedChildIds(){
  338. var treeObj = orgSel =="INNER" ? $.fn.zTree.getZTreeObj("myTree1"):$.fn.zTree.getZTreeObj("myTree2");
  339. var selNode = treeObj.getSelectedNodes()[0];
  340. var childNodes = treeObj.getNodesByParam("parentId",selNode.id,null);
  341. var zTree = $.fn.zTree.getZTreeObj("myTree3");
  342. for(var i =0;i<childNodes.length;i++){
  343. if(selectedOrgId.indexValuess(childNodes[i].id)==-1){
  344. selectedOrgId.push(childNodes[i].id);
  345. zTree.addNodes(null,gernerateSimpleNode(childNodes[i]));
  346. //treeObj.removeNode(childNodes[i]);
  347. }
  348. }
  349. $("#hiddenSelIds").val(selectedOrgId);
  350. getSelectedNum(selectedOrgId);
  351. }
  352. //清除所有选择的组织
  353. function backToEver(){
  354. initTree3();
  355. selectedOrgId=[];
  356. $("#hiddenSelIds").val("");
  357. getSelectedNum(selectedOrgId);
  358. }
  359. //手动生成简易的节点
  360. function gernerateSimpleNode(treeNode){
  361. var sNode ={id:"",name:"",parentId:"1",icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'};
  362. sNode.id=treeNode.id;
  363. sNode.name=treeNode.name;
  364. return sNode;
  365. }
  366. //更新已选择的数目
  367. function getSelectedNum(selectedOrgId){
  368. $("#selectedNum").html(decodeURI(groupName)+" ("+selectedOrgId.length+")");
  369. }
  370. //确认是否删除+删除处理
  371. function beforeRemove1(treeId, treeNode) {
  372. var zTree = $.fn.zTree.getZTreeObj("myTree3");
  373. //选中该节点
  374. zTree.selectNode(treeNode);
  375. zTree.removeNode(treeNode);
  376. var index =0;
  377. for(var i =0;i<selectedOrgId.length;i++){
  378. if(treeNode.id==selectedOrgId){
  379. index =i;
  380. break;
  381. }
  382. }
  383. selectedOrgId.splice( 0, index);
  384. getSelectedNum(selectedOrgId);
  385. return false;
  386. }
  387. function addHoverDom(treeId, treeNode) {
  388. if (treeNode.editNameFlag || $("#addBtn_" + treeNode.id).length > 0) return;
  389. var sObj = $("#" + treeNode.tId + "_span");
  390. var addStr = "<span class='zbutton add' id='addBtn_" + treeNode.id
  391. + "' title='选择到常用联系组' onfocus='this.blur();'></span>";
  392. sObj.append(addStr);
  393. var btn = $("#addBtn_" + treeNode.id);
  394. if (btn){
  395. btn.bind("click", function(){
  396. getHoverNode(treeNode);
  397. });
  398. }
  399. };
  400. function setRemoveBtn(treeId, treeNode) {
  401. return true;
  402. }
  403. function setRenameBtn(treeId, treeNode) {
  404. return false;
  405. }
  406. function removeHoverDom(treeId, treeNode) {
  407. $("#addBtn_" + treeNode.id).unbind().remove();
  408. };
  409. function beforeRemove1(treeId, treeNode) {
  410. var zTree = $.fn.zTree.getZTreeObj("myTree3");
  411. zTree.removeNode(treeNode);
  412. selectedOrgId.removeGetInfo(treeNode.id);
  413. $("#hiddenSelIds").val("");
  414. getSelectedNum(selectedOrgId);
  415. return false;
  416. }