123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633 |
- //登陆人的机构id
- var loginOrgId = top.com.sinosoft.lz.system.user.LoginInfo.getDeptids();
- //树的初始化
- var setting;
- //定义选项卡
- var tab;
- //新增选项卡的下标
- var tabIndex = 0;
- //设置机构树的对象
- var zTree;
- //设置当前选中的机构节点
- var selectedTreeNode;
- //定义初始化的根节点
- var rootNode;
- $(function(){
- //初始化布局组件
- initLayout();
- //初始化右侧选项卡信息
- tab = new TabView( {
- containerId :'tab_menu',
- pageid :'page',
- cid :'tab1',
- position :"top"
- });
- //设置页签id编号
- tabIndex = tabIndex +1;
- //默认添加机构人员信息的选项卡界面
- tab.add( {
- id :'tab1_index'+tabIndex,
- title :"机构人员信息",
- url :"/nwyj/page/business/am/org/query/AllInformation.jsp",
- isClosed :false
- });
- //树的设置
- setting = {
- view : {
- selectedMulti : false
- },
- edit: {
- enable: true,
- showRemoveBtn: false,
- showRenameBtn: false,
- drag: {
- //autoExpandTrigger: false,
-
- minMoveSize: 5,
-
- prev: true,
- next: true,
- inner: false
- }
- },
- async : {
- enable : true,
- dataType : 'JSON',
- dataName : 'treeNodes',
- aysnc : false,
- url : getAsyncUrl,
- autoParam : [ "id", "name", "orgLevel" ],
- otherParam : ["deptId", loginOrgId]
- },
- callback: {
- //响应右键
- onRightClick: OnRightClick,
- //树的拖拽
- beforeDrag: beforeDrag2,
- beforeDrop: beforeDrop2,
- //鼠标按键松开后的事件回调函数
- onMouseUp: onMouseUp,
-
- onClick: onClick,
- //beforeDragOpen: beforeDragOpen2,
- //onDrag: onDrag2,
- onDrop: onDrop2
-
- }
- };
- //初始化树
- initTree();
-
-
- //绑定查询框事件
- $("#queryInput1").on("keyup", function(event) {
- var getValue = $("#queryInput1").val();
- if(getValue!=""){
- inputTips(getValue);
- }
- });
- //绑定点击查询显示框的其他位置隐藏div方法
- $("body:eq(0)").bind("click" ,function (event){
- var e = event || window.event;
- var elem = e.srcElement || e.target;
- var inOrgHOS = $("#queryContent1").is(":hidden");
- if(!inOrgHOS){
- while(elem)
- {
- if(elem.id == "queryContent1")
- {
- return;
- }
- elem = elem.parentNode;
- }
- //隐藏div的方法
- $("#queryContent1").hide();
- }
- });
-
- //鼠标移入右键菜单效果
- $("#rMenu >div").hover(function(){
- $(this).addClass("b-m-ifocus");
- },function(){
- $(this).removeClass("b-m-ifocus");
- });
-
-
-
- });
- //鼠标按键松开后的事件回调函数 用于返回当前选中的
- function onMouseUp(event, treeId, treeNode){
- return selectedTreeNode = treeNode==null?selectedTreeNode:treeNode;
- }
- //新增成功后 调用新增机构的方法(用于显示树)
- function addNewVirtualOrg(parentNode,addNode){
- var newNodes = zTree.addNodes(parentNode,addNode);
-
- //选中新增的节点
- zTree.selectNode(newNodes[0]);
-
- selectedTreeNode = newNodes[0];
-
- //刷新information界面
- refreshInformation(newNodes[0],newNodes[0].id);
- }
- // 修改成功后 调用修改机构的方法(用于显示树)
- function updateVirtualOrg(newNode,oldNode){
- //更新节点的属性
- oldNode.name = newNode.name;
-
- zTree.updateNode(oldNode);
- //选中修改的节点
- zTree.selectNode(oldNode);
- //刷新information界面
- refreshInformation(oldNode,oldNode.id);
- }
- //组织机构树的点击事件
- function onClick(event, treeId, treeNode, clickFlag){
- tab.activate("tab1_index1");
- var frame = document.getElementById("page_tab1_index1");
- //sqlLoadParams = "IS_DEL=0 AND PARENT_DEPT_ID ='" + treeNode.id + "'";
- frame.contentWindow.refreshInformation(treeNode,selectedTreeNode.id);
- }
- //拖拽前的判定 不能拖拽(根节点不能拖拽)返回false
- function beforeDrag2(treeId, treeNodes) {
- for (var i = 0, l = treeNodes.length; i < l; i++) {
- if(treeNodes[i].id ==loginOrgId) {
- return false;
- }
- }
- return true;
- }
- //拖拽放下前的判定 只能在同级拖动 不能放下返回false
- function beforeDrop2(treeId, treeNodes, targetNode, moveType) {
- if(targetNode && targetNode.orgLevel == treeNodes[0].orgLevel){
-
- return true;
- }
- return false;
- }
- //拖拽完成后进行后台交互
- function onDrop2(event, treeId, treeNodes, targetNode, moveType, isCopy){
- if(targetNode){
- //后台交互
- $.ajax({
- url:$.pathname()+"/ws/InDepartmentService/InDepartmentService/updateSortNo",
- type:"post",
- dataType:"json",
- data:{"dragNodeId":treeNodes[0].id,
- "destNodeSortNo":targetNode.sortNo},
- success:function(data){
- if(data=="1"){
- //更新已变更的sortNo
- var treeObj = $.fn.zTree.getZTreeObj("myTree");
- var node = treeNodes[0];
- node.sortNo = (parseFloat(targetNode.sortNo) + 0.123401)+"";
- treeObj.updateNode(node);
- }
- }
- })
- }
- }
- //加载搜索框的提示信息
- function inputTips(inputValue) {
- var params = {
- "name":inputValue,
- "permissionId":loginOrgId
- }
- //清空ul
- $("#queryContent1").find("ul").empty();
- //查询字段
- $
- .ajax({
- url : $.pathname()
- + '/ws/InDepartmentService/InDepartmentService/queryOrgByName',
- data : params,
- dataType : 'json',
- type : 'post',
- success : function(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 >"
- + item.name
- + "</div><div style='text-align:right;margin : 0px 0px 0px 5px;' 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").append(
- "<div id='gengduo'>查看更多</div>");
- }
- //设置控件节点高度
- $("#gengduo").css({
- "font-size" : "12px",
- "line-height" : "1.4em",
- "text-align" : "center"
- });
- //绑定点击事件,
- $("#gengduo").on("click", function() {
- $("#gengduo").hide();
- moreOptions(result);
- });
- }
- }
- }
- });
- }
- //加载更多搜索选项
- function moreOptions(moreresult) {
- for (var i = 3; i < moreresult.length; i++) {
- item = moreresult[i];
- $("#queryContent1").find("ul").append(
- "<li><div>" + item.name
- + "</div><div style='vertical-align:right;margin : 0px 0px 0px 5px;' 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"));
- });
- }
- }
- //根据id精准搜索
- function findById(id) {
- $
- .ajax({
- url : $.pathname()
- + '/ws/InDepartmentService/InDepartmentService/getHigherOrgIds',
- data : {
- 'id' : id,
- 'permissionId':loginOrgId
- },
- type : 'post',
- dataType : 'json',
- success : function(data) {
- doSome(data, id);
- }
- })
- $("#queryContent1").hide();
- }
-
-
- //找到给定id的机构信息
- function doSome(data, mid) {
- var zTree =$.fn.zTree.getZTreeObj("myTree") ;
- //判定是否能直接在前台找到想要搜寻的机构
- if (canFind(mid)) {
- zTree.selectNode(zTree.getNodesByParam("id", mid, null)[0]);
- return;
- }
- //不能搜寻到就找出已经加载的节点信息 然后异步加载树
- isAdd = true;
- for (var i = 0; i < data.length; i++) {
- var treeNodes = zTree.getNodesByParam("id", data[i], null)[0];
- //var p = i - 1;
- if (treeNodes != null) {
-
- var pnode = zTree.getNodesByParam("id", data[i], null)[0];
- targetOrg = mid;
- zTree.reAsyncChildNodes(pnode, "refresh", true);
- break;
- }
- }
- setTimeout(function() {
-
- zTree.selectNode(zTree.getNodesByParam("id", mid, null)[0]);
- }, 300);
- isAdd = false;
- }
- //是否能直接在已加载的机构中找寻到
- function canFind(mid) {
- var treeObj = $.fn.zTree.getZTreeObj("myTree");
- var treeNodes = treeObj.getNodesByParam("id", mid, null)[0];
- return treeNodes != null;
- }
- //初始化树
- function initTree(){
- $.fn.zTree.init($("#myTree"), setting);
- zTree = $.fn.zTree.getZTreeObj("myTree");
- setTimeout(function(){
- //初始化后选中根节点(默认)
- var treeObj = $.fn.zTree.getZTreeObj("myTree");
- selectedTreeNode = treeObj.getNodeByParam("id",loginOrgId,null);
- rootNode = treeObj.getNodeByParam("id",loginOrgId,null);
- },500);
- }
- //点击右键处理
- function OnRightClick(event, treeId, treeNode) {
- //在节点之外显示一种菜单
- if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
- zTree.cancelSelectedNode();
- showRMenu("root", event.clientX, event.clientY);
- //在节点里面显示另一种菜单
- } else if(treeNode) {
- zTree.selectNode(treeNode);
- showRMenu("node", event.clientX, event.clientY);
- }
- }
-
- //根据设置弹出不同的右键菜单
- function showRMenu(type, x, y) {
- $("#rMenu ul").show();
- if(type == "root") {//树节点外只保留添加和恢复
- /* $("#m_add").show(); */
- $("#m_edit").show();
- $("#m_delete").show();
- /* $("#m_unCheck").show();
- $("#m_reset").show(); */
-
- $("#m_edit").hide();
- $("#m_delete").hide();
- /* $("#m_unCheck").hide(); */
-
- }else if(type == "nonLeafMenu") {//父节点保留添加和删除
- $("#m_add").show();
- $("#m_edit").show();
- $("#m_delete").show();
- /* $("#m_unCheck").show();
- $("#m_reset").show(); */
-
- /* $("#m_reset").hide(); */
- $("#m_delete").hide();
- /* $("#m_unCheck").hide();
- $("#m_reset").hide(); */
-
- }else if(type == "leafMenu") {//子节点保留选择和删除
- $("#m_add").show();
- $("#m_edit").show();
- $("#m_delete").show();
- /* $("#m_unCheck").show();
- $("#m_reset").show(); */
-
- $("#m_add").hide();
- $("#m_reset").hide();
- }else if(type=="node"){
- $("#m_add").show();
- $("#m_edit").show();
- $("#m_delete").show();
- }
-
- $("#rMenu").css({"top":y+"px", "left":x+"px", "visibility":"visible"});
-
- //点击菜单外时隐藏菜单
- $("body").bind("mousedown", onBodyMouseDown);
- }
-
- //点击菜单项时隐藏菜单
- function hideRMenu() {
- if ($("#rMenu")) $("#rMenu").css({"visibility": "hidden"});
- $("body").unbind("mousedown", onBodyMouseDown);
- }
-
- //点击菜单外时隐藏菜单
- function onBodyMouseDown(event){
- if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length > 0)) {
- $("#rMenu").css({"visibility" : "hidden"});
- }
- }
- //右键的新增 虚拟机构的方法(打开新的界面)
- function addVirtualOrg(){
- //获得点击的机构节点
- var pNode = selectedTreeNode;
- var url="Add_VirtualOrg.jsp";
- var name ="新增虚拟机构【"+pNode.name+"】";
- addTab(url,name);
- hideRMenu();
- };
- //右键修改机构信息学
- function editOrgInfo(){
- //获得点击的机构节点
- var pNode = selectedTreeNode;
- var url="Update_VirtualOrg.jsp?";
- var name ="修改【"+pNode.name+"】";
- addTab(url,name);
- hideRMenu();
- }
- //右键产出机构信息
- function deleteOrg(){
- //获得点击的机构节点
- var pNode = selectedTreeNode;
- hideRMenu();
- $.ajax({
- url:$.pathname() + "/ws/InDepartmentService/InDepartmentService/deleteOrgById",
- data:{
- "id":pNode.id
- },
- dataType :"json",
- type :"post",
- success : function(data){
- //如果删除成功那么在树上删除该节点
- if(data==pNode.id){
- zTree.removeNode(pNode);
- //刷新information界面
- refreshInformation(rootNode,rootNode.id);
- }
- }
- });
- }
- //判定是否为搜索的变量
- var isAdd = false;
- //定义需要搜索的机构id
- var targetOrg;
- // 异步加载树时的请求url变更
- function getAsyncUrl(treeId, treeNode) {
- return isAdd ? $.pathname()
- + "/ws/InDepartmentService/InDepartmentService/newOrgInfoById?targetOrg="
- + targetOrg
- : $.pathname()
- + "/ws/InDepartmentService/InDepartmentService/getOrgInfoById";
- };
- //新增页签的方法
- function addTab(url,name){
- tabIndex = tabIndex +1;
- tab.add( {
- id :'tab1_index'+tabIndex,
- title :name,
- url :url,
- isClosed :true
- });
- return 'tab1_index'+tabIndex;
- }
- //关闭页签的方法
- function closeTab(id){
- tab.close(id);
- }
- //切换页签的方法
- function avtiveTab(id){
- tab.activate(id);
- }
- // 布局组件初始化
- function initLayout() {
- var layout = $("#layout1").layout({
- leftWidth : 320,
- centerWidth : 760,
- height: 1200
- });
- layout.setRightCollapse(true);
- };
-
|