From c90ff7c419f03f9be439eb5f67f765c4461defd2 Mon Sep 17 00:00:00 2001 From: zlwu Date: Sat, 5 Sep 2026 18:31:59 +0800 Subject: [PATCH] feat(web-admin): submit stable load/delivery/product ids on plan save. Co-authored-by: Cursor --- web-admin/src/api/pl/index.ts | 1 + .../business/pl-plan-form-dialog/index.vue | 22 ++++++++++++++----- web-admin/src/utils/pl-plan-stop-form.ts | 6 +++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/web-admin/src/api/pl/index.ts b/web-admin/src/api/pl/index.ts index 386fe1d40..ee0c541f6 100644 --- a/web-admin/src/api/pl/index.ts +++ b/web-admin/src/api/pl/index.ts @@ -699,6 +699,7 @@ export interface PlanCreateFullPayload { load?: PlanLoad deliveries?: PlanDelivery[] products: Array<{ + id?: string productId: string productNo: string productName: string diff --git a/web-admin/src/components/business/pl-plan-form-dialog/index.vue b/web-admin/src/components/business/pl-plan-form-dialog/index.vue index ea80c8cc2..0e72fb4e0 100644 --- a/web-admin/src/components/business/pl-plan-form-dialog/index.vue +++ b/web-admin/src/components/business/pl-plan-form-dialog/index.vue @@ -1419,6 +1419,7 @@ return formData.products.map((item) => { prepareLineAliasAndBrandForSubmit(item) return { + ...(item.id ? { id: item.id } : {}), productId: item.productId, productNo: item.productNo, productName: item.productName, @@ -1779,13 +1780,24 @@ remark: data.remark || '' }) applyStopsFromPlan(data) - loadForm.value.products = loadForm.value.products.map((row) => ({ - ...row, - planProductId: undefined - })) + // 复制为新计划:不回传源计划段/段产品 id,避免误 upsert + loadForm.value = { + ...loadForm.value, + id: undefined, + products: loadForm.value.products.map((row) => ({ + ...row, + id: undefined, + planProductId: undefined + })) + } deliveryForms.value = deliveryForms.value.map((row) => ({ ...row, - products: row.products.map((product) => ({ ...product, planProductId: undefined })) + id: undefined, + products: row.products.map((product) => ({ + ...product, + id: undefined, + planProductId: undefined + })) })) loadedTransportStatus.value = 'pending' loadedFollowStatus.value = '' diff --git a/web-admin/src/utils/pl-plan-stop-form.ts b/web-admin/src/utils/pl-plan-stop-form.ts index 83f6e9b39..248d95c2a 100644 --- a/web-admin/src/utils/pl-plan-stop-form.ts +++ b/web-admin/src/utils/pl-plan-stop-form.ts @@ -84,6 +84,7 @@ export function formatStopArchiveAmount( } export interface PlanLoadForm { + id?: string customerId: string customerName: string address: string @@ -99,6 +100,7 @@ export interface PlanLoadForm { } export interface PlanDeliveryForm { + id?: string seq: number customerId: string customerName: string @@ -440,6 +442,7 @@ export function mapLoadFromApi( vehiclePlate ) return { + id: load.id || undefined, customerId: load.customerId || '', customerName: load.customerName || '', address: load.address || '', @@ -472,6 +475,7 @@ export function mapDeliveriesFromApi( vehiclePlate ) return { + id: row.id || undefined, seq: row.seq ?? index + 1, customerId: row.customerId || '', customerName: row.customerName || '', @@ -721,6 +725,7 @@ export function buildStopProductPayload(row: PlanStopProductFormRow) { export function buildLoadPayload(load: PlanLoadForm) { return { + ...(load.id ? { id: load.id } : {}), customerId: load.customerId, customerName: load.customerName, address: load.address || undefined, @@ -738,6 +743,7 @@ export function buildLoadPayload(load: PlanLoadForm) { export function buildDeliveriesPayload(deliveries: PlanDeliveryForm[]) { return deliveries.map((row, index) => ({ + ...(row.id ? { id: row.id } : {}), seq: row.seq || index + 1, customerId: row.customerId, customerName: row.customerName,