- 修改证据下载接口,分别签发预览地址与带保存名的下载地址,避免浏览器使用对象键哈希作为保存名。 - 待匹配清单接口调整,按外部单号合计数量,不再返回外部项次,提升数据展示的清晰度。 - 移除待匹配桶的「清空并重新解析」功能,简化操作流程,确保用户体验一致性。 - 新增跨页全选支持的 API,允许用户在待处理池中选择全部待处理明细 ID,优化批量操作体验。
481 lines
19 KiB
Vue
481 lines
19 KiB
Vue
<!--
|
||
features/chat/components/messages/TransferMessageView.vue
|
||
用途:在途调拨消息卡片的自驱动挂载视图——按 payload 形态渲染卡片,并把卡片按钮
|
||
(生成调拨单 / 下载 / 重查库存 / 关闭 / 重新触发 / 关闭单)经 useChatTransfer 真实调用 API。
|
||
依赖:Transfer*Card、useChatTransfer、i18n chat.transfer.*。
|
||
逻辑:payload 作为初始状态(ChatLog 回放;历史行无 item_id 仅展示不可选);仅携带
|
||
matching_id 时按 ID 恢复匹配卡(最近匹配入口);勾选/执行按明细 item_id;
|
||
来源选择卡重试入站 RPA 为 202 异步——存在抓取中来源时组合式函数自动轮询
|
||
GET /sources,RPA 回调收口后状态自动刷新,离开来源卡即停轮询;
|
||
来源卡证据清单「重新解析」完成 emit reparsed → loadSources 同步芯片(不走路由 retry);
|
||
来源选择卡挂载时并行拉取来源列表与调拨类型配置(Task 7 接口化,
|
||
类型选项=GET /transfer-types 接口下发);
|
||
可调拨明细/待处理异常挂载时也拉类型配置,表格「调拨类型」列按 names 多语言显示;
|
||
待处理异常的重查库存(行级与批量)都走 batch-requery,完成后刷新待处理池,
|
||
并用一句结果报出已可执行、仍阻断、失败;预检卡提交 202(D8)→ 切融合卡 kind='run'(run_no 传卡,
|
||
轮询由融合卡自驱动,父级停自身轮询),门禁 4xx → useMessage 行内报错 + 预检状态刷新;
|
||
融合卡失败单「重查库存」复用 batch-requery(会话明细行关联 item_id)、「关闭单」
|
||
上抛 closed 事件后刷新 run 调拨单清单与可执行池(D18 行脱离回 ready_to_execute);
|
||
下载走 requestBlob;不展示执行审计入口(决策 19);全程无取消执行入口(D9)。
|
||
-->
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, ref, watch } from '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, getTransferMatching, retryTransferOrder, requeryTransferMatchingItems } from '../../api/transfer.api';
|
||
import { triggerBlobDownload } from '@/shared/utils/download';
|
||
import { useMessage } from '@/shared/composables/useMessage';
|
||
import type {
|
||
TransferBacklogItem,
|
||
TransferMatchingItem,
|
||
TransferMatchingSummary,
|
||
TransferRunResult,
|
||
TransferSourceProgress,
|
||
TransferOrder,
|
||
TransferType,
|
||
} from '../../types/transfer.types';
|
||
|
||
const props = defineProps<{
|
||
payload?: Record<string, unknown> | null;
|
||
}>();
|
||
|
||
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 ?? 'match'));
|
||
const mode = ref(kind.value);
|
||
/** 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());
|
||
/** 上次提交执行的明细行快照(失败单「重查库存」按物料/异动日期关联 item_id 用)。 */
|
||
const lastExecutedItems = ref<TransferMatchingItem[]>([]);
|
||
|
||
const transfer = useChatTransfer();
|
||
|
||
/** 待处理异常视图:进入时拉取列表与汇总(2026-10-16 服务端分页:首拉由
|
||
* 待办卡挂载时上抛 query-change 触发(携带计数卡切片 initialFilter),
|
||
* 此处不再兜底首拉避免双请求)。 */
|
||
onMounted(() => {
|
||
if (kind.value === 'source-select') {
|
||
void transfer.loadSources();
|
||
}
|
||
// 来源选择、可调拨明细、待处理异常都要类型配置:表格「调拨类型」列按 names 显示名称。
|
||
if (kind.value === 'source-select' || kind.value === 'executable' || kind.value === 'backlog') {
|
||
void transfer.loadTransferTypes();
|
||
}
|
||
if (kind.value === 'executable') {
|
||
void transfer.loadExecutableItems();
|
||
}
|
||
});
|
||
|
||
/** 待办卡查询变更(翻页/筛选/首挂载):转调组合式函数按服务端分页拉取。 */
|
||
function onBacklogQueryChange(query: { page: number; keyword: string; resultFilter: 'all' | 'recoverable' | 'closed' | 'unknown' }) {
|
||
void transfer.loadBacklog(query);
|
||
}
|
||
|
||
/** payload 更新时重置本地状态(历史回放/刷新);初始化组合式函数上下文 */
|
||
function applyPayload(payload?: Record<string, unknown> | null) {
|
||
if (!payload) return;
|
||
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 TransferMatchingSummary) ?? null;
|
||
if (summaryValue) {
|
||
transfer.matchingId.value = summaryValue.matching_id;
|
||
// 默认勾选可执行明细行(按 item_id);历史回放行无 item_id 不参与勾选
|
||
transfer.selected.value = new Set(
|
||
((payload.items as TransferMatchingItem[]) ?? [])
|
||
.filter((item) => item.result === 'executable' && item.item_id != null)
|
||
.map((item) => item.item_id as number),
|
||
);
|
||
}
|
||
if (runNo.value) {
|
||
transfer.runNo.value = runNo.value;
|
||
}
|
||
}
|
||
|
||
applyPayload(props.payload);
|
||
watch(() => props.payload, applyPayload);
|
||
|
||
// 离开来源选择卡即停来源轮询(确认匹配切匹配卡/回放替换 payload 后,
|
||
// 来源抓取状态与本卡无关;轮询实例由 useChatTransfer 作用域销毁兜底清理)
|
||
watch(mode, (value) => {
|
||
if (value !== 'source-select') transfer.stopSourcePolling();
|
||
});
|
||
|
||
/**
|
||
* 打包下载选中来源的证据文件。
|
||
* 核心逻辑:把来源卡传来的调拨类型一并 POST;保存名用后端 Content-Disposition
|
||
* (evidence-files-N.zip),响应没给文件名时才用同一前缀兜底。
|
||
* @param sourceCodes - 来源编码
|
||
* @param transferType - 当前所选调拨类型
|
||
*/
|
||
async function onDownloadSources(sourceCodes: string[], transferType?: string) {
|
||
if (!sourceCodes.length || !transferType) return;
|
||
busy.value = true;
|
||
try {
|
||
const result = await downloadTransferSourceFiles(sourceCodes, transferType);
|
||
triggerBlobDownload(result.blob, result.filename ?? `evidence-files-${sourceCodes.length}.zip`);
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/** 重新获取 ERP 库存:批量重查后用服务端明细原位刷新(保留勾选中仍阻断的行) */
|
||
async function onRequery(invoiceNos: string[]) {
|
||
if (!invoiceNos.length || !transfer.matchingId.value) return;
|
||
busy.value = true;
|
||
try {
|
||
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 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)),
|
||
);
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/** 可调拨明细行重查:批量核对最新库存后刷新队列(复用 batch-requery 唯一批量后端,
|
||
* 后端按组织一次外部查询——禁止逐行调单行 retry 把 N 行放大成 N 次外部调用) */
|
||
async function onExecutableRequery(itemIds: number[]) {
|
||
if (!itemIds.length) return;
|
||
busy.value = true;
|
||
try {
|
||
await transfer.batchRequery(itemIds);
|
||
await transfer.loadExecutableItems();
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 预检卡提交(匹配卡/可执行卡点「生成调拨单」):门禁在后端,失败抛 BusinessError。
|
||
* D8 异步 202:只拿 {run_no, status:'queued'} 即切融合卡(kind='run')——
|
||
* 融合卡自驱动轮询接管进度/结果,父级停掉本实例轮询防双打点;提交受理 toast 反馈。
|
||
* 门禁 4xx:useMessage 行内报错 + 预检状态刷新(匹配详情/可执行池可能已变化)。
|
||
*/
|
||
async function onExecute(itemIds: number[]) {
|
||
busy.value = true;
|
||
try {
|
||
transfer.selected.value = new Set(itemIds);
|
||
// 快照本次执行明细行(融合卡失败单「重查库存」关联 item_id 的数据源之一):
|
||
// 本地 items(匹配卡回放)/ composable 匹配与可执行池三处都可能持有行记录
|
||
const executedSet = new Set(itemIds);
|
||
lastExecutedItems.value = [...items.value, ...transfer.items.value, ...transfer.executableItems.value]
|
||
.filter((item) => item.item_id != null && executedSet.has(item.item_id));
|
||
const outcome = await transfer.execute();
|
||
if (outcome) {
|
||
transfer.stopRunPolling(); // 融合卡(自驱动轮询)接管,父级轮询停止
|
||
mode.value = 'run';
|
||
runNo.value = outcome.run_no;
|
||
status.value = outcome.status;
|
||
run.value = transfer.run.value;
|
||
notifySuccess(t('chat.transfer.execute.accepted'));
|
||
}
|
||
} catch (e) {
|
||
reportError(e);
|
||
await refreshPrecheckState();
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/** 门禁失败后的预检状态刷新(best-effort:匹配视图重拉详情、可执行池重拉队列,不掩盖原错误)。 */
|
||
async function refreshPrecheckState() {
|
||
try {
|
||
if (mode.value === 'match' && transfer.matchingId.value) {
|
||
await transfer.refreshMatching();
|
||
} else if (mode.value === 'executable') {
|
||
await transfer.loadExecutableItems();
|
||
}
|
||
} catch {
|
||
// 刷新失败静默:原门禁错误已经 useMessage 提示
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 融合卡失败单「重试」(一键恢复主路径):POST /documents/{doc_no}/retry——
|
||
* 后端按单圈行逐行重查,全部 ready 自动建新 Run 重跑(复用原单号,分支②);
|
||
* 部分行仍阻断则不重跑,阻断明细以 toast 摘要提示、行留恢复池。
|
||
*/
|
||
async function onOrderRetry(order: TransferOrder) {
|
||
busy.value = true;
|
||
try {
|
||
const result = await retryTransferOrder(order.doc_no);
|
||
if (result.rerun) {
|
||
notifySuccess(t('chat.transfer.orderAction.retryAccepted', { docNo: order.doc_no }));
|
||
} else {
|
||
notifyError(t('chat.transfer.orderAction.retryPartial', {
|
||
ready: result.ready,
|
||
blocked: result.blocked.length,
|
||
}));
|
||
}
|
||
await refreshPrecheckState();
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 融合卡关闭单完成(D18 上抛事件):行脱离单回 ready_to_execute——
|
||
* 父级刷新 run 调拨单清单与可执行池(best-effort,失败经 useMessage 提示)。
|
||
*/
|
||
async function onOrderClosed() {
|
||
try {
|
||
await transfer.refreshRun();
|
||
await transfer.loadExecutableItems();
|
||
} catch (e) {
|
||
reportError(e);
|
||
}
|
||
}
|
||
|
||
async function onDownloadInbound() {
|
||
try {
|
||
await transfer.downloadInboundFiles();
|
||
} catch (e) {
|
||
reportError(e);
|
||
}
|
||
}
|
||
|
||
async function onDownloadErp() {
|
||
try {
|
||
await transfer.downloadErpInventory();
|
||
} catch (e) {
|
||
reportError(e);
|
||
}
|
||
}
|
||
|
||
async function onDownloadExceptions() {
|
||
try {
|
||
await transfer.downloadExceptions();
|
||
} catch (e) {
|
||
reportError(e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 待处理异常重查库存(行级与批量同一入口)。
|
||
* 核心逻辑:调 batch-requery,按返回行分成已可执行、仍阻断、失败后提示,再刷新本列表。
|
||
* @param itemIds - 要重查的明细 id
|
||
*/
|
||
async function onBacklogRequery(itemIds: number[]) {
|
||
busy.value = true;
|
||
try {
|
||
const result = await transfer.batchRequery(itemIds);
|
||
const ready = result.results.filter((entry) => entry.ok && entry.status === 'ready_to_execute').length;
|
||
const failed = result.results.filter((entry) => !entry.ok).length;
|
||
const blocked = result.results.length - ready - failed;
|
||
notifySuccess(t('chat.transfer.toastRequeryOutcome', { ready, blocked, failed }));
|
||
await transfer.loadBacklog();
|
||
} 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 },
|
||
transferType?: TransferType,
|
||
) {
|
||
busy.value = true;
|
||
try {
|
||
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) {
|
||
reportError(e);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 对来源重试证据流,重试期间标记该来源(busy 独立于 confirm busy)。
|
||
* 核心逻辑:批量按钮无论选中几个来源都走 retry-rpa-batch,body 由组合式函数写成
|
||
* { source_codes, transfer_type }。只有行内 ↻(detail.recordKind)走单源重试,body 为 { record_kind }。
|
||
* @param sourceCodes - 来源编码
|
||
* @param detail - 行内 ↻ 带 recordKind;批量按钮只带 transferType
|
||
*/
|
||
async function onSourceRetry(
|
||
sourceCodes: string[],
|
||
detail?: { recordKind?: 'inbound' | 'outbound'; transferType?: string },
|
||
) {
|
||
const codes = Array.isArray(sourceCodes) ? sourceCodes : [sourceCodes];
|
||
retryingSource.value = new Set([...retryingSource.value, ...codes]);
|
||
try {
|
||
const [first] = codes;
|
||
if (detail?.recordKind && first !== undefined && codes.length === 1) {
|
||
await transfer.retrySourceRpa(first, detail.recordKind);
|
||
} else if (codes.length > 0) {
|
||
await transfer.retrySourcesRpaBatch(codes, detail?.transferType);
|
||
}
|
||
} catch (e) {
|
||
reportError(e);
|
||
} finally {
|
||
const next = new Set(retryingSource.value);
|
||
for (const code of codes) next.delete(code);
|
||
retryingSource.value = next;
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div>
|
||
<TransferFileProgressCard
|
||
v-if="mode === 'file-progress'"
|
||
:sources="(props.payload?.sources as TransferSourceProgress[]) ?? []"
|
||
/>
|
||
<TransferSourceSelectCard
|
||
v-else-if="mode === 'source-select'"
|
||
:sources="transfer.sourceOptions.value"
|
||
:transfer-types="transfer.transferTypes.value"
|
||
:busy="busy"
|
||
:retrying="retryingSource"
|
||
@confirm="onSourceConfirm"
|
||
@download="onDownloadSources"
|
||
@retry="onSourceRetry"
|
||
@reparsed="transfer.loadSources()"
|
||
/>
|
||
<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="(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"
|
||
:transfer-types="transfer.transferTypes.value"
|
||
:busy="busy"
|
||
@refresh="() => transfer.loadExecutableItems()"
|
||
@requery="onExecutableRequery"
|
||
@execute="onExecute"
|
||
/>
|
||
<TransferProgressCard v-else-if="mode === 'progress'" :run-no="runNo" :status="status" :busy="busy" />
|
||
<!-- 融合卡(D9:调拨单清单=进度=结果):run_no 自驱动轮询;kind='run' 为 202 新流程,'result' 兼容历史回放 -->
|
||
<TransferResultCard
|
||
v-else-if="(mode === 'run' || mode === 'result') && (runNo || run?.run_no)"
|
||
:run-no="runNo || String(run?.run_no ?? '')"
|
||
:initial-run="run"
|
||
@download-inbound="onDownloadInbound"
|
||
@download-erp="onDownloadErp"
|
||
@download-exceptions="onDownloadExceptions"
|
||
@retry="onOrderRetry"
|
||
@closed="onOrderClosed"
|
||
/>
|
||
<TransferBacklogSummaryCard
|
||
v-else-if="mode === 'backlog'"
|
||
:items="transfer.backlog.value"
|
||
:total="transfer.backlogTotal.value"
|
||
:transfer-types="transfer.transferTypes.value"
|
||
:busy="busy"
|
||
:initial-filter="backlogInitialFilter"
|
||
@query-change="onBacklogQueryChange"
|
||
@requery="onBacklogRequery"
|
||
@close="onBacklogClose"
|
||
@batch-close="onBacklogBatchClose"
|
||
@refresh="() => transfer.loadBacklog()"
|
||
/>
|
||
<TransferManualCloseDialog
|
||
v-if="closeTarget || batchCloseIds.length"
|
||
:open="Boolean(closeTarget || batchCloseIds.length)"
|
||
:invoice-no="closeTarget?.invoice_no ?? ''"
|
||
:count="batchCloseIds.length"
|
||
@confirm="onCloseConfirm"
|
||
@cancel="onCancelClose"
|
||
/>
|
||
</div>
|
||
</template>
|