- 行不迁移:匹配记录降级为评估留痕(scope/counts/hash 留痕不拦执行), 匹配/重查原地刷新行并续行级新鲜度(updated_at) - 执行改按行:POST /items/execute 三层门禁(行级新鲜度 TTL/文件版本对账/写前复查), Run 留痕不绑匹配记录;消失行 blocked_file_removed fail-closed 入异常池 - 恢复处理收敛为行级重查(batch-resume 删除);待处理池补齐匹配窗口字段, 排序改业务稳定键(收料日期→Invoice→created_at,操作不再引起跳位) - 首页待办看板四队列:可调拨明细/待恢复异常/已人工关闭/结果未知;「最近预检」移除; 收料日期默认 T-1 并加输入期限制;「重新查询 ERP」更名「重查」 - 术语重构 precheck→match:表 transfer_matchings、列 matching_id/matching_no/matching_hash、 API /matchings、单号前缀 MTG、状态值 prechecking→matching(迁移 rn1a2b3c4d5e6,模块未上线无兼容层) - 修复 integration_connector mapping 扇出嵌套丢行缺陷;对账结论:0 vs 30/40/36 系收料仓库映射曾指向错误账套 TGHX(已改 TGHX1),探针留档 backend/tmp - 测试:后端 in_transit_transfer+api+connector 393 passed;前端 chat 713 passed;build ✓
305 lines
13 KiB
Vue
305 lines
13 KiB
Vue
<!--
|
||
features/chat/components/messages/TransferBacklogSummaryCard.vue
|
||
用途:待处理异常卡(可恢复/已关闭/结果未知三组)——列与匹配窗口一致,
|
||
支持关键字/结果筛选、多选批量操作(重查/恢复处理/标记无需处理)与行级快捷操作。
|
||
依赖: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';
|
||
|
||
const props = defineProps<{
|
||
items: TransferBacklogItem[];
|
||
busy?: boolean;
|
||
/** 初始结果筛选(首页计数卡切片进入:closed 卡落「已关闭」切片等)。 */
|
||
initialFilter?: 'all' | 'recoverable' | 'closed' | 'unknown';
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
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',
|
||
escalate_5d: 'chat.transfer.agingEscalate',
|
||
critical_7d: 'chat.transfer.agingCritical',
|
||
result_unknown: 'chat.transfer.resultUnknown',
|
||
closed: 'chat.transfer.statusClosed',
|
||
};
|
||
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>
|
||
<div class="my-2 rounded-2xl border border-brand-100 bg-surface p-4 shadow-sm" data-testid="transfer-backlog-card">
|
||
<div class="mb-2 flex items-center justify-between">
|
||
<h3 class="text-sm font-bold text-primary">{{ $t('chat.transfer.backlogTitle') }}</h3>
|
||
<button
|
||
type="button"
|
||
class="rounded-lg border border-default px-2 py-1 text-xs text-secondary hover-surface-soft"
|
||
data-testid="transfer-backlog-refresh"
|
||
@click="emit('refresh')"
|
||
>
|
||
{{ $t('chat.transfer.refreshProgress') }}
|
||
</button>
|
||
</div>
|
||
|
||
<!-- 批量操作条:勾选 ≥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)"
|
||
>
|
||
{{ $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>
|
||
</div>
|
||
</template>
|