树分组过滤实现

树节点展示样式高度设置

 pageOpenAfter:function(e){
            waf(".ztree").css("height", "650px");   //树组件样式设置:高度设置为650px
        }

方式一: js 中写过滤事件

       //页面渲染前事件
		beforePageXuanRan:function(e){
        _self.setInitComponentCallBack(function(type,option,el){ //组件初始化回调事件
            if(option.id == 'tree'){ //tree 为树组件id
                var controlUnitId =waf.getContext().controlUnit.id;
                if(controlUnitId!="00000000-0000-0000-0000-000000000000CCE7AED4"){
                    var a = waf.parseSql.getFilter("CU.id", "=",controlUnitId);
                    option.filterItems =a
                }
            }
           });
        }

方式二: handler 构建json树数数据返回

package com.kingdee.eas.assetmamage.commonmz;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.eventbus.event.action.KDActionEvent;
import com.kingdee.bos.webframework.exception.WafException;
import com.kingdee.bos.webframework.json.JSONUtils;
import com.kingdee.bos.webframework.context.WafContext;
import com.kingdee.bos.webframework.dynamic.handler.AbstractWebEventHandler;
import com.kingdee.bos.eventbus.event.action.IActionEventHandler;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.basedata.org.CtrlUnitInfo;
import com.kingdee.eas.basedata.org.OrgType;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.util.StringUtils;

public class GetChildNodesHandler extends AbstractWebEventHandler implements IActionEventHandler {
	
	public void onAction(KDActionEvent event) throws WafException,BOSException {
	    HttpServletRequest request = event.getReqeustContext().getHttpServletRequest();
	    String parentId = request.getParameter("parentId");//  F7 左树右表发送的参数
	    String level = request.getParameter("level"); // 房源树形基础资料发送的参数
	    String uipk = request.getParameter("uipk");   // 房源树形基础资料发送的参数
	    String parentId_base = request.getParameter("id");   // 房源树形基础资料发送的参数--父节点id
	    if(uipk.equals("com.kingdee.eas.assetmamage.operationmanage.basedata.CRoomList")){
	    	 JSONArray roomTree = roomTree(  parentId_base  );
	    	 writeJson(JSONUtils.convertObjectToJson(roomTree));
	     }else{
	    	  JSONUtils.SUCCESS(roomTree_F7(  parentId  ));
	    	 // writeJson(JSONUtils.convertObjectToJson(roomTree_F7(  parentId  )));
	     }
	}
	
	/**
	 *  
	 * @param parentid
	 * @return
	 * @throws BOSException
	 * @throws EASBizException
	 */
	 protected Map<String, Map<String, String>> getExpenseTypefl(String parentid) throws BOSException, EASBizException
	  {
	    Map expenseTypes = new HashMap();
	    Context ctx = WafContext.getInstance().getContext();
	    CtrlUnitInfo companyOrgUnitInfo = (CtrlUnitInfo) ctx.get(OrgType.ControlUnit);
	    String sql = "";
	     if(companyOrgUnitInfo.getId().toString().equals("00000000-0000-0000-0000-000000000000CCE7AED4")){
		  sql = " select  fcontrolunitid  companyId,  fid , fnumber,fname_l2  fname  , fisleaf, fparentid  from T_BAS_RoomTREE   where fparentid='"+parentid+"'  ";
	     }else{
	 	   sql = " select  fcontrolunitid  companyId,  fid , fnumber,fname_l2  fname  , fisleaf, fparentid  from T_BAS_RoomTREE   where fparentid='"+parentid+"'  and  fcontrolunitid='"+companyOrgUnitInfo.getId()+"'   ";
	     }
	    IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
	    try
	    {
	      while (rowSet.next()) {
	        Map expenseType = new HashMap();
	        String expenseTypeId = (String)rowSet.getObject("fid");
	        expenseType.put("id", expenseTypeId);
	        expenseType.put("name", (String)rowSet.getObject("fname"));
	        expenseType.put("number", (String)rowSet.getObject("fnumber"));
	        expenseType.put("fparentid", rowSet.getObject("fparentid"));
	        expenseType.put("fisleaf", rowSet.getObject("fisleaf"));
	        expenseType.put("companyId", rowSet.getObject("companyId"));
	        expenseTypes.put(expenseTypeId, expenseType);
	      }
	    } catch (SQLException localSQLException) {
	    }
	    return expenseTypes;
	  }
	 
	 
 

