Files
syops/frontend/src/features/chat/components/messages/TransferExecutableCard.vue
T
hugo 0cf3c24119 refactor(in-transit-transfer): 行归属解耦、按行执行三层门禁并重构术语为匹配
- 行不迁移:匹配记录降级为评估留痕(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 ✓
2026-09-24 00:24:03 +08:00

213 lines
9.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
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>