|
|
@@ -968,24 +968,25 @@ function isReturnLinePendingReturn(row: DeviceListItem) {
|
|
|
return (Number(row.available_quantity) || 0) > 0;
|
|
|
}
|
|
|
|
|
|
-/** 扫码命中列表中的设备时:归还数量 +1,不超过待归还数 available_quantity */
|
|
|
-function applyReturnScanIncrement(row: DeviceListItem): boolean {
|
|
|
+/**
|
|
|
+ * 扫码命中列表中的设备时:归还数量 +1,不超过待归还数。
|
|
|
+ * 成功返回 null;失败返回提示文案。不在此调用 ElMessage,由扫码/RFID 批处理处统一只弹一次。
|
|
|
+ */
|
|
|
+function tryApplyReturnScanIncrement(row: DeviceListItem): string | null {
|
|
|
const cap = row.available_quantity ?? 0;
|
|
|
if (cap <= 0) {
|
|
|
- ElMessage.warning('该设备无待归还数量');
|
|
|
- return false;
|
|
|
+ return '该设备无待归还数量';
|
|
|
}
|
|
|
const current = Number(row.borrow_count) || 0;
|
|
|
if (current >= cap) {
|
|
|
- ElMessage.warning('该设备归还数量已达待归还上限');
|
|
|
- return false;
|
|
|
+ return '该设备归还数量已达待归还上限';
|
|
|
}
|
|
|
row.borrow_count = current + 1;
|
|
|
if (row.borrow_count >= cap) {
|
|
|
row.is_return = true;
|
|
|
row.return_time = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
|
}
|
|
|
- return true;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
// 统一判定「该明细是否已把本次可归还数记满」:用于选设备白名单/全部完成判断(不依赖硬编码业务状态值)
|
|
|
@@ -1037,6 +1038,40 @@ function getWarehouseName(id: any) {
|
|
|
return warehouseMap.value[key] ?? id;
|
|
|
}
|
|
|
|
|
|
+/** 从 Promise.allSettled 单条结果安全取出 success/message,避免解构 undefined 导致整批 try 抛错、误报「处理批次时发生错误」 */
|
|
|
+function readSettledListStepResult(
|
|
|
+ result: PromiseSettledResult<unknown>,
|
|
|
+ codeLabel: string
|
|
|
+): { success: boolean; message?: string } {
|
|
|
+ if (result.status === 'rejected') {
|
|
|
+ const err = result.reason instanceof Error ? result.reason.message : String(result.reason);
|
|
|
+ return { success: false, message: `处理设备编号 ${codeLabel} 时发生错误: ${err}` };
|
|
|
+ }
|
|
|
+ const v = result.value as { success?: boolean; message?: string } | null | undefined;
|
|
|
+ if (v == null || typeof v !== 'object' || typeof v.success !== 'boolean') {
|
|
|
+ return { success: false, message: `处理设备编号 ${codeLabel} 时返回数据异常` };
|
|
|
+ }
|
|
|
+ return { success: v.success, message: v.message };
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 从设备查询接口解析可借/可用数量(领取页扫码):先取根字段,再取 inventory.available_quantity
|
|
|
+ */
|
|
|
+function getDeviceAvailableQuantityForBorrow(device: any): number {
|
|
|
+ if (device == null) return 0;
|
|
|
+ const top = device.available_quantity;
|
|
|
+ if (top !== undefined && top !== null && String(top) !== '') {
|
|
|
+ const n = Number(top);
|
|
|
+ if (!Number.isNaN(n)) return Math.max(0, Math.floor(n));
|
|
|
+ }
|
|
|
+ const inv = device.inventory?.available_quantity;
|
|
|
+ if (inv !== undefined && inv !== null && String(inv) !== '') {
|
|
|
+ const n = Number(inv);
|
|
|
+ if (!Number.isNaN(n)) return Math.max(0, Math.floor(n));
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
// 添加结算单相关的状态
|
|
|
const showSettlementDialog = ref(false);
|
|
|
const settlementData = ref<any>(null);
|
|
|
@@ -1243,8 +1278,10 @@ const autoSubmitPendingCodes = async () => {
|
|
|
|
|
|
if (res.data && res.data.length > 0) {
|
|
|
const device = res.data[0];
|
|
|
- if (device.available_quantity <= 0) {
|
|
|
- console.warn(`设备 ${trimmedCode} 当前无可用数量`);
|
|
|
+ const avail = getDeviceAvailableQuantityForBorrow(device);
|
|
|
+ if (avail <= 0) {
|
|
|
+ const label = [device.name, device.code].filter(Boolean).join(' ') || trimmedCode;
|
|
|
+ ElMessage.warning(`设备 ${label}(${trimmedCode})库存不足`);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -1266,7 +1303,7 @@ const autoSubmitPendingCodes = async () => {
|
|
|
device_specification: device.specification,
|
|
|
model: device.model || '',
|
|
|
warehouse: device.warehouse,
|
|
|
- available_quantity: device.available_quantity
|
|
|
+ available_quantity: avail
|
|
|
});
|
|
|
console.log(`设备 ${trimmedCode} 已添加到列表`);
|
|
|
}
|
|
|
@@ -1961,8 +1998,9 @@ const handleScanSearch = async (event?: Event) => {
|
|
|
|
|
|
if (res.data && res.data.length > 0) {
|
|
|
const device = res.data[0];
|
|
|
- if (device.available_quantity <= 0) {
|
|
|
- return { success: false, code, message: `设备 ${code} 当前无可用数量` };
|
|
|
+ const avail = getDeviceAvailableQuantityForBorrow(device);
|
|
|
+ if (avail <= 0) {
|
|
|
+ return { success: false, code, message: `设备 ${code} 可借用数量为0,无法加入领取列表` };
|
|
|
}
|
|
|
|
|
|
// 收集设备数据,统一处理添加逻辑
|
|
|
@@ -1976,7 +2014,7 @@ const handleScanSearch = async (event?: Event) => {
|
|
|
device_specification: device.specification,
|
|
|
model: device.model || '',
|
|
|
warehouse: device.warehouse,
|
|
|
- available_quantity: device.available_quantity
|
|
|
+ available_quantity: avail
|
|
|
});
|
|
|
processedCodes.add(code);
|
|
|
return { success: true, code, deviceId: device.id };
|
|
|
@@ -1994,19 +2032,14 @@ const handleScanSearch = async (event?: Event) => {
|
|
|
|
|
|
// 统计结果(先不处理添加,只统计)
|
|
|
results.forEach((result, index) => {
|
|
|
- if (result.status === 'fulfilled') {
|
|
|
- const { success, message } = result.value;
|
|
|
- if (success) {
|
|
|
- // 暂时不增加计数,等统一处理后再统计
|
|
|
- } else {
|
|
|
- failCount++;
|
|
|
- if (message) {
|
|
|
- errorMessages.push(message);
|
|
|
- }
|
|
|
- }
|
|
|
+ const { success, message } = readSettledListStepResult(result, batch[index] ?? String(index));
|
|
|
+ if (success) {
|
|
|
+ /* 暂时不增加计数,等统一处理后再统计 */
|
|
|
} else {
|
|
|
failCount++;
|
|
|
- errorMessages.push(`处理设备编号 ${batch[index]} 时发生错误`);
|
|
|
+ if (message) {
|
|
|
+ errorMessages.push(message);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -2167,8 +2200,9 @@ const processReturnRfidTagArray = async () => {
|
|
|
const existingDeviceIndex = returnDeviceList.value.findIndex(d => d.device_no === device.id);
|
|
|
if (existingDeviceIndex !== -1) {
|
|
|
const row = returnDeviceList.value[existingDeviceIndex];
|
|
|
- if (!applyReturnScanIncrement(row)) {
|
|
|
- return { success: false, code, message: '归还数量未增加(已达待归还上限或无待还)' };
|
|
|
+ const errMsg = tryApplyReturnScanIncrement(row);
|
|
|
+ if (errMsg) {
|
|
|
+ return { success: false, code, message: errMsg };
|
|
|
}
|
|
|
return { success: true, code };
|
|
|
} else {
|
|
|
@@ -2193,29 +2227,25 @@ const processReturnRfidTagArray = async () => {
|
|
|
|
|
|
// 统计结果
|
|
|
results.forEach((result, index) => {
|
|
|
- if (result.status === 'fulfilled') {
|
|
|
- const { success, message } = result.value;
|
|
|
- if (success) {
|
|
|
- successCount++;
|
|
|
- } else {
|
|
|
- failCount++;
|
|
|
- if (message) {
|
|
|
- errorMessages.push(message);
|
|
|
- }
|
|
|
- }
|
|
|
+ const { success, message } = readSettledListStepResult(result, batch[index] ?? String(index));
|
|
|
+ if (success) {
|
|
|
+ successCount++;
|
|
|
} else {
|
|
|
- // Promise 被拒绝的情况
|
|
|
failCount++;
|
|
|
- const errorReason = result.reason instanceof Error ? result.reason.message : String(result.reason);
|
|
|
- errorMessages.push(`处理设备编号 ${batch[index]} 时发生错误: ${errorReason}`);
|
|
|
- console.error(`[processReturnRfidTagArray] Promise 被拒绝:`, result.reason);
|
|
|
+ if (message) {
|
|
|
+ errorMessages.push(message);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
} catch (batchError) {
|
|
|
// 即使某批处理失败,也继续处理下一批
|
|
|
console.error(`处理批次失败:`, batchError);
|
|
|
failCount += batch.length;
|
|
|
- errorMessages.push(`处理批次时发生错误`);
|
|
|
+ errorMessages.push(
|
|
|
+ `处理批次时发生错误${
|
|
|
+ batchError instanceof Error ? `:${batchError.message}` : ''
|
|
|
+ }`
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -2815,8 +2845,9 @@ const handleReturnScanSearch = async (event?: Event) => {
|
|
|
const existingDeviceIndex = returnDeviceList.value.findIndex(d => d.device_no === device.id);
|
|
|
if (existingDeviceIndex !== -1) {
|
|
|
const row = returnDeviceList.value[existingDeviceIndex];
|
|
|
- if (!applyReturnScanIncrement(row)) {
|
|
|
- return { success: false, code, message: '归还数量未增加(已达待归还上限或无待还)' };
|
|
|
+ const errMsg = tryApplyReturnScanIncrement(row);
|
|
|
+ if (errMsg) {
|
|
|
+ return { success: false, code, message: errMsg };
|
|
|
}
|
|
|
return { success: true, code };
|
|
|
} else {
|
|
|
@@ -2841,19 +2872,14 @@ const handleReturnScanSearch = async (event?: Event) => {
|
|
|
|
|
|
// 统计结果
|
|
|
results.forEach((result, index) => {
|
|
|
- if (result.status === 'fulfilled') {
|
|
|
- const { success, message } = result.value;
|
|
|
- if (success) {
|
|
|
- successCount++;
|
|
|
- } else {
|
|
|
- failCount++;
|
|
|
- if (message) {
|
|
|
- errorMessages.push(message);
|
|
|
- }
|
|
|
- }
|
|
|
+ const { success, message } = readSettledListStepResult(result, batch[index] ?? String(index));
|
|
|
+ if (success) {
|
|
|
+ successCount++;
|
|
|
} else {
|
|
|
failCount++;
|
|
|
- errorMessages.push(`处理设备编号 ${batch[index]} 时发生错误`);
|
|
|
+ if (message) {
|
|
|
+ errorMessages.push(message);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|