		  protected Map<String, Map<String, String>> getExpenseType() throws BOSException, EASBizException
		  {
		   
			  
		    Map expenseTypes = new HashMap();
		    Context ctx = WafContext.getInstance().getContext();
		    CtrlUnitInfo companyOrgUnitInfo = (CtrlUnitInfo) ctx.get(OrgType.ControlUnit);
		    String sql = "";
		     if(companyOrgUnitInfo.getId().toString().equals("00000000-0000-0000-0000-000000000000CCE7AED4")){
			  sql = " select  fcontrolunitid  companyId,  fid , fnumber  ,fname_l2  fname  , fisleaf, fparentid  from T_BAS_RoomTREE   where fparentid is null    ";
		     }else{
		       sql = " select  fcontrolunitid  companyId,  fid , fnumber  ,fname_l2  fname  , fisleaf, fparentid  from T_BAS_RoomTREE   where fparentid is null and fcontrolunitid='"+companyOrgUnitInfo.getId()+"'    ";
		     }
		    IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
		    try
		    {
		      while (rowSet.next()) {
		        Map expenseType = new HashMap();
		        String expenseTypeId = (String)rowSet.getObject("fid");
		        expenseType.put("id", expenseTypeId);
		        expenseType.put("name", (String)rowSet.getObject("fname"));
		        expenseType.put("number", (String)rowSet.getObject("fnumber"));
		        expenseType.put("fparentid", rowSet.getObject("fparentid"));
		        expenseType.put("fisleaf", rowSet.getObject("fisleaf"));
		        expenseType.put("companyId", rowSet.getObject("companyId"));
		        expenseTypes.put(expenseTypeId, expenseType);
		      }
		    } catch (SQLException localSQLException) {
		    }
		    return expenseTypes;
		  }

		  
		  
		  /**
		   * F7 左树右表用
		   * @param jsonArr
		   * @param id
		   * @param name
		   * @param parentId
		   * @param isLeaf
		   * @param companyId
		   * @param number
		   */
		  private void addNode(JSONArray jsonArr, String id, String name, String parentId, Boolean isLeaf,String companyId,String number)
		  {
		    JSONObject node = new JSONObject();
		    Map dataMap = new HashMap();
		    dataMap.put("id", id);
		    dataMap.put("number", number);
		    dataMap.put("companyId", companyId);
		    node.put("id", id);
		    node.put("name", name);
		    node.put("pId", parentId);
		    node.put("isLeaf", Boolean.valueOf(isLeaf.booleanValue()));
		    node.put("data", dataMap);
		    jsonArr.add(node);
		  }
	
	
	
		  
		  
		  /**
		   * 房源基础资料用 增加节点方法
		   * @param jsonArr
		   * @param id
		   * @param name
		   * @param parentId
		   * @param isLeaf
		   * @param companyId
		   * @param number
		   */
		  private void addNode_room(JSONArray jsonArr_node,   JSONObject  parentNode , String id, String name, String parentId, Boolean isLeaf,String companyId,String number)
		  {
		    JSONObject node = new JSONObject();
		    Map dataMap = new HashMap();
		    dataMap.put("id", id);
		    dataMap.put("number", number);
		    dataMap.put("companyId", companyId);
		    node.put("id", id);
		    node.put("name", name);
		    node.put("number", number);
		    node.put("pId", parentId);
		    node.put("isParent", !Boolean.valueOf(isLeaf.booleanValue()));
		    node.put("open",  !Boolean.valueOf(isLeaf.booleanValue()));
		    node.put("propMap", dataMap);
		    jsonArr_node.add(node);
		    
		  }
		  
		  
		  
		  
		  
	/**
	 * F7 房源基础资料左树右表	  
	 * @param parentId_base
	 * @return
	 */
	  public   JSONArray  roomTree_F7(  String  parentId  ){

    	  JSONArray jsonArr = new JSONArray(36);
  	     try {
  	      if (StringUtils.isEmpty(parentId)) {
  	       // addNode(jsonArr, "root", "费用类别", null, Boolean.valueOf(false));
  	    	 JSONObject node = new JSONObject();
  	    	 node.put("name", "房源分组")  ;
  	    	 node.put("id", "root")  ;
  	    	 node.put("open", "true")  ;
  	    	 jsonArr.add(node);
  	        Map provinces = getExpenseType();
  	        Set keys = provinces.keySet();
  	        Iterator iter = keys.iterator();
  	        while (iter.hasNext()) {
  	          String id = (String)iter.next();
  	          Map map = (Map)provinces.get(id);
  	          if (map.get("id") != null){
  	        	  boolean isLeaf=false;
  	        	  if(map.get("fisleaf").toString().equals("1")){
  	        		  isLeaf=true;  //是  1 的话  为子节点
  	        	  }
  	          String  parentid="root"; 
  	          if(null!=map.get("fparentid")){
  	        	  parentid=map.get("fparentid").toString();
  	          }	
  	          String number=map.get("number").toString();
  	          String companyId=map.get("companyId").toString();  
  	          addNode(jsonArr, (String)map.get("id"), 
  			  (String)map.get("name"), parentid, isLeaf,companyId ,number);
  	          }
  	          
  	        }
  	      }else{
  	    	 //如果点击了父类
  	    	   Map provinces = getExpenseTypefl(parentId);
  		        Set keys = provinces.keySet();
  		        Iterator iter = keys.iterator();
  		        while (iter.hasNext()) {
  		          String id = (String)iter.next();
  		          Map map = (Map)provinces.get(id);
  		          if (map.get("id") != null){
  		        	  boolean isLeaf=false;
  		        	  if(map.get("fisleaf").toString().equals("1")){
  		        		  isLeaf=true;  //是  1 的话  为子节点
  		        	  }
  		        	String  parentid="root"; 
  		          if(null!=map.get("fparentid")){
  		        	  parentid=map.get("fparentid").toString();
  		          }	
  		          String number=map.get("number").toString();
  		          String companyId=map.get("companyId").toString();  
  		        	  addNode(jsonArr, (String)map.get("id"), 
  				      (String)map.get("name"), parentid, isLeaf,companyId ,number);
  		          }
  		          
  		        }
  	      }
  	    } catch (Exception e) {
  	      e.printStackTrace();
  	    }
  	      return   jsonArr ;
			  
	  }  
		  
		  
			 
		  
		  
		  
	
