Merge branch 'hugo-shipping-notice' into dev
This commit is contained in:
commit
59b37422ab
113 files changed
+6036
-1759
No files matched your search
@@ -23,10 +23,10 @@ vi.mock('@/shared/utils/auth', () => ({
|
||||
|
||||
import {
|
||||
cancelTransferRun,
|
||||
createTransferPrecheck,
|
||||
executeTransferPrecheck,
|
||||
createTransferMatching,
|
||||
executeTransferItems,
|
||||
getTransferBacklogSummary,
|
||||
getTransferPrecheck,
|
||||
getTransferMatching,
|
||||
getTransferRun,
|
||||
listTransferSources,
|
||||
manualCloseTransferItem,
|
||||
@@ -39,21 +39,24 @@ describe('transfer.api JSON request contract', () => {
|
||||
requestBlob.mockReset();
|
||||
});
|
||||
|
||||
it('创建预检 POST 带 Content-Type: application/json 与序列化 source_codes', () => {
|
||||
createTransferPrecheck({ source_codes: ['DBS-AWSBI'], business_date: '2026-08-18' });
|
||||
it('创建匹配 POST 带 Content-Type: application/json 与序列化 source_codes', () => {
|
||||
createTransferMatching({ source_codes: ['DBS-AWSBI'], business_date: '2026-08-18' });
|
||||
const [url, init] = requestJson.mock.calls[0] as [string, RequestInit];
|
||||
expect(url).toBe('/api/in-transit-transfer/prechecks');
|
||||
expect(url).toBe('/api/in-transit-transfer/matchings');
|
||||
expect(init.method).toBe('POST');
|
||||
expect((init.headers as Record<string, string>)['Content-Type']).toBe('application/json');
|
||||
expect(init.body).toBe(JSON.stringify({ source_codes: ['DBS-AWSBI'], business_date: '2026-08-18' }));
|
||||
});
|
||||
|
||||
it('直接生成调拨单 POST 带 application/json', () => {
|
||||
executeTransferPrecheck('TPC-1', ['INV-001']);
|
||||
const [, init] = requestJson.mock.calls[0] as [string, RequestInit];
|
||||
it('按明细行执行调拨 POST /items/execute 带 application/json 与 item_ids 契约', () => {
|
||||
// [断言意图] 行式执行(2026-09-23 item-centric 重构):执行不再挂在旧匹配详情端点下,
|
||||
// 改为独立 items/execute,body 键从 invoice_nos 改为 item_ids;JSON 头契约不变。
|
||||
executeTransferItems([101, 102]);
|
||||
const [url, init] = requestJson.mock.calls[0] as [string, RequestInit];
|
||||
expect(url).toBe('/api/in-transit-transfer/items/execute');
|
||||
expect(init.method).toBe('POST');
|
||||
expect((init.headers as Record<string, string>)['Content-Type']).toBe('application/json');
|
||||
expect(init.body).toBe(JSON.stringify({ invoice_nos: ['INV-001'] }));
|
||||
expect(init.body).toBe(JSON.stringify({ item_ids: [101, 102] }));
|
||||
});
|
||||
|
||||
it('重试/关闭/取消 POST 带 application/json', () => {
|
||||
@@ -67,7 +70,7 @@ describe('transfer.api JSON request contract', () => {
|
||||
});
|
||||
|
||||
it('GET 端点只需鉴权头,不需要强制 Content-Type', () => {
|
||||
getTransferPrecheck('TPC-1');
|
||||
getTransferMatching('MTG-1');
|
||||
getTransferRun('RUN-1');
|
||||
getTransferBacklogSummary();
|
||||
listTransferSources();
|
||||
|
||||
@@ -10,9 +10,11 @@ import type {
|
||||
TransferActionResult,
|
||||
TransferBacklogItem,
|
||||
TransferBacklogSummary,
|
||||
TransferBatchResult,
|
||||
TransferExecuteResponse,
|
||||
TransferPrecheckDetail,
|
||||
TransferPrecheckSummary,
|
||||
TransferMatchingDetail,
|
||||
TransferMatchingItem,
|
||||
TransferMatchingSummary,
|
||||
TransferRunResult,
|
||||
TransferSourceFileStatus,
|
||||
TransferSourceOption,
|
||||
@@ -24,7 +26,7 @@ const BASE = '/api/in-transit-transfer';
|
||||
/** JSON 请求头:除鉴权外必须带 Content-Type: application/json,否则 Flask request.get_json 解析不到 body。 */
|
||||
const jsonHeaders = () => ({ 'Content-Type': 'application/json', ...getAuthHeaders() });
|
||||
|
||||
export interface CreatePrecheckPayload {
|
||||
export interface CreateMatchingPayload {
|
||||
source_codes: string[];
|
||||
business_date?: string;
|
||||
receipt_date_from?: string;
|
||||
@@ -33,26 +35,33 @@ export interface CreatePrecheckPayload {
|
||||
transfer_type?: TransferType;
|
||||
}
|
||||
|
||||
/** 创建预检(只读) */
|
||||
export const createTransferPrecheck = (payload: CreatePrecheckPayload) =>
|
||||
requestJson<TransferPrecheckSummary>(BASE + '/prechecks', {
|
||||
/** 创建匹配(只读) */
|
||||
export const createTransferMatching = (payload: CreateMatchingPayload) =>
|
||||
requestJson<TransferMatchingSummary>(BASE + '/matchings', {
|
||||
method: 'POST',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
/** 恢复预检进度与明细 */
|
||||
export const getTransferPrecheck = (precheckId: string) =>
|
||||
requestJson<TransferPrecheckDetail>(`${BASE}/prechecks/${precheckId}`, {
|
||||
/** 恢复匹配进度与明细 */
|
||||
export const getTransferMatching = (matchingId: string) =>
|
||||
requestJson<TransferMatchingDetail>(`${BASE}/matchings/${matchingId}`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
|
||||
/** 确认选择范围并直接生成执行 Run */
|
||||
export const executeTransferPrecheck = (precheckId: string, invoiceNos: string[]) =>
|
||||
requestJson<TransferExecuteResponse>(`${BASE}/prechecks/${precheckId}/execute`, {
|
||||
/** 可调拨明细:全局可执行行队列(勾选后 executeTransferItems 按行生成调拨单) */
|
||||
export const listExecutableTransferItems = () =>
|
||||
requestJson<{ items: TransferMatchingItem[]; counts: { executable_count: number } }>(
|
||||
`${BASE}/items/executable`,
|
||||
{ headers: getAuthHeaders() },
|
||||
);
|
||||
|
||||
/** 按明细行执行调拨(item-centric:body {item_ids};三层门禁在后端,失败抛 BusinessError) */
|
||||
export const executeTransferItems = (itemIds: number[]) =>
|
||||
requestJson<TransferExecuteResponse>(`${BASE}/items/execute`, {
|
||||
method: 'POST',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify({ invoice_nos: invoiceNos }),
|
||||
body: JSON.stringify({ item_ids: itemIds }),
|
||||
});
|
||||
|
||||
/** 恢复 Run 最终结果 */
|
||||
@@ -89,7 +98,7 @@ export const manualCloseTransferItem = (itemId: number, reason: string) =>
|
||||
export const downloadTransferReceiptFiles = (runNo: string) =>
|
||||
requestBlob(`${BASE}/runs/${runNo}/receipt-files`, { headers: getAuthHeaders() });
|
||||
|
||||
/** 下载预检冻结的 ERP 库存表(csv) */
|
||||
/** 下载匹配冻结的 ERP 库存表(csv) */
|
||||
export const downloadTransferErpInventory = (runNo: string) =>
|
||||
requestBlob(`${BASE}/runs/${runNo}/external-inventory`, { headers: getAuthHeaders() });
|
||||
|
||||
@@ -97,10 +106,26 @@ export const downloadTransferErpInventory = (runNo: string) =>
|
||||
export const downloadTransferExceptions = (runNo: string) =>
|
||||
requestBlob(`${BASE}/runs/${runNo}/exceptions.xlsx`, { headers: getAuthHeaders() });
|
||||
|
||||
/** 批量重查库存(待处理池多选;单行隔离,按明细 id 直取;恢复处理=重查的唯一后端) */
|
||||
export const batchRequeryTransferItems = (itemIds: number[]) =>
|
||||
requestJson<TransferBatchResult>(`${BASE}/items/batch-requery`, {
|
||||
method: 'POST',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify({ item_ids: itemIds }),
|
||||
});
|
||||
|
||||
/** 批量人工关闭异常项(原因整批共用;单行隔离) */
|
||||
export const batchManualCloseTransferItems = (itemIds: number[], reason: string) =>
|
||||
requestJson<TransferBatchResult>(`${BASE}/items/batch-manual-close`, {
|
||||
method: 'POST',
|
||||
headers: jsonHeaders(),
|
||||
body: JSON.stringify({ item_ids: itemIds, reason }),
|
||||
});
|
||||
|
||||
/** 批量重查 ERP 库存(可恢复阻断行;invoice_nos 缺省 = 全部阻断行) */
|
||||
export const requeryTransferItems = (precheckNo: string, invoiceNos?: string[]) =>
|
||||
requestJson<{ precheck_no: string; total: number; results: Array<Record<string, unknown>> }>(
|
||||
`${BASE}/prechecks/${precheckNo}/items/requery`,
|
||||
export const requeryTransferMatchingItems = (matchingNo: string, invoiceNos?: string[]) =>
|
||||
requestJson<{ matching_no: string; total: number; results: Array<Record<string, unknown>> }>(
|
||||
`${BASE}/matchings/${matchingNo}/items/requery`,
|
||||
{ method: 'POST', body: JSON.stringify(invoiceNos ? { invoice_nos: invoiceNos } : {}), headers: { ...getAuthHeaders(), 'Content-Type': 'application/json' } },
|
||||
);
|
||||
|
||||
|
||||
@@ -99,11 +99,11 @@ const RESTRICTED_INLINE_DOWNLOAD_FILE_NAME = '资产明细全量导出表.csv';
|
||||
const isContractReviewMessage = computed(() => message.type === 'procurement-contract-review');
|
||||
const isTransferMessage = computed(
|
||||
() =>
|
||||
message.type === 'transfer-precheck'
|
||||
message.type === 'transfer-match'
|
||||
|| message.type === 'transfer-progress'
|
||||
|| message.type === 'transfer-result',
|
||||
);
|
||||
/** 调拨消息带宽表格(预检明细 10+ 列),放宽气泡宽度上限避免横向挤压成局部布局。 */
|
||||
/** 调拨消息带宽表格(匹配明细 10+ 列),放宽气泡宽度上限避免横向挤压成局部布局。 */
|
||||
const wideMessage = computed(() => isTransferMessage.value || isContractReviewMessage.value);
|
||||
|
||||
const isLeaveMessage = computed(() =>
|
||||
|
||||
@@ -1,22 +1,93 @@
|
||||
<!--
|
||||
features/chat/components/messages/TransferBacklogSummaryCard.vue
|
||||
用途:待处理异常卡(可恢复/已关闭/结果未知三组)+ 人工重试/人工关闭入口。
|
||||
依赖:props.items、i18n chat.transfer.*。
|
||||
逻辑:result_unknown 只读(无重试/关闭按钮);人工关闭由父组件弹窗处理。
|
||||
用途:待处理异常卡(可恢复/已关闭/结果未知三组)——列与匹配窗口一致,
|
||||
支持关键字/结果筛选、多选批量操作(重查/恢复处理/标记无需处理)与行级快捷操作。
|
||||
依赖:props.items、i18n chat.transfer.*、transferBatch.deriveBatchNo。
|
||||
逻辑:仅 blocked_recoverable 可勾选与操作;result_unknown / manually_closed 只读;
|
||||
可恢复行按 result_code 细分徽标(blocked_file_removed=文件已移除);
|
||||
勾选集合为卡片本地态,操作经 emit 交父组件调用批量端点并刷新。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { deriveBatchNo } from './transferBatch';
|
||||
import type { TransferBacklogItem } from '../../types/transfer.types';
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
items: TransferBacklogItem[];
|
||||
busy?: boolean;
|
||||
/** 初始结果筛选(首页计数卡切片进入:closed 卡落「已关闭」切片等)。 */
|
||||
initialFilter?: 'all' | 'recoverable' | 'closed' | 'unknown';
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
retry: [itemId: number];
|
||||
close: [item: TransferBacklogItem];
|
||||
refresh: [];
|
||||
retry: [itemId: number];
|
||||
resume: [itemIds: number[]];
|
||||
requery: [itemIds: number[]];
|
||||
close: [item: TransferBacklogItem];
|
||||
batchClose: [itemIds: number[]];
|
||||
}>();
|
||||
|
||||
/** 勾选集合(本地视图态;仅可恢复行可勾选)。 */
|
||||
const selectedIds = ref<Set<number>>(new Set());
|
||||
const keyword = ref('');
|
||||
const resultFilter = ref<'all' | 'recoverable' | 'closed' | 'unknown'>(props.initialFilter ?? 'all');
|
||||
|
||||
function isActionable(item: TransferBacklogItem): boolean {
|
||||
return item.status === 'blocked_recoverable';
|
||||
}
|
||||
|
||||
const filtered = computed(() =>
|
||||
props.items.filter((item) => {
|
||||
const kw = keyword.value.trim().toLowerCase();
|
||||
if (kw) {
|
||||
const haystack = [item.invoice_no, item.material_no, item.material_name, item.source_code]
|
||||
.map((value) => String(value ?? '').toLowerCase());
|
||||
if (!haystack.some((value) => value.includes(kw))) return false;
|
||||
}
|
||||
if (resultFilter.value === 'recoverable' && item.status !== 'blocked_recoverable') return false;
|
||||
if (resultFilter.value === 'closed' && item.status !== 'manually_closed') return false;
|
||||
if (resultFilter.value === 'unknown' && item.status !== 'result_unknown') return false;
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
|
||||
const selectedActionableIds = computed(() =>
|
||||
filtered.value.filter((item) => isActionable(item) && selectedIds.value.has(item.item_id)).map((item) => item.item_id),
|
||||
);
|
||||
|
||||
const allFilteredSelected = computed(() => {
|
||||
const actionable = filtered.value.filter(isActionable);
|
||||
return actionable.length > 0 && actionable.every((item) => selectedIds.value.has(item.item_id));
|
||||
});
|
||||
|
||||
function toggleRow(item: TransferBacklogItem, checked: boolean) {
|
||||
const next = new Set(selectedIds.value);
|
||||
if (checked) next.add(item.item_id);
|
||||
else next.delete(item.item_id);
|
||||
selectedIds.value = next;
|
||||
}
|
||||
|
||||
function toggleAll(checked: boolean) {
|
||||
const next = new Set(selectedIds.value);
|
||||
for (const item of filtered.value.filter(isActionable)) {
|
||||
if (checked) next.add(item.item_id);
|
||||
else next.delete(item.item_id);
|
||||
}
|
||||
selectedIds.value = next;
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedIds.value = new Set();
|
||||
}
|
||||
|
||||
/** 行操作后/刷新后清理已消失行的勾选残留。 */
|
||||
function pruneSelection() {
|
||||
const alive = new Set(props.items.map((item) => item.item_id));
|
||||
selectedIds.value = new Set([...selectedIds.value].filter((id) => alive.has(id)));
|
||||
}
|
||||
defineExpose({ pruneSelection });
|
||||
|
||||
function agingLabel(level: string): string {
|
||||
const map: Record<string, string> = {
|
||||
warn_3d: 'chat.transfer.agingWarn',
|
||||
@@ -27,6 +98,19 @@ function agingLabel(level: string): string {
|
||||
};
|
||||
return map[level] ?? 'chat.transfer.agingNormal';
|
||||
}
|
||||
|
||||
function rowKey(item: TransferBacklogItem): string {
|
||||
return `${item.item_id}|${item.invoice_no}`;
|
||||
}
|
||||
|
||||
/** 结果徽标文案键:可恢复行按 result_code 细分(blocked_file_removed=文件已移除),其余按状态。 */
|
||||
function resultLabelKey(item: TransferBacklogItem): string {
|
||||
if (item.status === 'result_unknown') return 'chat.transfer.resultUnknown';
|
||||
if (item.status === 'manually_closed') return 'chat.transfer.statusClosed';
|
||||
return item.result_code === 'blocked_file_removed'
|
||||
? 'chat.transfer.resultFileRemoved'
|
||||
: 'chat.transfer.resultBlocked';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -42,47 +126,177 @@ function agingLabel(level: string): string {
|
||||
{{ $t('chat.transfer.refreshProgress') }}
|
||||
</button>
|
||||
</div>
|
||||
<ul v-if="items.length" class="flex flex-col gap-1.5">
|
||||
<li
|
||||
v-for="item in items"
|
||||
:key="item.item_id"
|
||||
class="flex items-center justify-between gap-2 rounded-lg border border-subtle px-3 py-2 text-xs"
|
||||
:data-testid="`transfer-backlog-${item.invoice_no}`"
|
||||
|
||||
<!-- 批量操作条:勾选 ≥1 行时原位替换筛选区 -->
|
||||
<div v-if="selectedActionableIds.length" class="mb-2 flex flex-wrap items-center gap-2">
|
||||
<span class="text-xs font-bold text-secondary" data-testid="transfer-backlog-selected-count">
|
||||
{{ $t('chat.transfer.selectedRows', { count: selectedActionableIds.length }) }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-brand-200 bg-brand-50 px-3 py-1 text-xs font-bold text-brand-700 transition hover:bg-brand-100 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
data-testid="transfer-backlog-batch-requery"
|
||||
:disabled="busy"
|
||||
@click="emit('requery', selectedActionableIds)"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<div class="font-semibold text-secondary">
|
||||
{{ item.invoice_no }}
|
||||
<span class="ml-1 text-muted">{{ item.source_code }}</span>
|
||||
</div>
|
||||
<div class="text-[11px] text-muted">
|
||||
{{ item.reason }} · {{ $t(agingLabel(item.aging_level)) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex shrink-0 gap-1.5">
|
||||
<template v-if="item.status === 'blocked_recoverable'">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-brand-200 px-2 py-1 font-bold text-brand-700 hover:bg-brand-50"
|
||||
data-testid="transfer-backlog-retry"
|
||||
@click="emit('retry', item.item_id)"
|
||||
>
|
||||
{{ $t('chat.transfer.retryErp') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-red-200 px-2 py-1 font-bold text-red-600 hover:bg-red-50"
|
||||
data-testid="transfer-backlog-close"
|
||||
@click="emit('close', item)"
|
||||
>
|
||||
{{ $t('chat.transfer.manualClose') }}
|
||||
</button>
|
||||
</template>
|
||||
<span v-else-if="item.status === 'result_unknown'" class="text-[11px] text-muted">
|
||||
{{ $t('chat.transfer.resultUnknownReadonly') }}
|
||||
</span>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
{{ $t('chat.transfer.requeryRow') }}({{ selectedActionableIds.length }})
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-brand-200 bg-brand-50 px-3 py-1 text-xs font-bold text-brand-700 transition hover:bg-brand-100 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
data-testid="transfer-backlog-batch-resume"
|
||||
:disabled="busy"
|
||||
@click="emit('resume', selectedActionableIds)"
|
||||
>
|
||||
{{ $t('chat.transfer.resumeAction') }}({{ selectedActionableIds.length }})
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-red-200 bg-red-50 px-3 py-1 text-xs font-bold text-red-600 transition hover:bg-red-100 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
data-testid="transfer-backlog-batch-close"
|
||||
:disabled="busy"
|
||||
@click="emit('batchClose', selectedActionableIds)"
|
||||
>
|
||||
{{ $t('chat.transfer.manualClose') }}({{ selectedActionableIds.length }})
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-default px-2 py-1 text-xs text-secondary hover-surface-soft"
|
||||
data-testid="transfer-backlog-clear-selection"
|
||||
@click="clearSelection"
|
||||
>
|
||||
{{ $t('chat.transfer.clearSelection') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="mb-2 flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
v-model="keyword"
|
||||
type="text"
|
||||
class="w-56 rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
|
||||
:placeholder="$t('chat.transfer.filterPlaceholder')"
|
||||
data-testid="transfer-backlog-filter"
|
||||
/>
|
||||
<select
|
||||
v-model="resultFilter"
|
||||
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
|
||||
data-testid="transfer-backlog-result-filter"
|
||||
>
|
||||
<option value="all">{{ $t('chat.transfer.filterAll') }}</option>
|
||||
<option value="recoverable">{{ $t('chat.transfer.homeRecoverable') }}</option>
|
||||
<option value="closed">{{ $t('chat.transfer.homeClosed') }}</option>
|
||||
<option value="unknown">{{ $t('chat.transfer.homeUnknown') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div v-if="filtered.length" class="overflow-x-auto">
|
||||
<table class="w-full min-w-[1180px] text-xs" data-testid="transfer-backlog-table">
|
||||
<thead>
|
||||
<tr class="border-b border-default bg-surface-soft text-left text-[11px] text-muted">
|
||||
<th class="p-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="allFilteredSelected"
|
||||
data-testid="transfer-backlog-select-all"
|
||||
@change="toggleAll(($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colSource') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colInvoice') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colReceiptDate') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colMaterial') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colName') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colFromWarehouse') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colFromBatch') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colFromQty') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colToWarehouse') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colToQty') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colResult') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colAging') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colAction') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="item in filtered"
|
||||
:key="rowKey(item)"
|
||||
class="border-b border-subtle"
|
||||
:class="{ 'bg-surface-soft text-muted': !isActionable(item) }"
|
||||
:data-testid="`transfer-backlog-${item.invoice_no}`"
|
||||
>
|
||||
<td class="p-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="selectedIds.has(item.item_id)"
|
||||
:disabled="!isActionable(item) || busy"
|
||||
:data-testid="`transfer-backlog-check-${item.invoice_no}`"
|
||||
@change="toggleRow(item, ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
</td>
|
||||
<td class="p-2">{{ item.source_code }}</td>
|
||||
<td class="p-2 font-semibold">{{ item.invoice_no }}</td>
|
||||
<td class="p-2">{{ item.receipt_date || '—' }}</td>
|
||||
<td class="p-2">{{ item.material_no }}</td>
|
||||
<td class="p-2">{{ item.material_name || '—' }}</td>
|
||||
<td class="p-2">{{ item.from_warehouse || '—' }}</td>
|
||||
<td class="p-2">{{ deriveBatchNo(item.lot_no ?? '') || '—' }}</td>
|
||||
<td class="p-2">{{ item.external_quantity ?? '—' }}</td>
|
||||
<td class="p-2">{{ item.to_warehouse || '—' }}</td>
|
||||
<td class="p-2">{{ item.receipt_quantity ?? '—' }}</td>
|
||||
<td class="p-2">
|
||||
<span
|
||||
class="rounded-full px-2 py-0.5 font-bold"
|
||||
:class="{
|
||||
'bg-red-50 text-red-700': item.status === 'blocked_recoverable',
|
||||
'bg-amber-50 text-amber-700': item.status === 'result_unknown',
|
||||
'bg-surface-soft text-muted': item.status === 'manually_closed',
|
||||
}"
|
||||
:title="item.reason || undefined"
|
||||
data-testid="transfer-backlog-result"
|
||||
>
|
||||
{{
|
||||
$t(resultLabelKey(item))
|
||||
}}
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-2">{{ $t(agingLabel(item.aging_level)) }}</td>
|
||||
<td class="p-2">
|
||||
<template v-if="isActionable(item)">
|
||||
<button
|
||||
type="button"
|
||||
class="mr-1 rounded border border-brand-200 px-1 py-0.5 text-[10px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
|
||||
:data-testid="`transfer-backlog-requery-${item.invoice_no}`"
|
||||
:disabled="busy"
|
||||
@click="emit('retry', item.item_id)"
|
||||
>
|
||||
{{ $t('chat.transfer.requeryRow') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="mr-1 rounded border border-brand-200 px-1 py-0.5 text-[10px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
|
||||
:data-testid="`transfer-backlog-resume-${item.invoice_no}`"
|
||||
:disabled="busy"
|
||||
@click="emit('resume', [item.item_id])"
|
||||
>
|
||||
{{ $t('chat.transfer.resumeAction') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded border border-red-200 px-1 py-0.5 text-[10px] font-bold text-red-600 transition hover:bg-red-50 disabled:opacity-40"
|
||||
:data-testid="`transfer-backlog-close-${item.invoice_no}`"
|
||||
:disabled="busy"
|
||||
@click="emit('close', item)"
|
||||
>
|
||||
{{ $t('chat.transfer.manualClose') }}
|
||||
</button>
|
||||
</template>
|
||||
<span v-else-if="item.status === 'result_unknown'" class="text-[11px] text-muted">
|
||||
{{ $t('chat.transfer.resultUnknownReadonly') }}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-else class="rounded-lg bg-surface-soft p-3 text-xs text-muted">
|
||||
{{ $t('chat.transfer.noBacklog') }}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
<!--
|
||||
features/chat/components/messages/TransferExecutableCard.vue
|
||||
用途:可调拨明细卡——全局可执行行队列(跨匹配范围):勾选明细行后按行生成调拨单。
|
||||
依赖:props.items、i18n chat.transfer.*、transferBatch.deriveBatchNo。
|
||||
逻辑:行由后端按业务稳定键排序(收料日期→Invoice→创建时间);勾选为卡片本地态;
|
||||
stale/file_current 行置灰提示(执行门禁在后端,失败经 BusinessError 展示);
|
||||
无 item_id 的历史回放行禁选。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { deriveBatchNo } from './transferBatch';
|
||||
import type { TransferMatchingItem } from '../../types/transfer.types';
|
||||
|
||||
const props = defineProps<{
|
||||
items: TransferMatchingItem[];
|
||||
busy?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
refresh: [];
|
||||
execute: [itemIds: number[]];
|
||||
requery: [itemIds: number[]];
|
||||
}>();
|
||||
|
||||
/** 勾选集合(本地视图态,按明细行 item_id)。 */
|
||||
const selectedIds = ref<Set<number>>(new Set());
|
||||
const keyword = ref('');
|
||||
|
||||
const filtered = computed(() =>
|
||||
props.items.filter((item) => {
|
||||
const kw = keyword.value.trim().toLowerCase();
|
||||
if (!kw) return true;
|
||||
const haystack = [item.invoice_no, item.material_no, item.material_name, item.source_code, item.lot_no]
|
||||
.map((value) => String(value ?? '').toLowerCase());
|
||||
return haystack.some((value) => value.includes(kw));
|
||||
}),
|
||||
);
|
||||
|
||||
const checked = computed(() =>
|
||||
filtered.value.filter((item) => item.item_id != null && selectedIds.value.has(item.item_id)),
|
||||
);
|
||||
|
||||
const allFilteredSelected = computed(() =>
|
||||
filtered.value.length > 0 && filtered.value.every((item) => item.item_id != null && selectedIds.value.has(item.item_id)),
|
||||
);
|
||||
|
||||
function toggleRow(item: TransferMatchingItem, checkedBox: boolean) {
|
||||
if (item.item_id == null) return;
|
||||
const next = new Set(selectedIds.value);
|
||||
if (checkedBox) next.add(item.item_id);
|
||||
else next.delete(item.item_id);
|
||||
selectedIds.value = next;
|
||||
}
|
||||
|
||||
function toggleAll(checkedBox: boolean) {
|
||||
const next = new Set(selectedIds.value);
|
||||
for (const item of filtered.value) {
|
||||
if (item.item_id == null) continue;
|
||||
if (checkedBox) next.add(item.item_id);
|
||||
else next.delete(item.item_id);
|
||||
}
|
||||
selectedIds.value = next;
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedIds.value = new Set();
|
||||
}
|
||||
|
||||
function rowKey(item: TransferMatchingItem): string {
|
||||
return `${item.item_id ?? 'na'}|${item.invoice_no}`;
|
||||
}
|
||||
|
||||
/** 查询时刻展示(HH:mm);无 checked_at 不渲染。 */
|
||||
function checkedTime(item: TransferMatchingItem): string {
|
||||
if (!item.checked_at) return '';
|
||||
const date = new Date(item.checked_at);
|
||||
return Number.isNaN(date.getTime()) ? '' : date.toTimeString().slice(0, 5);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="my-2 rounded-2xl border border-brand-100 bg-surface p-4 shadow-sm" data-testid="transfer-executable-card">
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<h3 class="text-sm font-bold text-primary">{{ $t('chat.transfer.executableTitle') }}</h3>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg border border-default px-2 py-1 text-xs text-secondary hover-surface-soft"
|
||||
data-testid="transfer-executable-refresh"
|
||||
@click="emit('refresh')"
|
||||
>
|
||||
{{ $t('chat.transfer.refreshProgress') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="mb-2 flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
v-model="keyword"
|
||||
type="text"
|
||||
class="w-56 rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
|
||||
:placeholder="$t('chat.transfer.filterPlaceholder')"
|
||||
data-testid="transfer-executable-filter"
|
||||
/>
|
||||
<span v-if="checked.length" class="text-xs font-bold text-secondary" data-testid="transfer-executable-selected-count">
|
||||
{{ $t('chat.transfer.selectedRows', { count: checked.length }) }}
|
||||
</span>
|
||||
<button
|
||||
v-if="checked.length"
|
||||
type="button"
|
||||
class="rounded-lg border border-default px-2 py-1 text-xs text-secondary hover-surface-soft"
|
||||
data-testid="transfer-executable-clear-selection"
|
||||
@click="clearSelection"
|
||||
>
|
||||
{{ $t('chat.transfer.clearSelection') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="filtered.length" class="overflow-x-auto">
|
||||
<table class="w-full min-w-[1100px] text-xs" data-testid="transfer-executable-table">
|
||||
<thead>
|
||||
<tr class="border-b border-default bg-surface-soft text-left text-[11px] text-muted">
|
||||
<th class="p-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="allFilteredSelected"
|
||||
data-testid="transfer-executable-select-all"
|
||||
@change="toggleAll(($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colSource') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colInvoice') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colReceiptDate') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colMaterial') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colName') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colFromWarehouse') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colFromBatch') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colFromQty') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colToWarehouse') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colToQty') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colResult') }}</th>
|
||||
<th class="p-2">{{ $t('chat.transfer.colAction') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="item in filtered"
|
||||
:key="rowKey(item)"
|
||||
class="border-b border-subtle"
|
||||
:class="{ 'bg-surface-soft text-muted': item.stale || item.file_current === false }"
|
||||
:data-testid="`transfer-executable-${item.invoice_no}`"
|
||||
>
|
||||
<td class="p-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="item.item_id != null && selectedIds.has(item.item_id)"
|
||||
:disabled="item.item_id == null || busy"
|
||||
:data-testid="`transfer-executable-check-${item.invoice_no}`"
|
||||
@change="toggleRow(item, ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
</td>
|
||||
<td class="p-2">{{ item.source_code }}</td>
|
||||
<td class="p-2 font-semibold">{{ item.invoice_no }}</td>
|
||||
<td class="p-2">{{ item.receipt_date || '—' }}</td>
|
||||
<td class="p-2">{{ item.material_no }}</td>
|
||||
<td class="p-2">{{ item.material_name }}</td>
|
||||
<td class="p-2">{{ item.from_warehouse }}</td>
|
||||
<td class="p-2">{{ deriveBatchNo(item.lot_no ?? '') || '—' }}</td>
|
||||
<td class="p-2">
|
||||
{{ item.from_quantity ?? '—' }}
|
||||
<div v-if="checkedTime(item)" class="text-[10px] text-muted">{{ checkedTime(item) }}</div>
|
||||
</td>
|
||||
<td class="p-2">{{ item.to_warehouse }}</td>
|
||||
<td class="p-2">{{ item.to_quantity }}</td>
|
||||
<td class="p-2">
|
||||
<span class="rounded-full bg-emerald-50 px-2 py-0.5 font-bold text-emerald-700" data-testid="transfer-executable-result">
|
||||
{{ $t('chat.transfer.resultExecutable') }}
|
||||
</span>
|
||||
<div v-if="item.stale" class="mt-0.5 text-[10px] text-amber-600">{{ $t('chat.transfer.staleRow') }}</div>
|
||||
<div v-else-if="item.file_current === false" class="mt-0.5 text-[10px] text-amber-600">{{ $t('chat.transfer.fileChangedRow') }}</div>
|
||||
</td>
|
||||
<td class="p-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded border border-brand-200 px-1 py-0.5 text-[10px] font-bold text-brand-700 transition hover:bg-brand-50 disabled:opacity-40"
|
||||
:data-testid="`transfer-executable-requery-${item.invoice_no}`"
|
||||
:disabled="busy || item.item_id == null"
|
||||
@click="item.item_id != null && emit('requery', [item.item_id])"
|
||||
>
|
||||
{{ $t('chat.transfer.requeryRow') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-else class="rounded-lg bg-surface-soft p-3 text-xs text-muted" data-testid="transfer-executable-empty">
|
||||
{{ $t('chat.transfer.executableEmpty') }}
|
||||
</div>
|
||||
|
||||
<div class="mt-3 flex items-center justify-end gap-3 border-t border-subtle pt-3">
|
||||
<span class="text-xs text-muted">{{ $t('chat.transfer.executableSelectedCount', { count: checked.length }) }}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg bg-brand-600 px-4 py-1.5 text-sm font-bold text-white hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
:disabled="busy || checked.length === 0"
|
||||
data-testid="transfer-executable-generate"
|
||||
@click="emit('execute', checked.map((item) => item.item_id as number))"
|
||||
>
|
||||
{{ $t('chat.transfer.generateTransfer') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -11,9 +11,9 @@ import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
createTransferPrecheck: vi.fn(),
|
||||
getTransferPrecheck: vi.fn(),
|
||||
executeTransferPrecheck: vi.fn(),
|
||||
createTransferMatching: vi.fn(),
|
||||
getTransferMatching: vi.fn(),
|
||||
executeTransferItems: vi.fn(),
|
||||
getTransferRun: vi.fn(),
|
||||
retryTransferItem: vi.fn(),
|
||||
manualCloseTransferItem: vi.fn(),
|
||||
@@ -23,6 +23,7 @@ const api = vi.hoisted(() => ({
|
||||
listTransferBacklog: vi.fn(),
|
||||
getTransferBacklogSummary: vi.fn(),
|
||||
listTransferSources: vi.fn(),
|
||||
listExecutableTransferItems: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/features/chat/api/transfer.api', () => api);
|
||||
@@ -43,6 +44,7 @@ describe('TransferHomePanel chat home entry', () => {
|
||||
recoverable: 6, closed: 2, unknown: 1, aging: { warn_3d: 3, escalate_5d: 2, critical_7d: 1 },
|
||||
});
|
||||
api.listTransferBacklog.mockResolvedValue([]);
|
||||
api.listExecutableTransferItems.mockResolvedValue({ items: [], counts: { executable_count: 0 } });
|
||||
api.listTransferSources.mockResolvedValue([
|
||||
{ source_code: 'DBS-AWSBI', display_name: 'AWSBI', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' },
|
||||
]);
|
||||
@@ -59,19 +61,19 @@ describe('TransferHomePanel chat home entry', () => {
|
||||
expect(api.getTransferBacklogSummary).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('点击“发起今日调拨预检”独立触发来源选择卡(复用 TransferMessageView)', async () => {
|
||||
api.createTransferPrecheck.mockResolvedValue({
|
||||
precheck_id: 'TPC-1', status: 'ready_to_execute', business_date: '2026-08-06',
|
||||
it('点击“匹配可调拨库存”今日待办入口独立触发来源选择卡(复用 TransferMessageView)', async () => {
|
||||
api.createTransferMatching.mockResolvedValue({
|
||||
matching_id: 'MTG-1', status: 'ready_to_execute', business_date: '2026-08-06',
|
||||
eligible_receipt_date_to: '2026-08-05', expires_at: '',
|
||||
counts: { file_invoice_count: 1, not_matured_count: 0, prechecked_count: 1, executable_count: 1, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '1200', estimated_external_write_count: 1, precheck_hash: 'sha256:x',
|
||||
counts: { file_invoice_count: 1, not_matured_count: 0, matched_count: 1, executable_count: 1, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '1200', estimated_external_write_count: 1, matching_hash: 'sha256:x',
|
||||
});
|
||||
api.getTransferPrecheck.mockResolvedValue({
|
||||
api.getTransferMatching.mockResolvedValue({
|
||||
summary: {
|
||||
precheck_id: 'TPC-1', status: 'ready_to_execute', business_date: '2026-08-06',
|
||||
matching_id: 'MTG-1', status: 'ready_to_execute', business_date: '2026-08-06',
|
||||
eligible_receipt_date_to: '2026-08-05', expires_at: '',
|
||||
counts: { file_invoice_count: 1, not_matured_count: 0, prechecked_count: 1, executable_count: 1, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '1200', estimated_external_write_count: 1, precheck_hash: 'sha256:x',
|
||||
counts: { file_invoice_count: 1, not_matured_count: 0, matched_count: 1, executable_count: 1, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '1200', estimated_external_write_count: 1, matching_hash: 'sha256:x',
|
||||
},
|
||||
items: [{
|
||||
source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器组件', specification: 'A',
|
||||
@@ -89,18 +91,44 @@ describe('TransferHomePanel chat home entry', () => {
|
||||
expect(api.listTransferSources).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('点击历史待办计数卡独立触发 backlog 卡片', async () => {
|
||||
it('点击历史待办计数卡独立触发 backlog 卡片,并按计数卡切片初始筛选', async () => {
|
||||
// [断言意图] 三张计数卡不再落入同一份全量列表:可恢复/已关闭/结果未知
|
||||
// 各自带对应 resultFilter 打开待处理池(否则 0 行的已关闭/结果未知被 50 行可恢复淹没)。
|
||||
api.listTransferBacklog.mockResolvedValue([
|
||||
{ item_id: 7, source_code: 'DBS-AWSBI', invoice_no: 'INV-001', material_no: 'MAT-1',
|
||||
status: 'blocked_recoverable', reason: '收料 1200 / ERP 1000', age_days: 1, aging_level: 'normal' },
|
||||
{ item_id: 8, source_code: 'DBS-AWSBI', invoice_no: 'INV-002', material_no: 'MAT-2',
|
||||
status: 'manually_closed', reason: '线下处理', age_days: 2, aging_level: 'closed' },
|
||||
{ item_id: 9, source_code: 'DBS-AWSBI', invoice_no: 'INV-003', material_no: 'MAT-3',
|
||||
status: 'result_unknown', reason: '待人工核实', age_days: 3, aging_level: 'result_unknown' },
|
||||
]);
|
||||
|
||||
const wrapper = mountHome();
|
||||
await flushPromises();
|
||||
|
||||
await wrapper.find('[data-testid="transfer-home-recoverable"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(wrapper.find('[data-testid="transfer-backlog-card"]').exists()).toBe(true);
|
||||
expect(api.listTransferBacklog).toHaveBeenCalled();
|
||||
expect((wrapper.find('[data-testid="transfer-backlog-result-filter"]').element as HTMLSelectElement).value).toBe('recoverable');
|
||||
// 切片后仅可见对应状态行。
|
||||
expect(wrapper.text()).toContain('INV-001');
|
||||
expect(wrapper.text()).not.toContain('INV-002');
|
||||
|
||||
await wrapper.find('[data-testid="transfer-home-back"]').trigger('click');
|
||||
await flushPromises();
|
||||
await wrapper.find('[data-testid="transfer-home-closed"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect((wrapper.find('[data-testid="transfer-backlog-result-filter"]').element as HTMLSelectElement).value).toBe('closed');
|
||||
expect(wrapper.text()).toContain('INV-002');
|
||||
expect(wrapper.text()).not.toContain('INV-001');
|
||||
|
||||
await wrapper.find('[data-testid="transfer-home-back"]').trigger('click');
|
||||
await flushPromises();
|
||||
await wrapper.find('[data-testid="transfer-home-unknown"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect((wrapper.find('[data-testid="transfer-backlog-result-filter"]').element as HTMLSelectElement).value).toBe('unknown');
|
||||
expect(wrapper.text()).toContain('INV-003');
|
||||
});
|
||||
|
||||
it('子视图提供“返回首页”并切回 home', async () => {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<!--
|
||||
features/chat/components/messages/TransferHomePanel.vue
|
||||
用途:在途仓自动调拨 Agent 的 Chat 首页入口区——home 视图展示标题、今日待办
|
||||
入口与三张历史待办计数卡;点击入口独立触发 source-select / backlog 卡片。
|
||||
用途:在途仓自动调拨 Agent 的 Chat 首页入口区——上区「库存匹配」动作入口,
|
||||
下区「待办看板」四队列(可调拨明细/待恢复异常/已人工关闭/结果未知),
|
||||
点击进入对应处理视图(复用自驱动的 TransferMessageView)。
|
||||
依赖:TransferMessageView(复用自驱动卡片)、useChatTransfer、i18n chat.transfer.*。
|
||||
逻辑:home 时只消费 backlogSummary 计数;非 home 时渲染 TransferMessageView。
|
||||
卡片不注入消息流,因此无需后端 ChatLog 消息(决策:补首页入口 A 方案)。
|
||||
逻辑:home 时拉取待办汇总与可调拨明细计数;非 home 时渲染 TransferMessageView。
|
||||
卡片不注入消息流,因此无需后端 ChatLog 消息。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
@@ -20,31 +21,44 @@ const emit = defineEmits<{
|
||||
'flow-active': [active: boolean];
|
||||
}>();
|
||||
|
||||
type HomeView = 'home' | 'source-select' | 'backlog';
|
||||
type HomeView = 'home' | 'source-select' | 'backlog' | 'executable';
|
||||
/** 待处理池结果筛选(与 TransferBacklogSummaryCard 的筛选选项一致)。 */
|
||||
type BacklogFilter = 'all' | 'recoverable' | 'closed' | 'unknown';
|
||||
|
||||
const transfer = useChatTransfer();
|
||||
const view = ref<HomeView>('home');
|
||||
/** 历史待办计数卡对应的初始筛选:点击哪张卡就落到哪个切片。 */
|
||||
const backlogFilter = ref<BacklogFilter>('all');
|
||||
|
||||
/** 进入非 home 时通知父级隐藏聊天输入框(决策:来源选择为业务页,无对话输入区)。 */
|
||||
watch(view, (value) => emit('flow-active', value !== 'home'), { immediate: true });
|
||||
/** 打开待处理池并按计数卡切片(recoverable/closed/unknown)。 */
|
||||
function openBacklog(filter: BacklogFilter) {
|
||||
backlogFilter.value = filter;
|
||||
view.value = 'backlog';
|
||||
}
|
||||
|
||||
/** home 视图仅需要待办汇总;进入时拉取计数。 */
|
||||
/** home 视图需要待办汇总与可调拨明细计数;进入时拉取。 */
|
||||
async function loadHomeSummary() {
|
||||
if (view.value !== 'home') return;
|
||||
await transfer.loadBacklog();
|
||||
await Promise.all([
|
||||
transfer.loadBacklog().catch(() => undefined),
|
||||
transfer.loadExecutableItems().catch(() => undefined),
|
||||
]);
|
||||
}
|
||||
|
||||
onMounted(() => { void loadHomeSummary(); });
|
||||
watch(view, () => { void loadHomeSummary(); });
|
||||
|
||||
/** 进入非 home 时通知父级隐藏聊天输入框(来源选择/待办为业务页,无对话输入区)。 */
|
||||
watch(view, (value) => emit('flow-active', value !== 'home'), { immediate: true });
|
||||
|
||||
const displayAgentName = computed(() => props.agentName || '在途仓自动调拨');
|
||||
|
||||
/** 非 home 视图把当前入口透传给自驱动的 TransferMessageView(决定 source-select 或 backlog)。 */
|
||||
const childPayload = computed(() => (
|
||||
view.value === 'source-select'
|
||||
? { kind: 'source-select' }
|
||||
: { kind: 'backlog' }
|
||||
));
|
||||
/** 非 home 视图把当前入口透传给自驱动的 TransferMessageView。 */
|
||||
const childPayload = computed(() => {
|
||||
if (view.value === 'source-select') return { kind: 'source-select' };
|
||||
if (view.value === 'executable') return { kind: 'executable' };
|
||||
return { kind: 'backlog', filter: backlogFilter.value };
|
||||
});
|
||||
|
||||
function goBack() {
|
||||
view.value = 'home';
|
||||
@@ -53,7 +67,7 @@ function goBack() {
|
||||
|
||||
<template>
|
||||
<div class="flex w-full flex-col items-center px-4 pb-2 pt-6 md:pb-4">
|
||||
<!-- home:标题 + 今日/历史待办入口 -->
|
||||
<!-- home:库存匹配 + 待办看板 -->
|
||||
<template v-if="view === 'home'">
|
||||
<h2 data-testid="transfer-home" class="mb-8 mt-6 shrink-0 text-center text-2xl font-bold text-primary md:mt-10 md:text-3xl">
|
||||
{{ $t('chat.transfer.homeWelcome') }}
|
||||
@@ -61,9 +75,9 @@ function goBack() {
|
||||
</h2>
|
||||
|
||||
<div class="w-full max-w-3xl space-y-4">
|
||||
<!-- 今日待办 -->
|
||||
<section aria-label="今日待办">
|
||||
<p class="mb-2 text-sm font-bold text-secondary">{{ $t('chat.transfer.homeTodayLabel') }}</p>
|
||||
<!-- 库存匹配 -->
|
||||
<section aria-label="库存匹配">
|
||||
<p class="mb-2 text-sm font-bold text-secondary">{{ $t('chat.transfer.homeMatchLabel') }}</p>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="transfer-home-today"
|
||||
@@ -79,15 +93,25 @@ function goBack() {
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<!-- 历史待办 -->
|
||||
<section aria-label="历史待办">
|
||||
<p class="mb-2 text-sm font-bold text-secondary">{{ $t('chat.transfer.homeHistoryLabel') }}</p>
|
||||
<div class="grid grid-cols-1 gap-3 sm:grid-cols-3">
|
||||
<!-- 待办看板 -->
|
||||
<section aria-label="待办看板">
|
||||
<p class="mb-2 text-sm font-bold text-secondary">{{ $t('chat.transfer.homeBoardLabel') }}</p>
|
||||
<div class="grid grid-cols-2 gap-3 lg:grid-cols-4">
|
||||
<button
|
||||
type="button"
|
||||
data-testid="transfer-home-executable"
|
||||
class="rounded-2xl border border-emerald-200 bg-emerald-50 p-4 text-left transition-colors hover:bg-emerald-100"
|
||||
@click="view = 'executable'"
|
||||
>
|
||||
<b class="block text-2xl leading-none text-emerald-600">{{ transfer.executableItems.value.length }}</b>
|
||||
<b class="mt-2 block text-sm font-bold text-primary">{{ $t('chat.transfer.homeExecutable') }}</b>
|
||||
<span class="mt-1 block text-xs text-secondary">{{ $t('chat.transfer.homeExecutableHint') }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="transfer-home-recoverable"
|
||||
class="rounded-2xl border border-brand-200 bg-brand-50 p-4 text-left transition-colors hover:bg-brand-100"
|
||||
@click="view = 'backlog'"
|
||||
@click="openBacklog('recoverable')"
|
||||
>
|
||||
<b class="block text-2xl leading-none text-brand-600">{{ transfer.backlogSummary.value?.recoverable ?? 0 }}</b>
|
||||
<b class="mt-2 block text-sm font-bold text-primary">{{ $t('chat.transfer.homeRecoverable') }}</b>
|
||||
@@ -97,7 +121,7 @@ function goBack() {
|
||||
type="button"
|
||||
data-testid="transfer-home-closed"
|
||||
class="rounded-2xl border border-default bg-surface p-4 text-left transition-colors hover:border-brand-200 hover:bg-brand-50"
|
||||
@click="view = 'backlog'"
|
||||
@click="openBacklog('closed')"
|
||||
>
|
||||
<b class="block text-2xl leading-none text-secondary">{{ transfer.backlogSummary.value?.closed ?? 0 }}</b>
|
||||
<b class="mt-2 block text-sm font-bold text-primary">{{ $t('chat.transfer.homeClosed') }}</b>
|
||||
@@ -107,7 +131,7 @@ function goBack() {
|
||||
type="button"
|
||||
data-testid="transfer-home-unknown"
|
||||
class="rounded-2xl border border-amber-200 bg-amber-50 p-4 text-left transition-colors hover:bg-amber-100"
|
||||
@click="view = 'backlog'"
|
||||
@click="openBacklog('unknown')"
|
||||
>
|
||||
<b class="block text-2xl leading-none text-amber-600">{{ transfer.backlogSummary.value?.unknown ?? 0 }}</b>
|
||||
<b class="mt-2 block text-sm font-bold text-primary">{{ $t('chat.transfer.homeUnknown') }}</b>
|
||||
@@ -118,7 +142,7 @@ function goBack() {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 子流程:复用自驱动的 TransferMessageView(预检宽表格需要全宽,上限对齐消息气泡宽布局) -->
|
||||
<!-- 子流程:复用自驱动的 TransferMessageView(宽表格需要全宽,上限对齐消息气泡宽布局) -->
|
||||
<div v-else class="w-full max-w-[min(96vw,1500px)] pr-2">
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<!--
|
||||
features/chat/components/messages/TransferManualCloseDialog.vue
|
||||
用途:人工关闭弹窗(原因必填;关闭后永久排除,历史保留)。
|
||||
依赖:props(open/invoiceNo)、i18n chat.transfer.*。
|
||||
用途:人工关闭弹窗(原因必填;关闭后永久排除,历史保留);count>1 时按批量文案展示。
|
||||
依赖:props(open/invoiceNo/count)、i18n chat.transfer.*。
|
||||
逻辑:原因为空时确认按钮禁用;确认时 emit confirm(reason)。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
@@ -10,6 +10,8 @@ import { ref, watch } from 'vue';
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
invoiceNo: string;
|
||||
/** 批量关闭的行数;>1 时忽略 invoiceNo,标题/提示切换为批量文案。 */
|
||||
count?: number;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -34,8 +36,13 @@ watch(
|
||||
data-testid="transfer-manual-close-dialog"
|
||||
>
|
||||
<div class="w-full max-w-md rounded-2xl bg-surface p-5 shadow-xl">
|
||||
<h3 class="text-base font-bold text-primary">{{ $t('chat.transfer.manualCloseTitle') }}</h3>
|
||||
<p class="mt-1 text-xs text-muted">{{ invoiceNo }} · {{ $t('chat.transfer.manualCloseHint') }}</p>
|
||||
<h3 class="text-base font-bold text-primary">
|
||||
{{ $t(count && count > 1 ? 'chat.transfer.batchCloseTitle' : 'chat.transfer.manualCloseTitle', count && count > 1 ? { count } : {}) }}
|
||||
</h3>
|
||||
<p class="mt-1 text-xs text-muted">
|
||||
<template v-if="count && count > 1">{{ $t('chat.transfer.manualCloseHint') }}</template>
|
||||
<template v-else>{{ invoiceNo }} · {{ $t('chat.transfer.manualCloseHint') }}</template>
|
||||
</p>
|
||||
<textarea
|
||||
v-model="reason"
|
||||
rows="3"
|
||||
|
||||
+96
-39
@@ -1,38 +1,47 @@
|
||||
<!--
|
||||
features/chat/components/messages/TransferPrecheckCard.vue
|
||||
用途:预检卡——计数 + 来源失败提示 + 调拨明细表(含筛选)+ 勾选 + “直接生成调拨单”按钮。
|
||||
features/chat/components/messages/TransferMatchCard.vue
|
||||
用途:匹配卡——计数 + 来源失败提示 + 调拨明细表(含筛选)+ 勾选 + “直接生成调拨单”按钮。
|
||||
依赖:props(summary/items/sources/selected/busy)、i18n chat.transfer.*。
|
||||
逻辑:明细表渲染 filtered(关键字/结果筛选生效);阻断/未成熟项 checkbox 禁用;
|
||||
重查范围含可恢复阻断与可执行行;阻断原因经结果徽标 title 悬浮透出不占行高;
|
||||
无选择或 busy 时生成按钮禁用;emit execute(invoiceNos)(决策 4/5:无独立确认页);
|
||||
勾选键 = 明细行 item_id(历史回放行无 item_id 禁用防误选);
|
||||
库存数量下方小字透出查询时刻(checked_at);stale 行置灰 + 重查提示;
|
||||
file_current=false 行提示文件已更新;blocked_file_removed 徽标独立文案;
|
||||
重查范围含可恢复阻断与可执行行(重查仍按 invoice_no 提交);阻断原因经结果徽标
|
||||
title 悬浮透出不占行高;无选择或 busy 时生成按钮禁用;emit execute(itemIds);
|
||||
来源级解析/文件失败经 sources.error_code 透出(防"安静全 0")。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { deriveBatchNo } from './transferBatch';
|
||||
import type { TransferPrecheckItem, TransferPrecheckSummary, TransferSourceProgress } from '../../types/transfer.types';
|
||||
import type { TransferMatchingItem, TransferMatchingSummary, TransferSourceProgress } from '../../types/transfer.types';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const props = defineProps<{
|
||||
summary: TransferPrecheckSummary;
|
||||
items: TransferPrecheckItem[];
|
||||
summary: TransferMatchingSummary;
|
||||
items: TransferMatchingItem[];
|
||||
sources?: TransferSourceProgress[];
|
||||
selected: Set<string>;
|
||||
/** 勾选集合(明细行 item_id);历史回放行无 item_id 不可选 */
|
||||
selected: Set<number>;
|
||||
busy?: boolean;
|
||||
requeryBusy?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
toggle: [invoiceNo: string, checked: boolean];
|
||||
'toggle-all': [invoiceNos: string[], checked: boolean];
|
||||
execute: [invoiceNos: string[]];
|
||||
toggle: [itemId: number, checked: boolean];
|
||||
'toggle-all': [itemIds: number[], checked: boolean];
|
||||
execute: [itemIds: number[]];
|
||||
requery: [invoiceNos: string[]];
|
||||
}>();
|
||||
|
||||
/** 勾选可用范围:有 item_id 且(可执行或可恢复阻断);无 item_id 的历史行禁用防误选。 */
|
||||
function hasSelectionKey(item: TransferMatchingItem): boolean {
|
||||
return item.item_id != null;
|
||||
}
|
||||
|
||||
const selectedCount = computed(() =>
|
||||
props.items.filter((item) => item.result === 'executable' && props.selected.has(item.invoice_no)).length,
|
||||
props.items.filter((item) => item.result === 'executable' && isChecked(item)).length,
|
||||
);
|
||||
const executeDisabled = computed(() => props.busy || selectedCount.value === 0);
|
||||
|
||||
@@ -45,21 +54,21 @@ const failedSources = computed(() =>
|
||||
const keyword = ref('');
|
||||
const resultFilter = ref<'all' | 'executable' | 'blocked' | 'not_matured'>('all');
|
||||
|
||||
function isBlocked(item: TransferPrecheckItem): boolean {
|
||||
function isBlocked(item: TransferMatchingItem): boolean {
|
||||
return String(item.result).startsWith('blocked_');
|
||||
}
|
||||
|
||||
/** 勾选可用范围:可执行(可生成调拨)或可恢复阻断(可重查 ERP)。 */
|
||||
function isSelectable(item: TransferPrecheckItem): boolean {
|
||||
function isSelectable(item: TransferMatchingItem): boolean {
|
||||
return item.result === 'executable';
|
||||
}
|
||||
|
||||
function isCheckable(item: TransferPrecheckItem): boolean {
|
||||
return isSelectable(item) || isBlocked(item);
|
||||
function isCheckable(item: TransferMatchingItem): boolean {
|
||||
return hasSelectionKey(item) && (isSelectable(item) || isBlocked(item));
|
||||
}
|
||||
|
||||
/** 可重查行:可恢复阻断 + 可执行(已可执行也允许重查核对最新库存)。 */
|
||||
function isRequeryable(item: TransferPrecheckItem): boolean {
|
||||
function isRequeryable(item: TransferMatchingItem): boolean {
|
||||
return isBlocked(item) || item.result === 'executable';
|
||||
}
|
||||
|
||||
@@ -78,27 +87,48 @@ const filtered = computed(() =>
|
||||
}),
|
||||
);
|
||||
|
||||
const filteredInvoiceNos = computed(() => filtered.value.map((item) => item.invoice_no));
|
||||
/** 全选/批量提交范围:仅含拥有 item_id 的行(历史回放行无键不可参与)。 */
|
||||
const filteredItemIds = computed(() =>
|
||||
filtered.value.filter(hasSelectionKey).map((item) => item.item_id as number),
|
||||
);
|
||||
const allFilteredSelected = computed(() =>
|
||||
filteredInvoiceNos.value.length > 0 && filteredInvoiceNos.value.every((no) => props.selected.has(no)),
|
||||
filteredItemIds.value.length > 0 && filteredItemIds.value.every((id) => props.selected.has(id)),
|
||||
);
|
||||
const selectedRequeryableCount = computed(() =>
|
||||
filtered.value.filter((item) => isRequeryable(item) && props.selected.has(item.invoice_no)).length,
|
||||
filtered.value.filter((item) => isRequeryable(item) && isChecked(item)).length,
|
||||
);
|
||||
|
||||
function toggleAll(): void {
|
||||
emit('toggle-all', filteredInvoiceNos.value, !allFilteredSelected.value);
|
||||
emit('toggle-all', filteredItemIds.value, !allFilteredSelected.value);
|
||||
}
|
||||
|
||||
function requerySelected(): void {
|
||||
const nos = filtered.value
|
||||
.filter((item) => isRequeryable(item) && props.selected.has(item.invoice_no))
|
||||
.filter((item) => isRequeryable(item) && isChecked(item))
|
||||
.map((item) => item.invoice_no);
|
||||
if (nos.length) emit('requery', nos);
|
||||
}
|
||||
|
||||
function isChecked(item: TransferPrecheckItem): boolean {
|
||||
return props.selected.has(item.invoice_no);
|
||||
function isChecked(item: TransferMatchingItem): boolean {
|
||||
return item.item_id != null && props.selected.has(item.item_id);
|
||||
}
|
||||
|
||||
/** 生成调拨单提交范围:可执行且被勾选的明细行 id。 */
|
||||
const executableCheckedItemIds = computed(() =>
|
||||
props.items.filter((item) => isSelectable(item) && isChecked(item)).map((item) => item.item_id as number),
|
||||
);
|
||||
|
||||
/**
|
||||
* 库存查询时刻小字(HH:mm);无效/缺省 checked_at 返回 null 不渲染。
|
||||
* @param item 匹配明细行;checked_at 为后端 ISO 时间
|
||||
*/
|
||||
function checkedAtLabel(item: TransferMatchingItem): string | null {
|
||||
if (!item.checked_at) return null;
|
||||
const date = new Date(item.checked_at);
|
||||
if (Number.isNaN(date.getTime())) return null;
|
||||
const hh = String(date.getHours()).padStart(2, '0');
|
||||
const mm = String(date.getMinutes()).padStart(2, '0');
|
||||
return `${hh}:${mm}`;
|
||||
}
|
||||
|
||||
function resultLabel(result: string): string {
|
||||
@@ -108,6 +138,7 @@ function resultLabel(result: string): string {
|
||||
blocked_quantity_mismatch: 'chat.transfer.resultBlocked',
|
||||
blocked_inventory_not_found: 'chat.transfer.resultBlocked',
|
||||
blocked_future_date: 'chat.transfer.resultBlocked',
|
||||
blocked_file_removed: 'chat.transfer.resultFileRemoved',
|
||||
external_query_timeout: 'chat.transfer.resultUnknown',
|
||||
result_unknown: 'chat.transfer.resultUnknown',
|
||||
};
|
||||
@@ -122,7 +153,7 @@ const REASON_I18N_KEYS: Record<string, string> = {
|
||||
blocked_future_date: 'chat.transfer.reasonFutureDate',
|
||||
};
|
||||
|
||||
function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
function reasonTitle(item: TransferMatchingItem): string | undefined {
|
||||
if (!isBlocked(item) || !item.reason) return undefined;
|
||||
const key = REASON_I18N_KEYS[item.result];
|
||||
if (!key) return item.reason;
|
||||
@@ -136,13 +167,13 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="my-2 rounded-2xl border border-brand-100 bg-surface p-4 shadow-sm" data-testid="transfer-precheck-card">
|
||||
<div class="my-2 rounded-2xl border border-brand-100 bg-surface p-4 shadow-sm" data-testid="transfer-match-card">
|
||||
<div class="mb-3 flex flex-wrap items-center justify-between gap-3">
|
||||
<h3 class="text-sm font-bold text-primary">{{ $t('chat.transfer.precheckTitle') }}</h3>
|
||||
<h3 class="text-sm font-bold text-primary">{{ $t('chat.transfer.matchTitle') }}</h3>
|
||||
<span class="text-xs text-muted">{{ $t('chat.transfer.businessDate') }}:{{ summary.business_date }}</span>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 grid grid-cols-2 gap-2 sm:grid-cols-5" data-testid="transfer-precheck-counts">
|
||||
<div class="mb-3 grid grid-cols-2 gap-2 sm:grid-cols-5" data-testid="transfer-match-counts">
|
||||
<div class="rounded-lg bg-surface-soft p-2 text-center">
|
||||
<div class="text-lg font-black text-brand-600">{{ summary.counts.executable_count }}</div>
|
||||
<div class="text-[11px] text-muted">{{ $t('chat.transfer.executableCount') }}</div>
|
||||
@@ -168,7 +199,7 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
<div
|
||||
v-if="failedSources.length"
|
||||
class="mb-3 rounded-lg border border-red-200 bg-red-50 p-3 text-xs text-red-700"
|
||||
data-testid="transfer-precheck-source-errors"
|
||||
data-testid="transfer-match-source-errors"
|
||||
>
|
||||
<div class="mb-1 font-bold">{{ $t('chat.transfer.sourceErrorTitle') }}</div>
|
||||
<div v-for="source in failedSources" :key="source.source_code" class="leading-5">
|
||||
@@ -182,9 +213,9 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
type="text"
|
||||
class="w-56 rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
|
||||
:placeholder="$t('chat.transfer.filterPlaceholder')"
|
||||
data-testid="transfer-precheck-filter"
|
||||
data-testid="transfer-match-filter"
|
||||
/>
|
||||
<select v-model="resultFilter" class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary" data-testid="transfer-precheck-result-filter">
|
||||
<select v-model="resultFilter" class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary" data-testid="transfer-match-result-filter">
|
||||
<option value="all">{{ $t('chat.transfer.filterAll') }}</option>
|
||||
<option value="executable">{{ $t('chat.transfer.resultExecutable') }}</option>
|
||||
<option value="blocked">{{ $t('chat.transfer.resultBlocked') }}</option>
|
||||
@@ -194,21 +225,21 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
type="button"
|
||||
class="rounded-lg border border-brand-200 bg-brand-50 px-3 py-1 text-xs font-bold text-brand-700 transition hover:bg-brand-100 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
:disabled="props.requeryBusy || selectedRequeryableCount === 0"
|
||||
data-testid="transfer-precheck-requery-selected"
|
||||
data-testid="transfer-match-requery-selected"
|
||||
@click="requerySelected"
|
||||
>
|
||||
{{ $t('chat.transfer.requerySelected') }}{{ selectedRequeryableCount ? `(${selectedRequeryableCount})` : '' }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full min-w-[1100px] text-xs" data-testid="transfer-precheck-table">
|
||||
<table class="w-full min-w-[1100px] text-xs" data-testid="transfer-match-table">
|
||||
<thead>
|
||||
<tr class="border-b border-default bg-surface-soft text-left text-[11px] text-muted">
|
||||
<th class="p-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="allFilteredSelected"
|
||||
data-testid="transfer-precheck-select-all"
|
||||
data-testid="transfer-match-select-all"
|
||||
@change="toggleAll"
|
||||
/>
|
||||
</th>
|
||||
@@ -230,7 +261,7 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
v-for="item in filtered"
|
||||
:key="`${item.source_code}|${item.invoice_no}|${item.material_no}|${item.receipt_date ?? ''}`"
|
||||
class="border-b border-subtle"
|
||||
:class="{ 'bg-surface-soft text-muted': !isSelectable(item) }"
|
||||
:class="{ 'bg-surface-soft text-muted': !isSelectable(item), 'opacity-60': item.stale === true }"
|
||||
:data-testid="`transfer-item-${item.invoice_no}`"
|
||||
>
|
||||
<td class="p-2">
|
||||
@@ -239,7 +270,7 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
:checked="isChecked(item)"
|
||||
:disabled="!isCheckable(item) || busy"
|
||||
:data-testid="`transfer-check-${item.invoice_no}`"
|
||||
@change="emit('toggle', item.invoice_no, ($event.target as HTMLInputElement).checked)"
|
||||
@change="emit('toggle', item.item_id as number, ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
</td>
|
||||
<td class="p-2">{{ item.source_code }}</td>
|
||||
@@ -249,11 +280,22 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
<td class="p-2">{{ item.material_name }}</td>
|
||||
<td class="p-2">{{ item.from_warehouse }}</td>
|
||||
<td class="p-2">{{ deriveBatchNo(item.lot_no) }}</td>
|
||||
<td class="p-2">{{ item.from_quantity ?? '—' }}</td>
|
||||
<td class="p-2">
|
||||
<div>{{ item.from_quantity ?? '—' }}</div>
|
||||
<!-- 库存查询时刻小字:数据新鲜度溯源(stale 门禁的可见依据) -->
|
||||
<div
|
||||
v-if="checkedAtLabel(item)"
|
||||
class="text-[10px] text-muted"
|
||||
:title="$t('chat.transfer.stockCheckedAtTitle', { time: checkedAtLabel(item) })"
|
||||
:data-testid="`transfer-checked-at-${item.invoice_no}`"
|
||||
>
|
||||
{{ checkedAtLabel(item) }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-2">{{ item.to_warehouse }}</td>
|
||||
<td class="p-2">{{ item.to_quantity }}</td>
|
||||
<td class="p-2">
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="flex flex-wrap items-center gap-1">
|
||||
<!-- 阻断原因经悬浮提示(title)透出:不占行高;可执行行也提供重查入口 -->
|
||||
<span
|
||||
class="rounded-full px-2 py-0.5 font-bold"
|
||||
@@ -267,6 +309,21 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
>
|
||||
{{ $t(resultLabel(item.result)) }}
|
||||
</span>
|
||||
<!-- 行级警示小标:stale(超 TTL 执行会被拦截)/ 文件版本已过期 -->
|
||||
<span
|
||||
v-if="item.stale === true"
|
||||
class="rounded border border-amber-300 px-1 py-0.5 text-[10px] text-amber-700"
|
||||
data-testid="transfer-item-stale"
|
||||
>
|
||||
{{ $t('chat.transfer.staleRow') }}
|
||||
</span>
|
||||
<span
|
||||
v-if="item.file_current === false"
|
||||
class="rounded border border-amber-300 px-1 py-0.5 text-[10px] text-amber-700"
|
||||
data-testid="transfer-item-file-changed"
|
||||
>
|
||||
{{ $t('chat.transfer.fileChangedRow') }}
|
||||
</span>
|
||||
<button
|
||||
v-if="isRequeryable(item)"
|
||||
type="button"
|
||||
@@ -294,7 +351,7 @@ function reasonTitle(item: TransferPrecheckItem): string | undefined {
|
||||
class="rounded-lg bg-brand-600 px-4 py-1.5 text-sm font-bold text-white hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
:disabled="executeDisabled"
|
||||
:data-testid="'transfer-generate-button'"
|
||||
@click="emit('execute', items.filter(isSelectable).filter(isChecked).map((item) => item.invoice_no))"
|
||||
@click="emit('execute', executableCheckedItemIds)"
|
||||
>
|
||||
{{ $t('chat.transfer.generateTransfer') }}
|
||||
</button>
|
||||
@@ -1,8 +1,9 @@
|
||||
/**
|
||||
* features/chat/components/messages/TransferMessageView.spec.ts
|
||||
* 用途:验证卡片自驱动接线——预检卡渲染、点“直接生成调拨单”真实调 API 并切换结果卡、
|
||||
* 用途:验证卡片自驱动接线——匹配卡渲染(勾选键 = 明细 item_id)、点“生成调拨单”
|
||||
* 真实调 /items/execute 并切换结果卡、恢复处理 = 批量重查(不跳匹配卡)、
|
||||
* 下载按钮调 requestBlob 封装、结果页无审计入口。
|
||||
* 依赖:vi.mock(transfer.api)、@vue/test-utils、i18n。
|
||||
* 依赖:vi.mock(transfer.api)、vi.mock(useMessage)、@vue/test-utils、i18n。
|
||||
* 逻辑:Mock API 断言调用参数与状态切换(对应后端 197 项测试的契约面)。
|
||||
*/
|
||||
import { mount, flushPromises } from '@vue/test-utils';
|
||||
@@ -10,12 +11,15 @@ import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
createTransferPrecheck: vi.fn(),
|
||||
getTransferPrecheck: vi.fn(),
|
||||
executeTransferPrecheck: vi.fn(),
|
||||
createTransferMatching: vi.fn(),
|
||||
getTransferMatching: vi.fn(),
|
||||
listExecutableTransferItems: vi.fn(),
|
||||
executeTransferItems: vi.fn(),
|
||||
getTransferRun: vi.fn(),
|
||||
retryTransferItem: vi.fn(),
|
||||
manualCloseTransferItem: vi.fn(),
|
||||
batchRequeryTransferItems: vi.fn(),
|
||||
batchManualCloseTransferItems: vi.fn(),
|
||||
downloadTransferReceiptFiles: vi.fn(),
|
||||
downloadTransferErpInventory: vi.fn(),
|
||||
downloadTransferExceptions: vi.fn(),
|
||||
@@ -26,22 +30,35 @@ const api = vi.hoisted(() => ({
|
||||
|
||||
vi.mock('@/features/chat/api/transfer.api', () => api);
|
||||
|
||||
const messageMocks = vi.hoisted(() => ({
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
info: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/shared/composables/useMessage', () => ({
|
||||
useMessage: () => messageMocks,
|
||||
}));
|
||||
|
||||
import TransferMessageView from './TransferMessageView.vue';
|
||||
import { eligibleReceiptDateTo } from './transferDate';
|
||||
|
||||
const payload = {
|
||||
kind: 'precheck',
|
||||
kind: 'match',
|
||||
summary: {
|
||||
precheck_id: 'TPC-1',
|
||||
matching_id: 'MTG-1',
|
||||
status: 'ready_to_execute',
|
||||
business_date: '2026-08-06',
|
||||
eligible_receipt_date_to: '2026-08-05',
|
||||
expires_at: '',
|
||||
counts: { file_invoice_count: 1, not_matured_count: 0, prechecked_count: 1, executable_count: 1, blocked_count: 0 },
|
||||
counts: { file_invoice_count: 1, not_matured_count: 0, matched_count: 1, executable_count: 1, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '1200',
|
||||
estimated_external_write_count: 1,
|
||||
precheck_hash: 'sha256:x',
|
||||
matching_hash: 'sha256:x',
|
||||
},
|
||||
items: [{
|
||||
item_id: 101,
|
||||
source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器组件', specification: 'A',
|
||||
invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200',
|
||||
to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable',
|
||||
@@ -70,29 +87,29 @@ const runPayload = {
|
||||
describe('TransferMessageView self-driving wiring', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
api.executeTransferPrecheck.mockResolvedValue({ run_no: 'RUN-1', status: 'success' });
|
||||
api.executeTransferItems.mockResolvedValue({ run_no: 'RUN-1', status: 'success' });
|
||||
api.getTransferRun.mockResolvedValue(runPayload.run);
|
||||
api.downloadTransferReceiptFiles.mockResolvedValue({ blob: new Blob(['z']), filename: 'r.zip' });
|
||||
api.downloadTransferErpInventory.mockResolvedValue({ blob: new Blob(['c']), filename: 'e.csv' });
|
||||
});
|
||||
|
||||
it('预检 payload 渲染预检卡,且默认勾选可执行项', () => {
|
||||
it('匹配 payload 渲染匹配卡,且默认按 item_id 勾选可执行行', () => {
|
||||
const wrapper = mount(TransferMessageView, {
|
||||
props: { payload },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
expect(wrapper.find('[data-testid="transfer-precheck-card"]').exists()).toBe(true);
|
||||
expect(wrapper.find('[data-testid="transfer-match-card"]').exists()).toBe(true);
|
||||
expect((wrapper.find('[data-testid="transfer-check-INV-001"]').element as HTMLInputElement).checked).toBe(true);
|
||||
});
|
||||
|
||||
it('点击“直接生成调拨单”调用 execute API 并切换为结果卡', async () => {
|
||||
it('点击“生成调拨单”按明细行 id 调 /items/execute 并切换为结果卡', async () => {
|
||||
const wrapper = mount(TransferMessageView, {
|
||||
props: { payload },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await wrapper.find('[data-testid="transfer-generate-button"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.executeTransferPrecheck).toHaveBeenCalledWith('TPC-1', ['INV-001']);
|
||||
expect(api.executeTransferItems).toHaveBeenCalledWith([101]);
|
||||
expect(wrapper.find('[data-testid="transfer-result-card"]').exists()).toBe(true);
|
||||
});
|
||||
|
||||
@@ -116,10 +133,12 @@ describe('TransferMessageView self-driving wiring', () => {
|
||||
expect(wrapper.text()).not.toContain('审计');
|
||||
});
|
||||
|
||||
it('backlog 视图拉取待处理列表,重试/关闭调用对应 API', async () => {
|
||||
it('backlog 视图拉取待处理列表,行级重查/关闭调用对应 API', async () => {
|
||||
api.listTransferBacklog.mockResolvedValue([{
|
||||
item_id: 7, source_code: 'DBS-AWSBI', invoice_no: 'INV-001', material_no: 'MAT-1',
|
||||
status: 'blocked_recoverable', reason: '收料 1200 / ERP 1000', age_days: 1, aging_level: 'normal',
|
||||
receipt_date: '2026-08-05', material_name: '连接器组件', from_warehouse: 'DBS-TRANSIT',
|
||||
to_warehouse: 'HUB-CN01', lot_no: 'LOT-10', receipt_quantity: '1200', external_quantity: '1000',
|
||||
}]);
|
||||
api.getTransferBacklogSummary.mockResolvedValue({
|
||||
recoverable: 1, closed: 0, unknown: 0, aging: { warn_3d: 0, escalate_5d: 0, critical_7d: 0 },
|
||||
@@ -135,23 +154,156 @@ describe('TransferMessageView self-driving wiring', () => {
|
||||
expect(wrapper.find('[data-testid="transfer-backlog-card"]').exists()).toBe(true);
|
||||
expect(wrapper.text()).toContain('INV-001');
|
||||
|
||||
await wrapper.find('[data-testid="transfer-backlog-retry"]').trigger('click');
|
||||
// 行级重查(原「重新查询 ERP」改名「重查」,复用单行端点)。
|
||||
await wrapper.find('[data-testid="transfer-backlog-requery-INV-001"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.retryTransferItem).toHaveBeenCalledWith(7);
|
||||
|
||||
await wrapper.find('[data-testid="transfer-backlog-close"]').trigger('click');
|
||||
// 行级关闭:弹窗原因必填后提交。
|
||||
await wrapper.find('[data-testid="transfer-backlog-close-INV-001"]').trigger('click');
|
||||
await wrapper.find('[data-testid="transfer-close-reason"]').setValue('线下已处理');
|
||||
await wrapper.find('[data-testid="transfer-close-confirm"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.manualCloseTransferItem).toHaveBeenCalledWith(7, '线下已处理');
|
||||
});
|
||||
|
||||
it('来源实例选择:加载列表 → 确认范围 → 创建预检并切换预检卡', async () => {
|
||||
it('backlog 批量:勾选后操作条出现,重查/恢复/批量关闭调用对应端点', async () => {
|
||||
api.listTransferBacklog.mockResolvedValue([
|
||||
{ item_id: 7, source_code: 'DBS-AWSBI', invoice_no: 'INV-001', material_no: 'MAT-1', status: 'blocked_recoverable', reason: '', age_days: 0, aging_level: 'normal' },
|
||||
{ item_id: 8, source_code: 'DBS-AWSBI', invoice_no: 'INV-002', material_no: 'MAT-2', status: 'result_unknown', reason: '', age_days: 2, aging_level: 'result_unknown' },
|
||||
]);
|
||||
api.getTransferBacklogSummary.mockResolvedValue({
|
||||
recoverable: 1, closed: 0, unknown: 1, aging: { warn_3d: 0, escalate_5d: 0, critical_7d: 0 },
|
||||
});
|
||||
api.batchRequeryTransferItems.mockResolvedValue({ total: 1, results: [{ item_id: 7, ok: true, status: 'ready_to_execute' }] });
|
||||
api.batchManualCloseTransferItems.mockResolvedValue({ total: 1, results: [{ item_id: 7, ok: true, status: 'manually_closed' }] });
|
||||
|
||||
const wrapper = mount(TransferMessageView, {
|
||||
props: { payload: { kind: 'backlog' } },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
|
||||
// result_unknown 行 checkbox 禁用(只读隔离)。
|
||||
expect((wrapper.find('[data-testid="transfer-backlog-check-INV-002"]').element as HTMLInputElement).disabled).toBe(true);
|
||||
// 未勾选时批量操作条不存在。
|
||||
expect(wrapper.find('[data-testid="transfer-backlog-batch-requery"]').exists()).toBe(false);
|
||||
|
||||
await wrapper.find('[data-testid="transfer-backlog-check-INV-001"]').setValue(true);
|
||||
expect(wrapper.find('[data-testid="transfer-backlog-batch-requery"]').exists()).toBe(true);
|
||||
|
||||
await wrapper.find('[data-testid="transfer-backlog-batch-requery"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.batchRequeryTransferItems).toHaveBeenCalledWith([7]);
|
||||
|
||||
// 恢复处理(批量)= 同一批量重查端点(恢复的唯一后端)。
|
||||
await wrapper.find('[data-testid="transfer-backlog-check-INV-001"]').setValue(true);
|
||||
await wrapper.find('[data-testid="transfer-backlog-batch-resume"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.batchRequeryTransferItems).toHaveBeenCalledWith([7]);
|
||||
|
||||
await wrapper.find('[data-testid="transfer-backlog-check-INV-001"]').setValue(true);
|
||||
await wrapper.find('[data-testid="transfer-backlog-batch-close"]').trigger('click');
|
||||
await wrapper.find('[data-testid="transfer-close-reason"]').setValue('整批线下处理');
|
||||
await wrapper.find('[data-testid="transfer-close-confirm"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.batchManualCloseTransferItems).toHaveBeenCalledWith([7], '整批线下处理');
|
||||
});
|
||||
|
||||
it('backlog 结果徽标:blocked_file_removed 行显示「文件已移除」,普通阻断仍为「已阻断」', async () => {
|
||||
// [断言意图] F1(2026-09-23 评审修复):backlog 行带 result_code 后,
|
||||
// 收料行已从最新文件移除(blocked_file_removed)的行必须与普通数量阻断区分展示。
|
||||
api.listTransferBacklog.mockResolvedValue([
|
||||
{ item_id: 9, source_code: 'DBS-AWSBI', invoice_no: 'INV-009', material_no: 'MAT-9', status: 'blocked_recoverable', result_code: 'blocked_file_removed', reason: '收料行已从最新文件移除', age_days: 0, aging_level: 'normal' },
|
||||
{ item_id: 10, source_code: 'DBS-AWSBI', invoice_no: 'INV-010', material_no: 'MAT-10', status: 'blocked_recoverable', result_code: 'blocked_quantity_mismatch', reason: '收料 300 / ERP 280', age_days: 0, aging_level: 'normal' },
|
||||
]);
|
||||
api.getTransferBacklogSummary.mockResolvedValue({
|
||||
recoverable: 2, closed: 0, unknown: 0, aging: { warn_3d: 0, escalate_5d: 0, critical_7d: 0 },
|
||||
});
|
||||
|
||||
const wrapper = mount(TransferMessageView, {
|
||||
props: { payload: { kind: 'backlog' } },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
const removedBadge = wrapper.find('[data-testid="transfer-backlog-INV-009"] [data-testid="transfer-backlog-result"]');
|
||||
const normalBadge = wrapper.find('[data-testid="transfer-backlog-INV-010"] [data-testid="transfer-backlog-result"]');
|
||||
expect(removedBadge.text()).toContain('文件已移除');
|
||||
expect(normalBadge.text()).toContain('已阻断');
|
||||
expect(normalBadge.text()).not.toContain('文件已移除');
|
||||
});
|
||||
|
||||
it('可调拨明细视图:加载全局可执行行,勾选后按行生成调拨单', async () => {
|
||||
// [断言意图] 行归属解耦后的执行入口:executable 视图聚合全部可执行行,
|
||||
// 勾选(item_id)→ /items/execute → 结果卡,恢复后的行在此闭环。
|
||||
api.listExecutableTransferItems.mockResolvedValue({ items: [{
|
||||
item_id: 77, source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器组件', specification: 'A',
|
||||
invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200',
|
||||
to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable',
|
||||
checked_at: '2026-09-23T10:21:00', stale: false, file_current: true,
|
||||
}], counts: { executable_count: 1 } });
|
||||
api.executeTransferItems.mockResolvedValue({ run_no: 'RUN-9', status: 'success' });
|
||||
api.getTransferRun.mockResolvedValue(runPayload.run);
|
||||
|
||||
const wrapper = mount(TransferMessageView, {
|
||||
props: { payload: { kind: 'executable' } },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
expect(api.listExecutableTransferItems).toHaveBeenCalled();
|
||||
expect(wrapper.find('[data-testid="transfer-executable-card"]').exists()).toBe(true);
|
||||
|
||||
await wrapper.find('[data-testid="transfer-executable-check-INV-001"]').setValue(true);
|
||||
await wrapper.find('[data-testid="transfer-executable-generate"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.executeTransferItems).toHaveBeenCalledWith([77]);
|
||||
expect(wrapper.find('[data-testid="transfer-result-card"]').exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('恢复处理(恢复=重查):按明细 id 调 batch-requery,留在待处理池并统计提示', async () => {
|
||||
// [断言意图] 行式执行重构(2026-09-23):恢复处理不再重建/打开匹配卡,
|
||||
// 语义收敛为按明细 id 重查库存;结果按 status 统计(ready_to_execute=已恢复),
|
||||
// 完成后留在待处理池(fail-closed),toast 汇总 recovered/blocked。
|
||||
api.listTransferBacklog.mockResolvedValue([
|
||||
{ item_id: 7, source_code: 'DBS-AWSBI', invoice_no: 'INV-001', material_no: 'MAT-1', status: 'blocked_recoverable', reason: '', age_days: 0, aging_level: 'normal' },
|
||||
{ item_id: 8, source_code: 'DBS-AWSBI', invoice_no: 'INV-002', material_no: 'MAT-2', status: 'blocked_recoverable', reason: '', age_days: 1, aging_level: 'normal' },
|
||||
]);
|
||||
api.getTransferBacklogSummary.mockResolvedValue({
|
||||
recoverable: 2, closed: 0, unknown: 0, aging: { warn_3d: 0, escalate_5d: 0, critical_7d: 0 },
|
||||
});
|
||||
api.batchRequeryTransferItems.mockResolvedValue({
|
||||
total: 2,
|
||||
results: [
|
||||
{ item_id: 7, invoice_no: 'INV-001', ok: true, status: 'ready_to_execute' },
|
||||
{ item_id: 8, invoice_no: 'INV-002', ok: true, status: 'blocked_recoverable' },
|
||||
],
|
||||
});
|
||||
|
||||
const wrapper = mount(TransferMessageView, {
|
||||
props: { payload: { kind: 'backlog' } },
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
await flushPromises();
|
||||
await wrapper.find('[data-testid="transfer-backlog-check-INV-001"]').setValue(true);
|
||||
await wrapper.find('[data-testid="transfer-backlog-batch-resume"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.batchRequeryTransferItems).toHaveBeenCalledWith([7]);
|
||||
expect(api.getTransferMatching).not.toHaveBeenCalled();
|
||||
expect(wrapper.find('[data-testid="transfer-match-card"]').exists()).toBe(false);
|
||||
expect(wrapper.find('[data-testid="transfer-backlog-card"]').exists()).toBe(true);
|
||||
// 恢复统计 toast:1 笔已可执行 · 1 笔仍阻断。
|
||||
expect(messageMocks.success).toHaveBeenCalledTimes(1);
|
||||
const toastText = String(messageMocks.success.mock.calls[0][0]);
|
||||
expect(toastText).toContain('可执行');
|
||||
expect(toastText).toContain('仍阻断');
|
||||
});
|
||||
|
||||
it('来源实例选择:加载列表 → 确认范围 → 创建匹配并切换匹配卡(默认携带 D+1 日期范围)', async () => {
|
||||
api.listTransferSources.mockResolvedValue([
|
||||
{ source_code: 'DBS-AWSBI', display_name: 'AWSBI', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' },
|
||||
]);
|
||||
api.createTransferPrecheck.mockResolvedValue(payload.summary);
|
||||
api.getTransferPrecheck.mockResolvedValue({
|
||||
api.createTransferMatching.mockResolvedValue(payload.summary);
|
||||
api.getTransferMatching.mockResolvedValue({
|
||||
summary: payload.summary,
|
||||
items: payload.items,
|
||||
sources: payload.sources,
|
||||
@@ -167,7 +319,12 @@ describe('TransferMessageView self-driving wiring', () => {
|
||||
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
|
||||
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
|
||||
await flushPromises();
|
||||
expect(api.createTransferPrecheck).toHaveBeenCalledWith({ source_codes: ['DBS-AWSBI'], transfer_type: 'in_transit_to_hub' });
|
||||
expect(wrapper.find('[data-testid="transfer-precheck-card"]').exists()).toBe(true);
|
||||
const cutoff = eligibleReceiptDateTo();
|
||||
expect(api.createTransferMatching).toHaveBeenCalledWith({
|
||||
source_codes: ['DBS-AWSBI'], business_date: undefined,
|
||||
receipt_date_from: cutoff, receipt_date_to: cutoff,
|
||||
transfer_type: 'in_transit_to_hub',
|
||||
});
|
||||
expect(wrapper.find('[data-testid="transfer-match-card"]').exists()).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,28 +1,33 @@
|
||||
<!--
|
||||
features/chat/components/messages/TransferMessageView.vue
|
||||
用途:在途调拨消息卡片的自驱动挂载视图——按 payload 形态渲染卡片,并把卡片按钮
|
||||
(直接生成调拨单 / 下载 / 重试 / 关闭)经 useChatTransfer 真实调用 API。
|
||||
(生成调拨单 / 下载 / 重查 / 恢复处理 / 关闭)经 useChatTransfer 真实调用 API。
|
||||
依赖:Transfer*Card、useChatTransfer、i18n chat.transfer.*。
|
||||
逻辑:payload 作为初始状态(ChatLog 回放);执行后切换为结果卡;下载走 requestBlob;
|
||||
逻辑:payload 作为初始状态(ChatLog 回放;历史行无 item_id 仅展示不可选);仅携带
|
||||
matching_id 时按 ID 恢复匹配卡(最近匹配入口);勾选/执行按明细 item_id;
|
||||
恢复处理 = 按明细 id 重查库存(batch-requery 唯一后端),完成后刷新待处理池并
|
||||
统计提示,不再跳转匹配卡;执行后切换为结果卡;下载走 requestBlob;
|
||||
不展示执行审计入口(决策 19)。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import TransferPrecheckCard from './TransferPrecheckCard.vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import TransferMatchCard from './TransferMatchCard.vue';
|
||||
import TransferFileProgressCard from './TransferFileProgressCard.vue';
|
||||
import TransferProgressCard from './TransferProgressCard.vue';
|
||||
import TransferResultCard from './TransferResultCard.vue';
|
||||
import TransferBacklogSummaryCard from './TransferBacklogSummaryCard.vue';
|
||||
import TransferExecutableCard from './TransferExecutableCard.vue';
|
||||
import TransferManualCloseDialog from './TransferManualCloseDialog.vue';
|
||||
import TransferSourceSelectCard from './TransferSourceSelectCard.vue';
|
||||
import { useChatTransfer } from '../../composables/useChatTransfer';
|
||||
import { downloadTransferSourceFiles, getTransferPrecheck, requeryTransferItems } from '../../api/transfer.api';
|
||||
import { downloadTransferSourceFiles, getTransferMatching, requeryTransferMatchingItems } from '../../api/transfer.api';
|
||||
import { triggerBlobDownload } from '@/shared/utils/download';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type {
|
||||
TransferBacklogItem,
|
||||
TransferPrecheckItem,
|
||||
TransferPrecheckSummary,
|
||||
TransferMatchingItem,
|
||||
TransferMatchingSummary,
|
||||
TransferRunResult,
|
||||
TransferSourceProgress,
|
||||
TransferType,
|
||||
@@ -32,22 +37,31 @@ const props = defineProps<{
|
||||
payload?: Record<string, unknown> | null;
|
||||
}>();
|
||||
|
||||
const { error: notifyError } = useMessage();
|
||||
const { t } = useI18n();
|
||||
const { error: notifyError, success: notifySuccess } = useMessage();
|
||||
|
||||
/** 统一错误提示:BusinessError 带本地化 message,其余回退到 String(e)。 */
|
||||
function reportError(e: unknown) {
|
||||
notifyError(e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
|
||||
const kind = computed(() => String(props.payload?.kind ?? 'precheck'));
|
||||
const kind = computed(() => String(props.payload?.kind ?? 'match'));
|
||||
const mode = ref(kind.value);
|
||||
const summaryRef = ref<TransferPrecheckSummary | null>((props.payload?.summary as TransferPrecheckSummary) ?? null);
|
||||
const items = ref<TransferPrecheckItem[]>((props.payload?.items as TransferPrecheckItem[]) ?? []);
|
||||
/** backlog 初始筛选(首页计数卡切片进入:recoverable/closed/unknown;白名单外回落 all)。 */
|
||||
const backlogInitialFilter = computed<'all' | 'recoverable' | 'closed' | 'unknown'>(() => {
|
||||
const value = String(props.payload?.filter ?? 'all');
|
||||
const allowed = ['all', 'recoverable', 'closed', 'unknown'] as const;
|
||||
return (allowed as readonly string[]).includes(value) ? (value as (typeof allowed)[number]) : 'all';
|
||||
});
|
||||
const summaryRef = ref<TransferMatchingSummary | null>((props.payload?.summary as TransferMatchingSummary) ?? null);
|
||||
const items = ref<TransferMatchingItem[]>((props.payload?.items as TransferMatchingItem[]) ?? []);
|
||||
const runNo = ref(String(props.payload?.run_no ?? ''));
|
||||
const status = ref(String(props.payload?.status ?? 'executing'));
|
||||
const run = ref<TransferRunResult | null>((props.payload?.run as TransferRunResult) ?? null);
|
||||
const busy = ref(false);
|
||||
const closeTarget = ref<TransferBacklogItem | null>(null);
|
||||
/** 批量标记无需处理的明细 id 集合(与单行关闭共用同一弹窗)。 */
|
||||
const batchCloseIds = ref<number[]>([]);
|
||||
/** 正在重试收料 RPA 的来源编码集合(按来源独立展示重试中)。 */
|
||||
const retryingSource = ref<Set<string>>(new Set());
|
||||
|
||||
@@ -61,24 +75,28 @@ onMounted(() => {
|
||||
if (kind.value === 'source-select') {
|
||||
void transfer.loadSources();
|
||||
}
|
||||
if (kind.value === 'executable') {
|
||||
void transfer.loadExecutableItems();
|
||||
}
|
||||
});
|
||||
|
||||
/** payload 更新时重置本地状态(历史回放/刷新);初始化组合式函数上下文 */
|
||||
function applyPayload(payload?: Record<string, unknown> | null) {
|
||||
if (!payload) return;
|
||||
mode.value = String(payload.kind ?? 'precheck');
|
||||
summaryRef.value = (payload.summary as TransferPrecheckSummary) ?? null;
|
||||
items.value = (payload.items as TransferPrecheckItem[]) ?? [];
|
||||
mode.value = String(payload.kind ?? 'match');
|
||||
summaryRef.value = (payload.summary as TransferMatchingSummary) ?? null;
|
||||
items.value = (payload.items as TransferMatchingItem[]) ?? [];
|
||||
runNo.value = String(payload.run_no ?? '');
|
||||
status.value = String(payload.status ?? 'executing');
|
||||
run.value = (payload.run as TransferRunResult) ?? null;
|
||||
const summaryValue = (payload.summary as TransferPrecheckSummary) ?? null;
|
||||
const summaryValue = (payload.summary as TransferMatchingSummary) ?? null;
|
||||
if (summaryValue) {
|
||||
transfer.precheckId.value = summaryValue.precheck_id;
|
||||
transfer.matchingId.value = summaryValue.matching_id;
|
||||
// 默认勾选可执行明细行(按 item_id);历史回放行无 item_id 不参与勾选
|
||||
transfer.selected.value = new Set(
|
||||
(payload.items as TransferPrecheckItem[] ?? [])
|
||||
.filter((item) => item.result === 'executable')
|
||||
.map((item) => item.invoice_no),
|
||||
((payload.items as TransferMatchingItem[]) ?? [])
|
||||
.filter((item) => item.result === 'executable' && item.item_id != null)
|
||||
.map((item) => item.item_id as number),
|
||||
);
|
||||
}
|
||||
if (runNo.value) {
|
||||
@@ -105,17 +123,21 @@ async function onDownloadSources(sourceCodes: string[]) {
|
||||
|
||||
/** 重新获取 ERP 库存:批量重查后用服务端明细原位刷新(保留勾选中仍阻断的行) */
|
||||
async function onRequery(invoiceNos: string[]) {
|
||||
if (!invoiceNos.length || !transfer.precheckId.value) return;
|
||||
if (!invoiceNos.length || !transfer.matchingId.value) return;
|
||||
busy.value = true;
|
||||
try {
|
||||
await requeryTransferItems(transfer.precheckId.value, invoiceNos);
|
||||
const detail = await getTransferPrecheck(transfer.precheckId.value);
|
||||
await requeryTransferMatchingItems(transfer.matchingId.value, invoiceNos);
|
||||
const detail = await getTransferMatching(transfer.matchingId.value);
|
||||
items.value = detail.items;
|
||||
if (detail.summary) summaryRef.value = detail.summary;
|
||||
const stillBlocked = new Set(
|
||||
items.value.filter((item) => String(item.result).startsWith('blocked_')).map((item) => item.invoice_no),
|
||||
const stillBlockedIds = new Set(
|
||||
items.value
|
||||
.filter((item) => String(item.result).startsWith('blocked_') && item.item_id != null)
|
||||
.map((item) => item.item_id as number),
|
||||
);
|
||||
transfer.selected.value = new Set(
|
||||
[...transfer.selected.value].filter((id) => stillBlockedIds.has(id)),
|
||||
);
|
||||
transfer.selected.value = new Set([...transfer.selected.value].filter((no) => stillBlocked.has(no)));
|
||||
} catch (e) {
|
||||
reportError(e);
|
||||
} finally {
|
||||
@@ -123,11 +145,26 @@ async function onRequery(invoiceNos: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 直接生成调拨单(决策 4/5:无独立确认页) */
|
||||
async function onExecute(invoiceNos: string[]) {
|
||||
/** 可调拨明细行重查:逐行核对最新库存后刷新队列(行级 retry 不依赖匹配) */
|
||||
async function onExecutableRequery(itemIds: number[]) {
|
||||
busy.value = true;
|
||||
try {
|
||||
transfer.selected.value = new Set(invoiceNos);
|
||||
for (const itemId of itemIds) {
|
||||
await transfer.retry(itemId);
|
||||
}
|
||||
await transfer.loadExecutableItems();
|
||||
} catch (e) {
|
||||
reportError(e);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 按勾选明细行直接生成调拨单(item-centric:门禁在后端,失败经 reportError 展示) */
|
||||
async function onExecute(itemIds: number[]) {
|
||||
busy.value = true;
|
||||
try {
|
||||
transfer.selected.value = new Set(itemIds);
|
||||
const outcome = await transfer.execute();
|
||||
if (outcome) {
|
||||
mode.value = 'result';
|
||||
@@ -178,16 +215,13 @@ async function onBacklogRetry(itemId: number) {
|
||||
}
|
||||
}
|
||||
|
||||
function onBacklogClose(item: TransferBacklogItem) {
|
||||
closeTarget.value = item;
|
||||
}
|
||||
|
||||
async function onCloseConfirm(reason: string) {
|
||||
if (!closeTarget.value) return;
|
||||
/** 批量重查(待处理池多选):逐行隔离,完成后刷新列表并弹汇总。 */
|
||||
async function onBacklogRequery(itemIds: number[]) {
|
||||
busy.value = true;
|
||||
try {
|
||||
await transfer.manualClose(closeTarget.value.item_id, reason);
|
||||
closeTarget.value = null;
|
||||
const result = await transfer.batchRequery(itemIds);
|
||||
const ok = result.results.filter((entry) => entry.ok).length;
|
||||
notifySuccess(t('chat.transfer.toastRequeryDone', { ok, failed: result.total - ok }));
|
||||
await transfer.loadBacklog();
|
||||
} catch (e) {
|
||||
reportError(e);
|
||||
@@ -196,7 +230,59 @@ async function onCloseConfirm(reason: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 来源实例选择确认 → 创建预检并切换预检卡(决策 4:两步第一步;收料日期范围为查询范围;调拨类型决定数据范围) */
|
||||
/** 恢复处理(行级/多选):恢复语义 = 按明细 id 重查库存(batch-requery 唯一后端);
|
||||
* 完成后刷新待处理池,并按结果统计提示(ready_to_execute 计为已可执行,其余仍阻断);
|
||||
* 不再跳转匹配卡(行式执行重构后恢复与匹配卡解耦)。 */
|
||||
async function onBacklogResume(itemIds: number[]) {
|
||||
busy.value = true;
|
||||
try {
|
||||
const result = await transfer.resume(itemIds);
|
||||
await transfer.loadBacklog();
|
||||
const recovered = result.results.filter((entry) => entry.status === 'ready_to_execute').length;
|
||||
const still = result.total - recovered;
|
||||
notifySuccess(t('chat.transfer.toastRequeryRecovered', { recovered, blocked: still }));
|
||||
} catch (e) {
|
||||
reportError(e);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onBacklogClose(item: TransferBacklogItem) {
|
||||
closeTarget.value = item;
|
||||
}
|
||||
|
||||
/** 批量标记无需处理:复用关闭弹窗(批量文案)。 */
|
||||
function onBacklogBatchClose(itemIds: number[]) {
|
||||
batchCloseIds.value = itemIds;
|
||||
}
|
||||
|
||||
function onCancelClose() {
|
||||
closeTarget.value = null;
|
||||
batchCloseIds.value = [];
|
||||
}
|
||||
|
||||
async function onCloseConfirm(reason: string) {
|
||||
busy.value = true;
|
||||
try {
|
||||
if (batchCloseIds.value.length) {
|
||||
const result = await transfer.batchManualClose(batchCloseIds.value, reason);
|
||||
const ok = result.results.filter((entry) => entry.ok).length;
|
||||
notifySuccess(t('chat.transfer.toastCloseDone', { ok, failed: result.total - ok }));
|
||||
batchCloseIds.value = [];
|
||||
} else if (closeTarget.value) {
|
||||
await transfer.manualClose(closeTarget.value.item_id, reason);
|
||||
closeTarget.value = null;
|
||||
}
|
||||
await transfer.loadBacklog();
|
||||
} catch (e) {
|
||||
reportError(e);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 来源实例选择确认 → 创建匹配并切换匹配卡(决策 4:两步第一步;收料日期范围为查询范围;调拨类型决定数据范围) */
|
||||
async function onSourceConfirm(
|
||||
sourceCodes: string[],
|
||||
dateRange?: { from?: string; to?: string },
|
||||
@@ -204,9 +290,9 @@ async function onSourceConfirm(
|
||||
) {
|
||||
busy.value = true;
|
||||
try {
|
||||
await transfer.createPrecheck(sourceCodes, undefined, dateRange, transferType);
|
||||
mode.value = 'precheck';
|
||||
summaryRef.value = transfer.precheck.value;
|
||||
await transfer.createMatching(sourceCodes, undefined, dateRange, transferType);
|
||||
mode.value = 'match';
|
||||
summaryRef.value = transfer.matching.value;
|
||||
items.value = transfer.items.value;
|
||||
run.value = null;
|
||||
} catch (e) {
|
||||
@@ -250,19 +336,27 @@ async function onSourceRetry(sourceCodes: string[]) {
|
||||
@download="onDownloadSources"
|
||||
@retry="onSourceRetry"
|
||||
/>
|
||||
<TransferPrecheckCard
|
||||
v-else-if="mode === 'precheck' && summaryRef"
|
||||
<TransferMatchCard
|
||||
v-else-if="mode === 'match' && summaryRef"
|
||||
:summary="summaryRef"
|
||||
:items="items"
|
||||
:sources="transfer.sources.value"
|
||||
:selected="transfer.selected.value"
|
||||
:requery-busy="busy"
|
||||
:busy="busy"
|
||||
@toggle="(invoiceNo, checked) => transfer.toggleSelect(invoiceNo, checked)"
|
||||
@toggle-all="(invoiceNos, checked) => invoiceNos.forEach((no) => transfer.toggleSelect(no, checked))"
|
||||
@toggle="(itemId, checked) => transfer.toggleSelect(itemId, checked)"
|
||||
@toggle-all="(itemIds, checked) => itemIds.forEach((id) => transfer.toggleSelect(id, checked))"
|
||||
@requery="onRequery"
|
||||
@execute="onExecute"
|
||||
/>
|
||||
<TransferExecutableCard
|
||||
v-else-if="mode === 'executable'"
|
||||
:items="transfer.executableItems.value"
|
||||
:busy="busy"
|
||||
@refresh="() => transfer.loadExecutableItems()"
|
||||
@requery="onExecutableRequery"
|
||||
@execute="onExecute"
|
||||
/>
|
||||
<TransferProgressCard v-else-if="mode === 'progress'" :run-no="runNo" :status="status" :busy="busy" />
|
||||
<TransferResultCard
|
||||
v-else-if="mode === 'result' && run"
|
||||
@@ -274,16 +368,22 @@ async function onSourceRetry(sourceCodes: string[]) {
|
||||
<TransferBacklogSummaryCard
|
||||
v-else-if="mode === 'backlog'"
|
||||
:items="transfer.backlog.value"
|
||||
:busy="busy"
|
||||
:initial-filter="backlogInitialFilter"
|
||||
@retry="onBacklogRetry"
|
||||
@requery="onBacklogRequery"
|
||||
@resume="onBacklogResume"
|
||||
@close="onBacklogClose"
|
||||
@batch-close="onBacklogBatchClose"
|
||||
@refresh="() => transfer.loadBacklog()"
|
||||
/>
|
||||
<TransferManualCloseDialog
|
||||
v-if="closeTarget"
|
||||
:open="Boolean(closeTarget)"
|
||||
:invoice-no="closeTarget.invoice_no"
|
||||
v-if="closeTarget || batchCloseIds.length"
|
||||
:open="Boolean(closeTarget || batchCloseIds.length)"
|
||||
:invoice-no="closeTarget?.invoice_no ?? ''"
|
||||
:count="batchCloseIds.length"
|
||||
@confirm="onCloseConfirm"
|
||||
@cancel="closeTarget = null"
|
||||
@cancel="onCancelClose"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -25,7 +25,7 @@ function reasonLabel(reason: string): string {
|
||||
business_failed: 'chat.transfer.exceptionBusinessFailed',
|
||||
technical_failed: 'chat.transfer.exceptionTechnicalFailed',
|
||||
result_unknown: 'chat.transfer.resultUnknown',
|
||||
precheck_expired: 'chat.transfer.exceptionPrecheckExpired',
|
||||
matching_expired: 'chat.transfer.exceptionMatchExpired',
|
||||
};
|
||||
return map[reason] ?? 'chat.transfer.resultBlocked';
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
* 确认提交、重试收料 RPA。
|
||||
* 依赖:@vue/test-utils、i18n。
|
||||
* 逻辑:平台 DBS/Crane 仅分组;实例为选择与执行边界(决策 2/3/4);
|
||||
* 所选来源需至少一个 has_ready_file 才能确认预检(决策:无 ready 文件禁止确认)。
|
||||
* 所选来源需至少一个 has_ready_file 才能确认匹配(决策:无 ready 文件禁止确认)。
|
||||
*/
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import i18n from '@/i18n';
|
||||
import TransferSourceSelectCard from './TransferSourceSelectCard.vue';
|
||||
import { eligibleReceiptDateTo } from './transferDate';
|
||||
|
||||
const readySources = [
|
||||
{ source_code: 'DBS-AWSBI', display_name: 'AWSBI 在途仓', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' },
|
||||
@@ -85,7 +86,33 @@ describe('TransferSourceSelectCard', () => {
|
||||
it('D+1 规则提示收进 ⓘ 悬浮(title),不再平铺占宽', () => {
|
||||
// [断言意图] 长规则文案通过原生 title 渐进披露,紧凑日期行不换行错位。
|
||||
const wrapper = mountCard();
|
||||
expect(wrapper.find('[data-testid="transfer-source-date-hint"]').attributes('title')).toBe('截止不超出 D+1 规则(业务日期前一天)');
|
||||
const title = wrapper.find('[data-testid="transfer-source-date-hint"]').attributes('title') ?? '';
|
||||
expect(title).toContain('D+1 规则');
|
||||
expect(title).toContain('业务日期前一天');
|
||||
});
|
||||
|
||||
it('收料日期默认为 D+1 规则日期(T-1)且上限锁定(输入期限制)', () => {
|
||||
// [断言意图] 默认值与 max 均为上海口径 T-1,未来日期在选择器层面不可选。
|
||||
const wrapper = mountCard();
|
||||
const from = wrapper.find('[data-testid="transfer-source-date-from"]').element as HTMLInputElement;
|
||||
const to = wrapper.find('[data-testid="transfer-source-date-to"]').element as HTMLInputElement;
|
||||
const cutoff = eligibleReceiptDateTo();
|
||||
expect(from.value).toBe(cutoff);
|
||||
expect(to.value).toBe(cutoff);
|
||||
expect(from.max).toBe(cutoff);
|
||||
expect(to.max).toBe(cutoff);
|
||||
});
|
||||
|
||||
it('起始晚于截止时行内提示并禁用确认(不等提交报错)', async () => {
|
||||
// [断言意图] 日期维护期即时卡控:非法区间直接禁用确认并显示行内红字。
|
||||
const wrapper = mountCard();
|
||||
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
|
||||
await wrapper.find('[data-testid="transfer-source-date-from"]').setValue('2026-09-20');
|
||||
await wrapper.find('[data-testid="transfer-source-date-to"]').setValue('2026-09-10');
|
||||
expect(wrapper.find('[data-testid="transfer-source-date-invalid"]').exists()).toBe(true);
|
||||
expect((wrapper.find('[data-testid="transfer-source-confirm"]').element as HTMLButtonElement).disabled).toBe(true);
|
||||
await wrapper.find('[data-testid="transfer-source-date-to"]').setValue('2026-09-22');
|
||||
expect(wrapper.find('[data-testid="transfer-source-date-invalid"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('“只选可重试”勾选无文件/失败来源', async () => {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<!--
|
||||
features/chat/components/messages/TransferSourceSelectCard.vue
|
||||
用途:来源实例选择卡(决策 2/3/4:手工两步第一步)——按平台 DBS/Crane 分组勾选实例,
|
||||
选择调拨类型后“确认范围并预检”发起预检。
|
||||
选择调拨类型后“确认范围并匹配”发起匹配。
|
||||
依赖:props.sources、i18n chat.transfer.*。
|
||||
逻辑:预检参数区(调拨类型 + 收料日期,确认时一并提交)→ 选择辅助/上下文操作条
|
||||
逻辑:匹配参数区(调拨类型 + 收料日期,确认时一并提交)→ 选择辅助/上下文操作条
|
||||
(有选中时原位替换辅助区,承载批量重试/下载/清空选择)→ 平台分组来源列表
|
||||
(平台仅分组不可直接执行)→ 底部唯一实心主按钮「确认范围并预检」(未选禁用);
|
||||
(平台仅分组不可直接执行)→ 底部唯一实心主按钮「确认范围并匹配」(未选禁用);
|
||||
调拨类型决定收料数据范围(类型 1 仅纳入 INVOICE 前缀 HOM/HOX/WTP),
|
||||
类型 2/3 一期占位(禁用,后端同样 fail-closed)。
|
||||
-->
|
||||
@@ -13,6 +13,7 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { eligibleReceiptDateTo } from './transferDate';
|
||||
import type { TransferSourceOption, TransferType } from '../../types/transfer.types';
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -33,10 +34,19 @@ const { warning: notifyWarning } = useMessage();
|
||||
const { t } = useI18n();
|
||||
|
||||
const selected = ref<Set<string>>(new Set());
|
||||
/** 收料日期范围(预检查询范围);截止不得超出 D+1 规则(后端卡控)。 */
|
||||
const dateFrom = ref('');
|
||||
const dateTo = ref('');
|
||||
/** 调拨业务类型:决定本次预检纳入哪些收料数据;一期仅类型 1 开放。 */
|
||||
/** 收料日期范围(匹配查询范围):默认 D+1 规则日期(T-1),上限同(输入期限制,
|
||||
* 不等提交报错);后端 RECEIPT_DATE_RANGE_INVALID 卡控保留为双保险。 */
|
||||
const maxReceiptDate = eligibleReceiptDateTo();
|
||||
const dateFrom = ref(maxReceiptDate);
|
||||
const dateTo = ref(maxReceiptDate);
|
||||
|
||||
/** 起始不得晚于截止(清空视为不限,提交 undefined)。 */
|
||||
const dateRangeInvalid = computed(() => {
|
||||
const from = dateFrom.value || null;
|
||||
const to = dateTo.value || null;
|
||||
return from !== null && to !== null && from > to;
|
||||
});
|
||||
/** 调拨业务类型:决定本次匹配纳入哪些收料数据;一期仅类型 1 开放。 */
|
||||
const transferType = ref<TransferType>('in_transit_to_hub');
|
||||
|
||||
/** 类型选项元数据;enabled=false 为占位类型(UI 禁用 + 后端 fail-closed 双保险)。 */
|
||||
@@ -66,11 +76,13 @@ const selectedRetryableCount = computed(() =>
|
||||
);
|
||||
const batchRetryDisabled = computed(() => props.busy || selectedRetryableCount.value === 0);
|
||||
|
||||
/** 已选来源中是否有具备 ready 文件的(门禁:都无 ready 文件则禁止确认预检)。 */
|
||||
/** 已选来源中是否有具备 ready 文件的(门禁:都无 ready 文件则禁止确认匹配)。 */
|
||||
const selectedHasReadyFile = computed(() =>
|
||||
[...selected.value].some((code) => props.sources.find((s) => s.source_code === code)?.has_ready_file),
|
||||
);
|
||||
const confirmDisabled = computed(() => props.busy || selectedCount.value === 0 || !selectedHasReadyFile.value);
|
||||
const confirmDisabled = computed(() =>
|
||||
props.busy || selectedCount.value === 0 || !selectedHasReadyFile.value || dateRangeInvalid.value,
|
||||
);
|
||||
const downloadDisabled = computed(() => props.busy || !selectedHasReadyFile.value);
|
||||
|
||||
function toggle(sourceCode: string, checked: boolean) {
|
||||
@@ -143,9 +155,9 @@ function confirm() {
|
||||
<h3 class="mb-1 text-sm font-bold text-primary">{{ $t('chat.transfer.sourceSelectTitle') }}</h3>
|
||||
<p class="mb-3 text-xs text-muted">{{ $t('chat.transfer.sourceSelectHint') }}</p>
|
||||
|
||||
<!-- [ZONE 1] 预检参数区:调拨类型 + 收料日期同组(确认预检时一并提交,参数先行定范围)。 -->
|
||||
<!-- [ZONE 1] 匹配参数区:调拨类型 + 收料日期同组(确认匹配时一并提交,参数先行定范围)。 -->
|
||||
<div class="mb-3 rounded-lg border border-subtle p-3" data-testid="transfer-source-params">
|
||||
<p class="mb-2 text-[11px] font-bold text-muted">{{ $t('chat.transfer.precheckParams') }}</p>
|
||||
<p class="mb-2 text-[11px] font-bold text-muted">{{ $t('chat.transfer.matchParams') }}</p>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<span class="text-xs font-bold text-secondary">{{ $t('chat.transfer.transferTypeLabel') }}</span>
|
||||
<button
|
||||
@@ -170,6 +182,7 @@ function confirm() {
|
||||
<input
|
||||
v-model="dateFrom"
|
||||
type="date"
|
||||
:max="maxReceiptDate"
|
||||
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
|
||||
data-testid="transfer-source-date-from"
|
||||
/>
|
||||
@@ -177,6 +190,8 @@ function confirm() {
|
||||
<input
|
||||
v-model="dateTo"
|
||||
type="date"
|
||||
:max="maxReceiptDate"
|
||||
:min="dateFrom || undefined"
|
||||
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
|
||||
data-testid="transfer-source-date-to"
|
||||
/>
|
||||
@@ -186,6 +201,10 @@ function confirm() {
|
||||
:title="$t('chat.transfer.receiptDateHint')"
|
||||
data-testid="transfer-source-date-hint"
|
||||
>ⓘ</span>
|
||||
<!-- 输入期校验:起始晚于截止时行内提示并禁用确认(不等提交报错)。 -->
|
||||
<span v-if="dateRangeInvalid" class="text-xs font-bold text-red-600" data-testid="transfer-source-date-invalid">
|
||||
{{ $t('chat.transfer.receiptDateInvalid') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -338,7 +357,7 @@ function confirm() {
|
||||
data-testid="transfer-source-confirm"
|
||||
@click="confirm"
|
||||
>
|
||||
{{ $t('chat.transfer.confirmScopeAndPrecheck') }}
|
||||
{{ $t('chat.transfer.confirmScopeAndMatch') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/chat/components/messages/transferCards.spec.ts
|
||||
* 用途:验证在途调拨三张核心卡片(文件进度/预检/结果)+ 关闭弹窗的交互与禁用语义。
|
||||
* 用途:验证在途调拨三张核心卡片(文件进度/匹配/结果)+ 关闭弹窗的交互与禁用语义。
|
||||
* 依赖:@vue/test-utils、i18n、transfer.types。
|
||||
* 逻辑:断言按钮禁用、勾选禁用、ERP 单号展开/收起、异常展示、下载按钮与
|
||||
* 结果页不出现“查看执行审计”入口(决策 19)。
|
||||
@@ -9,27 +9,27 @@ import { mount } from '@vue/test-utils';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import i18n from '@/i18n';
|
||||
import TransferFileProgressCard from './TransferFileProgressCard.vue';
|
||||
import TransferPrecheckCard from './TransferPrecheckCard.vue';
|
||||
import TransferMatchCard from './TransferMatchCard.vue';
|
||||
import TransferResultCard from './TransferResultCard.vue';
|
||||
import TransferManualCloseDialog from './TransferManualCloseDialog.vue';
|
||||
|
||||
const mountOptions = { global: { plugins: [i18n] } };
|
||||
|
||||
const summary = {
|
||||
precheck_id: 'TPC-1',
|
||||
matching_id: 'MTG-1',
|
||||
status: 'ready_to_execute',
|
||||
business_date: '2026-08-06',
|
||||
eligible_receipt_date_to: '2026-08-05',
|
||||
expires_at: '',
|
||||
counts: { file_invoice_count: 3, not_matured_count: 1, prechecked_count: 2, executable_count: 2, blocked_count: 0 },
|
||||
counts: { file_invoice_count: 3, not_matured_count: 1, matched_count: 2, executable_count: 2, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '2400',
|
||||
estimated_external_write_count: 2,
|
||||
precheck_hash: 'sha256:x',
|
||||
matching_hash: 'sha256:x',
|
||||
};
|
||||
|
||||
const items = [
|
||||
{ source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器', specification: 'A', invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ source_code: 'DBS-AWSBI', material_no: 'MAT-2', material_name: '控制器', specification: 'B', invoice_no: 'INV-041', from_warehouse: '', from_quantity: null, to_warehouse: '', to_quantity: '400', result: 'not_matured' },
|
||||
{ item_id: 101, source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器', specification: 'A', invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable', checked_at: '2026-09-23T09:05:00+08:00' },
|
||||
{ item_id: 102, source_code: 'DBS-AWSBI', material_no: 'MAT-2', material_name: '控制器', specification: 'B', invoice_no: 'INV-041', from_warehouse: '', from_quantity: null, to_warehouse: '', to_quantity: '400', result: 'not_matured' },
|
||||
];
|
||||
|
||||
describe('TransferFileProgressCard', () => {
|
||||
@@ -46,41 +46,88 @@ describe('TransferFileProgressCard', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('TransferPrecheckCard', () => {
|
||||
it('阻断/未成熟项 checkbox 禁用;可执行项可选', () => {
|
||||
const wrapper = mount(TransferPrecheckCard, {
|
||||
props: { summary, items, selected: new Set(['INV-001']) },
|
||||
describe('TransferMatchCard', () => {
|
||||
it('勾选键为明细行 item_id:阻断/未成熟项 checkbox 禁用,可执行项可选', () => {
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items, selected: new Set<number>([101]) },
|
||||
...mountOptions,
|
||||
});
|
||||
const executableCheck = wrapper.find('[data-testid="transfer-check-INV-001"]');
|
||||
const maturedCheck = wrapper.find('[data-testid="transfer-check-INV-041"]');
|
||||
expect((executableCheck.element as HTMLInputElement).disabled).toBe(false);
|
||||
expect((executableCheck.element as HTMLInputElement).checked).toBe(true);
|
||||
expect((maturedCheck.element as HTMLInputElement).disabled).toBe(true);
|
||||
});
|
||||
|
||||
it('历史回放行(无 item_id)checkbox 禁用,防误选', () => {
|
||||
// [断言意图] 行式执行重构(2026-09-23):chat 消息流回放的旧 payload 行没有
|
||||
// item_id,不能作为执行勾选键;这类行必须禁选(防误选后 400)。
|
||||
const legacyItems = [{ ...items[0], item_id: undefined }];
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items: legacyItems, selected: new Set<number>() },
|
||||
...mountOptions,
|
||||
});
|
||||
expect((wrapper.find('[data-testid="transfer-check-INV-001"]').element as HTMLInputElement).disabled).toBe(true);
|
||||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||||
});
|
||||
|
||||
it('未选择任何项时生成按钮禁用', () => {
|
||||
const wrapper = mount(TransferPrecheckCard, {
|
||||
props: { summary, items, selected: new Set() },
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items, selected: new Set<number>() },
|
||||
...mountOptions,
|
||||
});
|
||||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||||
});
|
||||
|
||||
it('busy 时生成按钮禁用', () => {
|
||||
const wrapper = mount(TransferPrecheckCard, {
|
||||
props: { summary, items, selected: new Set(['INV-001']), busy: true },
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items, selected: new Set<number>([101]), busy: true },
|
||||
...mountOptions,
|
||||
});
|
||||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||||
});
|
||||
|
||||
it('点击生成按钮仅提交可执行勾选项', async () => {
|
||||
const wrapper = mount(TransferPrecheckCard, {
|
||||
props: { summary, items, selected: new Set(['INV-001']) },
|
||||
it('点击生成按钮提交可执行勾选行的 item_id 数组', async () => {
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items, selected: new Set<number>([101]) },
|
||||
...mountOptions,
|
||||
});
|
||||
await wrapper.find('[data-testid="transfer-generate-button"]').trigger('click');
|
||||
expect(wrapper.emitted('execute')?.[0][0]).toEqual(['INV-001']);
|
||||
expect(wrapper.emitted('execute')?.[0][0]).toEqual([101]);
|
||||
});
|
||||
|
||||
it('库存数量下方小字展示查询时刻(HH:mm)', () => {
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items, selected: new Set<number>() },
|
||||
...mountOptions,
|
||||
});
|
||||
const cell = wrapper.find('[data-testid="transfer-checked-at-INV-001"]');
|
||||
expect(cell.exists()).toBe(true);
|
||||
expect(cell.text()).toMatch(/^\d{2}:\d{2}$/);
|
||||
expect(wrapper.find('[data-testid="transfer-checked-at-INV-041"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('stale 行置灰 + 重查小标;file_current=false 行展示文件更新小标', () => {
|
||||
const flaggedItems = [
|
||||
{ ...items[0], stale: true, file_current: false },
|
||||
];
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items: flaggedItems, selected: new Set<number>() },
|
||||
...mountOptions,
|
||||
});
|
||||
const row = wrapper.find('[data-testid="transfer-item-INV-001"]');
|
||||
expect(row.classes()).toContain('opacity-60');
|
||||
expect(wrapper.find('[data-testid="transfer-item-stale"]').text()).toContain('重查');
|
||||
expect(wrapper.find('[data-testid="transfer-item-file-changed"]').text()).toContain('重新匹配');
|
||||
});
|
||||
|
||||
it('blocked_file_removed 结果行展示「文件已移除」独立徽标', () => {
|
||||
const removedItems = [{ ...items[0], result: 'blocked_file_removed' }];
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items: removedItems, selected: new Set<number>() },
|
||||
...mountOptions,
|
||||
});
|
||||
expect(wrapper.find('[data-testid="transfer-item-result"]').text()).toContain('文件已移除');
|
||||
});
|
||||
|
||||
it('同 Invoice 跨收料日期拆票(重复 invoice_no)时,筛选后仅渲染匹配行', async () => {
|
||||
@@ -89,16 +136,16 @@ describe('TransferPrecheckCard', () => {
|
||||
// 筛选后不匹配行残留/克隆(用户输入 HOX 仍见 SLC2PHX 行)。
|
||||
// 行身份 = (来源, Invoice, 料号, 收料日期),key 必须用同一粒度。
|
||||
const dupItems = [
|
||||
{ source_code: 'CRANE', material_no: 'M-1', material_name: '机框', specification: '', invoice_no: 'HOX-1', receipt_date: '2026-09-11', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||||
{ source_code: 'CRANE', material_no: 'M-2', material_name: '护罩', specification: '', invoice_no: 'DUP-1', receipt_date: '2026-09-03', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||||
{ source_code: 'CRANE', material_no: 'M-2', material_name: '护罩', specification: '', invoice_no: 'DUP-1', receipt_date: '2026-09-04', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||||
{ item_id: 201, source_code: 'CRANE', material_no: 'M-1', material_name: '机框', specification: '', invoice_no: 'HOX-1', receipt_date: '2026-09-11', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||||
{ item_id: 202, source_code: 'CRANE', material_no: 'M-2', material_name: '护罩', specification: '', invoice_no: 'DUP-1', receipt_date: '2026-09-03', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||||
{ item_id: 203, source_code: 'CRANE', material_no: 'M-2', material_name: '护罩', specification: '', invoice_no: 'DUP-1', receipt_date: '2026-09-04', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||||
];
|
||||
const wrapper = mount(TransferPrecheckCard, {
|
||||
props: { summary, items: dupItems, selected: new Set() },
|
||||
const wrapper = mount(TransferMatchCard, {
|
||||
props: { summary, items: dupItems, selected: new Set<number>() },
|
||||
...mountOptions,
|
||||
});
|
||||
expect(wrapper.findAll('tbody tr').length).toBe(3);
|
||||
await wrapper.find('[data-testid="transfer-precheck-filter"]').setValue('HOX');
|
||||
await wrapper.find('[data-testid="transfer-match-filter"]').setValue('HOX');
|
||||
const rows = wrapper.findAll('tbody tr');
|
||||
expect(rows.length).toBe(1);
|
||||
expect(rows[0].text()).toContain('HOX-1');
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* features/chat/components/messages/transferDate.ts
|
||||
* 用途:在途调拨业务日期工具——按 Asia/Shanghai 计算业务日期(T)与
|
||||
* D+1 成熟规则的可匹配截止日(T-1),与后端 date_policy 完全同口径。
|
||||
* 依赖:无(纯函数,便于单测)。
|
||||
* 逻辑:浏览器本地时区不可靠(部署/用户时区任意),必须固定上海时区口径,
|
||||
* 否则前端日期上限与后端 TRANSFER.RECEIPT_DATE_RANGE_INVALID 卡控会漂移。
|
||||
*/
|
||||
|
||||
/** Asia/Shanghai 当前业务日期(YYYY-MM-DD)。 */
|
||||
export function shanghaiBusinessDate(now: Date = new Date()): string {
|
||||
// en-CA 输出恰为 ISO YYYY-MM-DD(locale 无关的稳定格式技巧)。
|
||||
return new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
}).format(now);
|
||||
}
|
||||
|
||||
/** D+1 规则可匹配截止日(业务日期 T - 1 天,YYYY-MM-DD)。 */
|
||||
export function eligibleReceiptDateTo(now: Date = new Date()): string {
|
||||
const business = new Date(`${shanghaiBusinessDate(now)}T00:00:00Z`);
|
||||
business.setUTCDate(business.getUTCDate() - 1);
|
||||
return business.toISOString().slice(0, 10);
|
||||
}
|
||||
@@ -1,19 +1,20 @@
|
||||
/**
|
||||
* features/chat/composables/useChatTransfer.spec.ts
|
||||
* 用途:验证预检创建/恢复、选择范围、直接生成执行 Run、结果恢复与防重复。
|
||||
* 用途:验证匹配创建/恢复、选择范围、直接生成执行 Run、结果恢复与防重复。
|
||||
* 依赖:vi.mock(transfer.api)、useChatTransfer。
|
||||
* 逻辑:用 Mock API 驱动组合式函数,断言状态流转与调用参数。
|
||||
*/
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
createTransferPrecheck: vi.fn(),
|
||||
getTransferPrecheck: vi.fn(),
|
||||
executeTransferPrecheck: vi.fn(),
|
||||
createTransferMatching: vi.fn(),
|
||||
getTransferMatching: vi.fn(),
|
||||
executeTransferItems: vi.fn(),
|
||||
getTransferRun: vi.fn(),
|
||||
cancelTransferRun: vi.fn(),
|
||||
retryTransferItem: vi.fn(),
|
||||
manualCloseTransferItem: vi.fn(),
|
||||
batchRequeryTransferItems: vi.fn(),
|
||||
downloadTransferReceiptFiles: vi.fn(),
|
||||
downloadTransferErpInventory: vi.fn(),
|
||||
downloadTransferExceptions: vi.fn(),
|
||||
@@ -24,33 +25,33 @@ vi.mock('../api/transfer.api', () => api);
|
||||
import { useChatTransfer } from './useChatTransfer';
|
||||
|
||||
const summary = {
|
||||
precheck_id: 'TPC-20260806-001',
|
||||
matching_id: 'MTG-20260806-001',
|
||||
status: 'ready_to_execute',
|
||||
business_date: '2026-08-06',
|
||||
eligible_receipt_date_to: '2026-08-05',
|
||||
expires_at: '',
|
||||
counts: { file_invoice_count: 2, not_matured_count: 0, prechecked_count: 2, executable_count: 2, blocked_count: 0 },
|
||||
counts: { file_invoice_count: 2, not_matured_count: 0, matched_count: 2, executable_count: 2, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '2400',
|
||||
estimated_external_write_count: 2,
|
||||
precheck_hash: 'sha256:abc',
|
||||
matching_hash: 'sha256:abc',
|
||||
};
|
||||
|
||||
const detail = {
|
||||
summary,
|
||||
sources: [{ source_code: 'DBS-AWSBI', stage: 'file_ready', file_no: 'REC-1' }],
|
||||
items: [
|
||||
{ source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: 'x', specification: 'y', invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ source_code: 'DBS-AWSBI', material_no: 'MAT-2', material_name: 'x', specification: 'y', invoice_no: 'INV-002', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ source_code: 'DBS-AWSBI', material_no: 'MAT-3', material_name: 'x', specification: 'y', invoice_no: 'INV-041', from_warehouse: '', from_quantity: null, to_warehouse: '', to_quantity: '400', result: 'not_matured' },
|
||||
{ item_id: 11, source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: 'x', specification: 'y', invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ item_id: 12, source_code: 'DBS-AWSBI', material_no: 'MAT-2', material_name: 'x', specification: 'y', invoice_no: 'INV-002', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ item_id: 13, source_code: 'DBS-AWSBI', material_no: 'MAT-3', material_name: 'x', specification: 'y', invoice_no: 'INV-041', from_warehouse: '', from_quantity: null, to_warehouse: '', to_quantity: '400', result: 'not_matured' },
|
||||
],
|
||||
};
|
||||
|
||||
describe('useChatTransfer', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
api.createTransferPrecheck.mockResolvedValue(summary);
|
||||
api.getTransferPrecheck.mockResolvedValue(detail);
|
||||
api.executeTransferPrecheck.mockResolvedValue({ run_no: 'RUN-20260806-1', status: 'success' });
|
||||
api.createTransferMatching.mockResolvedValue(summary);
|
||||
api.getTransferMatching.mockResolvedValue(detail);
|
||||
api.executeTransferItems.mockResolvedValue({ run_no: 'RUN-20260806-1', status: 'success' });
|
||||
api.getTransferRun.mockResolvedValue({
|
||||
run_no: 'RUN-20260806-1',
|
||||
status: 'success',
|
||||
@@ -58,55 +59,71 @@ describe('useChatTransfer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('创建预检后默认勾选全部可执行项,未成熟项不可勾选', async () => {
|
||||
it('创建匹配后默认按 item_id 勾选全部可执行行,未成熟项不可勾选', async () => {
|
||||
const transfer = useChatTransfer();
|
||||
await transfer.createPrecheck(['DBS-AWSBI'], '2026-08-06');
|
||||
expect(transfer.precheckId.value).toBe('TPC-20260806-001');
|
||||
expect(transfer.executableInvoices.value).toEqual(['INV-001', 'INV-002']);
|
||||
expect(transfer.selected.value.has('INV-001')).toBe(true);
|
||||
expect(transfer.selected.value.has('INV-041')).toBe(false);
|
||||
await transfer.createMatching(['DBS-AWSBI'], '2026-08-06');
|
||||
expect(transfer.matchingId.value).toBe('MTG-20260806-001');
|
||||
expect(transfer.executableItemIds.value).toEqual([11, 12]);
|
||||
expect(transfer.selected.value.has(11)).toBe(true);
|
||||
expect(transfer.selected.value.has(13)).toBe(false);
|
||||
});
|
||||
|
||||
it('执行时提交勾选范围并恢复 Run', async () => {
|
||||
it('执行时按明细行 id 提交勾选范围并恢复 Run', async () => {
|
||||
const transfer = useChatTransfer();
|
||||
await transfer.createPrecheck(['DBS-AWSBI']);
|
||||
transfer.toggleSelect('INV-001', false);
|
||||
await transfer.createMatching(['DBS-AWSBI']);
|
||||
transfer.toggleSelect(11, false);
|
||||
await transfer.execute();
|
||||
expect(api.executeTransferPrecheck).toHaveBeenCalledWith('TPC-20260806-001', ['INV-002']);
|
||||
expect(api.executeTransferItems).toHaveBeenCalledWith([12]);
|
||||
expect(transfer.runNo.value).toBe('RUN-20260806-1');
|
||||
expect(api.getTransferRun).toHaveBeenCalledWith('RUN-20260806-1');
|
||||
});
|
||||
|
||||
it('无选择时执行被拦截(不调用 API)', async () => {
|
||||
const transfer = useChatTransfer();
|
||||
await transfer.createPrecheck(['DBS-AWSBI']);
|
||||
await transfer.createMatching(['DBS-AWSBI']);
|
||||
transfer.selected.value = new Set();
|
||||
const result = await transfer.execute().catch(() => null);
|
||||
expect(result).toBeNull();
|
||||
expect(api.executeTransferPrecheck).not.toHaveBeenCalled();
|
||||
expect(api.executeTransferItems).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('resume 是批量重查的语义别名:按明细 id 直调 batch-requery', async () => {
|
||||
// [断言意图] 行式执行重构(2026-09-23):恢复处理不再重建匹配,
|
||||
// 前端 resume 与 batchRequery 同源(batch-requery 是恢复的唯一后端)。
|
||||
api.batchRequeryTransferItems.mockResolvedValue({
|
||||
total: 2,
|
||||
results: [
|
||||
{ item_id: 7, ok: true, status: 'ready_to_execute' },
|
||||
{ item_id: 8, ok: false, error: 'blocked' },
|
||||
],
|
||||
});
|
||||
const transfer = useChatTransfer();
|
||||
const result = await transfer.resume([7, 8]);
|
||||
expect(api.batchRequeryTransferItems).toHaveBeenCalledWith([7, 8]);
|
||||
expect(result.results.filter((entry) => entry.status === 'ready_to_execute')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('busy 在请求期间置位,完成后复位(防重复点击)', async () => {
|
||||
let resolvePrecheck!: (value: unknown) => void;
|
||||
api.getTransferPrecheck.mockImplementation(
|
||||
() => new Promise((resolve) => { resolvePrecheck = resolve; }),
|
||||
let resolveMatching!: (value: unknown) => void;
|
||||
api.getTransferMatching.mockImplementation(
|
||||
() => new Promise((resolve) => { resolveMatching = resolve; }),
|
||||
);
|
||||
const transfer = useChatTransfer();
|
||||
const promise = transfer.createPrecheck(['DBS-AWSBI']);
|
||||
// 推进微任务链:createTransferPrecheck → getTransferPrecheck(mock 已执行)
|
||||
const promise = transfer.createMatching(['DBS-AWSBI']);
|
||||
// 推进微任务链:createTransferMatching → getTransferMatching(mock 已执行)
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
expect(transfer.busy.value).toBe(true);
|
||||
resolvePrecheck(detail);
|
||||
resolveMatching(detail);
|
||||
await promise;
|
||||
expect(transfer.busy.value).toBe(false);
|
||||
});
|
||||
|
||||
it('reset 清空全部状态', async () => {
|
||||
const transfer = useChatTransfer();
|
||||
await transfer.createPrecheck(['DBS-AWSBI']);
|
||||
await transfer.createMatching(['DBS-AWSBI']);
|
||||
transfer.reset();
|
||||
expect(transfer.precheckId.value).toBeNull();
|
||||
expect(transfer.matchingId.value).toBeNull();
|
||||
expect(transfer.items.value).toHaveLength(0);
|
||||
expect(transfer.run.value).toBeNull();
|
||||
});
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
/**
|
||||
* features/chat/composables/useChatTransfer.ts
|
||||
* 用途:在途仓自动调拨聊天编排入口——预检创建/恢复、选择范围、直接生成执行 Run、
|
||||
* Run 进度与结果恢复、人工重试/关闭、下载。
|
||||
* 用途:在途仓自动调拨聊天编排入口——匹配创建/恢复、选择范围(按明细 item_id)、
|
||||
* 按行直接生成执行 Run、Run 进度与结果恢复、人工重试/关闭、恢复处理(重查)、下载。
|
||||
* 依赖:transfer.api、transfer.types、useMessage、Vue refs/computed。
|
||||
* 逻辑:前端只消费稳定 DTO;Run 是异步真相源,刷新/重进由 GET 恢复;
|
||||
* 勾选集合以明细行 item_id 为键(历史回放行无 item_id 不可选);
|
||||
* 恢复处理 = 按明细 id 重查库存(batch-requery 是唯一后端);
|
||||
* 防重复点击(busy);错误统一 useMessage 展示 BusinessError。
|
||||
*/
|
||||
import { computed, ref, type Ref } from 'vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
batchManualCloseTransferItems,
|
||||
batchRequeryTransferItems,
|
||||
cancelTransferRun,
|
||||
createTransferPrecheck,
|
||||
createTransferMatching,
|
||||
downloadTransferErpInventory,
|
||||
downloadTransferExceptions,
|
||||
downloadTransferReceiptFiles,
|
||||
executeTransferPrecheck,
|
||||
executeTransferItems,
|
||||
getTransferBacklogSummary,
|
||||
getTransferPrecheck,
|
||||
getTransferMatching,
|
||||
getTransferRun,
|
||||
listExecutableTransferItems,
|
||||
listTransferBacklog,
|
||||
listTransferSources,
|
||||
manualCloseTransferItem,
|
||||
@@ -27,9 +32,10 @@ import {
|
||||
import type {
|
||||
TransferBacklogItem,
|
||||
TransferBacklogSummary,
|
||||
TransferPrecheckDetail,
|
||||
TransferPrecheckItem,
|
||||
TransferPrecheckSummary,
|
||||
TransferBatchResult,
|
||||
TransferMatchingDetail,
|
||||
TransferMatchingItem,
|
||||
TransferMatchingSummary,
|
||||
TransferRunResult,
|
||||
TransferSourceOption,
|
||||
TransferSourceProgress,
|
||||
@@ -39,29 +45,32 @@ import type {
|
||||
export function useChatTransfer() {
|
||||
const { error: notifyError } = useMessage();
|
||||
|
||||
const precheckId = ref<string | null>(null);
|
||||
const precheck = ref<TransferPrecheckSummary | null>(null);
|
||||
const items = ref<TransferPrecheckItem[]>([]);
|
||||
const matchingId = ref<string | null>(null);
|
||||
const matching = ref<TransferMatchingSummary | null>(null);
|
||||
const items = ref<TransferMatchingItem[]>([]);
|
||||
const sources = ref<TransferSourceProgress[]>([]);
|
||||
const runNo = ref<string | null>(null);
|
||||
const run = ref<TransferRunResult | null>(null);
|
||||
const backlog = ref<TransferBacklogItem[]>([]);
|
||||
const backlogSummary = ref<TransferBacklogSummary | null>(null);
|
||||
const executableItems = ref<TransferMatchingItem[]>([]);
|
||||
const sourceOptions = ref<TransferSourceOption[]>([]);
|
||||
const selected = ref<Set<string>>(new Set());
|
||||
const selected = ref<Set<number>>(new Set());
|
||||
const busy = ref(false);
|
||||
const error = ref('');
|
||||
|
||||
/** 全部可执行 Invoice(阻断/未成熟不可勾选) */
|
||||
const executableInvoices = computed(() =>
|
||||
items.value.filter((item) => item.result === 'executable').map((item) => item.invoice_no),
|
||||
/** 全部可执行明细行 id(阻断/未成熟/无 item_id 的历史行不可勾选) */
|
||||
const executableItemIds = computed(() =>
|
||||
items.value
|
||||
.filter((item) => item.result === 'executable' && item.item_id != null)
|
||||
.map((item) => item.item_id as number),
|
||||
);
|
||||
|
||||
const selectedCount = computed(() => selected.value.size);
|
||||
const estimatedQuantity = computed(() => precheck.value?.estimated_transfer_quantity ?? '0');
|
||||
const estimatedQuantity = computed(() => matching.value?.estimated_transfer_quantity ?? '0');
|
||||
|
||||
/** 创建预检(缺文件时来源级阶段展示等待/失败);transferType 决定收料数据范围,缺省在途仓至HUB仓 */
|
||||
async function createPrecheck(
|
||||
/** 创建匹配(缺文件时来源级阶段展示等待/失败);transferType 决定收料数据范围,缺省在途仓至HUB仓 */
|
||||
async function createMatching(
|
||||
sourceCodes: string[],
|
||||
businessDate?: string,
|
||||
dateRange?: { from?: string; to?: string },
|
||||
@@ -70,15 +79,15 @@ export function useChatTransfer() {
|
||||
busy.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const summary = await createTransferPrecheck({
|
||||
const summary = await createTransferMatching({
|
||||
source_codes: sourceCodes,
|
||||
business_date: businessDate,
|
||||
receipt_date_from: dateRange?.from,
|
||||
receipt_date_to: dateRange?.to,
|
||||
transfer_type: transferType,
|
||||
});
|
||||
precheckId.value = summary.precheck_id;
|
||||
await refreshPrecheck();
|
||||
matchingId.value = summary.matching_id;
|
||||
await refreshMatching();
|
||||
return summary;
|
||||
} catch (e) {
|
||||
error.value = String(e);
|
||||
@@ -88,42 +97,43 @@ export function useChatTransfer() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 恢复预检进度(页面刷新/会话恢复) */
|
||||
async function refreshPrecheck() {
|
||||
if (!precheckId.value) return null;
|
||||
const detail = await getTransferPrecheck(precheckId.value);
|
||||
/** 恢复匹配进度(页面刷新/会话恢复) */
|
||||
async function refreshMatching() {
|
||||
if (!matchingId.value) return null;
|
||||
const detail = await getTransferMatching(matchingId.value);
|
||||
applyDetail(detail);
|
||||
return detail;
|
||||
}
|
||||
|
||||
function applyDetail(detail: TransferPrecheckDetail) {
|
||||
precheck.value = detail.summary;
|
||||
function applyDetail(detail: TransferMatchingDetail) {
|
||||
matching.value = detail.summary;
|
||||
items.value = detail.items;
|
||||
sources.value = detail.sources;
|
||||
// 默认勾选全部可执行项;阻断/未成熟不可选
|
||||
// 默认勾选全部可执行明细行(按 item_id);阻断/未成熟/无 item_id 不可选
|
||||
selected.value = new Set(
|
||||
detail.items.filter((item) => item.result === 'executable').map((item) => item.invoice_no),
|
||||
detail.items
|
||||
.filter((item) => item.result === 'executable' && item.item_id != null)
|
||||
.map((item) => item.item_id as number),
|
||||
);
|
||||
}
|
||||
|
||||
function toggleSelect(invoiceNo: string, checked: boolean) {
|
||||
function toggleSelect(itemId: number, checked: boolean) {
|
||||
const next = new Set(selected.value);
|
||||
if (checked) next.add(invoiceNo);
|
||||
else next.delete(invoiceNo);
|
||||
if (checked) next.add(itemId);
|
||||
else next.delete(itemId);
|
||||
selected.value = next;
|
||||
}
|
||||
|
||||
/** 直接生成调拨单(决策 4/5:无独立确认页) */
|
||||
/** 按勾选明细行直接生成调拨单(item-centric:门禁在后端,失败抛 BusinessError) */
|
||||
async function execute() {
|
||||
if (!precheckId.value) throw new Error('precheck not created');
|
||||
if (selected.value.size === 0) {
|
||||
notifyError('请至少选择一个可执行 Invoice');
|
||||
notifyError('请至少选择一个可执行明细行');
|
||||
return null;
|
||||
}
|
||||
busy.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const result = await executeTransferPrecheck(precheckId.value, [...selected.value]);
|
||||
const result = await executeTransferItems([...selected.value]);
|
||||
runNo.value = result.run_no;
|
||||
await refreshRun();
|
||||
return result;
|
||||
@@ -154,14 +164,14 @@ export function useChatTransfer() {
|
||||
/** 人工重试异常项 */
|
||||
async function retry(itemId: number) {
|
||||
const result = await retryTransferItem(itemId);
|
||||
await refreshPrecheck();
|
||||
await refreshMatching();
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 人工关闭异常项 */
|
||||
async function manualClose(itemId: number, reason: string) {
|
||||
const result = await manualCloseTransferItem(itemId, reason);
|
||||
await refreshPrecheck();
|
||||
await refreshMatching();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -173,7 +183,7 @@ export function useChatTransfer() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 下载预检冻结的 ERP 库存表(csv) */
|
||||
/** 下载匹配冻结的 ERP 库存表(csv) */
|
||||
async function downloadErpInventory() {
|
||||
if (!runNo.value) return null;
|
||||
const result = await downloadTransferErpInventory(runNo.value);
|
||||
@@ -210,6 +220,29 @@ export function useChatTransfer() {
|
||||
return { items, summary };
|
||||
}
|
||||
|
||||
/** 加载可调拨明细(全局可执行行队列;恢复后的行会出现在这里) */
|
||||
async function loadExecutableItems() {
|
||||
const payload = await listExecutableTransferItems();
|
||||
executableItems.value = payload.items;
|
||||
return executableItems.value;
|
||||
}
|
||||
|
||||
/** 批量重查库存(单行隔离,结果由调用方刷新列表后展示) */
|
||||
async function batchRequery(itemIds: number[]): Promise<TransferBatchResult> {
|
||||
return batchRequeryTransferItems(itemIds);
|
||||
}
|
||||
|
||||
/** 恢复处理(行级/多选):恢复语义 = 按明细 id 重查库存(batch-requery 唯一后端);
|
||||
* 返回批量结果,由视图统计 recovered(status=ready_to_execute)与仍阻断数。 */
|
||||
async function resume(itemIds: number[]): Promise<TransferBatchResult> {
|
||||
return batchRequeryTransferItems(itemIds);
|
||||
}
|
||||
|
||||
/** 批量人工关闭(原因整批共用;单行隔离) */
|
||||
async function batchManualClose(itemIds: number[], reason: string): Promise<TransferBatchResult> {
|
||||
return batchManualCloseTransferItems(itemIds, reason);
|
||||
}
|
||||
|
||||
function saveBlob(blob: Blob, filename: string) {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
@@ -220,37 +253,39 @@ export function useChatTransfer() {
|
||||
}
|
||||
|
||||
function reset() {
|
||||
precheckId.value = null;
|
||||
precheck.value = null;
|
||||
matchingId.value = null;
|
||||
matching.value = null;
|
||||
items.value = [];
|
||||
sources.value = [];
|
||||
runNo.value = null;
|
||||
run.value = null;
|
||||
backlog.value = [];
|
||||
backlogSummary.value = null;
|
||||
executableItems.value = [];
|
||||
sourceOptions.value = [];
|
||||
selected.value = new Set();
|
||||
error.value = '';
|
||||
}
|
||||
|
||||
return {
|
||||
precheckId,
|
||||
precheck,
|
||||
matchingId,
|
||||
matching,
|
||||
items,
|
||||
sources,
|
||||
runNo,
|
||||
run,
|
||||
backlog,
|
||||
backlogSummary,
|
||||
executableItems,
|
||||
sourceOptions,
|
||||
selected,
|
||||
selectedCount,
|
||||
executableInvoices,
|
||||
executableItemIds,
|
||||
estimatedQuantity,
|
||||
busy,
|
||||
error,
|
||||
createPrecheck,
|
||||
refreshPrecheck,
|
||||
createMatching,
|
||||
refreshMatching,
|
||||
toggleSelect,
|
||||
execute,
|
||||
refreshRun,
|
||||
@@ -260,6 +295,10 @@ export function useChatTransfer() {
|
||||
loadSources,
|
||||
retrySourceRpa,
|
||||
loadBacklog,
|
||||
loadExecutableItems,
|
||||
batchRequery,
|
||||
resume,
|
||||
batchManualClose,
|
||||
downloadReceiptFiles,
|
||||
downloadErpInventory,
|
||||
downloadExceptions,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* features/chat/e2e/in-transit-transfer.spec.ts
|
||||
* 用途:在途仓自动调拨全链路契约冒烟(对应 TDD §10 主路径)——
|
||||
* 预检 → 选择子集 → 直接生成调拨单 → Run 恢复 → 下载留底。
|
||||
* 匹配 → 选择子集 → 生成调拨单 → Run 恢复 → 下载留底。
|
||||
* 依赖:Vitest、vi.mock(transfer.api)、useChatTransfer。
|
||||
* 逻辑:不启浏览器;用组合式函数 + Mock API 断言产品契约,避免 e2e 环境依赖
|
||||
* (与仓库 shipping e2e 约定一致)。
|
||||
@@ -9,9 +9,9 @@
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
createTransferPrecheck: vi.fn(),
|
||||
getTransferPrecheck: vi.fn(),
|
||||
executeTransferPrecheck: vi.fn(),
|
||||
createTransferMatching: vi.fn(),
|
||||
getTransferMatching: vi.fn(),
|
||||
executeTransferItems: vi.fn(),
|
||||
getTransferRun: vi.fn(),
|
||||
retryTransferItem: vi.fn(),
|
||||
manualCloseTransferItem: vi.fn(),
|
||||
@@ -23,25 +23,25 @@ const api = vi.hoisted(() => ({
|
||||
vi.mock('@/features/chat/api/transfer.api', () => api);
|
||||
|
||||
import { useChatTransfer } from '@/features/chat/composables/useChatTransfer';
|
||||
import type { TransferPrecheckDetail } from '@/features/chat/types/transfer.types';
|
||||
import type { TransferMatchingDetail } from '@/features/chat/types/transfer.types';
|
||||
|
||||
const detail: TransferPrecheckDetail = {
|
||||
const detail: TransferMatchingDetail = {
|
||||
summary: {
|
||||
precheck_id: 'TPC-20260806-001',
|
||||
matching_id: 'MTG-20260806-001',
|
||||
status: 'ready_to_execute',
|
||||
business_date: '2026-08-06',
|
||||
eligible_receipt_date_to: '2026-08-05',
|
||||
expires_at: '',
|
||||
counts: { file_invoice_count: 3, not_matured_count: 1, prechecked_count: 2, executable_count: 2, blocked_count: 0 },
|
||||
counts: { file_invoice_count: 3, not_matured_count: 1, matched_count: 2, executable_count: 2, blocked_count: 0 },
|
||||
estimated_transfer_quantity: '2400',
|
||||
estimated_external_write_count: 2,
|
||||
precheck_hash: 'sha256:abc',
|
||||
matching_hash: 'sha256:abc',
|
||||
},
|
||||
sources: [{ source_code: 'DBS-AWSBI', stage: 'file_ready', file_no: 'REC-1', file_version: 'v3' }],
|
||||
items: [
|
||||
{ source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器组件', specification: 'A', invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ source_code: 'DBS-AWSBI', material_no: 'MAT-2', material_name: '控制器组件', specification: 'B', invoice_no: 'INV-002', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ source_code: 'DBS-AWSSG', material_no: 'MAT-41', material_name: '连接器', specification: 'C', invoice_no: 'INV-041', from_warehouse: '', from_quantity: null, to_warehouse: '', to_quantity: '400', result: 'not_matured' },
|
||||
{ item_id: 11, source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器组件', specification: 'A', invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ item_id: 12, source_code: 'DBS-AWSBI', material_no: 'MAT-2', material_name: '控制器组件', specification: 'B', invoice_no: 'INV-002', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable' },
|
||||
{ item_id: 13, source_code: 'DBS-AWSSG', material_no: 'MAT-41', material_name: '连接器', specification: 'C', invoice_no: 'INV-041', from_warehouse: '', from_quantity: null, to_warehouse: '', to_quantity: '400', result: 'not_matured' },
|
||||
],
|
||||
};
|
||||
|
||||
@@ -68,23 +68,23 @@ const runResult = {
|
||||
describe('in-transit-transfer e2e contract', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
api.createTransferPrecheck.mockResolvedValue(detail.summary);
|
||||
api.getTransferPrecheck.mockResolvedValue(detail);
|
||||
api.executeTransferPrecheck.mockResolvedValue({ run_no: 'RUN-20260806-001', status: 'success' });
|
||||
api.createTransferMatching.mockResolvedValue(detail.summary);
|
||||
api.getTransferMatching.mockResolvedValue(detail);
|
||||
api.executeTransferItems.mockResolvedValue({ run_no: 'RUN-20260806-001', status: 'success' });
|
||||
api.getTransferRun.mockResolvedValue(runResult);
|
||||
api.downloadTransferReceiptFiles.mockResolvedValue({ blob: new Blob(['zip']), filename: 'receipt-files.zip' });
|
||||
api.downloadTransferErpInventory.mockResolvedValue({ blob: new Blob(['csv']), filename: 'erp.csv' });
|
||||
});
|
||||
|
||||
it('主路径:预检 → 只选 INV-001 → 生成调拨单 → 结果按 ERP 单号聚合', async () => {
|
||||
it('主路径:匹配 → 只选 item 11 → 按明细行生成调拨单 → 结果按 ERP 单号聚合', async () => {
|
||||
const transfer = useChatTransfer();
|
||||
await transfer.createPrecheck(['DBS-AWSBI', 'DBS-AWSSG'], '2026-08-06');
|
||||
await transfer.createMatching(['DBS-AWSBI', 'DBS-AWSSG'], '2026-08-06');
|
||||
// 未成熟项默认不勾选
|
||||
expect(transfer.selected.value.has('INV-041')).toBe(false);
|
||||
// 取消 INV-002,只执行 INV-001
|
||||
transfer.toggleSelect('INV-002', false);
|
||||
expect(transfer.selected.value.has(13)).toBe(false);
|
||||
// 取消 item 12,只执行 item 11
|
||||
transfer.toggleSelect(12, false);
|
||||
await transfer.execute();
|
||||
expect(api.executeTransferPrecheck).toHaveBeenCalledWith('TPC-20260806-001', ['INV-001']);
|
||||
expect(api.executeTransferItems).toHaveBeenCalledWith([11]);
|
||||
expect(transfer.run.value?.result.external_documents[0].document_no).toBe('TRF-10001');
|
||||
});
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ export interface ChatMessage {
|
||||
content: string;
|
||||
/** 用户提交时固化的附件展示快照;助手消息不使用此字段。 */
|
||||
attachments?: ChatMessageAttachment[];
|
||||
type?: 'text' | 'leave-form' | 'leave-confirmation' | 'leave-result' | 'shipping-inventory-mapping' | 'shipping-parse-review' | 'shipping-match-result' | 'maintenance-device-result' | 'procurement-contract-review' | 'transfer-precheck' | 'transfer-progress' | 'transfer-result';
|
||||
type?: 'text' | 'leave-form' | 'leave-confirmation' | 'leave-result' | 'shipping-inventory-mapping' | 'shipping-parse-review' | 'shipping-match-result' | 'maintenance-device-result' | 'procurement-contract-review' | 'transfer-match' | 'transfer-progress' | 'transfer-result';
|
||||
retriever_resources?: RetrieverResource[];
|
||||
attribution_parts?: string[];
|
||||
chat_log_id?: number;
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
/** 调拨业务类型(与后端 TransferType 枚举一致;类型 2/3 一期占位未开放) */
|
||||
export type TransferType = 'in_transit_to_hub' | 'hub_repair_out' | 'hub_to_hub';
|
||||
|
||||
/** 预检计数 */
|
||||
export interface TransferPrecheckCounts {
|
||||
/** 匹配计数 */
|
||||
export interface TransferMatchingCounts {
|
||||
file_invoice_count: number;
|
||||
not_matured_count: number;
|
||||
prechecked_count: number;
|
||||
matched_count: number;
|
||||
executable_count: number;
|
||||
blocked_count: number;
|
||||
}
|
||||
@@ -24,21 +24,23 @@ export interface TransferRawLine {
|
||||
file_version: string;
|
||||
}
|
||||
|
||||
/** 预检摘要 */
|
||||
export interface TransferPrecheckSummary {
|
||||
precheck_id: string;
|
||||
/** 匹配摘要 */
|
||||
export interface TransferMatchingSummary {
|
||||
matching_id: string;
|
||||
status: string;
|
||||
business_date: string;
|
||||
eligible_receipt_date_to: string;
|
||||
expires_at: string;
|
||||
counts: TransferPrecheckCounts;
|
||||
counts: TransferMatchingCounts;
|
||||
estimated_transfer_quantity: string;
|
||||
estimated_external_write_count: number;
|
||||
precheck_hash: string;
|
||||
matching_hash: string;
|
||||
}
|
||||
|
||||
/** 预检明细项(决策 6:十列字段) */
|
||||
export interface TransferPrecheckItem {
|
||||
/** 匹配明细项(决策 6:十列字段 + 行装饰字段;item_id 为勾选/执行主键) */
|
||||
export interface TransferMatchingItem {
|
||||
/** 明细行 id(执行/重查的勾选键);历史回放 payload 可能缺省(缺省行禁选) */
|
||||
item_id?: number;
|
||||
source_code: string;
|
||||
material_no: string;
|
||||
material_name: string;
|
||||
@@ -54,6 +56,12 @@ export interface TransferPrecheckItem {
|
||||
erp_document_no?: string | null;
|
||||
raw_lines?: TransferRawLine[];
|
||||
lot_no?: string;
|
||||
/** 库存查询时刻(行评估时间,ISO);缺省为旧 payload */
|
||||
checked_at?: string | null;
|
||||
/** 匹配新鲜度:超过 TTL(10 分钟)为 true,执行门禁会拦截 */
|
||||
stale?: boolean;
|
||||
/** 行评估所用收料文件版本与来源最新可用文件是否一致;false = 文件已更新需重新匹配 */
|
||||
file_current?: boolean;
|
||||
}
|
||||
|
||||
/** 来源实例级进度(决策 18:来源隔离展示) */
|
||||
@@ -67,10 +75,10 @@ export interface TransferSourceProgress {
|
||||
error_message?: string | null;
|
||||
}
|
||||
|
||||
/** 预检恢复响应 */
|
||||
export interface TransferPrecheckDetail {
|
||||
summary: TransferPrecheckSummary;
|
||||
items: TransferPrecheckItem[];
|
||||
/** 匹配恢复响应 */
|
||||
export interface TransferMatchingDetail {
|
||||
summary: TransferMatchingSummary;
|
||||
items: TransferMatchingItem[];
|
||||
sources: TransferSourceProgress[];
|
||||
}
|
||||
|
||||
@@ -120,7 +128,7 @@ export interface TransferExecuteResponse {
|
||||
result?: TransferRunResult['result'];
|
||||
}
|
||||
|
||||
/** 待处理池项 */
|
||||
/** 待处理池项(明细字段与匹配窗口列一致) */
|
||||
export interface TransferBacklogItem {
|
||||
item_id: number;
|
||||
source_code: string;
|
||||
@@ -128,9 +136,24 @@ export interface TransferBacklogItem {
|
||||
material_no: string;
|
||||
status: string;
|
||||
reason: string;
|
||||
/** 最近一次结果码(如 blocked_file_removed=收料行已从最新文件移除);缺省为普通阻断 */
|
||||
result_code?: string | null;
|
||||
age_days: number;
|
||||
aging_level: string;
|
||||
last_attempt_at?: string | null;
|
||||
receipt_date?: string | null;
|
||||
material_name?: string | null;
|
||||
from_warehouse?: string | null;
|
||||
to_warehouse?: string | null;
|
||||
lot_no?: string | null;
|
||||
receipt_quantity?: string | null;
|
||||
external_quantity?: string | null;
|
||||
}
|
||||
|
||||
/** 批量操作结果(单行隔离:ok 行带 status,失败行带 error) */
|
||||
export interface TransferBatchResult {
|
||||
total: number;
|
||||
results: Array<{ item_id: number; invoice_no?: string; ok: boolean; status?: string; error?: string }>;
|
||||
}
|
||||
|
||||
/** 操作结果(重试/关闭/取消) */
|
||||
@@ -162,7 +185,7 @@ export interface TransferSourceOption {
|
||||
enabled: boolean;
|
||||
/** 收料文件状态:ready / fetching / failed / expired / none(只读投影货代收料事实) */
|
||||
file_status?: 'ready' | 'fetching' | 'failed' | 'expired' | 'none';
|
||||
/** 是否已有当前可用的收料文件(门禁:无 ready 文件禁止确认预检) */
|
||||
/** 是否已有当前可用的收料文件(门禁:无 ready 文件禁止确认匹配) */
|
||||
has_ready_file?: boolean;
|
||||
file_no?: string | null;
|
||||
file_sha256?: string | null;
|
||||
|
||||
Reference in new issue
Block a user