|
|
@@ -123,48 +123,72 @@ export function useReplenishmentOrder() {
|
|
|
selectedRows.value = selection;
|
|
|
}
|
|
|
|
|
|
+ // ==================== 辅助函数 ====================
|
|
|
+
|
|
|
+ /** 从 API 响应或异常中提取错误消息 */
|
|
|
+ function getErrorMessage(err: any): string {
|
|
|
+ if (err?.response?.data?.message) return err.response.data.message;
|
|
|
+ if (err?.message) return err.message;
|
|
|
+ return "操作失败";
|
|
|
+ }
|
|
|
+
|
|
|
// ==================== 单行操作 ====================
|
|
|
|
|
|
async function handleDelete(row: any) {
|
|
|
try {
|
|
|
- const { code } = await deleteOrder(row.id);
|
|
|
+ const { code, message: msg } = await deleteOrder(row.id);
|
|
|
if (code === 200) { message("删除成功", { type: "success" }); onSearch(); }
|
|
|
- } catch { /* handled */ }
|
|
|
+ else { message(msg || "删除失败", { type: "error" }); }
|
|
|
+ } catch (err) { message(getErrorMessage(err), { type: "error" }); }
|
|
|
}
|
|
|
|
|
|
async function handleSubmitToErp(row: any) {
|
|
|
try {
|
|
|
- await submitOrder(row.id);
|
|
|
+ const submitRes = await submitOrder(row.id);
|
|
|
+ if (submitRes.code !== 200) {
|
|
|
+ message(submitRes.message || "提交失败", { type: "error" });
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
- await syncToErp(row.id);
|
|
|
- message("已提交并同步ERP", { type: "success" });
|
|
|
- } catch {
|
|
|
- message("已提交,但ERP同步失败", { type: "warning" });
|
|
|
+ const syncRes = await syncToErp(row.id);
|
|
|
+ if (syncRes.code !== 200) {
|
|
|
+ message(syncRes.message || "ERP同步失败", { type: "error" });
|
|
|
+ } else {
|
|
|
+ message("已提交并同步ERP", { type: "success" });
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ message("已提交,但ERP同步失败: " + getErrorMessage(err), { type: "warning" });
|
|
|
}
|
|
|
onSearch();
|
|
|
- } catch { /* handled */ }
|
|
|
+ } catch (err) { message(getErrorMessage(err), { type: "error" }); }
|
|
|
}
|
|
|
|
|
|
async function handleRetrySync(row: any) {
|
|
|
try {
|
|
|
- await syncToErp(row.id);
|
|
|
- message("ERP同步成功", { type: "success" });
|
|
|
- onSearch();
|
|
|
- } catch { /* handled */ }
|
|
|
+ const syncRes = await syncToErp(row.id);
|
|
|
+ if (syncRes.code !== 200) {
|
|
|
+ message(syncRes.message || "ERP同步失败", { type: "error" });
|
|
|
+ } else {
|
|
|
+ message("ERP同步成功", { type: "success" });
|
|
|
+ onSearch();
|
|
|
+ }
|
|
|
+ } catch (err) { message(getErrorMessage(err), { type: "error" }); }
|
|
|
}
|
|
|
|
|
|
async function handleComplete(row: any) {
|
|
|
try {
|
|
|
- const { code } = await completeOrder(row.id);
|
|
|
+ const { code, message: msg } = await completeOrder(row.id);
|
|
|
if (code === 200) { message("完成补货单", { type: "success" }); onSearch(); }
|
|
|
- } catch { /* handled */ }
|
|
|
+ else { message(msg || "完成失败", { type: "error" }); }
|
|
|
+ } catch (err) { message(getErrorMessage(err), { type: "error" }); }
|
|
|
}
|
|
|
|
|
|
async function handleCancel(row: any) {
|
|
|
try {
|
|
|
- const { code } = await cancelOrder(row.id);
|
|
|
+ const { code, message: msg } = await cancelOrder(row.id);
|
|
|
if (code === 200) { message("取消成功", { type: "success" }); onSearch(); }
|
|
|
- } catch { /* handled */ }
|
|
|
+ else { message(msg || "取消失败", { type: "error" }); }
|
|
|
+ } catch (err) { message(getErrorMessage(err), { type: "error" }); }
|
|
|
}
|
|
|
|
|
|
// ==================== 批量操作 ====================
|
|
|
@@ -179,14 +203,36 @@ export function useReplenishmentOrder() {
|
|
|
} catch { return; }
|
|
|
|
|
|
let ok = 0, fail = 0;
|
|
|
+ const errors: string[] = [];
|
|
|
for (const row of drafts) {
|
|
|
try {
|
|
|
- await submitOrder(row.id);
|
|
|
- await syncToErp(row.id);
|
|
|
- ok++;
|
|
|
- } catch { fail++; }
|
|
|
+ const submitRes = await submitOrder(row.id);
|
|
|
+ if (submitRes.code !== 200) {
|
|
|
+ fail++;
|
|
|
+ errors.push(`${row.orderNo || row.id}: ${submitRes.message || "提交失败"}`);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const syncRes = await syncToErp(row.id);
|
|
|
+ if (syncRes.code !== 200) {
|
|
|
+ ok++;
|
|
|
+ errors.push(`${row.orderNo || row.id}: ERP - ${syncRes.message || "失败"}`);
|
|
|
+ } else { ok++; }
|
|
|
+ } catch (syncErr) {
|
|
|
+ ok++;
|
|
|
+ errors.push(`${row.orderNo || row.id}: ERP - ${getErrorMessage(syncErr)}`);
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ fail++;
|
|
|
+ errors.push(`${row.orderNo || row.id}: ${getErrorMessage(err)}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const resultMsg = `批量提交完成:${ok} 成功, ${fail} 失败`;
|
|
|
+ if (errors.length > 0) {
|
|
|
+ message(resultMsg + "\n" + errors.slice(0, 5).join("\n"), { type: fail > 0 ? "error" : "warning", duration: 5000 });
|
|
|
+ } else {
|
|
|
+ message(resultMsg, { type: "success" });
|
|
|
}
|
|
|
- message(`批量提交完成:${ok} 成功, ${fail} 失败`, { type: fail > 0 ? "warning" : "success" });
|
|
|
onSearch();
|
|
|
}
|
|
|
|
|
|
@@ -200,10 +246,20 @@ export function useReplenishmentOrder() {
|
|
|
} catch { return; }
|
|
|
|
|
|
let ok = 0, fail = 0;
|
|
|
+ const cancelErrors: string[] = [];
|
|
|
for (const row of cancelable) {
|
|
|
- try { await cancelOrder(row.id); ok++; } catch { fail++; }
|
|
|
+ try {
|
|
|
+ const { code, message: msg } = await cancelOrder(row.id);
|
|
|
+ if (code === 200) { ok++; }
|
|
|
+ else { fail++; cancelErrors.push(`${row.orderNo || row.id}: ${msg || "取消失败"}`); }
|
|
|
+ } catch (err) { fail++; cancelErrors.push(`${row.orderNo || row.id}: ${getErrorMessage(err)}`); }
|
|
|
+ }
|
|
|
+ const cancelMsg = `批量取消完成:${ok} 成功, ${fail} 失败`;
|
|
|
+ if (cancelErrors.length > 0) {
|
|
|
+ message(cancelMsg + "\n" + cancelErrors.slice(0, 5).join("\n"), { type: fail > 0 ? "error" : "warning", duration: 5000 });
|
|
|
+ } else {
|
|
|
+ message(cancelMsg, { type: "success" });
|
|
|
}
|
|
|
- message(`批量取消完成:${ok} 成功, ${fail} 失败`, { type: fail > 0 ? "warning" : "success" });
|
|
|
onSearch();
|
|
|
}
|
|
|
|
|
|
@@ -217,10 +273,20 @@ export function useReplenishmentOrder() {
|
|
|
} catch { return; }
|
|
|
|
|
|
let ok = 0, fail = 0;
|
|
|
+ const delErrors: string[] = [];
|
|
|
for (const row of drafts) {
|
|
|
- try { await deleteOrder(row.id); ok++; } catch { fail++; }
|
|
|
+ try {
|
|
|
+ const { code, message: msg } = await deleteOrder(row.id);
|
|
|
+ if (code === 200) { ok++; }
|
|
|
+ else { fail++; delErrors.push(`${row.orderNo || row.id}: ${msg || "删除失败"}`); }
|
|
|
+ } catch (err) { fail++; delErrors.push(`${row.orderNo || row.id}: ${getErrorMessage(err)}`); }
|
|
|
+ }
|
|
|
+ const delMsg = `批量删除完成:${ok} 成功, ${fail} 失败`;
|
|
|
+ if (delErrors.length > 0) {
|
|
|
+ message(delMsg + "\n" + delErrors.slice(0, 5).join("\n"), { type: fail > 0 ? "error" : "warning", duration: 5000 });
|
|
|
+ } else {
|
|
|
+ message(delMsg, { type: "success" });
|
|
|
}
|
|
|
- message(`批量删除完成:${ok} 成功, ${fail} 失败`, { type: fail > 0 ? "warning" : "success" });
|
|
|
onSearch();
|
|
|
}
|
|
|
|