| | |
| | | |
| | | /** 未绑定托盘下拉选项 */ |
| | | export interface PalletOption { |
| | | label: string; |
| | | value: number; |
| | | disabled?: boolean; |
| | | itemCode?: string; |
| | | itemId?: number; |
| | | itemName?: string; |
| | | itemCode?: string; |
| | | label: string; |
| | | value: number; |
| | | } |
| | | |
| | | export type TonBagOption = PalletOption; |
| | | |
| | | /** 托盘、吨袋下拉的交互事件(支持搜索与滚动分段加载) */ |
| | | /** 绑定类型(托盘/吨袋互斥,编辑补录时按已有绑定锁定其中一方) */ |
| | | export type BindingMode = 'pallet' | 'tonBag'; |
| | | |
| | | /** 托盘、吨袋下拉的交互事件(支持远程搜索与滚动分页加载) */ |
| | | export interface BindingSelectHandlers { |
| | | onChange?: (ids: number[]) => void; |
| | | onPopupScroll?: (event: Event) => void; |
| | | onSearch?: (keyword: string) => void; |
| | | } |
| | | |
| | | /** |
| | | * 刷新托盘选项禁用态。 |
| | | * |
| | | * 下拉已改为分页加载,选项数组本身就是渲染数据源,因此禁用态直接写到选项对象上, |
| | | * 每次加载新一页或表单值变化时重算,避免依赖机制里做数组映射导致新加载的数据被旧快照覆盖。 |
| | | */ |
| | | export function applyPalletOptionState( |
| | | options: PalletOption[], |
| | | values: Record<string, any>, |
| | | existingBinding?: BindingMode, |
| | | ) { |
| | | options.forEach((option) => { |
| | | option.disabled = |
| | | existingBinding === 'tonBag' || |
| | | !!values.tonBagIds?.length || |
| | | !option.itemId || |
| | | (!!values.itemId && option.itemId !== values.itemId); |
| | | }); |
| | | } |
| | | |
| | | /** 刷新吨袋选项禁用态,规则与 {@link applyPalletOptionState} 对称 */ |
| | | export function applyTonBagOptionState( |
| | | options: TonBagOption[], |
| | | values: Record<string, any>, |
| | | existingBinding?: BindingMode, |
| | | ) { |
| | | options.forEach((option) => { |
| | | option.disabled = |
| | | existingBinding === 'pallet' || |
| | | !!values.palletIds?.length || |
| | | (!!values.itemId && option.itemId !== values.itemId); |
| | | }); |
| | | } |
| | | |
| | | /** 新增/修改的表单 */ |
| | |
| | | palletHandlers: BindingSelectHandlers = {}, |
| | | tonBagOptions: TonBagOption[] = [], |
| | | tonBagHandlers: BindingSelectHandlers = {}, |
| | | existingBinding?: 'pallet' | 'tonBag', |
| | | existingBinding?: BindingMode, |
| | | ): VbenFormSchema[] { |
| | | const disabled = formType === 'detail'; |
| | | return [ |
| | |
| | | dependencies: { |
| | | triggerFields: ['itemId', 'tonBagIds'], |
| | | show: () => formType !== 'detail', |
| | | componentProps: (values) => ({ |
| | | options: palletOptions.map(option => ({ ...option, |
| | | disabled: existingBinding === 'tonBag' || !!values.tonBagIds?.length || !option.itemId || (!!values.itemId && option.itemId !== values.itemId), |
| | | })), |
| | | disabled: disabled || existingBinding === 'tonBag' || !!values.tonBagIds?.length, |
| | | }), |
| | | componentProps: (values) => { |
| | | applyPalletOptionState(palletOptions, values, existingBinding); |
| | | return { |
| | | options: palletOptions, |
| | | disabled: disabled || existingBinding === 'tonBag' || !!values.tonBagIds?.length, |
| | | }; |
| | | }, |
| | | }, |
| | | help: '只能绑定相同品种的托盘,品种信息自动带入;缺少品种的托盘请先装袋。绑定后批次直接进入生产中:托盘生成正式托盘码,托盘下未录批次的袋码自动级联录入本批次(袋码品种须一致);编辑时仅需勾选新增托盘,已绑定的不可解绑', |
| | | }, |
| | |
| | | dependencies: { |
| | | triggerFields: ['itemId', 'palletIds'], |
| | | show: () => formType !== 'detail', |
| | | componentProps: (values) => ({ |
| | | options: tonBagOptions.map(option => ({ ...option, |
| | | disabled: existingBinding === 'pallet' || !!values.palletIds?.length || (!!values.itemId && option.itemId !== values.itemId), |
| | | })), |
| | | disabled: disabled || existingBinding === 'pallet' || !!values.palletIds?.length, |
| | | }), |
| | | componentProps: (values) => { |
| | | applyTonBagOptionState(tonBagOptions, values, existingBinding); |
| | | return { |
| | | options: tonBagOptions, |
| | | disabled: disabled || existingBinding === 'pallet' || !!values.palletIds?.length, |
| | | }; |
| | | }, |
| | | }, |
| | | help: '仅可绑定计量单位为吨、无托盘且未录入批次的袋码;与绑定托盘互斥。编辑时仅选择新增吨袋,已绑定的不可解绑', |
| | | }, |