| | |
| | | |
| | | import { useVbenForm } from '#/adapter/form'; |
| | | import { getProcessSimpleList } from '#/api/mes/pro/process'; |
| | | import { getRouteProcessListByProduct } from '#/api/mes/pro/route/process'; |
| | | import { |
| | | createWorkOrderProcess, |
| | | getWorkOrderProcess, |
| | | updateWorkOrderProcess, |
| | | } from '#/api/mes/pro/workorder/process'; |
| | | import { getWarehouseSimpleList } from '#/api/mes/wm/warehouse'; |
| | | import { getWarehouseAreaSimpleList } from '#/api/mes/wm/warehouse/area'; |
| | | import { getWarehouseLocationSimpleList } from '#/api/mes/wm/warehouse/location'; |
| | | import { $t } from '#/locales'; |
| | | import { MdItemSelect } from '#/views/mes/md/item/components'; |
| | | |
| | |
| | | const workOrderId = ref<number>(); |
| | | const processList = ref<MesProWorkOrderProcessApi.WorkOrderProcess[]>([]); |
| | | const isCreateMode = ref(false); |
| | | const allowedOutputItemIds = ref<number[]>([]); |
| | | |
| | | const getTitle = computed(() => { |
| | | return formData.value?.id |
| | |
| | | })); |
| | | } |
| | | |
| | | /** |
| | | * 载入本工单产品可选的产出物料范围 |
| | | * |
| | | * 取工艺路线按产出归属过滤后的产出(通用半成品 + 本产品专属成品), |
| | | * 并并入该工序已配置的产出,避免历史数据在重新选择时被误清空。 |
| | | */ |
| | | async function loadAllowedOutputItemIds( |
| | | productId?: number, |
| | | currentOutputItemIds: number[] = [], |
| | | ): Promise<number[]> { |
| | | if (!productId) { |
| | | return []; |
| | | } |
| | | const ids = new Set<number>([productId, ...currentOutputItemIds]); |
| | | const routeProcessList = await getRouteProcessListByProduct(productId); |
| | | (routeProcessList || []).forEach((process) => { |
| | | (process.outputItemIds || []).forEach((id) => { |
| | | if (id) { |
| | | ids.add(id); |
| | | } |
| | | }); |
| | | }); |
| | | return [...ids]; |
| | | } |
| | | |
| | | /** 表单 schema */ |
| | | async function loadSchema(): Promise<VbenFormSchema[]> { |
| | | const processOptions = await loadProcessOptions(); |
| | | const [processOptions, warehouseList] = await Promise.all([ |
| | | loadProcessOptions(), |
| | | getWarehouseSimpleList(), |
| | | ]); |
| | | return [ |
| | | { |
| | | fieldName: 'id', |
| | |
| | | }, |
| | | { |
| | | fieldName: 'workOrderId', |
| | | component: 'Input', |
| | | dependencies: { triggerFields: [''], show: () => false }, |
| | | }, |
| | | { |
| | | fieldName: 'warehouseName', |
| | | component: 'Input', |
| | | dependencies: { triggerFields: [''], show: () => false }, |
| | | }, |
| | | { |
| | | fieldName: 'locationName', |
| | | component: 'Input', |
| | | dependencies: { triggerFields: [''], show: () => false }, |
| | | }, |
| | | { |
| | | fieldName: 'areaName', |
| | | component: 'Input', |
| | | dependencies: { triggerFields: [''], show: () => false }, |
| | | }, |
| | |
| | | componentProps: { |
| | | multiple: true, |
| | | placeholder: '请选择产出物料', |
| | | productIds: allowedOutputItemIds.value, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'warehouseId', |
| | | label: '报工仓库', |
| | | component: 'Select', |
| | | componentProps: { |
| | | allowClear: true, |
| | | options: (warehouseList || []).map((item) => ({ |
| | | label: item.name ?? '', |
| | | value: item.id!, |
| | | })), |
| | | placeholder: '默认取工艺路线配置,可修改', |
| | | onChange: async (value: number) => { |
| | | const warehouse = (warehouseList || []).find( |
| | | (item) => item.id === value, |
| | | ); |
| | | await formApi.setFieldValue('warehouseName', warehouse?.name); |
| | | await formApi.setFieldValue('locationId', undefined); |
| | | await formApi.setFieldValue('locationName', undefined); |
| | | await formApi.setFieldValue('areaId', undefined); |
| | | await formApi.setFieldValue('areaName', undefined); |
| | | }, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'locationId', |
| | | label: '报工库区', |
| | | component: 'Select', |
| | | dependencies: { |
| | | triggerFields: ['warehouseId'], |
| | | disabled: (values) => !values.warehouseId, |
| | | async componentProps(values) { |
| | | const options = values.warehouseId |
| | | ? await getWarehouseLocationSimpleList(values.warehouseId) |
| | | : []; |
| | | return { |
| | | allowClear: true, |
| | | fieldNames: { label: 'name', value: 'id' }, |
| | | options, |
| | | placeholder: '请选择报工库区', |
| | | onChange: async (value: number) => { |
| | | const location = options.find((item) => item.id === value); |
| | | await formApi.setFieldValue('locationName', location?.name); |
| | | await formApi.setFieldValue('areaId', undefined); |
| | | await formApi.setFieldValue('areaName', undefined); |
| | | }, |
| | | }; |
| | | }, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'areaId', |
| | | label: '报工库位', |
| | | component: 'Select', |
| | | dependencies: { |
| | | triggerFields: ['locationId'], |
| | | disabled: (values) => !values.locationId, |
| | | async componentProps(values) { |
| | | const options = values.locationId |
| | | ? await getWarehouseAreaSimpleList(values.locationId) |
| | | : []; |
| | | return { |
| | | allowClear: true, |
| | | fieldNames: { label: 'name', value: 'id' }, |
| | | options, |
| | | placeholder: '请选择报工库位', |
| | | onChange: async (value: number) => { |
| | | const area = options.find((item) => item.id === value); |
| | | await formApi.setFieldValue('areaName', area?.name); |
| | | }, |
| | | }; |
| | | }, |
| | | }, |
| | | }, |
| | | { |
| | |
| | | formData.value = undefined; |
| | | processList.value = []; |
| | | isCreateMode.value = false; |
| | | allowedOutputItemIds.value = []; |
| | | return; |
| | | } |
| | | modalApi.lock(); |
| | | try { |
| | | const schema = await loadSchema(); |
| | | formApi.setState({ schema }); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |
| | | |
| | | const data = modalApi.getData<{ |
| | | id?: number; |
| | | productId?: number; |
| | |
| | | processList.value = data.processList || []; |
| | | isCreateMode.value = !data.workOrderId; |
| | | |
| | | if (data.row) { |
| | | // 编辑临时列表中的工序 |
| | | formData.value = data.row; |
| | | await formApi.setValues(data.row); |
| | | } else if (data.id) { |
| | | // 编辑已保存的工序 |
| | | modalApi.lock(); |
| | | try { |
| | | formData.value = await getWorkOrderProcess(data.id); |
| | | modalApi.lock(); |
| | | try { |
| | | // 先取工序数据:编辑已保存工序时用于回显,也用于保留其已有产出 |
| | | const savedProcess = !data.row && data.id |
| | | ? await getWorkOrderProcess(data.id) |
| | | : undefined; |
| | | formData.value = data.row ?? savedProcess; |
| | | |
| | | allowedOutputItemIds.value = await loadAllowedOutputItemIds( |
| | | data.productId, |
| | | formData.value?.outputItemIds || [], |
| | | ); |
| | | formApi.setState({ schema: await loadSchema() }); |
| | | |
| | | if (formData.value) { |
| | | // 编辑临时列表中的工序 / 编辑已保存的工序 |
| | | await formApi.setValues(formData.value); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } else { |
| | | // 新增 |
| | | const maxSort = Math.max(0, ...processList.value.map((item) => item.sort || 0)); |
| | | await formApi.setValues({ |
| | | colorCode: '#00AEF3', |
| | | sort: maxSort + 1, |
| | | }); |
| | | } |
| | | } else { |
| | | // 新增 |
| | | formData.value = undefined; |
| | | const maxSort = Math.max(0, ...processList.value.map((item) => item.sort || 0)); |
| | | await formApi.setValues({ |
| | | colorCode: '#00AEF3', |
| | | sort: maxSort + 1, |
| | | }); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |
| | | }, |
| | | }); |