需求说明:
在bos界面新建了一个F7 带有分组的
waf2界面上实现这种效果
步骤:
1、
customF7=wafPromptSpecial_ExpenseType
2、
3、
4、
6、
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 parent;
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 parent;
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<String, Map<String, String>> 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<String, Map<String, String>> 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
备注:这样加的F7发现保存的时候数据没有保存上去,
8.5 8.6版本 js中这里做了调整
/*该函数用于当点击树的节点时,返回过滤条件,该方法由开发人员按自己需求进行覆盖
注意:选中某个节点时,会把 treeNode.id 传到后台,后台可以在 request.getParameter("parentId") 取到,所以后台想办法取得request即可
树 是异步加载的
*/
/* _getTreeNodeFilter: function(){
var selectedNodes = this.tree.wafTree('getSelectedNodes'),
ret = "";
if(selectedNodes.length>0){
var treeNode = selectedNodes[0];
ret = "treeid.id = '" + treeNode.id + "'";
// ret = treeNode = '" + treeNode.id + "' ;
// ret = "treeNode = '" + treeNode.id + "'";
}
//刚刚弹出F7时,没有选中的节点,所以会返回过滤条件为空,因此数据会全部加载
return ret;
}, */
_getSpecialFilter: function(){
var selectedNodes = this.tree.wafTree('getSelectedNodes');
var treeNode = selectedNodes[0];
if(!selectedNodes || selectedNodes.length < 1){
return null;
}
var ret=waf.parseSql.getFilter("treeid.id", "=", treeNode.id)
var obj={filterItems:ret};
return obj ;
}