From 0d62d9184a24fdfcb43702db0dbd0cc9d3108625 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 22 五月 2026 16:50:18 +0800
Subject: [PATCH] fix(product): 产品型号复制功能的进行勾选复制

---
 src/views/productionManagement/workOrder/components/ProductionRecordForm.vue |  119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 115 insertions(+), 4 deletions(-)

diff --git a/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue b/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
index 908e637..10bfc44 100644
--- a/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
+++ b/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
@@ -16,6 +16,21 @@
   labelWidth: {
     type: Number,
     default: 120
+  },
+  /** 鏈鐢熶骇鏁伴噺锛堟垚鍨嬪伐搴忕敤浜庤绠楁姇鍏ラ噸閲忥級 */
+  quantity: {
+    type: Number,
+    default: null
+  },
+  /** 褰撳墠宸ュ簭鏄惁涓恒�屾垚鍨嬨�� */
+  isFormingProcess: {
+    type: Boolean,
+    default: false
+  },
+  /** 宸ュ崟 BOM 鎶曞叆閲嶉噺锛岄潪鎴愬瀷宸ュ簭鍥炴樉鍒般�屾姇鍏ラ噸閲忋�� */
+  bomInputQty: {
+    type: Number,
+    default: null
   }
 });
 
@@ -49,14 +64,77 @@
   deviceOptions.value = data;
 };
 
+const normalizeUnit = (unit) => String(unit ?? "").trim().toLowerCase();
+
+const isInputWeightItem = (item) =>
+  String(item?.parameterItem ?? "").includes("鎶曞叆閲嶉噺") &&
+  normalizeUnit(item?.unit) === "kg";
+
+const isBlankCoeffItem = (item) =>
+  String(item?.parameterItem ?? "").includes("鐢熷澂绯绘暟") &&
+  normalizeUnit(item?.unit) === "g";
+
+/** 鎶曞叆閲嶉噺(KG) = 鏈鐢熶骇鏁伴噺 脳 鐢熷澂绯绘暟(g) / 1000 */
+const syncFormingInputWeight = () => {
+  if (!props.isFormingProcess) return;
+  const weightItem = formData.list.find(isInputWeightItem);
+  if (!weightItem) return;
+
+  const qty = Number(props.quantity);
+  const coeffItem = formData.list.find(isBlankCoeffItem);
+  const coeff = coeffItem?.value === null || coeffItem?.value === undefined || coeffItem?.value === ""
+    ? NaN
+    : Number(coeffItem.value);
+
+  if (!Number.isFinite(qty) || qty < 1 || !Number.isFinite(coeff)) {
+    return;
+  }
+
+  weightItem.value = Number(((qty * coeff) / 1000).toFixed(4));
+};
+
+/** 闈炴垚鍨嬶細鎶曞叆閲嶉噺鍙栧伐鍗� bomInputQty锛堜粎鍥炴樉锛屼笉瑕嗙洊鐢ㄦ埛宸茬紪杈戠殑鍊硷級 */
+const syncBomInputWeight = (force = false) => {
+  if (props.isFormingProcess) return;
+  const weightItem = formData.list.find(isInputWeightItem);
+  if (!weightItem) return;
+  const bom = props.bomInputQty;
+  if (bom === null || bom === undefined || Number.isNaN(Number(bom))) {
+    return;
+  }
+  const current = weightItem.value;
+  const isEmpty =
+    current === null || current === undefined || current === "";
+  if (!force && !isEmpty) {
+    return;
+  }
+  weightItem.value = Number(bom);
+};
+
+const syncInputWeight = () => {
+  if (props.isFormingProcess) {
+    syncFormingInputWeight();
+  } else {
+    syncBomInputWeight();
+  }
+};
+
+const cloneParamList = (list) =>
+  JSON.parse(JSON.stringify(list || []));
+
 const initData = () => {
-  formData.list = props.list || [];
+  formData.list = cloneParamList(props.list);
   formData.list.forEach(item => {
     if (item.value === undefined) {
       item.value = null;
     }
   });
-  loadDeviceName()
+  loadDeviceName();
+  if (props.isFormingProcess) {
+    syncFormingInputWeight();
+  } else {
+    syncBomInputWeight(true);
+  }
 };
 
 const submitData = async () => {
@@ -74,11 +152,44 @@
     () => {
       initData();
     },
-    {immediate: true, deep: true}
+    {immediate: true}
+);
+
+watch(
+    () => [props.quantity, props.isFormingProcess],
+    () => {
+      if (props.isFormingProcess) {
+        syncFormingInputWeight();
+      }
+    }
+);
+
+watch(
+    () => {
+      const coeffItem = formData.list.find(isBlankCoeffItem);
+      return coeffItem?.value;
+    },
+    () => {
+      if (props.isFormingProcess) {
+        syncFormingInputWeight();
+      }
+    }
+);
+
+watch(
+    () => [props.bomInputQty, props.isFormingProcess],
+    () => {
+      if (!props.isFormingProcess) {
+        syncBomInputWeight();
+      }
+    }
 );
 
 defineExpose({
-  submitData
+  submitData,
+  syncFormingInputWeight,
+  syncBomInputWeight,
+  syncInputWeight
 })
 </script>
 

--
Gitblit v1.9.3