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 | 141 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 134 insertions(+), 7 deletions(-)
diff --git a/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue b/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
index 908e637..444e470 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
}
});
@@ -24,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 || "鏂囨湰鏍煎紡";
@@ -37,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;
@@ -49,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 () => {
@@ -74,11 +168,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