From 0c4429a719f5c95a7690fae51efaaa799ef4e77d Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期一, 25 五月 2026 10:02:48 +0800
Subject: [PATCH] fix: 投入重量改成投入重量/数量

---
 src/views/productionManagement/workOrder/components/ProductionRecordForm.vue |  274 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 204 insertions(+), 70 deletions(-)

diff --git a/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue b/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
index 9b2938e..444e470 100644
--- a/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
+++ b/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
@@ -12,6 +12,25 @@
     default() {
       return [];
     }
+  },
+  labelWidth: {
+    type: Number,
+    default: 120
+  },
+  /** 鏈鐢熶骇鏁伴噺锛堟垚鍨嬪伐搴忕敤浜庤绠楁姇鍏ラ噸閲�/鏁伴噺锛� */
+  quantity: {
+    type: Number,
+    default: null
+  },
+  /** 褰撳墠宸ュ簭鏄惁涓恒�屾垚鍨嬨�� */
+  isFormingProcess: {
+    type: Boolean,
+    default: false
+  },
+  /** 宸ュ崟 BOM 鎶曞叆閲嶉噺锛岄潪鎴愬瀷宸ュ簭鍥炴樉鍒般�屾姇鍏ラ噸閲�/鏁伴噺銆� */
+  bomInputQty: {
+    type: Number,
+    default: null
   }
 });
 
@@ -20,11 +39,21 @@
   list: [] as any[],
 });
 
+const INPUT_WEIGHT_PARAM_ITEM = "鎶曞叆閲嶉噺/鏁伴噺";
+
+/** 鍙傛暟椤瑰睍绀哄悕锛堝吋瀹瑰簱鍐呮棫鍚嶃�屾姇鍏ラ噸閲忋�嶏級 */
+const displayParameterItem = (name) => {
+  const trimmed = String(name ?? "").trim();
+  if (trimmed === "鎶曞叆閲嶉噺") return INPUT_WEIGHT_PARAM_ITEM;
+  return trimmed;
+};
+
 const fieldLabel = (item: any) => {
+  const parameterItem = displayParameterItem(item.parameterItem);
   if (!item.unit || item.unit === "/") {
-    return item.parameterItem;
+    return parameterItem;
   }
-  return `${item.parameterItem}锛�${item.unit}锛塦;
+  return `${parameterItem}锛�${item.unit}锛塦;
 };
 
 const getType = (item: any) => item.type || "鏂囨湰鏍煎紡";
@@ -33,7 +62,11 @@
   const result: Record<string, any[]> = {};
   formData.list.forEach((item, index) => {
     if (String(item.isRequired) === "1") {
-      result[`list.${index}.value`] = [{required: true, message: `璇疯緭鍏�${item.parameterItem}`, trigger: "blur"}];
+      result[`list.${index}.value`] = [{
+        required: true,
+        message: `璇疯緭鍏�${displayParameterItem(item.parameterItem)}`,
+        trigger: "blur"
+      }];
     }
   });
   return result;
@@ -45,14 +78,79 @@
   deviceOptions.value = data;
 };
 
