feat(退回补送): 售后页「主系统退回」处置面板——重新入库(需批次)/丢弃(行内二次确认)/质量确认,列表接口+三语;补送单号可见
This commit is contained in:
@@ -1943,6 +1943,24 @@ router.post('/after-sales/returns/ingest', authMiddleware, async (req: AuthReque
|
||||
}
|
||||
});
|
||||
|
||||
/** 退回单列表(售后 → 退回处置页):GET /after-sales/returns?disposition=pending */
|
||||
router.get('/after-sales/returns', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['aftersales_manage']);
|
||||
const { listMainSystemReturns } = await import('../../../services/mainSystemReturnService');
|
||||
const data = await listMainSystemReturns({
|
||||
branchCode: String(req.query?.branch_code || ctx?.branchCode || ''),
|
||||
disposition: typeof req.query?.disposition === 'string' ? req.query.disposition : null,
|
||||
limit: Number(req.query?.limit) || 100,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
const status = Number(error?.status) || 400;
|
||||
return res.status(status).json({ error: error?.code || 'server_error', error_description: error?.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/after-sales/returns/:returnCode/disposition', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
|
||||
@@ -521,3 +521,64 @@ export async function resolveOrderCodeByPrepId(input: {
|
||||
);
|
||||
return String(rows[0]?.our_order_code || '').trim() || null;
|
||||
}
|
||||
|
||||
/** 退回单列表(售后 → 退回处置用;按处置状态筛)。 */
|
||||
export async function listMainSystemReturns(input: {
|
||||
branchCode: string;
|
||||
disposition?: string | null;
|
||||
limit?: number;
|
||||
}): Promise<
|
||||
Array<{
|
||||
return_code: string;
|
||||
aftersale_code: string;
|
||||
order_code: string | null;
|
||||
sku_code: string | null;
|
||||
item_name: string | null;
|
||||
quantity: number;
|
||||
reason: string | null;
|
||||
disposition: string;
|
||||
quality_status: string | null;
|
||||
resupply_order_code: string | null;
|
||||
restock_batch_no: string | null;
|
||||
returned_at: string | null;
|
||||
}>
|
||||
> {
|
||||
const branchCode = String(input.branchCode || '').trim();
|
||||
if (!branchCode) return [];
|
||||
const limit = Math.min(Math.max(Number(input.limit) || 100, 1), 300);
|
||||
const disposition = String(input.disposition || '').trim();
|
||||
const params: unknown[] = [branchCode];
|
||||
let filter = '';
|
||||
if (disposition) {
|
||||
params.push(disposition);
|
||||
filter = ` AND r.disposition = $${params.length}`;
|
||||
}
|
||||
params.push(limit);
|
||||
const { rows } = await pool.query(
|
||||
`SELECT r.return_code, r.aftersale_code, r.order_code, r.sku_code,
|
||||
COALESCE(oi.item_name, r.sku_code) AS item_name,
|
||||
r.quantity, r.reason, COALESCE(r.disposition, 'pending') AS disposition,
|
||||
r.quality_status, r.resupply_order_code, r.restock_batch_no,
|
||||
to_char(r.returned_at, 'YYYY-MM-DD HH24:MI') AS returned_at
|
||||
FROM after_sale_returns r
|
||||
LEFT JOIN order_items oi ON oi.order_code = r.order_code AND oi.sku_code = r.sku_code
|
||||
WHERE r.branch_code = $1${filter}
|
||||
ORDER BY r.returned_at DESC NULLS LAST, r.created_at DESC
|
||||
LIMIT $${params.length}`,
|
||||
params
|
||||
);
|
||||
return rows.map((r: any) => ({
|
||||
return_code: String(r.return_code),
|
||||
aftersale_code: String(r.aftersale_code),
|
||||
order_code: r.order_code ?? null,
|
||||
sku_code: r.sku_code ?? null,
|
||||
item_name: r.item_name ?? null,
|
||||
quantity: Number(r.quantity) || 0,
|
||||
reason: r.reason ?? null,
|
||||
disposition: String(r.disposition || 'pending'),
|
||||
quality_status: r.quality_status ?? null,
|
||||
resupply_order_code: r.resupply_order_code ?? null,
|
||||
restock_batch_no: r.restock_batch_no ?? null,
|
||||
returned_at: r.returned_at ?? null,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
import { useI18n } from '../../i18n';
|
||||
import { notify } from '../../utils/notify';
|
||||
import {
|
||||
applyReturnDispositionApi,
|
||||
confirmReturnQualityApi,
|
||||
fetchReturnNotesApi,
|
||||
type ReturnNoteDto,
|
||||
} from '../../utils/workflowApi';
|
||||
|
||||
/**
|
||||
* 主系统「商品退回」处置面板(2026-10-20 确认稿 docs/design/20261020-主系统退回与补送.md)。
|
||||
*
|
||||
* 退回一到就会:① 售后记录 ② **立即生成补送单**(补送作业与这里解耦)。
|
||||
* 这里只处理**退回货物本身的去向**:
|
||||
* · 重新入库 ⇒ 先进「待检不可用」,质量确认合格才转可用(方案 B)
|
||||
* · 丢弃 ⇒ 记损耗(scrap)
|
||||
* 不使用浏览器原生 confirm(按开发者要求),采用行内两步确认。
|
||||
*/
|
||||
export const ReturnDispositionPanel: React.FC = () => {
|
||||
const { t } = useI18n();
|
||||
const [rows, setRows] = useState<ReturnNoteDto[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [batchDraft, setBatchDraft] = useState<Record<string, string>>({});
|
||||
const [pendingConfirm, setPendingConfirm] = useState<string | null>(null);
|
||||
const [busyCode, setBusyCode] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await fetchReturnNotesApi();
|
||||
setRows(Array.isArray(data) ? data : []);
|
||||
} catch {
|
||||
setRows([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
const actionable = rows.filter(
|
||||
(r) => r.disposition === 'pending' || r.disposition === 'restock_pending_inspect'
|
||||
);
|
||||
|
||||
const act = async (row: ReturnNoteDto, action: 'restock' | 'discard') => {
|
||||
if (busyCode) return;
|
||||
setBusyCode(row.return_code);
|
||||
try {
|
||||
await applyReturnDispositionApi(row.return_code, {
|
||||
action,
|
||||
batchNo: action === 'restock' ? String(batchDraft[row.return_code] || '').trim() : null,
|
||||
});
|
||||
notify.success(t('aftersales.return.done'));
|
||||
await load();
|
||||
} catch (error: any) {
|
||||
notify.error(error?.message || t('aftersales.return.fail'));
|
||||
} finally {
|
||||
setBusyCode(null);
|
||||
setPendingConfirm(null);
|
||||
}
|
||||
};
|
||||
|
||||
const confirmQuality = async (row: ReturnNoteDto, qualified: boolean) => {
|
||||
if (busyCode) return;
|
||||
setBusyCode(row.return_code);
|
||||
try {
|
||||
await confirmReturnQualityApi(row.return_code, qualified);
|
||||
notify.success(t('aftersales.return.qualityDone'));
|
||||
await load();
|
||||
} catch (error: any) {
|
||||
notify.error(error?.message || t('aftersales.return.fail'));
|
||||
} finally {
|
||||
setBusyCode(null);
|
||||
}
|
||||
};
|
||||
|
||||
if (!loading && actionable.length === 0) return null;
|
||||
|
||||
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>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void load()}
|
||||
className="inline-flex items-center gap-1 text-xs text-indigo-600 hover:underline"
|
||||
>
|
||||
<RefreshCw className="w-3.5 h-3.5" />
|
||||
{t('common.refresh')}
|
||||
</button>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100 dark:divide-slate-800">
|
||||
{actionable.map((row) => (
|
||||
<tr key={row.return_code}>
|
||||
<td className="px-4 py-2 font-mono text-xs">{row.return_code}</td>
|
||||
<td className="px-4 py-2 text-xs text-gray-500">{row.order_code || '—'}</td>
|
||||
<td className="px-4 py-2">{row.item_name || row.sku_code || '—'}</td>
|
||||
<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')}
|
||||
</td>
|
||||
<td className="px-4 py-2 font-mono text-xs">{row.resupply_order_code || '—'}</td>
|
||||
<td className="px-4 py-2">
|
||||
{row.disposition === 'restock_pending_inspect' ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
disabled={busyCode === row.return_code}
|
||||
onClick={() => void confirmQuality(row, true)}
|
||||
className="text-xs text-emerald-600 hover:underline disabled:opacity-50"
|
||||
>
|
||||
{t('aftersales.return.qualityPass')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busyCode === row.return_code}
|
||||
onClick={() => void confirmQuality(row, false)}
|
||||
className="text-xs text-red-600 hover:underline disabled:opacity-50"
|
||||
>
|
||||
{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"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busyCode === 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')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busyCode === 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')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ReturnDispositionPanel;
|
||||
@@ -145,4 +145,24 @@ export const afterSales: MessageDict = {
|
||||
'toast.created': 'Case created (includes 24h sign-off check)',
|
||||
'toast.createFail': 'Create failed',
|
||||
'toast.unsupportedAction': 'This page does not support action {id}',
|
||||
'return.title': 'Returns from main system',
|
||||
'return.colReturn': 'Return No.',
|
||||
'return.colOrder': 'Order',
|
||||
'return.colItem': 'Item',
|
||||
'return.colQty': 'Qty',
|
||||
'return.colStatus': 'Status',
|
||||
'return.colResupply': 'Resupply',
|
||||
'return.colAction': 'Action',
|
||||
'return.statusPending': 'Pending',
|
||||
'return.statusPendingInspect': 'Awaiting inspection',
|
||||
'return.restock': 'Restock',
|
||||
'return.discard': 'Discard',
|
||||
'return.confirm': 'Confirm discard',
|
||||
'return.confirmDiscard': 'Click again to confirm discard',
|
||||
'return.qualityPass': 'Qualified',
|
||||
'return.qualityReject': 'Reject',
|
||||
'return.batchPh': 'Batch no.',
|
||||
'return.done': 'Done',
|
||||
'return.qualityDone': 'Quality confirmed',
|
||||
'return.fail': 'Failed',
|
||||
};
|
||||
|
||||
@@ -145,4 +145,24 @@ export const afterSales: MessageDict = {
|
||||
'toast.created': 'Kasus dibuat (termasuk cek tanda terima 24 jam)',
|
||||
'toast.createFail': 'Gagal membuat',
|
||||
'toast.unsupportedAction': 'Halaman ini tidak mendukung aksi {id}',
|
||||
'return.title': 'Pengembalian dari sistem utama',
|
||||
'return.colReturn': 'No. retur',
|
||||
'return.colOrder': 'Pesanan',
|
||||
'return.colItem': 'Barang',
|
||||
'return.colQty': 'Jumlah',
|
||||
'return.colStatus': 'Status',
|
||||
'return.colResupply': 'Kirim ulang',
|
||||
'return.colAction': 'Aksi',
|
||||
'return.statusPending': 'Tertunda',
|
||||
'return.statusPendingInspect': 'Menunggu inspeksi',
|
||||
'return.restock': 'Stok ulang',
|
||||
'return.discard': 'Buang',
|
||||
'return.confirm': 'Konfirmasi buang',
|
||||
'return.confirmDiscard': 'Klik lagi untuk konfirmasi',
|
||||
'return.qualityPass': 'Lolos QC',
|
||||
'return.qualityReject': 'Tidak lolos',
|
||||
'return.batchPh': 'No. batch',
|
||||
'return.done': 'Selesai',
|
||||
'return.qualityDone': 'QC dikonfirmasi',
|
||||
'return.fail': 'Gagal',
|
||||
};
|
||||
|
||||
@@ -142,4 +142,24 @@ export const afterSales: MessageDict = {
|
||||
'toast.created': '售后单已创建(含 24h 签收校验)',
|
||||
'toast.createFail': '创建失败',
|
||||
'toast.unsupportedAction': '当前页不支持操作 {id}',
|
||||
'return.title': '主系统退回(待处置)',
|
||||
'return.colReturn': '退回单号',
|
||||
'return.colOrder': '原订单',
|
||||
'return.colItem': '商品',
|
||||
'return.colQty': '退回数量',
|
||||
'return.colStatus': '处置状态',
|
||||
'return.colResupply': '补送单',
|
||||
'return.colAction': '操作',
|
||||
'return.statusPending': '待处置',
|
||||
'return.statusPendingInspect': '待检(已入库待确认)',
|
||||
'return.restock': '重新入库',
|
||||
'return.discard': '丢弃',
|
||||
'return.confirm': '确认丢弃',
|
||||
'return.confirmDiscard': '再点一次「确认丢弃」完成',
|
||||
'return.qualityPass': '质量合格',
|
||||
'return.qualityReject': '不合格丢弃',
|
||||
'return.batchPh': '回补批次号',
|
||||
'return.done': '已处置',
|
||||
'return.qualityDone': '质量确认完成',
|
||||
'return.fail': '处置失败',
|
||||
};
|
||||
|
||||
@@ -56,6 +56,7 @@ import { useClientTableSort } from '../../hooks/useClientTableSort';
|
||||
import { useClientTablePagination } from '../../hooks/useClientTablePagination';
|
||||
import { TablePaginationBar } from '../../components/ui/TablePaginationBar';
|
||||
import { SortableThLabel } from '../../components/ui/SortableThLabel';
|
||||
import { ReturnDispositionPanel } from '../../components/aftersales/ReturnDispositionPanel';
|
||||
import { useT } from '../../i18n';
|
||||
|
||||
type AfterSalesColumnId =
|
||||
@@ -708,6 +709,7 @@ export const AfterSalesManagement: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<ReturnDispositionPanel />
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4 lg:gap-4">
|
||||
<StatusSummaryCard className="app-surface app-border rounded-xl border p-4 shadow-sm">
|
||||
<div className="flex items-center gap-3 mb-3">
|
||||
|
||||
@@ -7311,3 +7311,46 @@ export async function submitMainSystemBidQuotesApi(
|
||||
{ preserveErrorBody: true }
|
||||
).then((res) => res.data);
|
||||
}
|
||||
|
||||
/** 主系统退回:列表 / 处置 / 质量确认(售后 → 退回补送) */
|
||||
export interface ReturnNoteDto {
|
||||
return_code: string;
|
||||
aftersale_code: string;
|
||||
order_code: string | null;
|
||||
sku_code: string | null;
|
||||
item_name: string | null;
|
||||
quantity: number;
|
||||
reason: string | null;
|
||||
disposition: string;
|
||||
quality_status: string | null;
|
||||
resupply_order_code: string | null;
|
||||
restock_batch_no: string | null;
|
||||
returned_at: string | null;
|
||||
}
|
||||
|
||||
export async function fetchReturnNotesApi(params?: { disposition?: string; branchCode?: string }) {
|
||||
const qs = new URLSearchParams();
|
||||
if (params?.disposition) qs.set('disposition', params.disposition);
|
||||
if (params?.branchCode) qs.set('branch_code', params.branchCode);
|
||||
const q = qs.toString();
|
||||
return workflowFetch<{ data: ReturnNoteDto[] }>(`/after-sales/returns${q ? `?${q}` : ''}`).then(
|
||||
(r) => r.data
|
||||
);
|
||||
}
|
||||
|
||||
export async function applyReturnDispositionApi(
|
||||
returnCode: string,
|
||||
input: { action: 'restock' | 'discard'; batchNo?: string | null }
|
||||
) {
|
||||
return workflowFetch<{ data: { disposition: string; qualityStatus: string | null } }>(
|
||||
`/after-sales/returns/${encodeURIComponent(returnCode)}/disposition`,
|
||||
{ method: 'POST', body: JSON.stringify({ action: input.action, batch_no: input.batchNo || undefined }) }
|
||||
).then((r) => r.data);
|
||||
}
|
||||
|
||||
export async function confirmReturnQualityApi(returnCode: string, qualified: boolean) {
|
||||
return workflowFetch<{ data: { disposition: string; qualityStatus: string } }>(
|
||||
`/after-sales/returns/${encodeURIComponent(returnCode)}/quality`,
|
||||
{ method: 'POST', body: JSON.stringify({ qualified }) }
|
||||
).then((r) => r.data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user