From 428ffc413a5c0596d2073b829023ef3a96f5bdb1 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期一, 18 五月 2026 14:45:07 +0800
Subject: [PATCH] fix: 电压分选档位数量限制
---
src/views/productionManagement/workOrder/components/VoltageSortingForm.vue | 126 +++++++++++++++++++++++++++++++++--------
1 files changed, 101 insertions(+), 25 deletions(-)
diff --git a/src/views/productionManagement/workOrder/components/VoltageSortingForm.vue b/src/views/productionManagement/workOrder/components/VoltageSortingForm.vue
index a43a22f..caa127d 100644
--- a/src/views/productionManagement/workOrder/components/VoltageSortingForm.vue
+++ b/src/views/productionManagement/workOrder/components/VoltageSortingForm.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import {computed, onMounted, reactive, ref} from "vue";
+import {computed, onMounted, reactive, ref, watch} from "vue";
import dayjs from "dayjs";
import {userListNoPageByTenantId} from "@/api/system/user.js";
import {getDeviceLedger} from "@/api/equipmentManagement/ledger.js";
@@ -49,9 +49,9 @@
scrapingDate: dayjs().format('YYYY-MM-DD HH:mm:ss'), // 鍒噺鏃ユ湡
machineNumber: undefined, // 鏈哄彴鍙�
receiveQuantity: undefined, // 鎺ユ敹鏁伴噺
- voltageSpecs: [], // 鐢靛帇瑙勬牸,
- voltage: [], // 鐢靛帇
- quantity: [], // 鏁伴噺
+ voltageSpecs: [undefined, undefined, undefined, undefined, undefined], // 鐢靛帇瑙勬牸
+ voltage: [undefined, undefined, undefined, undefined, undefined], // 鐢靛帇
+ quantity: [undefined, undefined, undefined, undefined, undefined], // 鏁伴噺
comprehensiveHit: undefined, // 缁煎悎鍛戒腑鏈�
userId: undefined, // 浣滀笟鍛�
userName: undefined, // 浣滀笟鍛�
@@ -82,19 +82,77 @@
deviceOptions.value = [];
}
};
+const GEAR_COUNT = 5;
+const GEAR_LABELS = ['涓�妗�', '浜屾。', '涓夋。', '鍥涙。', '浜旀。'];
+
+const isEmpty = (val: unknown) => val === undefined || val === null || val === '';
+
+const normalizeGearArray = (arr: unknown[] | undefined, length = GEAR_COUNT) =>
+ Array.from({length}, (_, i) => arr?.[i] ?? undefined);
+
+const isColumnTouched = (index: number) => {
+ const {voltageSpecs, voltage, quantity} = formData.otherData;
+ return !isEmpty(voltageSpecs[index]) || !isEmpty(voltage[index]) || !isEmpty(quantity[index]);
+};
+
+const isColumnComplete = (index: number) => {
+ const {voltageSpecs, voltage, quantity} = formData.otherData;
+ return !isEmpty(voltageSpecs[index]) && !isEmpty(voltage[index]) && !isEmpty(quantity[index]);
+};
+
+const syncOutputQuantity = () => {
+ const sum = formData.otherData.quantity.reduce((acc, val) => {
+ const num = Number(val);
+ return acc + (Number.isFinite(num) ? num : 0);
+ }, 0);
+ formData.quantity = sum > 0 ? sum : undefined;
+};
+
+const validateGearColumns = () => {
+ const incompleteLabels: string[] = [];
+ let completeCount = 0;
+
+ for (let i = 0; i < GEAR_COUNT; i++) {
+ if (isColumnTouched(i)) {
+ if (isColumnComplete(i)) {
+ completeCount++;
+ } else {
+ incompleteLabels.push(GEAR_LABELS[i]);
+ }
+ }
+ }
+
+ if (completeCount === 0) {
+ ElMessage.error('璇疯嚦灏戝畬鏁村~鍐欎竴妗g殑鐢靛帇瑙勬牸銆佺數鍘嬪拰鏁伴噺');
+ return false;
+ }
+
+ if (incompleteLabels.length > 0) {
+ ElMessage.error(`璇峰畬鏁村~鍐�${incompleteLabels.join('銆�')}鐨勭數鍘嬭鏍笺�佺數鍘嬪拰鏁伴噺`);
+ return false;
+ }
+
+ return true;
+};
+
// 鐢ㄦ埛閫夋嫨鍙樺寲鏃舵洿鏂� userName
const handleUserChange = (value) => {
if (value) {
formData.otherData.userName = userOptions.value.find(user => user.userId === value).userName;
}
};
+
const handleReport = () => {
if (!formData.userId) {
ElMessage.error('璇烽�夋嫨浣滀笟鍛�')
return;
}
+ if (!validateGearColumns()) {
+ return;
+ }
+ syncOutputQuantity();
if (!formData.quantity || formData.quantity <= 0) {
- ElMessage.error('璇疯緭鍏ヤ骇鍑烘暟閲�')
+ ElMessage.error('浜у嚭鏁伴噺椤诲ぇ浜�0锛岃濉啓鏁伴噺')
return;
}
@@ -118,9 +176,17 @@
});
};
+const initGearArrays = () => {
+ const {otherData} = formData;
+ otherData.voltageSpecs = normalizeGearArray(otherData.voltageSpecs);
+ otherData.voltage = normalizeGearArray(otherData.voltage);
+ otherData.quantity = normalizeGearArray(otherData.quantity);
+};
+
const initData = () => {
if (!props.isEdit) {
formData.otherData = JSON.parse(props.row.otherData || '{}');
+ initGearArrays();
formData.quantity = props.row.quantity;
formData.scrapQty = props.row.scrapQty;
} else {
@@ -130,8 +196,19 @@
formData.workOrderId = row.id
formData.reportWork = row.reportWork
formData.productMainId = row.productMainId
+ initGearArrays();
+ syncOutputQuantity();
}
}
+
+watch(
+ () => formData.otherData.quantity.map((val) => val),
+ () => {
+ if (props.isEdit) {
+ syncOutputQuantity();
+ }
+ }
+);
const displayValue = (value: any) => {
return value === undefined || value === null || value === "" ? "-" : value;
@@ -239,7 +316,14 @@
</td>
<td class="label" colspan="2">浜у嚭鏁伴噺</td>
<td colspan="6">
- <el-input-number v-if="props.isEdit" controls-position="right" v-model="formData.quantity" style="width: 100%;" placeholder="璇疯緭鍏�"/>
+ <el-input-number
+ v-if="props.isEdit"
+ v-model="formData.quantity"
+ controls-position="right"
+ disabled
+ style="width: 100%;"
+ placeholder="鑷姩姹囨��"
+ />
<span v-else class="view-value">{{ displayValue(formData.quantity) }}</span>
</td>
</tr>
@@ -273,25 +357,17 @@
</tr>
<tr>
<td class="label" colspan="2">鏁伴噺</td>
- <td colspan="2">
- <el-input-number v-if="props.isEdit" controls-position="right" v-model="formData.otherData.quantity[0]" placeholder="璇疯緭鍏�"/>
- <span v-else class="view-value">{{ displayValue(formData.otherData.quantity[0]) }}</span>
- </td>
- <td colspan="2">
- <el-input-number v-if="props.isEdit" controls-position="right" v-model="formData.otherData.quantity[1]" placeholder="璇疯緭鍏�"/>
- <span v-else class="view-value">{{ displayValue(formData.otherData.quantity[1]) }}</span>
- </td>
- <td colspan="2">
- <el-input-number v-if="props.isEdit" controls-position="right" v-model="formData.otherData.quantity[2]" placeholder="璇疯緭鍏�"/>
- <span v-else class="view-value">{{ displayValue(formData.otherData.quantity[2]) }}</span>
- </td>
- <td colspan="2">
- <el-input-number v-if="props.isEdit" controls-position="right" v-model="formData.otherData.quantity[3]" placeholder="璇疯緭鍏�"/>
- <span v-else class="view-value">{{ displayValue(formData.otherData.quantity[3]) }}</span>
- </td>
- <td colspan="2">
- <el-input-number v-if="props.isEdit" controls-position="right" v-model="formData.otherData.quantity[4]" placeholder="璇疯緭鍏�"/>
- <span v-else class="view-value">{{ displayValue(formData.otherData.quantity[4]) }}</span>
+ <td v-for="gearIndex in GEAR_COUNT" :key="'qty-' + gearIndex" colspan="2">
+ <el-input-number
+ v-if="props.isEdit"
+ v-model="formData.otherData.quantity[gearIndex - 1]"
+ controls-position="right"
+ :min="0"
+ :precision="0"
+ style="width: 100%;"
+ placeholder="璇疯緭鍏�"
+ />
+ <span v-else class="view-value">{{ displayValue(formData.otherData.quantity[gearIndex - 1]) }}</span>
</td>
<td class="label" colspan="2">缁煎悎鍛戒腑鏈�</td>
<td colspan="6">
--
Gitblit v1.9.3