NC Cloud参照过滤
在业务进行过程中,二开的单据需要我们自行设置参照过滤,本文详细讲解。
单表、主子表查询区过滤
举例:查询区的银行账户需要根据已选择的财务组织进行过滤,更改财务组织时清空已选择的银行账户。
-
首先,更改财务组织时清空已选择的银行账户,需要用到表头的编辑后事件,就要看创建查询区时是否创建此事件,未创建的话则自行创建。
- 找到页面的入口:
-
单表为mian/index.js
-
主子表为list/index.js
-
找到NCCreateSearch方法
{NCCreateSearch(LIST.search_id, { clickSearchBtn: this.clickSearchBtn, onAfterEvent: this.onAfterEvent })}
-
其中的onAfterEvent就是编辑后事件的方法注册
onAfterEvent = (key, value, moduleId) => { if (key === 'pk_org' && moduleId === LIST.search_id) { this.props.search.setSearchValByField(moduleId, 'pk_bankacc', { value: null } ); } }
这样就完成了这一点需求!!!
-
- 找到页面的入口:
-
查询区的银行账户需要根据已选择的财务组织进行过滤。
-
我们要知道参照过滤,需要在列表页面模板渲染时就将过滤方式设置好。
-
查找单表页面入库mian/index.js
-
查找主子表页面入口list/index.js
-
在页面中查找initTemplate方法入库
-
在initTemplate方法中会注册modifierMeta方法,在这个方法中进行加工meta
-
pk_org为页面其它输入框输入的值,也可以是dbilldate,controlorg,accattribute等其它任意字段
-
GridRefActionExt为参照过滤属性
不同的参照类型对应不同的过滤属性
TreeRefActionExt(树型参照后端自定义过滤扩展属性)
GridRefActionExt(表型参照后端自定义过滤扩展属性)
-
TreeGridActionExt(树表参照后端自定义过滤扩展属性)
function modifierMeta(props, meta) { meta[searchid].items.find(item => item.attrcode === 'pk_oppacount').queryCondition = () => { return { // AppCode : props.getSearchParam('c'), pk_org : props.search.getSearchValByField(searchid, 'pk_org').value.firstvalue, GridRefActionExt: "nccloud.web.tmpub.filter.AccountOrg4BankPermissionFilter"//后台逻辑处理类路径 } } ...... }
-
-
在后端代码中对查询过滤逻辑进行处理,即编写nccloud.web.tmpub.filter.AccountOrg4BankPermissionFilter类。
该类在src/client下,出的补丁放在home\hotwebs\nccloud\WEB-INF\classes下
package nccloud.web.tmpub.filter; import nc.vo.tmpub.util.SqlUtil; import nc.vo.tmpub.util.StringUtil; import nccloud.framework.web.processor.IRefSqlBuilder; import nccloud.framework.web.processor.refgrid.RefQueryInfo; import nccloud.framework.web.ui.meta.RefMeta; import nccloud.pubitf.platform.db.SqlParameterCollection; public class AccountOrg4BankPermissionFilter implements IRefSqlBuilder { @Override public String getExtraSql(RefQueryInfo para, RefMeta meta) { // 添加查询条件 StringBuilder returnSql = new StringBuilder(); String pk_org = para.getQueryCondition().get("pk_org"); if (!StringUtil.isNull(pk_org)) { String[] pk_orgs = pk_org.split(","); if (pk_orgs != null && pk_orgs.length > 0) { returnSql.append(" and pk_bankaccbas in (select pk_bankaccbas from bd_bankaccbas where ") .append(SqlUtil.buildSqlForIn("controlorg", pk_orgs)).append(")");//通过银行账户-核算归属组织进行过滤 } } return returnSql.toString(); } @Override public SqlParameterCollection getExtraSqlParameter(RefQueryInfo para, RefMeta meta) { return null; } @Override public String getOrderSql(RefQueryInfo para, RefMeta meta) { return null; } }
-
报表查询区过滤
报表发布后,如果需要修改,可以申请uap/report/default/simple/index.js的源码,然后将源码复制一份,比如说uap/report/default/example/index.js,然后将应用注册页面地址由/nccloud/resources/uap/report/default/simple/index.html改为/nccloud/resources/uap/report/default/example/index.html,这样我们就可以针对这个报表做定制修改。
-
查询区参照过滤需要在index.js中,找到报表初始化加载处SimpleReport,修改其中的disposeSearch==即可。
<SimpleReport getRowData={this.getRowData} getSelectRowData={this.getSelectRowData} CreateNewSearchArea={this.CreateNewSearchArea.bind(this)} setDefaultVal={this.setDefaultVal.bind(this)} disposeSearch={this.disposeSearch.bind(this)} />
disposeSearch(meta, props) { // 参照过滤 let items = meta['light_report'].items; items.forEach((item) => { if (item.attrcode == 'pk_org') { item.isMultiSelectedEnabled = true; //财务组织多选 item.isTreelazyLoad = false; item.queryCondition = () => { return { funcode: props.getSearchParam('c'),//appcode获取 TreeRefActionExt: 'nccloud.web.tmpub.filter.FinanceOrgPermissionFilter' }; }; } }); return meta; // 处理后的过滤参照返回给查询区模板 }
-
至于查询区参照过滤值得获取和后端过滤逻辑业务处理类则和单表查询过滤的处理方式一致。
单表表格区过滤
和单表查询区过滤一样,是在modifierMeta方法中进行设置。
/**
* 加工meta
* @param {*} props
* @param {*} meta
*/
function modifierMeta(props, meta) {
meta[gridid].items = meta[gridid].items.map((item, key) => {
if (item.attrcode == 'cashaccount') {
item.queryCondition = (param) => {
let pk_org = props.editTable.getValByKeyAndIndex(gridid, props.editTable.getClickRowIndex(gridid).index, 'pk_org').value;
return {
pk_org: pk_org ? pk_org : null
};
};
}
return item;
});
return meta;
}
主子表表格区过滤
-
表头表体均可在modifierMeta进行处理
function modifierMeta(props, meta) { //表头参照过滤 meta[CARD.form_id].items.map(item => { if (item.attrcode === FIELD.org) { //财务组织 item.queryCondition = () => { return { funcode: props.getSearchParam('c')//appcode获取 }; }; } }); //表体参照过滤 meta[CARD.table_code].items.map(item => { if (item.attrcode === FIELD.org) { //财务组织 item.queryCondition = () => { return { funcode: props.getSearchParam('c')//appcode获取 }; }; } }); return meta; }
-
表头还可以在beforeHeadEvent进行处理
import { CARD } from "../../constant"; /** * @description: 表头编辑前事件 * @param: moduleId 区域编码 * @param: key 当前字段编码 * @return: 布尔 true表示可编辑 */ export function beforeHeadEvent(props, moduleId, key, value, data) { // 后面都是为参照做的修改 let meta = props.meta.getMeta(); meta[CARD.form_id].items.map((item) => { var attrcode = item.attrcode; if (attrcode == key) { switch (attrcode) { case 'pk_dept': item.queryCondition = () => { return { pk_org: props.form.getFormItemsValue(moduleId, 'pk_org') ? props.form.getFormItemsValue(moduleId, 'pk_org').value : null }; }; break; default: break; } } }); props.meta.setMeta(meta); // 默认返回true return true; }
-
表体还可以在beforeTableEvent进行处理
import { CARD } from "../../constant"; /** * @description: 表体编辑前事件 * @param: moduleId 区域编码 * @param: key 当前字段编码 * @return: 布尔 true表示可编辑 */ export function beforeTableEvent(props, moduleId, key, value, index, record, status) { // 添加自定义档案参照过滤 let meta = props.meta.getMeta(); meta[moduleId].items.map((item) => { // item.isShowUnit = false; // item.isShowDisabledData = false; var attrcode = item.attrcode; if (attrcode == key) { if (attrcode == 'pk_costpart') { props.cardTable.setQueryCondition(moduleId, { [key]: () => { return { pk_org: props.form.getFormItemsValue(CARD.form_id, 'pk_org') ? props.form.getFormItemsValue(CARD.form_id, 'pk_org').value : null, pk_defdoclist: '1001X110000000007JQJ' }; } }); }else if (attrcode.startsWith('def')) { props.cardTable.setQueryCondition(moduleId, { [key]: () => { return { pk_org: props.form.getFormItemsValue(CARD.form_id, 'pk_org') ? props.form.getFormItemsValue(CARD.form_id, 'pk_org').value : null }; } }); } } }); props.meta.setMeta(meta); // 标准返回值true return true; }