Waf2自定义F7左树右表的实现

需求说明:

在bos界面新建了一个F7 带有分组的

Waf2自定义F7左树右表的实现_第1张图片

waf2界面上实现这种效果

Waf2自定义F7左树右表的实现_第2张图片

 

步骤:

1、Waf2自定义F7左树右表的实现_第3张图片

customF7=wafPromptSpecial_ExpenseType

2、

Waf2自定义F7左树右表的实现_第4张图片

3、

Waf2自定义F7左树右表的实现_第5张图片

4、

Waf2自定义F7左树右表的实现_第6张图片

6、

Waf2自定义F7左树右表的实现_第7张图片

8、后台代码

package com.kingdee.eas.custom;

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.RequestContext;
import com.kingdee.bos.eventbus.event.action.IActionEventHandler;
import com.kingdee.bos.eventbus.event.action.KDActionEvent;
import com.kingdee.bos.webframework.context.WafContext;
import com.kingdee.bos.webframework.dynamic.handler.AbstractWebEventHandler;
import com.kingdee.bos.webframework.exception.WafException;
import com.kingdee.bos.webframework.json.JSONUtils;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.util.StringUtils;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;

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");
		    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();
		    }
		    JSONUtils.SUCCESS(jsonArr);
		  }

	
	
	  protected Map> getExpenseTypefl(String parentid) throws BOSException, EASBizException
	  {
	    Map expenseTypes = new HashMap();
	    Context ctx = WafContext.getInstance().getContext();
	    String sql = " select  fcontrolunitid  companyId,  fid , fnumber,fname_l2  fname  , fisleaf, fparentid  from t_Krw_Costbasetree   where fparentid='"+parentid+"' ";
	    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> getExpenseType() throws BOSException, EASBizException
		  {
		    Map expenseTypes = new HashMap();
		    Context ctx = WafContext.getInstance().getContext();
		    String sql = " select  fcontrolunitid  companyId,  fid , fnumber,fname_l2  fname  , fisleaf, fparentid  from t_Krw_Costbasetree   where fparentid is null ";
		    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;
		  }

		  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);
		  }
	 
}

9、点击组别过滤query

Waf2自定义F7左树右表的实现_第8张图片

备注:这样加的F7发现保存的时候数据没有保存上去,

Waf2自定义F7左树右表的实现_第9张图片

你可能感兴趣的:(金蝶waf2)