From 59574c146df99fdab01856bc82816a6008890ab9 Mon Sep 17 00:00:00 2001 From: hwj Date: Thu, 26 Feb 2026 16:04:20 +0800 Subject: [PATCH] =?UTF-8?q?fixed=EF=BC=9A=E6=A8=A1=E5=85=B7=E5=87=BA?= =?UTF-8?q?=E5=BA=93/=E6=A8=A1=E5=85=B7=E5=85=A5=E5=BA=93-=E7=BC=96?= =?UTF-8?q?=E8=BE=91-=E9=87=8D=E5=A4=8D=E4=BC=A0=E5=8F=82=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/mes/moldget/MoldGetForm.vue | 41 +++++++++++++----- src/views/mes/moldreturn/MoldReturnForm.vue | 47 ++++++++++++++++----- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/src/views/mes/moldget/MoldGetForm.vue b/src/views/mes/moldget/MoldGetForm.vue index 370c14df..3a2e3070 100644 --- a/src/views/mes/moldget/MoldGetForm.vue +++ b/src/views/mes/moldget/MoldGetForm.vue @@ -203,16 +203,37 @@ const submitForm = async () => { // 提交请求 formLoading.value = true try { - itemFormRef.value.selectedRows.forEach((item, index) => { - const i = { - warehouseId : formData.value.warehouseId, - productId : item.id, - productPrice: 0, - count: 1, - } - formData.value.items.push(i) - console.log(formData.value.items) -}); + const existingByProductId = new Map( + (formData.value.items ?? []) + .filter((it: any) => it && (it.productId ?? it.id) !== undefined && (it.productId ?? it.id) !== null) + .map((it: any) => [Number(it.productId ?? it.id), it]) + ) + + const selectedProductIds = (itemFormRef.value.selectedRows ?? []) + .map((it: any) => it?.id) + .filter((id: any) => id !== undefined && id !== null) + .map((id: any) => Number(id)) + .filter((id: any) => !Number.isNaN(id)) + + formData.value.items = selectedProductIds.map((productId) => { + const existing = existingByProductId.get(productId) + if (existing) { + return { + id: existing.id, + warehouseId: formData.value.warehouseId, + productId, + productPrice: existing.productPrice ?? 0, + count: existing.count ?? 1, + remark: existing.remark ?? null + } + } + return { + warehouseId: formData.value.warehouseId, + productId, + productPrice: 0, + count: 1 + } + }) const data = formData.value as unknown as StockOutVO if (formType.value === 'create') { await StockOutApi.createStockOut(data) diff --git a/src/views/mes/moldreturn/MoldReturnForm.vue b/src/views/mes/moldreturn/MoldReturnForm.vue index 1e440e8e..271b9bc3 100644 --- a/src/views/mes/moldreturn/MoldReturnForm.vue +++ b/src/views/mes/moldreturn/MoldReturnForm.vue @@ -159,7 +159,12 @@ const open = async (type: string, id?: number) => { if (id) { formLoading.value = true try { - formData.value = await StockInApi.getStockIn(id) + const data = await StockInApi.getStockIn(id) + const itemWarehouseId = (data as any)?.items?.[0]?.warehouseId + formData.value = { + ...(data as any), + warehouseId: itemWarehouseId ?? (data as any)?.warehouseId + } } finally { formLoading.value = false } @@ -179,15 +184,37 @@ const submitForm = async () => { // 提交请求 formLoading.value = true try { - itemFormRef.value.selectedRows.forEach((item, index) => { - const i = { - warehouseId : formData.value.warehouseId, - productId : item.id, - productPrice: 0, - count: 1, - } - formData.value.items.push(i) -}); + const existingByProductId = new Map( + (formData.value.items ?? []) + .filter((it: any) => it && (it.productId ?? it.id) !== undefined && (it.productId ?? it.id) !== null) + .map((it: any) => [Number(it.productId ?? it.id), it]) + ) + + const selectedProductIds = (itemFormRef.value.selectedRows ?? []) + .map((it: any) => it?.id) + .filter((id: any) => id !== undefined && id !== null) + .map((id: any) => Number(id)) + .filter((id: any) => !Number.isNaN(id)) + + formData.value.items = selectedProductIds.map((productId) => { + const existing = existingByProductId.get(productId) + if (existing) { + return { + id: existing.id, + warehouseId: formData.value.warehouseId, + productId, + productPrice: existing.productPrice ?? 0, + count: existing.count ?? 1, + remark: existing.remark ?? null + } + } + return { + warehouseId: formData.value.warehouseId, + productId, + productPrice: 0, + count: 1 + } + }) const data = formData.value as unknown as StockInVO if (formType.value === 'create') { await StockInApi.createStockIn(data)