From 7465eb431e134576b4c9c43103c9fc6f918d1696 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 20 五月 2026 17:37:21 +0800
Subject: [PATCH] fix: 每个工序添加投入重量字段
---
src/views/productionManagement/workOrder/components/ProductionRecordForm.vue | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 100 insertions(+), 2 deletions(-)
diff --git a/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue b/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
index 908e637..9ab62b0 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,6 +64,55 @@
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 = () => {
+ 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;
+ }
+ weightItem.value = Number(bom);
+};
+
+const syncInputWeight = () => {
+ if (props.isFormingProcess) {
+ syncFormingInputWeight();
+ } else {
+ syncBomInputWeight();
+ }
+};
+
const initData = () => {
formData.list = props.list || [];
formData.list.forEach(item => {
@@ -56,7 +120,8 @@
item.value = null;
}
});
- loadDeviceName()
+ loadDeviceName();
+ syncInputWeight();
};
const submitData = async () => {
@@ -77,8 +142,41 @@
{immediate: true, deep: 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