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 | 252 +++++++++++++++++++++++++++++++++++++-------------
1 files changed, 185 insertions(+), 67 deletions(-)
diff --git a/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue b/src/views/productionManagement/workOrder/components/ProductionRecordForm.vue
index 9b2938e..10bfc44 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
}
});
@@ -45,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 () => {
@@ -70,77 +152,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