| | |
| | | import type { VbenFormSchema } from '#/adapter/form'; |
| | | import type { MesWmProductIssueLineApi } from '#/api/mes/wm/productissue/line'; |
| | | |
| | | import { computed, markRaw, ref } from 'vue'; |
| | | import { computed, ref } from 'vue'; |
| | | |
| | | import { useVbenModal } from '@vben/common-ui'; |
| | | |
| | | import { message } from 'ant-design-vue'; |
| | | |
| | | import { useVbenForm } from '#/adapter/form'; |
| | | import { getWorkOrderBomListByTaskId } from '#/api/mes/pro/workorder/bom'; |
| | | import { getProductIssue } from '#/api/mes/wm/productissue'; |
| | | import { |
| | | createProductIssueLine, |
| | | getProductIssueLine, |
| | | updateProductIssueLine, |
| | | } from '#/api/mes/wm/productissue/line'; |
| | | import { MdItemSelect } from '#/views/mes/md/item/components'; |
| | | |
| | | const emit = defineEmits(['success']); |
| | | const formData = ref<MesWmProductIssueLineApi.ProductIssueLine>(); |
| | |
| | | }); |
| | | |
| | | /** 物料行表单 schema */ |
| | | function buildLineFormSchema(): VbenFormSchema[] { |
| | | function buildLineFormSchema(options: { label: string; value: number }[] = []): VbenFormSchema[] { |
| | | return [ |
| | | { |
| | | fieldName: 'itemId', |
| | | label: '产品物料', |
| | | component: markRaw(MdItemSelect), |
| | | componentProps: { placeholder: '请选择产品物料' }, |
| | | component: 'Select', |
| | | componentProps: { |
| | | options, |
| | | showSearch: true, |
| | | optionFilterProp: 'label', |
| | | placeholder: options.length ? '请选择当前工序物料' : '请先维护当前工序投入物料', |
| | | }, |
| | | rules: 'selectRequired', |
| | | }, |
| | | { |
| | |
| | | } |
| | | const data = modalApi.getData<{ id?: number; issueId: number }>(); |
| | | issueId.value = data.issueId; |
| | | if (!data.id) { |
| | | await formApi.resetForm(); |
| | | return; |
| | | } |
| | | modalApi.lock(); |
| | | try { |
| | | formData.value = await getProductIssueLine(data.id); |
| | | await formApi.setValues(formData.value); |
| | | const issue = await getProductIssue(data.issueId); |
| | | const boms = issue.taskId ? await getWorkOrderBomListByTaskId(issue.taskId) : []; |
| | | const optionMap = new Map<number, { label: string; value: number }>(); |
| | | for (const item of boms) { |
| | | if (item.itemId != null) { |
| | | optionMap.set(item.itemId, { |
| | | value: item.itemId, |
| | | label: `${item.itemCode ?? ''} ${item.itemName ?? ''}`.trim(), |
| | | }); |
| | | } |
| | | } |
| | | const options = [...optionMap.values()]; |
| | | await formApi.updateSchema(buildLineFormSchema(options)); |
| | | await formApi.resetForm(); |
| | | if (data.id) { |
| | | formData.value = await getProductIssueLine(data.id); |
| | | await formApi.setValues(formData.value); |
| | | } |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |