当前位置: 代码迷 >> 综合 >> ExtJs TreePanel
  详细解决方案

ExtJs TreePanel

热度:23   发布时间:2024-01-12 13:38:35.0

 

//行政机构管理、事业机构管理
Ext.BLANK_IMAGE_URL = '../extjs/resources/images/default/s.gif';
Ext.SSL_SECURE_URL = '../extjs/resources/images/default/s.gif';
var pageSize1 = 14;
var resultStore;
var querFormPanel;
var xtlb;
var jbgg;
var bzlx;
var currentNode;
var parentNode; 
var parentNodeid;
var formpanel;
var currentOrgId;
var currentOrgName;
//设置默认qhdm和xltb
var store;
var qhlbn=session.qhdm;
var xtlbn=1;
Ext.onReady(function() {checkSession();bzlx = document.getElementById('bzlx').value;/*** 创建树*///	var treePanel=createTree();//------------------------------------------------------------------------------------------------------------------------------------------//	alert(Ext.getCmp('qhlbcomb').getValue());// 动态根节点var root = new Ext.tree.TreeNode({id : "-1",text : "组织机构"});var root1= new Ext.tree.AsyncTreeNode({id:'0',text:'行政机构'});root.appendChild(root1);var root2= new Ext.tree.AsyncTreeNode({id:'1',text:'事业机构'});root.appendChild(root2);// 机构树var treePanel = new Ext.tree.TreePanel({root : root,animate : true, // 动画效果border : false, // 边框rootVisible : false, // 隐藏根节点//autoScroll : false, // 自动滚动enableDD : false, // 拖拽节点containerScroll : true,width : '100%',loader : new Ext.tree.TreeLoader({//url : 'showJigouTree.action'})});//页面加载自动刷新//11.3.24修改添加bzlxtreePanel.on('beforeload', function(node) {treePanel.loader.dataUrl = 'showJigouTree.action?orgid=' + node.id+'&qhdm='+qhlbn+'&xtlb='+xtlbn+'&bzlx='+bzlx; // 定义子节点的Loader
});//展开节点事件
//	treePanel.on('expand',function (node){
//			currentNode = node;
//			parentNode = node.parentNode;
//			currentOrgId = node.attributes.id;
//			currentOrgName = node.attributes.text;
//			currentType=currentNode.attributes.type;
//		var params = resultStore.baseParams;
//	 	     Ext.apply(params,{"orgid":currentOrgId},{'type':'1'},{'bzlx':bzlx}); 
//	 	     resultStore.reload();
//	});//点击节点事件treePanel.on('click', function(node,event) {currentNode = node;parentNode = node.parentNode;currentOrgId = node.attributes.id;currentOrgName = node.attributes.text;currentType=currentNode.attributes.type;// 做两件事情,一件事情是设置重载参数var params = resultStore.baseParams;Ext.apply(params,{"orgid":currentOrgId},{'type':currentType},{'bzlx':bzlx},{'name':currentOrgName}); resultStore.reload();});//当页面node的text改变之后执行*无效(11.3.26)
//	treePanel.on('textchange',function( node,text,oldText){
//			node.parentNode.reload();
//	});//插入事件treePanel.on('insert',function(tree,parent,node,refNode){});treePanel.on('expandnode',function(node){if (node.attributes.id != "0")	treePanel.fireEvent("click",node);});var qhlb = new Ext.data.JsonStore({url : '../showDict.action?xmlDict=qhdm&type=1&loginUserQhdm='+session.qhdm,autoLoad : true,// 自动载入autoDestroy : true,fields : ["value", "text"],idIndex : 0,listeners:{'load':function(){xtlb.load();}}// id for each record will be the first element});xtlb = new Ext.data.JsonStore({url : '../showDict.action?xmlDict=class',autoLoad : false,// 自动载入autoDestroy : true,fields : ["value", "text"],idIndex : 0,listeners:{'load':function(){//系统列表加载的时候自动加载树的默认值treePanel.loader = new Ext.tree.TreeLoader({   dataUrl: 'showJigouTree.action?qhdm=' +qhlbn+'&xtlb='+xtlbn+'&bzlx='+bzlx//dataUrl: 'showJigouTree.action?qhdm=220221&xtlb=1&bzlx='+bzlx});//treePanel.getRootNode().reload(); 刷新树根}}});//机构级别规格jbgg = new Ext.data.Store({url : '../showDict.action?xmlDict=grade',reader : new Ext.data.JsonReader({fields : ["value", "text"]})});jbgg.load();//区划列表栏var qhlbcomb = new Ext.form.ComboBox({id : 'qhlbcomb',store : qhlb,valueField : "value",inputValue : "value",displayField : "text",forceSelection : true,mode : "local",editable : false,triggerAction : 'all',allowBlank : true,fieldLabel : '区划',width : 180,hiddenName : 'qhlb',//选择事件listeners:{"select":function(){qhlbn=Ext.get("qhlb").dom.value;treePanel.loader = new Ext.tree.TreeLoader({   dataUrl: 'showJigouTree.action?qhdm=' +qhlbn+'&xtlb='+xtlbn+'&bzlx='+bzlx});treePanel.getNodeById('0').reload();treePanel.getNodeById('1').reload();//根据选择 显示部门信息(11年3月24 暂时没用上)//注意加上 bzlx 也就是数据库里的 qfbsvar params = resultStore.baseParams;Ext.apply(params,{"qhdm":qhlbn},{'xtlbn':xtlbn},{'bzlx':bzlx}); resultStore.reload();}}});var xtlbcomb = new Ext.form.ComboBox({id : 'xtlbcomb',store : xtlb,valueField : "value",inputValue : "value",displayField : "text",forceSelection : true,mode : "local",editable : false,triggerAction : 'all',allowBlank : true,fieldLabel : '系统类别',width : 80,hiddenName : 'xtlb',//选择事件listeners:{"select":function(){xtlbn=Ext.get("xtlb").dom.value;treePanel.loader = new Ext.tree.TreeLoader({   dataUrl: 'showJigouTree.action?qhdm=' +qhlbn+'&xtlb='+xtlbn+'&bzlx='+bzlx});treePanel.getNodeById('0').reload();treePanel.getNodeById('1').reload();//根据选择 显示部门信息(11年3月24 暂时没用上)//注意加上 bzlx 也就是数据库里的 qfbsvar params = resultStore.baseParams;Ext.apply(params,{"qhdm":qhlbn},{'xtlbn':xtlbn},{'bzlx':bzlx}); resultStore.reload();}}});			// 获取区划列表qhlb.on("load", function() {qhlbcomb.setValue(qhlb.getAt(0).data.value);});// 获取系统列表xtlb.on("load", function() {xtlbcomb.setValue(xtlb.getAt(0).data.value);});// 查询结果面板var resultRecord = new Ext.data.Record.create([{name : 'orgid'}, {name : 'orgname'}, {name : 'jbgg'}, {name : 'wh'}, {name : 'lds'}, {name : 'jgs'}, {name : 'zjgdm'}, {name : 'qfbs'}, {name : 'xtlb'}, {name : 'qhdm'}]);// create the data storevar colsM = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(),{header : "机构名称",dataIndex : "orgname",sortable: true,width : .30}, {header : "机构级别规格",dataIndex : "jbgg",sortable: true,width : .20,renderer : function(value, p, record) {var jbggcode = record.data.jbgg;var index = jbgg.find("value",jbggcode);return jbgg.getAt(index).data.text;}},{header : "批准文号",dataIndex : "wh",sortable: true,width : .20},{header : "领导职数",dataIndex : "lds",sortable: true,width : .10}, {header : "内设机构数",dataIndex : "jgs",sortable: true,width : .15},   {header : "操作",dataIndex : "caozuo",width : .10,renderer : function(value, p, record) {var orgid = record.data.orgid;var orgname = record.data.orgname;var qfbs = record.data.qfbs;var xtlb = record.data.xtlb;var qhdm = record.data.qhdm;var returnstr='&nbsp;&nbsp;&nbsp;&nbsp;'returnstr +='<a href="javascript:void(0)" οnclick="editOrg(\''+orgid+'\',\''+orgname+'\',\''+qfbs+'\',\''+xtlb+'\',\''+qhdm+'\')"><img src="../images/edit.gif" alt="查看编辑机构信息"/></a>';returnstr +='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'returnstr +='<a href="javascript:void(0)" ><img src="../images/delete.gif" οnclick="deleteOrg(\''+orgid+'\',\''+orgname+'\')" alt="撤销机构信息"/></a>';return returnstr;}}]);colsM.defaultSortable = true;resultStore = new Ext.data.Store({//url : 'searchOrg.action',url :'getSubOrganizationAction.action',remoteSort : true,listeners : {beforeload : {fn : function(thiz, options) {Ext.apply(thiz.baseParams, Ext.getCmp('in-query-form').form.getValues());}}},reader : new Ext.data.JsonReader({root : 'list',totalProperty : 'total'}, resultRecord)});var resultGridPane = new Ext.grid.GridPanel({// enableDragDrop : false,autoWidth : true,
//		doLayout : function() {
//			this.setSize(Ext.get(this.getEl().dom.parentNode).getSize(true));
//			Ext.grid.GridPanel.prototype.doLayout.call(this);
//		},enableColumnHide : true,// 是否显示列选择菜单tbar : [{text : '机构查询',icon : "../images/insp_sbook.gif",handler : function() {doSubmit();}},{text : '重置',icon : "../images/reload.png",handler : function() {var orgnameid = Ext.getCmp('orgnameid');orgnameid.setValue("");}},'-',{text : '增加机构',icon : "../images/create.gif",handler : function() {//parent.show("tab ", "测试Tab窗口", "");if(currentOrgId=='1'||parentNode.id=='1'){//显示添加事业单位窗口showAddShiyeWindow(qhlbn,xtlbn,currentOrgId,currentOrgName);}else if(currentOrgId=='0'||parentNode.id=='0'){//判断是否选择子节点,未选择 设置默认值//显示添加行政单位窗口showAddXingzhenWindow(qhlbn,xtlbn,currentOrgId,currentOrgName);}//显示机添加机构面板//showAddJigouWindow();}}],cm : colsM,store : resultStore,iconCls : 'icon-grid',stripeRows : true,loadMask : {msg : '正在加载数据,请稍侯……'},viewConfig : {sortAscText : '升序',sortDescText : '降序',columnsText : '显示列',forceFit : true},bbar : new Ext.PagingToolbar({pageSize : pageSize1,store : resultStore,displayInfo : true,displayMsg : '显示第 {0} 条到 {1} 条记录,一共 {2} 条',plugins : new Ext.ux.ProgressBarPager(),emptyMsg : "没有记录"}),layout : 'fit'// 表格内列内容填充满,按列头比例填充});resultGridPane.on('dblclick', function(object) {var record = this.getSelectionModel().getSelected()
//	showLiucheng(record.get('piid'))});// 搜索条件面板querFormPanel = new Ext.form.FormPanel({id : "in-query-form",frame : true,layout : "fit",labelWidth : 55,autoWidth : true,height : 50,keys : [{key : Ext.EventObject.ENTER,fn : doSubmit,scope : this}],items : [{layout : 'column',items : [{name:'bzlx',xtype : 'hidden',value:bzlx}, {columnWidth : .30,layout : 'form',labelWidth : 40,items : [qhlbcomb]}, {columnWidth : .3,layout : 'form',labelWidth : 60,items : [xtlbcomb]}, {columnWidth : .30,layout : 'form',labelWidth : 60,items : [{fieldLabel : "机构名称",xtype : "textfield",name : "orgname",id:"orgnameid",anchor : "95%"}]}]}]});	var panel = new Ext.Viewport({id : 'queryView',renderTo : document.body,frame : true,header : false,border : true,layout : 'border',items : [{id : 'QueryPanel',region : 'north',height : 40,items : [querFormPanel]},{region : "west",
//			title : "机构部门",width : 300,split : true,autoScroll:true,collapsible : true,titleCollapse : true,items : [treePanel]}, {id : 'resultPanel1',region : 'center',collapsible : false,margins : '5 0 5 5',cmargins : '5 5 5 5',bodyStyle : 'padding:1px;',split : false,resizeTabs:true,layout : 'fit',items : [resultGridPane]}]});});//编辑机构
function editOrg(orgid,orgname,qfbs,xtlb,qhdm){var url='';//机构区分标识 0 ,1   xtlb系统列表,qhdm区划代码// 这里这俩是 把 修改 url 改成了 showwindows() 原因 parent.show() 不好用..囧 //所以showShiyeGrouptabs.js和 showXingzhengGrouptabs.js有所改变if(qfbs=='0'){//url="showXingzhengGrouptabs.jsp?orgid="+orgid+"&orgname="+orgname+"&xtlb="+xtlb+"&qhdm="+qhdm;showXingzhengGrouptabs(orgid,orgname,qhdm);}else if(qfbs=='1'){//url="showShiyeGrouptabs.jsp?orgid="+orgid+"&orgname="+orgname+"&xtlb="+xtlb+"&qhdm="+qhdm;showShiyeGrouptabs(orgid,orgname,xtlb,qhdm);}//测试window.open(url);//parent.show(orgid, orgname, url);//测试parent.show('1', orgname, url);}
function deleteOrg(orgid,orgname){Ext.MessageBox.show({title:'撤销机构提示',msg: '你确定要撤销“'+orgname+'”吗?',buttons: Ext.MessageBox.YESNO,fn: function(btn){if(btn=="yes"){Ext.Ajax.timeout = 10000; // 10秒Ext.Ajax.request({url : 'shezhiJigouWuxiao.action',params : {'orgid' : orgid},method : 'POST',success : function(){//doSubmit();//成功之后刷新根节点refreshCurrentNode(0);resultStore.reload();},failure : function(result, request) {Ext.MessageBox.show({title : '错误',msg : '读取数据发生错误,请重试!',buttons : Ext.MessageBox.OK,icon : Ext.MessageBox.ERROR});}});}},//animEl: 'elId',icon: Ext.MessageBox.QUESTION});}function doSubmit() {querFormPanel.getForm().submit({url : 'searchOrg.action',//传递的参数params : 'start=0&limit=' + pageSize1,waitTitle : '请等待...',waitMsg : '正在查询机构信息信息...',success : function(form, action) {// resultStore.load();// resultStore.reload();resultStore.removeAll();resultStore.loadData(action.result);},failure : function(form, action) {Ext.Msg.alert('提示', '查询出现错误');}});
}
//显示添加机构窗口
function showAddJigouWindow(){//取出区划代码var qhdm=Ext.getCmp('qhlbcomb').getValue();//取出系统类别var xtlb=Ext.getCmp('xtlbcomb').getValue();if(bzlx=='0'){//如果编制类型是“0”,显示添加行政机构窗口showAddXingzhenWindow(qhdm,xtlb,-1,-1);resultStore.reload();}else{showAddShiyeWindow(qhdm,xtlb,-1,-1);resultStore.reload();}
}//************************************************************************************************
function requestDepInfo2(){//alert(currentDepId);Ext.QuickTips.init();// ???tips???Ext.form.Field.prototype.msgTarget = 'side';// ??????????????"qtip","title","under","side"//===Ajax??????=======================================================================Ext.Ajax.timeout = 10000; // 10??Ext.Ajax.request({url : '../jigouguanli/showDepartmentInfo.action',params : {'id' : currentDepId},method : 'POST',success : showDepInfo,failure : function(result, request) {Ext.MessageBox.show({title : '????',msg : '??????????!',buttons : Ext.MessageBox.OK,icon : Ext.MessageBox.ERROR});}});
}//增加部门???????
function addDepartment() {//alert("??????");if(validAddForm()){submitAddForm();}else{Ext.getCmp("fdepName").focus();}
}// ???????
function resetAddForm() {Ext.getCmp('fdepId').setValue("");Ext.getCmp('fdepName').setValue("");
}//刷新节点
function refreshCurrentNode(optr){if (optr == 0 || optr == 2){if (currentNode.isExpanded()){if (optr == 2 && currentNode.childNodes.length == 1) {parentNode.reload();} else currentNode.reload();}else{parentNode.reload();}} elsecurrentNode.reload();
}
//当点击可展开的条件的时候显示该子节点信息
//function getDepartment(id, name) {
//		 	var params = resultStore.baseParams;
//	     Ext.apply(params,{"orgid":id},{'name':name}); //	     resultStore.reload();	 	    
//}//******************************************************************************************************
ShowJiGouTree.action
package com.euler.services.impls.jigouguanli;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import com.euler.actions.jigouguanli.StructureTreeModel;
import com.euler.orm.Organization;
import com.euler.services.AbstractService;public class ShowJigouTreeImpl extends AbstractService {@Overridepublic Map execute(Map map) throws Exception {String orgid = (String) map.get("orgid");String qhdm = (String) map.get("qhdm");String xtlb = (String) map.get("xtlb");String bzlx = (String) map.get("bzlx");List resultList = new ArrayList();List paraList = new ArrayList();String orderby = "  order by jbgg,porgid,orderid ";String commonhql = null;// 建立子节点//0是行政 1是 事业//当是 事业的时候封闭 这里&&bzlx.equals("0")if (orgid.equals("0")) {commonhql = "from Organization where qhdm='" + qhdm+ "' and xtlb='" + xtlb+ "' and porgid='-1' and youxiao='1' and qfbs='0'";//当是行政和事业都执行}else if(orgid.equals("1")) {commonhql = "from Organization where qhdm='" + qhdm+ "' and xtlb='" + xtlb+ "' and porgid='-1' and youxiao='1' and qfbs='1'";//else 创建 相关子叶} else {/** Time:11.3.26 行政单位下设事业单位执行sql 建立叶子节点*/commonhql = "from Organization where porgid=? and youxiao='1' ";paraList.add(orgid);}List list = dao.query(commonhql + orderby, paraList.toArray());for (int i = 0; i < list.size(); i++) {Organization org = (Organization) list.get(i);// 判断是否有子叶String counthql="";if(orgid.equals("0")){counthql = "select count(orgid) from Organization where porgid=? and youxiao='1' and qfbs='0'";}else{counthql = "select count(orgid) from Organization where porgid=? and youxiao='1' and qfbs='1'";}int count = Integer.parseInt(dao.query(counthql, org.getOrgid()).get(0).toString());// 创建树模型结构StructureTreeModel model = new StructureTreeModel();model.setId(org.getOrgid());model.setText(org.getOrgname());// 如果是叶子都是2if (count == 0) {model.setLeaf(true);model.setType("2");model.setHref("");// model.setHref("javascript:getDepartment('"+org.getOrgid()+"','"+org.getOrgname()+"')");// model.setCls("folder");// 如果是子节点都是1} else {model.setLeaf(false);model.setType("1");// model.setHref("javascript:getDepartment('"+org.getOrgid()+"','"+org.getOrgname()+"')");// model.setCls("file");}resultList.add(model);}Map returnMap = new HashMap();returnMap.put("list", resultList);return returnMap;}
}


  相关解决方案