修复配送订单创建方动态联动
This commit is contained in:
@@ -39,6 +39,14 @@ export type ResourceRelationLinkage = {
|
||||
parentChangeMessage?: string;
|
||||
};
|
||||
|
||||
/** 根据父字段值选择关系资源,用于创建方等多类型业务主体。 */
|
||||
export type ResourceDynamicRelation = {
|
||||
parentKey: string;
|
||||
parentLabel: string;
|
||||
resources: Record<string, string>;
|
||||
parentChangeMessage?: string;
|
||||
};
|
||||
|
||||
export type ResourceField = {
|
||||
key: string;
|
||||
label: string;
|
||||
@@ -60,6 +68,8 @@ export type ResourceField = {
|
||||
readonlyOnCreate?: boolean;
|
||||
unknownValueLabel?: string;
|
||||
relationLinkage?: ResourceRelationLinkage;
|
||||
/** 父字段值决定实际关系资源,未选择父字段时不加载候选。 */
|
||||
dynamicRelation?: ResourceDynamicRelation;
|
||||
/** 关联选项优先使用的业务展示字段。 */
|
||||
relationOptionLabelKey?: string;
|
||||
/** 该字段为真时,在关联选项后追加“默认地址”。 */
|
||||
@@ -523,7 +533,7 @@ export const resources: ResourceUiDefinition[] = [
|
||||
{ name: '解绑气瓶', resource: '/gasorder_contract_product/:identity/unbind', danger: true, fields: reason },
|
||||
]),
|
||||
define('gasorder_contract_revision', '合同修订记录', 'readonly', []),
|
||||
define('gasorder_basic', '气体配送订单', 'append_only', [f('request_no', { required: true }), relation('gasorder_contract_identity', '/gasorder_contract', true, { label: '配送合同', placeholder: '请选择当前可履约的生效合同', relationFilters: { candidate: 'order' }, relationStrictFilter: true, relationInvalidMessage: '所选配送合同已不可履约,已清空,请重新选择', relationEmptyText: '暂无可下单的生效合同,请先启用或续签配送合同' }), f('creator_type', { required: true, type: 'select', options: resourceSearchEnumOptions('gasorder_basic', 'creator_type') }), f('creator_identity', { required: true }), relation('user_address_identity', '/user_address', true, {
|
||||
define('gasorder_basic', '气体配送订单', 'append_only', [f('request_no', { required: true }), relation('gasorder_contract_identity', '/gasorder_contract', true, { label: '配送合同', placeholder: '请选择当前可履约的生效合同', relationFilters: { candidate: 'order' }, relationStrictFilter: true, relationInvalidMessage: '所选配送合同已不可履约,已清空,请重新选择', relationEmptyText: '暂无可下单的生效合同,请先启用或续签配送合同' }), f('creator_type', { required: true, type: 'select', options: resourceSearchEnumOptions('gasorder_basic', 'creator_type') }), f('creator_identity', { label: '创建方', required: true, placeholder: '请选择创建方', relationEmptyText: '当前类型暂无可用的创建方数据', dynamicRelation: { parentKey: 'creator_type', parentLabel: '创建方类型', resources: { user: '/user_account', staff: '/staff_account', delivery: '/delivery_basic', gas: '/gas_basic' }, parentChangeMessage: '创建方类型已变更,请重新选择创建方' } }), relation('user_address_identity', '/user_address', true, {
|
||||
label: '收货地址', placeholder: '请先选择配送合同,再选择该合同用户的收货地址',
|
||||
relationOptionLabelKey: 'address', relationOptionDefaultKey: 'is_default',
|
||||
relationAutoSelectKey: 'is_default', relationEmptyText: '该合同用户暂无收货地址,请先维护用户地址',
|
||||
@@ -619,3 +629,14 @@ export function getResource(resourcePath: string): ResourceUiDefinition {
|
||||
if (!definition) throw new Error(`未知资源:${resourcePath}`);
|
||||
return definition;
|
||||
}
|
||||
|
||||
/** 返回动态关系字段当前应使用的资源;父值为空或未知时返回空字符串。 */
|
||||
export function dynamicRelationResource(
|
||||
field: ResourceField,
|
||||
values: Record<string, unknown>,
|
||||
) {
|
||||
const dynamic = field.dynamicRelation;
|
||||
if (!dynamic) return field.relation ?? '';
|
||||
const parentValue = String(values[dynamic.parentKey] ?? '').trim();
|
||||
return dynamic.resources[parentValue] ?? '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user