	 /**
	  *  房源基础资料树列表
	  */
	public   JSONArray  roomTree(  String  parentId_base  ){
  	  JSONArray jsonArr = new JSONArray(36);
	     try {
	      if (StringUtils.isEmpty(parentId_base)) {
	       // addNode(jsonArr, "root", "费用类别", null, Boolean.valueOf(false));
	    	 JSONObject parentNode = new JSONObject();
	    	 parentNode.put("name", "房源分组")  ;
	    	 parentNode.put("id", "rootId")  ;
	    	 parentNode.put("pId", null)  ;
	    	 parentNode.put("number", "rootNumber")  ;
	    	 parentNode.put("open", true)  ;
	    	 parentNode.put("isParent", false)  ;
	    	 parentNode.put("parentId", null);
	    	
	        JSONArray jsonArr_node = new JSONArray(36);
	        Map provinces = getExpenseType();    //查找 所有父节点
	        Set keys = provinces.keySet();
	        Iterator iter = keys.iterator();
	        while (iter.hasNext()) {
	          String id = (String)iter.next();
	          Map map = (Map)provinces.get(id);
	          if (map.get("id") != null){
	        	  boolean isLeaf=false;
	        	  if(map.get("fisleaf").toString().equals("1")){
	        		  isLeaf=true;  //是  1 的话  为子节点
	        	  }
	          String  parentid=null; 
	          if(null!=map.get("fparentid")){
	        	  parentid=map.get("fparentid").toString();
	          }	
	          String number=map.get("number").toString();
	          String companyId=map.get("companyId").toString();  
	          addNode_room( jsonArr_node ,  parentNode, (String)map.get("id"), (String)map.get("name"), parentid, isLeaf,companyId ,number);
	          }
	        }
	        parentNode.put("children", jsonArr_node);
	        jsonArr.add(parentNode);
	      }else{
	    	  
	    	   //如果点击了父类
	    	   JSONArray jsonArr_node = new JSONArray(36);
	    	    Map provinces = getExpenseTypefl(parentId_base);
		        Set keys = provinces.keySet();
		        Iterator iter = keys.iterator();
		        while (iter.hasNext()) {
		          String id = (String)iter.next();
		          Map map = (Map)provinces.get(id);
		          if (map.get("id") != null){
		        	  boolean isLeaf=false;
		        	  if(map.get("fisleaf").toString().equals("1")){
		        		  isLeaf=true;  //是  1 的话  为子节点
		        	  }
		        	String  parentid="root"; 
		          if(null!=map.get("fparentid")){
		        	  parentid=map.get("fparentid").toString();
		          }	
		          String number=map.get("number").toString();
		          String companyId=map.get("companyId").toString();  
		          addNode_room(jsonArr_node ,  null,  (String)map.get("id"), (String)map.get("name"), parentid, isLeaf,companyId ,number);
		          }
		          
		        }
		        return jsonArr_node;
	      }
	    } catch (Exception e) {
	      e.printStackTrace();
	    }
	    return jsonArr;
	 
	}
	   
	
 	private static void writeJson(String json) throws WafException {
		ServletResponse response = WafContext.getInstance().getResponse();
		response.setContentType("application/json;charset=UTF-8");
		PrintWriter pw;
		try {
			pw = response.getWriter();
		} catch (IOException e) {
			throw new WafException(
					"An exception happend on \"response.getWriter()\" ");
		}

		if (json == null)
			return;
		pw.write(json);
		pw.flush();
	}
	 
	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值