2 changed files with 306 additions and 0 deletions
@ -0,0 +1,211 @@ |
|||||||
|
package apelet.association.plugin.member; |
||||||
|
|
||||||
|
import apelet.common.core.object.ObjectCollection; |
||||||
|
import apelet.common.core.object.ObjectValue; |
||||||
|
import apelet.common.generator.utils.OrmGenDataSourceUtil; |
||||||
|
import apelet.common.online.abstractplugin.ExecutePluginParent; |
||||||
|
import apelet.common.online.model.constant.AttributeEnum; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName: UnitNameChangeFormInitPlugin |
||||||
|
* @Author: huangdehua |
||||||
|
* @Date: 2026/5/9 |
||||||
|
* @Description: 入会申请与审核表单初始化插件(变更模式) |
||||||
|
* 如果是从"变更"按钮弹出的表单,则设置其他字段为只读,只有单位名称可编辑 |
||||||
|
*/ |
||||||
|
public class UnitNameChangeFormInitPlugin extends ExecutePluginParent { |
||||||
|
|
||||||
|
/** |
||||||
|
* 来源参数key - 单据ID |
||||||
|
*/ |
||||||
|
private static final String PARAM_BILL_ID = "sourceBillId"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 来源参数key - 单据编号 |
||||||
|
*/ |
||||||
|
private static final String PARAM_BILL_NUMBER = "sourceBillNumber"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 需要设置为只读的字段列表(除单位名称外) |
||||||
|
*/ |
||||||
|
private static final String[] READONLY_FIELDS = { |
||||||
|
"id", // 主键
|
||||||
|
"number", // 单据编号
|
||||||
|
"billstatus", // 单据状态
|
||||||
|
"membershipMangerId",// 会员负责人
|
||||||
|
"unitName", // 单位名称
|
||||||
|
"natureUnit", // 单位性质
|
||||||
|
"menbershipAttributes",// 会员属性
|
||||||
|
"scopeBusiness", // 业务经营范围
|
||||||
|
"membershipType", // 会员类型
|
||||||
|
"businessRegistNumber",// 工商注册号
|
||||||
|
"registCapital", // 注册资金
|
||||||
|
"registTime", // 注册时间
|
||||||
|
"bankReceiptV", // 银行收款凭证号
|
||||||
|
"companyAddress", // 企业地址
|
||||||
|
"history", // 是否历史
|
||||||
|
"versionNumber", // 版本号
|
||||||
|
"membership_apply_entry", |
||||||
|
"table1777360622546" |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* 允许在变更模式下编辑的字段列表(单位名称相关) |
||||||
|
*/ |
||||||
|
private static final String[] EDITABLE_UNIT_NAME_FIELDS = { |
||||||
|
"unitName", |
||||||
|
"unitname" |
||||||
|
}; |
||||||
|
|
||||||
|
@Override |
||||||
|
public void formCreated(String widgetVariableName, ObjectValue objectValue) { |
||||||
|
super.formCreated(widgetVariableName, objectValue); |
||||||
|
|
||||||
|
// 获取源单据ID
|
||||||
|
String sourceBillId = getSourceBillId(objectValue); |
||||||
|
String sourceBillNumber = getSourceBillNumber(objectValue); |
||||||
|
|
||||||
|
// 如果没有源单据ID,说明不是变更操作,正常返回
|
||||||
|
if (sourceBillId == null || sourceBillId.isEmpty()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 这是从"变更"按钮弹出的表单
|
||||||
|
// 1. 查询源单据数据并填充到当前表单
|
||||||
|
fillSourceBillData(objectValue, sourceBillId, sourceBillNumber); |
||||||
|
|
||||||
|
// 2. 设置其他字段为只读,只有单位名称可编辑
|
||||||
|
setFieldsReadonly(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 从ObjectValue中获取源单据ID |
||||||
|
* 从 eventparams 中获取 |
||||||
|
*/ |
||||||
|
private String getSourceBillId(ObjectValue objectValue) { |
||||||
|
Object eventparams = objectValue.get("eventparams"); |
||||||
|
if (eventparams instanceof JSONObject){ |
||||||
|
return ((JSONObject) eventparams).getString(PARAM_BILL_ID); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 从ObjectValue中获取源单据编号 |
||||||
|
* 从 eventparams 中获取 |
||||||
|
*/ |
||||||
|
private String getSourceBillNumber(ObjectValue objectValue) { |
||||||
|
Object eventparams = objectValue.get("eventparams"); |
||||||
|
if (eventparams instanceof JSONObject){ |
||||||
|
return ((JSONObject) eventparams).getString(PARAM_BILL_NUMBER); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置字段为只读 |
||||||
|
* 只有单位名称字段可编辑,其他字段全部只读 |
||||||
|
*/ |
||||||
|
private void setFieldsReadonly() { |
||||||
|
// 设置所有需要只读的字段为禁用(不可编辑)
|
||||||
|
for (String field : READONLY_FIELDS) { |
||||||
|
try { |
||||||
|
this.setWidgetAttribute(field, AttributeEnum.DISABLED, true); |
||||||
|
} catch (Exception e) { |
||||||
|
// 字段可能不存在,忽略异常
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 确保单位名称字段可编辑
|
||||||
|
for (String field : EDITABLE_UNIT_NAME_FIELDS) { |
||||||
|
try { |
||||||
|
this.setWidgetAttribute(field, AttributeEnum.DISABLED, false); |
||||||
|
this.setWidgetAttribute(field, AttributeEnum.SHOW, true); |
||||||
|
} catch (Exception e) { |
||||||
|
// 字段可能不存在,忽略异常
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 禁用子表
|
||||||
|
try { |
||||||
|
this.setWidgetAttribute("membership_apply_entry", AttributeEnum.DISABLED, true); |
||||||
|
this.setWidgetAttribute("membershipApplyEntry", AttributeEnum.DISABLED, true); |
||||||
|
this.setWidgetAttribute("table1777360622546", AttributeEnum.DISABLED, true); |
||||||
|
} catch (Exception e) { |
||||||
|
// 子表可能不存在,忽略异常
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取源单据数据并填充到当前表单 |
||||||
|
* |
||||||
|
* @param objectValue 当前表单数据对象 |
||||||
|
* @param sourceBillId 源单据ID |
||||||
|
* @param sourceBillNumber 源单据编号 |
||||||
|
*/ |
||||||
|
private void fillSourceBillData(ObjectValue objectValue, String sourceBillId, String sourceBillNumber) { |
||||||
|
try { |
||||||
|
// 从数据库查询源单据数据
|
||||||
|
apelet.common.generator.utils.OrmGenDataSourceUtil ormUtil = (OrmGenDataSourceUtil) ormGenDataSourceUtil(); |
||||||
|
if (ormUtil == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
apelet.common.orm.impl.Filter filter = new apelet.common.orm.impl.Filter(); |
||||||
|
if (sourceBillId != null && !sourceBillId.isEmpty()) { |
||||||
|
filter.add(new apelet.common.orm.impl.FilterItem("id", "=", sourceBillId)); |
||||||
|
} else if (sourceBillNumber != null && !sourceBillNumber.isEmpty()) { |
||||||
|
filter.add(new apelet.common.orm.impl.FilterItem("number", "=", sourceBillNumber)); |
||||||
|
} else { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
ObjectCollection sourceCollection = ormUtil.query("membership_apply", filter, null); |
||||||
|
if (sourceCollection == null || sourceCollection.isEmpty()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
ObjectValue sourceBill = sourceCollection.getObject(0); |
||||||
|
if (sourceBill == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 将源单据的数据填充到当前表单(除了ID和状态字段)
|
||||||
|
Map<String, Object> values = sourceBill.getValues(); |
||||||
|
for (Map.Entry<String, Object> entry : values.entrySet()) { |
||||||
|
String key = entry.getKey(); |
||||||
|
Object value = entry.getValue(); |
||||||
|
|
||||||
|
// 跳过ID和状态字段,这些字段由系统处理
|
||||||
|
if ("id".equals(key) || "billstatus".equals(key) || |
||||||
|
"is_history".equals(key) || "version_number".equals(key) || |
||||||
|
"isHistory".equals(key) || "versionNumber".equals(key)) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
// 设置字段值到ObjectValue
|
||||||
|
if (value != null) { |
||||||
|
objectValue.put(key, value); |
||||||
|
} |
||||||
|
|
||||||
|
// 设置字段值到表单控件
|
||||||
|
try { |
||||||
|
this.setWidgetAttribute(key, AttributeEnum.VALUE_CHANGE, value); |
||||||
|
} catch (Exception e) { |
||||||
|
// 字段可能不存在,忽略异常
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 保存源单据ID作为标识(用于后续业务逻辑)
|
||||||
|
objectValue.put(PARAM_BILL_ID, sourceBillId); |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,95 @@ |
|||||||
|
package apelet.association.plugin.member; |
||||||
|
|
||||||
|
import apelet.common.core.object.ObjectValue; |
||||||
|
import apelet.common.online.abstractplugin.ExecutePluginParent; |
||||||
|
import apelet.common.online.model.ShowParameter; |
||||||
|
import apelet.common.online.model.constant.ShowTypeEnum; |
||||||
|
import apelet.common.online.model.constant.ViewStatus; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName: UnitNameChangePopupPlugin |
||||||
|
* @Author: huangdehua |
||||||
|
* @Date: 2026/5/9 |
||||||
|
* @Description: 入会申请与审核 - 变更单位名称弹窗插件 |
||||||
|
* 点击"变更"按钮时,弹出入会申请表单,并将列表中选中行数据带入弹窗中 |
||||||
|
*/ |
||||||
|
public class UnitNameChangePopupPlugin extends ExecutePluginParent { |
||||||
|
|
||||||
|
/** |
||||||
|
* 目标表单ID - membership_apply 表单在平台中的表单ID |
||||||
|
*/ |
||||||
|
private static final String TARGET_FORM_ID = "2048951917157027840"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 触发按钮的标识 - 对应表单上按钮的 key/标识 |
||||||
|
*/ |
||||||
|
private static final String BUTTON_KEY = "变更"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 列表页面中表格控件的变量名/key |
||||||
|
*/ |
||||||
|
private static final String TABLE_WIDGET_KEY = "table1777354992881"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 传递到弹窗的参数key - 单据ID |
||||||
|
*/ |
||||||
|
private static final String PARAM_BILL_ID = "sourceBillId"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 传递到弹窗的参数key - 单据编号 |
||||||
|
*/ |
||||||
|
private static final String PARAM_BILL_NUMBER = "sourceBillNumber"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 按钮点击事件(列表按钮) |
||||||
|
* 点击"变更"按钮时,通过 getSelectData 获取列表中选中行的单据数据, |
||||||
|
* 以弹窗方式打开入会申请表单,并将选中行数据带入 |
||||||
|
* |
||||||
|
* @param buttonKey 按钮标识 |
||||||
|
* @param objectValue 列表按钮事件数据对象(非表单数据) |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void buttonTriggered(String buttonKey, ObjectValue objectValue) { |
||||||
|
// 仅响应"变更"按钮的点击事件
|
||||||
|
if (!BUTTON_KEY.equals(buttonKey)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 【列表场景】通过框架提供的 getSelectData 方法获取选中/点击行的数据
|
||||||
|
// objectValue 中的 rowdata 包含列表所有行,getSelectData 会找到
|
||||||
|
// 标记了 isClick=true(点击行)或 isSelect=true(勾选行)的那一行
|
||||||
|
Map<String, Object> selectedRow = getSelectData(objectValue, TABLE_WIDGET_KEY); |
||||||
|
|
||||||
|
if (selectedRow == null) { |
||||||
|
showWarningMessage("请先在列表中选中一条单据"); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 从选中行中获取单据ID和编号
|
||||||
|
String billId = selectedRow.get("id") != null ? selectedRow.get("id").toString() : ""; |
||||||
|
String billNumber = selectedRow.get("number") != null ? selectedRow.get("number").toString() : ""; |
||||||
|
|
||||||
|
if (billId.isEmpty()) { |
||||||
|
showWarningMessage("选中的单据缺少ID信息,请重新选择"); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// 调用 showForm 打开入会申请表单(新建空表单,不加载任何已有记录)
|
||||||
|
ShowParameter showParameter = new ShowParameter(); |
||||||
|
showParameter.setFormId(TARGET_FORM_ID); |
||||||
|
showParameter.setHowType(ShowTypeEnum.OPEN_ONLINE_MODAL); |
||||||
|
showParameter.setStatus(ViewStatus.EDIT); |
||||||
|
showParameter.setPkId(null); // 明确指定为空,表示新建表单而非打开已有单据
|
||||||
|
|
||||||
|
// 设置自定义参数,用于在目标表单中获取源单据数据
|
||||||
|
Map<String, Object> customParam = new HashMap<>(); |
||||||
|
customParam.put(PARAM_BILL_ID, billId); |
||||||
|
customParam.put(PARAM_BILL_NUMBER, billNumber); |
||||||
|
showParameter.setCustomParam(customParam); |
||||||
|
|
||||||
|
super.showForm(showParameter); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue