Преглед на файлове

feat(web-admin): submit stable load/delivery/product ids on plan save.

Co-authored-by: Cursor <cursoragent@cursor.com>
zlwu преди 1 месец
родител
ревизия
c90ff7c419
променени са 3 файла, в които са добавени 24 реда и са изтрити 5 реда
  1. 1 0
      web-admin/src/api/pl/index.ts
  2. 17 5
      web-admin/src/components/business/pl-plan-form-dialog/index.vue
  3. 6 0
      web-admin/src/utils/pl-plan-stop-form.ts

+ 1 - 0
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

+ 17 - 5
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 = ''

+ 6 - 0
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,