| | |
| | | } from '#/api/mes/wm/salesnotice/line'; |
| | | import { $t } from '#/locales'; |
| | | |
| | | import { useLineFormSchema } from '../data'; |
| | | import { |
| | | loadAvailableQuantity, |
| | | loadQualifiedStockBatchOptions, |
| | | loadQualifiedStockItemOptions, |
| | | useLineFormSchema, |
| | | } from '../data'; |
| | | |
| | | const emit = defineEmits(['success']); |
| | | const formData = ref<MesWmSalesNoticeLineApi.SalesNoticeLine>(); |
| | |
| | | ? $t('ui.actionTitle.edit', ['发货通知单行']) |
| | | : $t('ui.actionTitle.create', ['发货通知单行']); |
| | | }); |
| | | |
| | | async function updateBatchOptions(itemId?: number) { |
| | | const batchOptions = itemId |
| | | ? await loadQualifiedStockBatchOptions(itemId) |
| | | : []; |
| | | formApi.updateSchema([ |
| | | { |
| | | fieldName: 'batchId', |
| | | componentProps: { options: batchOptions }, |
| | | }, |
| | | ]); |
| | | } |
| | | |
| | | async function refreshAvailableQuantity(itemId?: number, batchId?: number) { |
| | | const quantity = await loadAvailableQuantity(itemId, batchId); |
| | | await formApi.setFieldValue( |
| | | 'availableQuantity', |
| | | quantity > 0 ? `${quantity}` : undefined, |
| | | ); |
| | | } |
| | | |
| | | const [Form, formApi] = useVbenForm({ |
| | | commonConfig: { |
| | |
| | | layout: 'horizontal', |
| | | schema: useLineFormSchema(), |
| | | showDefaultActions: false, |
| | | handleValuesChange: async (values, fieldsChanged) => { |
| | | // setValues 编辑回填时 itemId/batchId 同时变化,不清批次仅刷新选项 |
| | | const itemChanged = fieldsChanged.includes('itemId'); |
| | | const batchChanged = fieldsChanged.includes('batchId'); |
| | | if (itemChanged && batchChanged) { |
| | | await updateBatchOptions(values.itemId as number | undefined); |
| | | await refreshAvailableQuantity( |
| | | values.itemId as number | undefined, |
| | | values.batchId as number | undefined, |
| | | ); |
| | | return; |
| | | } |
| | | if (itemChanged) { |
| | | await formApi.setFieldValue('batchId', undefined); |
| | | await updateBatchOptions(values.itemId as number | undefined); |
| | | await refreshAvailableQuantity(values.itemId as number | undefined); |
| | | return; |
| | | } |
| | | if (batchChanged) { |
| | | await updateBatchOptions(values.itemId as number | undefined); |
| | | await refreshAvailableQuantity( |
| | | values.itemId as number | undefined, |
| | | values.batchId as number | undefined, |
| | | ); |
| | | } |
| | | }, |
| | | wrapperClass: 'grid-cols-3', |
| | | }); |
| | | |
| | |
| | | return; |
| | | } |
| | | modalApi.lock(); |
| | | // 提交表单 |
| | | const data = |
| | | (await formApi.getValues()) as MesWmSalesNoticeLineApi.SalesNoticeLine; |
| | | // 提交表单(可发货数量仅作提示,不提交到后端) |
| | | const values = (await formApi.getValues()) as MesWmSalesNoticeLineApi.SalesNoticeLine & { |
| | | availableQuantity?: unknown; |
| | | }; |
| | | delete values.availableQuantity; |
| | | const data = values; |
| | | data.noticeId = noticeId.value; |
| | | try { |
| | | await (formData.value?.id |
| | |
| | | await modalApi.close(); |
| | | emit('success'); |
| | | message.success($t('ui.actionMessage.operationSuccess')); |
| | | } catch (error) { |
| | | const response = error as { |
| | | response?: { data?: { message?: string; msg?: string } }; |
| | | }; |
| | | message.error( |
| | | response.response?.data?.message ?? |
| | | response.response?.data?.msg ?? |
| | | '保存失败,请检查正式库库存是否充足', |
| | | ); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |
| | |
| | | // 加载数据 |
| | | const data = modalApi.getData<{ id?: number; noticeId: number }>(); |
| | | noticeId.value = data.noticeId; |
| | | if (!data.id) { |
| | | return; |
| | | } |
| | | modalApi.lock(); |
| | | try { |
| | | // 物料选项:仅展示正式库有库存的物料 |
| | | const itemOptions = await loadQualifiedStockItemOptions(); |
| | | formApi.updateSchema([ |
| | | { |
| | | fieldName: 'itemId', |
| | | componentProps: { options: itemOptions }, |
| | | }, |
| | | ]); |
| | | if (!data.id) { |
| | | return; |
| | | } |
| | | formData.value = await getSalesNoticeLine(data.id); |
| | | // 设置到 values |
| | | // 设置到 values,联动加载批次选项 |
| | | await formApi.setValues(formData.value); |
| | | await updateBatchOptions(formData.value?.itemId); |
| | | await refreshAvailableQuantity( |
| | | formData.value?.itemId, |
| | | formData.value?.batchId, |
| | | ); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |