spring
2026-05-18 428ffc413a5c0596d2073b829023ef3a96f5bdb1
fix: 电压分选档位数量限制
已修改1个文件
126 ■■■■ 文件已修改
src/views/productionManagement/workOrder/components/VoltageSortingForm.vue 126 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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('请至少完整填写一档的电压规格、电压和数量');
    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">