+const normalizeUnit = (unit) => String(unit ?? "").trim().toLowerCase();
+
+const isInputWeightItem = (item) => {
+  const name = String(item?.parameterItem ?? "").trim();
+  return (name === "鎶曞叆閲嶉噺" || name.includes(INPUT_WEIGHT_PARAM_ITEM)) &&
+    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 () => {
@@ -70,77 +168,113 @@
     () => {
       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>
 
 <template>
-  <el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
-    <el-form-item
-        v-for="(item, index) in formData.list"
-        :key="item.id"
-        :label="fieldLabel(item)"
-        :prop="`list.${index}.value`"
-    >
-      <el-input-number
-          v-if="getType(item) === '鏁板�兼牸寮�'"
-          v-model="item.value"
-          :controls="false"
-          style="width: 100%"
-          placeholder="璇疯緭鍏�"
-      />
-      <el-date-picker
-          v-else-if="getType(item) === '鏃堕棿鏍煎紡'"
-          v-model="item.value"
-          type="datetime"
-          value-format="YYYY-MM-DD HH:mm:ss"
-          format="YYYY-MM-DD HH:mm:ss"
-          placeholder="璇烽�夋嫨"
-          style="width: 100%"
-      />
-      <el-date-picker
-          v-else-if="getType(item) === '鏃ユ湡鏍煎紡'"
-          v-model="item.value"
-          type="date"
-          value-format="YYYY-MM-DD"
-          format="YYYY-MM-DD"
-          placeholder="璇烽�夋嫨"
-          style="width: 100%"
-      />
-      <el-select
-          v-else-if="getType(item) === '鏄�/鍚﹂�夋'"
-          v-model="item.value"
-          placeholder="璇烽�夋嫨"
-          clearable
-          style="width: 100%"
-      >
-        <el-option label="鏄�" value="鏄�"/>
-        <el-option label="鍚�" value="鍚�"/>
-      </el-select>
-      <el-select
-          v-else-if="getType(item) === '鏈哄彴閫夋嫨'"
-          v-model="item.value"
-          placeholder="璇烽�夋嫨"
-          clearable
-          style="width: 100%"
-      >
-        <el-option
-            v-for="(item, index) in deviceOptions"
-            :key="index"
-            :label="item.deviceName"
-            :value="item.deviceName"
-        ></el-option>
-      </el-select>
-      <el-input
-          v-else
-          v-model="item.value"
-          placeholder="璇疯緭鍏�"
-          clearable
-      />
-    </el-form-item>
+  <el-form ref="formRef" :model="formData" :rules="rules" :label-width="`${labelWidth}px`">
+    <el-row :gutter="20">
+      <el-col :span="12" v-for="(item, index) in formData.list" :key="item.id">
+        <el-form-item
+            :label="fieldLabel(item)"
+            :prop="`list.${index}.value`"
+        >
+          <el-input-number
+              v-if="getType(item) === '鏁板�兼牸寮�'"
+              v-model="item.value"
+              :controls="false"
+              style="width: 100%"
+              placeholder="璇疯緭鍏�"
+          />
+          <el-date-picker
+              v-else-if="getType(item) === '鏃堕棿鏍煎紡'"
+              v-model="item.value"
+              type="datetime"
+              value-format="YYYY-MM-DD HH:mm:ss"
+              format="YYYY-MM-DD HH:mm:ss"
+              placeholder="璇烽�夋嫨"
+              style="width: 100%"
+          />
+          <el-date-picker
+              v-else-if="getType(item) === '鏃ユ湡鏍煎紡'"
+              v-model="item.value"
+              type="date"
+              value-format="YYYY-MM-DD"
+              format="YYYY-MM-DD"
+              placeholder="璇烽�夋嫨"
+              style="width: 100%"
+          />
+          <el-select
+              v-else-if="getType(item) === '鏄�/鍚﹂�夋'"
+              v-model="item.value"
+              placeholder="璇烽�夋嫨"
+              clearable
+              style="width: 100%"
+          >
+            <el-option label="鏄�" value="鏄�"/>
+            <el-option label="鍚�" value="鍚�"/>
+          </el-select>
+          <el-select
+              v-else-if="getType(item) === '鏈哄彴閫夋嫨'"
+              v-model="item.value"
+              placeholder="璇烽�夋嫨"
+              clearable
+              style="width: 100%"
+          >
+            <el-option
+                v-for="(device, deviceIndex) in deviceOptions"
+                :key="deviceIndex"
+                :label="device.deviceName"
+                :value="device.deviceName"
+            ></el-option>
+          </el-select>
+          <el-input
+              v-else
+              v-model="item.value"
+              placeholder="璇疯緭鍏�"
+              clearable
+              style="width: 100%"
+          />
+        </el-form-item>
+      </el-col>
+    </el-row>
   </el-form>
 </template>
\ No newline at end of file

--
Gitblit v1.9.3