| | |
| | | <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"; |
| | |
| | | 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, // 作业员 |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | }); |
| | | }; |
| | | |
| | | 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 { |
| | |
| | | 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; |
| | |
| | | </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> |
| | |
| | | </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"> |