9e85c39d4f993d54fb5d3487584f1b134f678c19.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. //登陆人的机构id
  2. var loginOrgId = top.com.sinosoft.lz.system.user.LoginInfo.getDeptids();
  3. //树的初始化
  4. var setting;
  5. //定义选项卡
  6. var tab;
  7. //新增选项卡的下标
  8. var tabIndex = 0;
  9. //设置机构树的对象
  10. var zTree;
  11. //设置当前选中的机构节点
  12. var selectedTreeNode;
  13. //定义初始化的根节点
  14. var rootNode;
  15. $(function(){
  16. //初始化布局组件
  17. initLayout();
  18. //初始化右侧选项卡信息
  19. tab = new TabView( {
  20. containerId :'tab_menu',
  21. pageid :'page',
  22. cid :'tab1',
  23. position :"top"
  24. });
  25. //设置页签id编号
  26. tabIndex = tabIndex +1;
  27. //默认添加机构人员信息的选项卡界面
  28. tab.add( {
  29. id :'tab1_index'+tabIndex,
  30. title :"机构人员信息",
  31. url :"/nwyj/page/business/am/org/query/AllInformation.jsp",
  32. isClosed :false
  33. });
  34. //树的设置
  35. setting = {
  36. view : {
  37. selectedMulti : false
  38. },
  39. edit: {
  40. enable: true,
  41. showRemoveBtn: false,
  42. showRenameBtn: false,
  43. drag: {
  44. //autoExpandTrigger: false,
  45. minMoveSize: 5,
  46. prev: true,
  47. next: true,
  48. inner: false
  49. }
  50. },
  51. async : {
  52. enable : true,
  53. dataType : 'JSON',
  54. dataName : 'treeNodes',
  55. aysnc : false,
  56. url : getAsyncUrl,
  57. autoParam : [ "id", "name", "orgLevel" ],
  58. otherParam : ["deptId", loginOrgId]
  59. },
  60. callback: {
  61. //响应右键
  62. onRightClick: OnRightClick,
  63. //树的拖拽
  64. beforeDrag: beforeDrag2,
  65. beforeDrop: beforeDrop2,
  66. //鼠标按键松开后的事件回调函数
  67. onMouseUp: onMouseUp,
  68. onClick: onClick,
  69. //beforeDragOpen: beforeDragOpen2,
  70. //onDrag: onDrag2,
  71. onDrop: onDrop2
  72. }
  73. };
  74. //初始化树
  75. initTree();
  76. //绑定查询框事件
  77. $("#queryInput1").on("keyup", function(event) {
  78. var getValue = $("#queryInput1").val();
  79. if(getValue!=""){
  80. inputTips(getValue);
  81. }
  82. });
  83. //绑定点击查询显示框的其他位置隐藏div方法
  84. $("body:eq(0)").bind("click" ,function (event){
  85. var e = event || window.event;
  86. var elem = e.srcElement || e.target;
  87. var inOrgHOS = $("#queryContent1").is(":hidden");
  88. if(!inOrgHOS){
  89. while(elem)
  90. {
  91. if(elem.id == "queryContent1")
  92. {
  93. return;
  94. }
  95. elem = elem.parentNode;
  96. }
  97. //隐藏div的方法
  98. $("#queryContent1").hide();
  99. }
  100. });
  101. //鼠标移入右键菜单效果
  102. $("#rMenu >div").hover(function(){
  103. $(this).addClass("b-m-ifocus");
  104. },function(){
  105. $(this).removeClass("b-m-ifocus");
  106. });
  107. });
  108. //鼠标按键松开后的事件回调函数 用于返回当前选中的
  109. function onMouseUp(event, treeId, treeNode){
  110. return selectedTreeNode = treeNode==null?selectedTreeNode:treeNode;
  111. }
  112. //新增成功后 调用新增机构的方法(用于显示树)
  113. function addNewVirtualOrg(parentNode,addNode){
  114. var newNodes = zTree.addNodes(parentNode,addNode);
  115. //选中新增的节点
  116. zTree.selectNode(newNodes[0]);
  117. selectedTreeNode = newNodes[0];
  118. //刷新information界面
  119. refreshInformation(newNodes[0],newNodes[0].id);
  120. }
  121. // 修改成功后 调用修改机构的方法(用于显示树)
  122. function updateVirtualOrg(newNode,oldNode){
  123. //更新节点的属性
  124. oldNode.name = newNode.name;
  125. zTree.updateNode(oldNode);
  126. //选中修改的节点
  127. zTree.selectNode(oldNode);
  128. //刷新information界面
  129. refreshInformation(oldNode,oldNode.id);
  130. }
  131. //组织机构树的点击事件
  132. function onClick(event, treeId, treeNode, clickFlag){
  133. tab.activate("tab1_index1");
  134. var frame = document.getElementById("page_tab1_index1");
  135. //sqlLoadParams = "IS_DEL=0 AND PARENT_DEPT_ID ='" + treeNode.id + "'";
  136. frame.contentWindow.refreshInformation(treeNode,selectedTreeNode.id);
  137. }
  138. //拖拽前的判定 不能拖拽(根节点不能拖拽)返回false
  139. function beforeDrag2(treeId, treeNodes) {
  140. for (var i = 0, l = treeNodes.length; i < l; i++) {
  141. if(treeNodes[i].id ==loginOrgId) {
  142. return false;
  143. }
  144. }
  145. return true;
  146. }
  147. //拖拽放下前的判定 只能在同级拖动 不能放下返回false
  148. function beforeDrop2(treeId, treeNodes, targetNode, moveType) {
  149. if(targetNode && targetNode.orgLevel == treeNodes[0].orgLevel){
  150. return true;
  151. }
  152. return false;
  153. }
  154. //拖拽完成后进行后台交互
  155. function onDrop2(event, treeId, treeNodes, targetNode, moveType, isCopy){
  156. if(targetNode){
  157. //后台交互
  158. $.ajax({
  159. url:$.pathname()+"/ws/InDepartmentService/InDepartmentService/updateSortNo",
  160. type:"post",
  161. dataType:"json",
  162. data:{"dragNodeId":treeNodes[0].id,
  163. "destNodeSortNo":targetNode.sortNo},
  164. success:function(data){
  165. if(data=="1"){
  166. //更新已变更的sortNo
  167. var treeObj = $.fn.zTree.getZTreeObj("myTree");
  168. var node = treeNodes[0];
  169. node.sortNo = (parseFloat(targetNode.sortNo) + 0.123401)+"";
  170. treeObj.updateNode(node);
  171. }
  172. }
  173. })
  174. }
  175. }
  176. //加载搜索框的提示信息
  177. function inputTips(inputValue) {
  178. var params = {
  179. "name":inputValue,
  180. "permissionId":loginOrgId
  181. }
  182. //清空ul
  183. $("#queryContent1").find("ul").empty();
  184. //查询字段
  185. $
  186. .ajax({
  187. url : $.pathname()
  188. + '/ws/InDepartmentService/InDepartmentService/queryOrgByName',
  189. data : params,
  190. dataType : 'json',
  191. type : 'post',
  192. success : function(result) {
  193. if (result.length > 0) {
  194. $("#queryContent1").show();
  195. };
  196. for (var i = 0; i < result.length; i++) {
  197. var item = result[i];
  198. if (i < 3) {
  199. //遍历加载字段
  200. $("#queryContent1")
  201. .find("ul")
  202. .append(
  203. "<li><div >"
  204. + item.name
  205. + "</div><div style='text-align:right;margin : 0px 0px 0px 5px;' title='"+item.path+"'>"
  206. + item.spath
  207. + "<hr class='hr3'/></div></li>");
  208. $("#queryContent1").find("ul").find("li")
  209. .last().data("id", item.id)
  210. .on("click", function() {
  211. findById($(this).data("id"));
  212. });
  213. }
  214. if (i == 3) {
  215. if ($("#queryContent1").find("#gengduo").size() == 0) {
  216. $("#queryContent1")
  217. .find("ul").append(
  218. "<div id='gengduo'>查看更多</div>");
  219. }
  220. //设置控件节点高度
  221. $("#gengduo").css({
  222. "font-size" : "12px",
  223. "line-height" : "1.4em",
  224. "text-align" : "center"
  225. });
  226. //绑定点击事件,
  227. $("#gengduo").on("click", function() {
  228. $("#gengduo").hide();
  229. moreOptions(result);
  230. });
  231. }
  232. }
  233. }
  234. });
  235. }
  236. //加载更多搜索选项
  237. function moreOptions(moreresult) {
  238. for (var i = 3; i < moreresult.length; i++) {
  239. item = moreresult[i];
  240. $("#queryContent1").find("ul").append(
  241. "<li><div>" + item.name
  242. + "</div><div style='vertical-align:right;margin : 0px 0px 0px 5px;' title='"+item.path+"'>"
  243. + " " + item.spath
  244. + "<hr class='hr3'/></div></li>");
  245. $("#queryContent1").find("ul").find("li").last()
  246. .data("id", item.id).on("click", function() {
  247. findById($(this).data("id"));
  248. });
  249. }
  250. }
  251. //根据id精准搜索
  252. function findById(id) {
  253. $
  254. .ajax({
  255. url : $.pathname()
  256. + '/ws/InDepartmentService/InDepartmentService/getHigherOrgIds',
  257. data : {
  258. 'id' : id,
  259. 'permissionId':loginOrgId
  260. },
  261. type : 'post',
  262. dataType : 'json',
  263. success : function(data) {
  264. doSome(data, id);
  265. }
  266. })
  267. $("#queryContent1").hide();
  268. }
  269. //找到给定id的机构信息
  270. function doSome(data, mid) {
  271. var zTree =$.fn.zTree.getZTreeObj("myTree") ;
  272. //判定是否能直接在前台找到想要搜寻的机构
  273. if (canFind(mid)) {
  274. zTree.selectNode(zTree.getNodesByParam("id", mid, null)[0]);
  275. return;
  276. }
  277. //不能搜寻到就找出已经加载的节点信息 然后异步加载树
  278. isAdd = true;
  279. for (var i = 0; i < data.length; i++) {
  280. var treeNodes = zTree.getNodesByParam("id", data[i], null)[0];
  281. //var p = i - 1;
  282. if (treeNodes != null) {
  283. var pnode = zTree.getNodesByParam("id", data[i], null)[0];
  284. targetOrg = mid;
  285. zTree.reAsyncChildNodes(pnode, "refresh", true);
  286. break;
  287. }
  288. }
  289. setTimeout(function() {
  290. zTree.selectNode(zTree.getNodesByParam("id", mid, null)[0]);
  291. }, 300);
  292. isAdd = false;
  293. }
  294. //是否能直接在已加载的机构中找寻到
  295. function canFind(mid) {
  296. var treeObj = $.fn.zTree.getZTreeObj("myTree");
  297. var treeNodes = treeObj.getNodesByParam("id", mid, null)[0];
  298. return treeNodes != null;
  299. }
  300. //初始化树
  301. function initTree(){
  302. $.fn.zTree.init($("#myTree"), setting);
  303. zTree = $.fn.zTree.getZTreeObj("myTree");
  304. setTimeout(function(){
  305. //初始化后选中根节点(默认)
  306. var treeObj = $.fn.zTree.getZTreeObj("myTree");
  307. selectedTreeNode = treeObj.getNodeByParam("id",loginOrgId,null);
  308. rootNode = treeObj.getNodeByParam("id",loginOrgId,null);
  309. },500);
  310. }
  311. //点击右键处理
  312. function OnRightClick(event, treeId, treeNode) {
  313. //在节点之外显示一种菜单
  314. if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
  315. zTree.cancelSelectedNode();
  316. showRMenu("root", event.clientX, event.clientY);
  317. //在节点里面显示另一种菜单
  318. } else if(treeNode) {
  319. zTree.selectNode(treeNode);
  320. showRMenu("node", event.clientX, event.clientY);
  321. }
  322. }
  323. //根据设置弹出不同的右键菜单
  324. function showRMenu(type, x, y) {
  325. $("#rMenu ul").show();
  326. if(type == "root") {//树节点外只保留添加和恢复
  327. /* $("#m_add").show(); */
  328. $("#m_edit").show();
  329. $("#m_delete").show();
  330. /* $("#m_unCheck").show();
  331. $("#m_reset").show(); */
  332. $("#m_edit").hide();
  333. $("#m_delete").hide();
  334. /* $("#m_unCheck").hide(); */
  335. }else if(type == "nonLeafMenu") {//父节点保留添加和删除
  336. $("#m_add").show();
  337. $("#m_edit").show();
  338. $("#m_delete").show();
  339. /* $("#m_unCheck").show();
  340. $("#m_reset").show(); */
  341. /* $("#m_reset").hide(); */
  342. $("#m_delete").hide();
  343. /* $("#m_unCheck").hide();
  344. $("#m_reset").hide(); */
  345. }else if(type == "leafMenu") {//子节点保留选择和删除
  346. $("#m_add").show();
  347. $("#m_edit").show();
  348. $("#m_delete").show();
  349. /* $("#m_unCheck").show();
  350. $("#m_reset").show(); */
  351. $("#m_add").hide();
  352. $("#m_reset").hide();
  353. }else if(type=="node"){
  354. $("#m_add").show();
  355. $("#m_edit").show();
  356. $("#m_delete").show();
  357. }
  358. $("#rMenu").css({"top":y+"px", "left":x+"px", "visibility":"visible"});
  359. //点击菜单外时隐藏菜单
  360. $("body").bind("mousedown", onBodyMouseDown);
  361. }
  362. //点击菜单项时隐藏菜单
  363. function hideRMenu() {
  364. if ($("#rMenu")) $("#rMenu").css({"visibility": "hidden"});
  365. $("body").unbind("mousedown", onBodyMouseDown);
  366. }
  367. //点击菜单外时隐藏菜单
  368. function onBodyMouseDown(event){
  369. if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length > 0)) {
  370. $("#rMenu").css({"visibility" : "hidden"});
  371. }
  372. }
  373. //右键的新增 虚拟机构的方法(打开新的界面)
  374. function addVirtualOrg(){
  375. //获得点击的机构节点
  376. var pNode = selectedTreeNode;
  377. var url="Add_VirtualOrg.jsp";
  378. var name ="新增虚拟机构【"+pNode.name+"】";
  379. addTab(url,name);
  380. hideRMenu();
  381. };
  382. //右键修改机构信息学
  383. function editOrgInfo(){
  384. //获得点击的机构节点
  385. var pNode = selectedTreeNode;
  386. var url="Update_VirtualOrg.jsp?";
  387. var name ="修改【"+pNode.name+"】";
  388. addTab(url,name);
  389. hideRMenu();
  390. }
  391. //右键产出机构信息
  392. function deleteOrg(){
  393. //获得点击的机构节点
  394. var pNode = selectedTreeNode;
  395. hideRMenu();
  396. $.ajax({
  397. url:$.pathname() + "/ws/InDepartmentService/InDepartmentService/deleteOrgById",
  398. data:{
  399. "id":pNode.id
  400. },
  401. dataType :"json",
  402. type :"post",
  403. success : function(data){
  404. //如果删除成功那么在树上删除该节点
  405. if(data==pNode.id){
  406. zTree.removeNode(pNode);
  407. //刷新information界面
  408. refreshInformation(rootNode,rootNode.id);
  409. }
  410. }
  411. });
  412. }
  413. //判定是否为搜索的变量
  414. var isAdd = false;
  415. //定义需要搜索的机构id
  416. var targetOrg;
  417. // 异步加载树时的请求url变更
  418. function getAsyncUrl(treeId, treeNode) {
  419. return isAdd ? $.pathname()
  420. + "/ws/InDepartmentService/InDepartmentService/newOrgInfoById?targetOrg="
  421. + targetOrg
  422. : $.pathname()
  423. + "/ws/InDepartmentService/InDepartmentService/getOrgInfoById";
  424. };
  425. //新增页签的方法
  426. function addTab(url,name){
  427. tabIndex = tabIndex +1;
  428. tab.add( {
  429. id :'tab1_index'+tabIndex,
  430. title :name,
  431. url :url,
  432. isClosed :true
  433. });
  434. return 'tab1_index'+tabIndex;
  435. }
  436. //关闭页签的方法
  437. function closeTab(id){
  438. tab.close(id);
  439. }
  440. //切换页签的方法
  441. function avtiveTab(id){
  442. tab.activate(id);
  443. }
  444. // 布局组件初始化
  445. function initLayout() {
  446. var layout = $("#layout1").layout({
  447. leftWidth : 320,
  448. centerWidth : 760,
  449. height: 1200
  450. });
  451. layout.setRightCollapse(true);
  452. };