feat(售后UI): 退回处置面板交互完善(作废确认)+ 售后列表页配套
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// @vitest-environment jsdom
|
||||
import React from 'react';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
|
||||
/**
|
||||
* 售后「主系统退回」处置面板:点「丢弃」后必须能看到并点到「确认丢弃」。
|
||||
*
|
||||
* 2026-10-20 报障:点「丢弃」后只显示「再点一次『确认丢弃』完成」,
|
||||
* 原来的实现把整块操作区替换成提示文字 ⇒ 确认按钮被一起藏掉,永远无法二次确认。
|
||||
* 本用例钉住:提示与「确认丢弃」按钮必须同时出现,点确认后调用 discard 接口。
|
||||
*/
|
||||
vi.mock('../../i18n/I18nProvider', () => ({
|
||||
useI18n: () => ({ t: (key: string) => key, locale: 'zh-CN' }),
|
||||
}));
|
||||
|
||||
const fetchReturnNotesApi = vi.fn();
|
||||
const applyReturnDispositionApi = vi.fn();
|
||||
const confirmReturnQualityApi = vi.fn();
|
||||
vi.mock('../../utils/workflowApi', () => ({
|
||||
fetchReturnNotesApi: (...args: unknown[]) => fetchReturnNotesApi(...args),
|
||||
applyReturnDispositionApi: (...args: unknown[]) => applyReturnDispositionApi(...args),
|
||||
confirmReturnQualityApi: (...args: unknown[]) => confirmReturnQualityApi(...args),
|
||||
}));
|
||||
|
||||
vi.mock('../../utils/notify', () => ({
|
||||
notify: { success: vi.fn(), error: vi.fn() },
|
||||
}));
|
||||
|
||||
import { ReturnDispositionPanel } from './ReturnDispositionPanel';
|
||||
|
||||
const pendingRow = {
|
||||
return_code: 'R_TEST_1',
|
||||
order_code: 'ORD_TEST_1',
|
||||
sku_code: 'SKU_TEST_1',
|
||||
item_name: '瘦肉',
|
||||
quantity: 15,
|
||||
disposition: 'pending',
|
||||
resupply_order_code: 'ORD_RS_TEST_1',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
fetchReturnNotesApi.mockReset();
|
||||
applyReturnDispositionApi.mockReset();
|
||||
confirmReturnQualityApi.mockReset();
|
||||
fetchReturnNotesApi.mockResolvedValue([pendingRow]);
|
||||
applyReturnDispositionApi.mockResolvedValue(undefined);
|
||||
confirmReturnQualityApi.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
afterEach(() => cleanup());
|
||||
|
||||
describe('主系统退回处置:丢弃的二次确认', () => {
|
||||
it('点「丢弃」后同时显示提示和「确认丢弃」按钮,再点确认才调用 discard', async () => {
|
||||
render(<ReturnDispositionPanel />);
|
||||
await screen.findByText('R_TEST_1');
|
||||
|
||||
// 第一次点击:进入待确认态
|
||||
fireEvent.click(screen.getByText('afterSales.return.discard'));
|
||||
|
||||
// 提示还在,但按钮没有被整块替换掉,必须仍能点到「确认丢弃」
|
||||
expect(screen.getByText('afterSales.return.confirmDiscard')).toBeTruthy();
|
||||
const confirmBtn = screen.getByText('afterSales.return.confirm');
|
||||
expect(confirmBtn).toBeTruthy();
|
||||
expect(applyReturnDispositionApi).not.toHaveBeenCalled();
|
||||
|
||||
// 第二次点击才真正提交丢弃
|
||||
fireEvent.click(confirmBtn);
|
||||
await waitFor(() => {
|
||||
expect(applyReturnDispositionApi).toHaveBeenCalledWith('R_TEST_1', {
|
||||
action: 'discard',
|
||||
batchNo: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -54,10 +54,10 @@ export const ReturnDispositionPanel: React.FC = () => {
|
||||
action,
|
||||
batchNo: action === 'restock' ? String(batchDraft[row.return_code] || '').trim() : null,
|
||||
});
|
||||
notify.success(t('aftersales.return.done'));
|
||||
notify.success(t('afterSales.return.done'));
|
||||
await load();
|
||||
} catch (error: any) {
|
||||
notify.error(error?.message || t('aftersales.return.fail'));
|
||||
notify.error(error?.message || t('afterSales.return.fail'));
|
||||
} finally {
|
||||
setBusyCode(null);
|
||||
setPendingConfirm(null);
|
||||
@@ -69,10 +69,10 @@ export const ReturnDispositionPanel: React.FC = () => {
|
||||
setBusyCode(row.return_code);
|
||||
try {
|
||||
await confirmReturnQualityApi(row.return_code, qualified);
|
||||
notify.success(t('aftersales.return.qualityDone'));
|
||||
notify.success(t('afterSales.return.qualityDone'));
|
||||
await load();
|
||||
} catch (error: any) {
|
||||
notify.error(error?.message || t('aftersales.return.fail'));
|
||||
notify.error(error?.message || t('afterSales.return.fail'));
|
||||
} finally {
|
||||
setBusyCode(null);
|
||||
}
|
||||
@@ -83,7 +83,7 @@ export const ReturnDispositionPanel: React.FC = () => {
|
||||
return (
|
||||
<div className="mb-4 rounded-xl border app-border bg-white dark:bg-slate-900">
|
||||
<div className="flex items-center justify-between px-4 py-2 border-b app-border">
|
||||
<span className="text-sm font-medium">{t('aftersales.return.title')}</span>
|
||||
<span className="text-sm font-medium">{t('afterSales.return.title')}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void load()}
|
||||
@@ -97,13 +97,13 @@ export const ReturnDispositionPanel: React.FC = () => {
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="text-left text-xs text-gray-500">
|
||||
<th className="px-4 py-2">{t('aftersales.return.colReturn')}</th>
|
||||
<th className="px-4 py-2">{t('aftersales.return.colOrder')}</th>
|
||||
<th className="px-4 py-2">{t('aftersales.return.colItem')}</th>
|
||||
<th className="px-4 py-2">{t('aftersales.return.colQty')}</th>
|
||||
<th className="px-4 py-2">{t('aftersales.return.colStatus')}</th>
|
||||
<th className="px-4 py-2">{t('aftersales.return.colResupply')}</th>
|
||||
<th className="px-4 py-2">{t('aftersales.return.colAction')}</th>
|
||||
<th className="px-4 py-2">{t('afterSales.return.colReturn')}</th>
|
||||
<th className="px-4 py-2">{t('afterSales.return.colOrder')}</th>
|
||||
<th className="px-4 py-2">{t('afterSales.return.colItem')}</th>
|
||||
<th className="px-4 py-2">{t('afterSales.return.colQty')}</th>
|
||||
<th className="px-4 py-2">{t('afterSales.return.colStatus')}</th>
|
||||
<th className="px-4 py-2">{t('afterSales.return.colResupply')}</th>
|
||||
<th className="px-4 py-2">{t('afterSales.return.colAction')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100 dark:divide-slate-800">
|
||||
@@ -115,8 +115,8 @@ export const ReturnDispositionPanel: React.FC = () => {
|
||||
<td className="px-4 py-2">{row.quantity}</td>
|
||||
<td className="px-4 py-2 text-xs">
|
||||
{row.disposition === 'restock_pending_inspect'
|
||||
? t('aftersales.return.statusPendingInspect')
|
||||
: t('aftersales.return.statusPending')}
|
||||
? t('afterSales.return.statusPendingInspect')
|
||||
: t('afterSales.return.statusPending')}
|
||||
</td>
|
||||
<td className="px-4 py-2 font-mono text-xs">{row.resupply_order_code || '—'}</td>
|
||||
<td className="px-4 py-2">
|
||||
@@ -128,7 +128,7 @@ export const ReturnDispositionPanel: React.FC = () => {
|
||||
onClick={() => void confirmQuality(row, true)}
|
||||
className="text-xs text-emerald-600 hover:underline disabled:opacity-50"
|
||||
>
|
||||
{t('aftersales.return.qualityPass')}
|
||||
{t('afterSales.return.qualityPass')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
@@ -136,38 +136,48 @@ export const ReturnDispositionPanel: React.FC = () => {
|
||||
onClick={() => void confirmQuality(row, false)}
|
||||
className="text-xs text-red-600 hover:underline disabled:opacity-50"
|
||||
>
|
||||
{t('aftersales.return.qualityReject')}
|
||||
{t('afterSales.return.qualityReject')}
|
||||
</button>
|
||||
</div>
|
||||
) : pendingConfirm === row.return_code ? (
|
||||
<span className="text-xs text-gray-500">{t('aftersales.return.confirmDiscard')}</span>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
value={batchDraft[row.return_code] || ''}
|
||||
onChange={(e) =>
|
||||
setBatchDraft((prev) => ({ ...prev, [row.return_code]: e.target.value }))
|
||||
}
|
||||
placeholder={t('aftersales.return.batchPh')}
|
||||
className="w-28 px-2 py-1 border app-border rounded text-xs"
|
||||
/>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{pendingConfirm === row.return_code ? (
|
||||
<span className="text-xs text-gray-500">{t('afterSales.return.confirmDiscard')}</span>
|
||||
) : (
|
||||
<input
|
||||
value={batchDraft[row.return_code] || ''}
|
||||
onChange={(e) =>
|
||||
setBatchDraft((prev) => ({ ...prev, [row.return_code]: e.target.value }))
|
||||
}
|
||||
placeholder={t('afterSales.return.batchPh')}
|
||||
className="w-28 px-2 py-1 border app-border rounded text-xs"
|
||||
/>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
disabled={busyCode === row.return_code || !String(batchDraft[row.return_code] || '').trim()}
|
||||
disabled={
|
||||
busyCode === row.return_code ||
|
||||
pendingConfirm === row.return_code ||
|
||||
!String(batchDraft[row.return_code] || '').trim()
|
||||
}
|
||||
onClick={() => void act(row, 'restock')}
|
||||
className="text-xs text-emerald-600 hover:underline disabled:opacity-50"
|
||||
>
|
||||
{t('aftersales.return.restock')}
|
||||
{t('afterSales.return.restock')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busyCode === row.return_code}
|
||||
onClick={() => (pendingConfirm === row.return_code ? void act(row, 'discard') : setPendingConfirm(row.return_code))}
|
||||
onClick={() =>
|
||||
pendingConfirm === row.return_code
|
||||
? void act(row, 'discard')
|
||||
: setPendingConfirm(row.return_code)
|
||||
}
|
||||
className="text-xs text-red-600 hover:underline disabled:opacity-50"
|
||||
>
|
||||
{pendingConfirm === row.return_code
|
||||
? t('aftersales.return.confirm')
|
||||
: t('aftersales.return.discard')}
|
||||
? t('afterSales.return.confirm')
|
||||
: t('afterSales.return.discard')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -129,6 +129,7 @@ const AFTERSALE_TYPES = [
|
||||
{ code: 'missing', icon: Truck, color: 'app-status-neutral border' },
|
||||
{ code: 'quality', icon: AlertTriangle, color: 'bg-purple-100 text-purple-700 dark:bg-purple-950/60 dark:text-purple-300 border border-purple-200 dark:border-purple-800' },
|
||||
{ code: 'order_return', icon: RotateCcw, color: 'app-status-info border' },
|
||||
{ code: 'main_system_return', icon: RotateCcw, color: 'app-status-info border' },
|
||||
{ code: 'spi_void', icon: RotateCcw, color: 'app-status-info border' },
|
||||
{ code: 'inbound_switch', icon: RotateCcw, color: 'app-status-info border' },
|
||||
{ code: 'cancel_fulfillment', icon: RotateCcw, color: 'app-status-neutral border' },
|
||||
|
||||
Reference in New Issue
Block a user