867 lines
46 KiB
Vue
867 lines
46 KiB
Vue
/**
|
||
* features/chat/components/shipping/ShippingOrderExtractionCard.vue
|
||
* 用途:聊天主区「订单识别任务」摘要卡——标题、文件数+状态、一行 handling 摘要、唯一主 CTA、查看详情。
|
||
* 依赖:订单抽取 Run 状态卡 DTO、shipping.api 文档/进度接口、ShippingOrderExtractionDetailsDrawer、vue-router、vue-i18n。
|
||
* 逻辑:对话区默认展示状态-EML 聚合;批次工作台打开后切换为紧凑摘要,长进度/Gate/刷新取消由工作台承接。
|
||
*/
|
||
<script setup lang="ts">
|
||
import { computed, inject, ref, watch } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { useRoute, useRouter } from 'vue-router';
|
||
import { AlertCircle, ArrowRight, CheckCircle2, ChevronDown, CircleX, FileText, LoaderCircle, Mail, RefreshCw, TriangleAlert } from 'lucide-vue-next';
|
||
import type {
|
||
ShippingOrderExtractionHandlingItemState,
|
||
ShippingOrderExtractionFileState,
|
||
ShippingOrderExtractionState,
|
||
} from '../../types/chat.types';
|
||
import type {
|
||
ShippingOrderExtractionDocumentResult,
|
||
ShippingOrderExtractionProgressEvent,
|
||
} from '../../types/shipping.api.types';
|
||
import type { ShippingProcessingProjection } from '../../types/shipping.api.types';
|
||
import { SHIPPING_WORKFLOW_KEY } from '../../shipping/useShippingNoticeWorkflow';
|
||
import {
|
||
resolveShippingProcessingReasonLabel,
|
||
resolveShippingProcessingStageLabel,
|
||
} from '../../shipping/shippingProcessingLabels';
|
||
import {
|
||
listWorkspaceShippingOrderExtractionDocuments,
|
||
listWorkspaceShippingOrderExtractionProgressEvents,
|
||
} from '../../api/shipping.api';
|
||
import ShippingOrderExtractionDetailsDrawer from './ShippingOrderExtractionDetailsDrawer.vue';
|
||
|
||
const props = defineProps<{
|
||
state: ShippingOrderExtractionState;
|
||
runNo?: string;
|
||
retrying?: boolean;
|
||
refreshing?: boolean;
|
||
cancelling?: boolean;
|
||
/** 新版 Run 已替代旧版时,历史卡仅允许查看详情。 */
|
||
readonly?: boolean;
|
||
readonlyReason?: string | null;
|
||
/** 可选统一投影;摘要卡不再渲染进度,仅保留 prop 兼容宿主。 */
|
||
processingProjection?: ShippingProcessingProjection | null;
|
||
/** 批次工作台打开时,左侧只保留摘要,避免与工作台重复展示文件明细。 */
|
||
compactProgress?: boolean;
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
retry: [];
|
||
refresh: [];
|
||
cancel: [reason?: string];
|
||
'open-batch-workbench': [];
|
||
}>();
|
||
|
||
const { t, te } = useI18n();
|
||
const route = useRoute();
|
||
const router = useRouter();
|
||
const shippingWorkflow = inject(SHIPPING_WORKFLOW_KEY, null);
|
||
|
||
type ConversationStatusGroups = NonNullable<import('../../types/shipping.api.types').ConversationProcessingProjection['status_groups']>;
|
||
type ConversationProcessing = import('../../types/shipping.api.types').ConversationProcessingProjection;
|
||
const conversationProcessing = computed<ConversationProcessing | null>(() => (
|
||
(shippingWorkflow as { processing?: { value?: ConversationProcessing | null } | null } | null)?.processing?.value || null
|
||
));
|
||
const hasAuthoritativeConversationProvider = computed(() => Boolean(
|
||
shippingWorkflow && 'processing' in shippingWorkflow,
|
||
));
|
||
const conversationProjectionLoading = computed(() => Boolean(
|
||
(shippingWorkflow as { initialLoading?: { value?: boolean } | null } | null)?.initialLoading?.value,
|
||
) || (hasAuthoritativeConversationProvider.value && !conversationProcessing.value));
|
||
const conversationStatusGroups = computed<ConversationStatusGroups | null>(() => conversationProcessing.value?.status_groups || null);
|
||
const hasConversationStatusGroups = computed(() => Boolean(conversationStatusGroups.value));
|
||
const statusGroupDefs = [
|
||
{ key: 'failed', label: 'chat.shippingProcessing.groupFailed' },
|
||
{ key: 'waiting_human', label: 'chat.shippingProcessing.groupWaitingHuman' },
|
||
{ key: 'processing', label: 'chat.shippingProcessing.groupProcessing' },
|
||
{ key: 'completed', label: 'chat.shippingProcessing.groupCompleted' },
|
||
{ key: 'cancelled', label: 'chat.shippingProcessing.groupCancelled' },
|
||
{ key: 'archived', label: 'chat.shippingProcessing.groupHistoryRecords' },
|
||
] as const;
|
||
const expandedStatusGroups = ref(new Set<string>(['failed', 'waiting_human', 'processing']));
|
||
const expandedEmlTasks = ref(new Set<string>());
|
||
function statusGroupTasks(key: typeof statusGroupDefs[number]['key']) {
|
||
return conversationStatusGroups.value?.[key] || [];
|
||
}
|
||
function statusGroupLabel(key: typeof statusGroupDefs[number]['key']) {
|
||
const count = statusGroupTasks(key).length;
|
||
return t(statusGroupDefs.find((item) => item.key === key)!.label, { count });
|
||
}
|
||
function toggleStatusGroup(key: string) {
|
||
const next = new Set(expandedStatusGroups.value);
|
||
if (next.has(key)) next.delete(key); else next.add(key);
|
||
expandedStatusGroups.value = next;
|
||
}
|
||
function toggleEmlTask(taskNo: string) {
|
||
const next = new Set(expandedEmlTasks.value);
|
||
if (next.has(taskNo)) next.delete(taskNo); else next.add(taskNo);
|
||
expandedEmlTasks.value = next;
|
||
}
|
||
function taskChildren(task: { aggregateChildren?: ShippingProcessingProjection[]; user_task_no?: string | null; aggregateSummary?: { intakeNo?: string | null } | null }) {
|
||
if (task.aggregateChildren?.length) return task.aggregateChildren;
|
||
// [AUTHORITY] 新会话投影必须自带 EML 子文件;不能从 Run 快照或另一份 work_items 补齐,
|
||
// 否则左右面板会出现不同文件数、不同状态的同一封邮件。
|
||
if (hasConversationStatusGroups.value) return [];
|
||
const projection = statusTaskProjection(task);
|
||
if (!projection) return [];
|
||
if (projection?.aggregateChildren?.length) return projection.aggregateChildren;
|
||
// 后端未返回 aggregate_children 时只展示聚合摘要。禁止用 childOrderTasks 或
|
||
// 历史聊天 Run 快照重新推导附件、Candidate、阶段或按钮。
|
||
return [];
|
||
}
|
||
function taskFileCount(task: { aggregateChildren?: ShippingProcessingProjection[]; file_count?: number | null; aggregateSummary?: { intakeNo?: string | null } | null }) {
|
||
// EML 是来源容器;统一只计其附件,避免聊天卡与批次中心相差一份 EML 本体。
|
||
const children = taskChildren(task).filter((child) => !String(
|
||
child.sourceSummary?.filename || '',
|
||
).trim().toLowerCase().endsWith('.eml'));
|
||
if (children.length) {
|
||
const ids = new Set(children.map((child) => String(child.sourceSummary?.documentId || child.workItemNo || '').trim()).filter(Boolean));
|
||
return ids.size || children.length;
|
||
}
|
||
if (hasConversationStatusGroups.value) return Math.max(0, Number(task.file_count || 0));
|
||
const projection = statusTaskProjection(task);
|
||
const sourceCount = Number(projection?.sourceSummary?.documentCount || 0);
|
||
return sourceCount > 0 ? sourceCount : Math.max(0, Number(task.file_count || 0));
|
||
}
|
||
function childStatusLabel(child: ShippingProcessingProjection) {
|
||
const status = displayProjectionStatus(child);
|
||
if (status === 'completed' && child.facts?.uploadState === 'succeeded') return t('chat.shippingProcessing.aggregate.completed', { count: 1 });
|
||
if (status === 'completed') return t('chat.shippingProcessing.groupRecordCompleted');
|
||
if (status === 'failed' || status === 'retryable') return t('chat.shippingProcessing.aggregate.failed', { count: 1 });
|
||
if (status === 'waiting_human') return t('chat.shippingProcessing.aggregate.needsAction', { count: 1 });
|
||
return t('chat.shippingProcessing.aggregate.processing', { count: 1 });
|
||
}
|
||
function displayReason(
|
||
reason?: import('../../types/shipping.api.types').ShippingProcessingBlockingReason | null,
|
||
) {
|
||
return resolveShippingProcessingReasonLabel(reason, te, t);
|
||
}
|
||
/** 新投影有 ui_state 时严格消费其状态;旧响应才回退 userStatus / status。 */
|
||
function displayProjectionStatus(item: ShippingProcessingProjection): string {
|
||
return String(item.uiState
|
||
? item.uiState.status
|
||
: (item.userStatus || item.status || '')).trim().toLowerCase();
|
||
}
|
||
function isFailedProjection(item: ShippingProcessingProjection): boolean {
|
||
const status = displayProjectionStatus(item);
|
||
return status === 'failed' || status === 'retryable';
|
||
}
|
||
function isWaitingProjection(item: ShippingProcessingProjection): boolean {
|
||
return displayProjectionStatus(item) === 'waiting_human';
|
||
}
|
||
function isCompletedProjection(item: ShippingProcessingProjection): boolean {
|
||
return displayProjectionStatus(item) === 'completed';
|
||
}
|
||
function taskReason(task: { uiState?: { blocking_reason: import('../../types/shipping.api.types').ShippingProcessingBlockingReason | null }; blockingReason?: import('../../types/shipping.api.types').ShippingProcessingBlockingReason | null }) {
|
||
return task.uiState ? task.uiState.blocking_reason : task.blockingReason;
|
||
}
|
||
function childStageLabel(child: ShippingProcessingProjection) {
|
||
const stage = String(child.uiState?.stage || child.userStage || child.stage || '').trim();
|
||
return resolveShippingProcessingStageLabel(stage, te, t);
|
||
}
|
||
function statusTaskProjection(task: { user_task_no?: string | null; aggregateSummary?: { intakeNo?: string | null } | null }) {
|
||
const items = shippingWorkflow?.processingWorkItems.value || [];
|
||
const intakeNo = String(task.aggregateSummary?.intakeNo || '').trim();
|
||
if (intakeNo) {
|
||
const intakeMatch = items.find((item) => (
|
||
item.sourceType === 'eml'
|
||
&& String(item.intakeNo || '').trim() === intakeNo
|
||
));
|
||
if (intakeMatch) return intakeMatch;
|
||
}
|
||
return items.find((item) => (
|
||
(item.workItemType === 'order_task' || item.workItemType === 'order_intake')
|
||
&& String(item.workItemNo || '').trim() === String((task as any).user_task_no || '').trim()
|
||
)) || null;
|
||
}
|
||
function aggregateStatusLabelFromSummary(summary: NonNullable<import('../../types/shipping.api.types').ConversationProcessingUserTask['aggregateSummary']>) {
|
||
const parts: string[] = [];
|
||
if (summary.completed) parts.push(t('chat.shippingProcessing.aggregate.completed', { count: summary.completed }));
|
||
if (summary.processing) parts.push(t('chat.shippingProcessing.aggregate.processing', { count: summary.processing }));
|
||
if (summary.needsAction) parts.push(t('chat.shippingProcessing.aggregate.needsAction', { count: summary.needsAction }));
|
||
if (summary.failed) parts.push(t('chat.shippingProcessing.aggregate.failed', { count: summary.failed }));
|
||
return parts.join(' · ');
|
||
}
|
||
|
||
/**
|
||
* 当前 Run 对应的 EML Intake 聚合项。
|
||
*
|
||
* 右侧投影轮询是增量可见的:一次响应暂未带回该 Intake 不能让聊天消息卡
|
||
* 降级为旧 Run 卡。消息卡保留最后一次同 Run/用户任务命中的聚合快照,只有
|
||
* 同一绑定再次命中时才更新;右侧面板仍直接消费实时投影。
|
||
*/
|
||
const matchedEmlAggregate = computed(() => {
|
||
const runNo = String(props.runNo || props.state.runNo || '').trim();
|
||
const userTaskNo = String(props.state.userTaskNo || '').trim();
|
||
const items = shippingWorkflow?.processingWorkItems.value || [];
|
||
return items.find((item) => (
|
||
item.workItemType === 'order_task'
|
||
&& item.sourceType === 'eml'
|
||
&& Boolean(item.aggregateSummary)
|
||
&& (
|
||
String(item.runNo || '').trim() === runNo
|
||
|| (Boolean(userTaskNo) && String(item.rootOrderTaskNo || '').trim() === userTaskNo)
|
||
)
|
||
)) || null;
|
||
});
|
||
const lastMatchedEmlAggregate = ref<ShippingProcessingProjection | null>(null);
|
||
watch(matchedEmlAggregate, (item) => {
|
||
if (item) lastMatchedEmlAggregate.value = item;
|
||
}, { immediate: true });
|
||
const emlAggregate = computed(() => (
|
||
// [AUTHORITY] 切换会话时先等待该会话的统一投影,禁止旧聊天消息 Run 快照抢占首屏;
|
||
// 请求完成后仍只消费后端 Projection,失败则保留既有兼容摘要。
|
||
hasConversationStatusGroups.value || conversationProjectionLoading.value
|
||
? null
|
||
: (matchedEmlAggregate.value || lastMatchedEmlAggregate.value)
|
||
));
|
||
const emlAggregateChildren = computed(() => emlAggregate.value?.aggregateChildren || []);
|
||
const emlAggregateExpanded = ref(false);
|
||
function aggregateStageLabel(item: ShippingProcessingProjection): string {
|
||
const stage = String(item.uiState ? item.uiState.stage : (item.userStage || item.stage || '')).trim();
|
||
return resolveShippingProcessingStageLabel(stage, te, t);
|
||
}
|
||
function aggregateChildStatusLabel(item: ShippingProcessingProjection): string {
|
||
const status = displayProjectionStatus(item);
|
||
if (status === 'completed' && item.facts?.uploadState === 'succeeded') return t('chat.shippingProcessing.aggregate.completed', { count: 1 });
|
||
if (status === 'completed') return t('chat.shippingProcessing.groupRecordCompleted');
|
||
if (status === 'failed' || status === 'retryable') return t('chat.shippingProcessing.aggregate.failed', { count: 1 });
|
||
if (status === 'waiting_human') return t('chat.shippingProcessing.aggregate.needsAction', { count: 1 });
|
||
return t('chat.shippingProcessing.aggregate.processing', { count: 1 });
|
||
}
|
||
function aggregateSummaryLabel(item: ShippingProcessingProjection): string {
|
||
const summary = item.aggregateSummary;
|
||
if (!summary) return '';
|
||
const parts: string[] = [];
|
||
if (summary.completed) parts.push(t('chat.shippingProcessing.aggregate.completed', { count: summary.completed }));
|
||
if (summary.processing) parts.push(t('chat.shippingProcessing.aggregate.processing', { count: summary.processing }));
|
||
if (summary.needsAction) parts.push(t('chat.shippingProcessing.aggregate.needsAction', { count: summary.needsAction }));
|
||
if (summary.failed) parts.push(t('chat.shippingProcessing.aggregate.failed', { count: summary.failed }));
|
||
return parts.join(' · ');
|
||
}
|
||
|
||
const detailsOpen = ref(false);
|
||
const detailsLoading = ref(false);
|
||
const detailsLoadFailed = ref(false);
|
||
const detailsDocuments = ref<ShippingOrderExtractionDocumentResult[]>([]);
|
||
const progressLoading = ref(false);
|
||
const progressLoadFailed = ref(false);
|
||
const progressEvents = ref<ShippingOrderExtractionProgressEvent[]>([]);
|
||
|
||
const displaySummary = computed(() => props.state.summary);
|
||
|
||
/**
|
||
* 旧聊天消息中的 handlingItems 是当时的 Run 快照;实时会话投影已返回时,
|
||
* 绝不能把它重新展示成当前待办或用它决定 CTA。当前待办仅由后端 work_items
|
||
* 与其 ui_state 裁决,旧卡在此模式下只保留历史消息本身。
|
||
*/
|
||
const handlingItems = computed(() => (
|
||
hasConversationStatusGroups.value ? [] : (props.state.handlingItems || [])
|
||
));
|
||
const fileRows = computed(() => props.state.documents || []);
|
||
const isEmailRow = (row: ShippingOrderExtractionFileState) => (
|
||
row.documentType === 'email_body' || row.fileName?.toLowerCase().endsWith('.eml')
|
||
);
|
||
/**
|
||
* 返回当前 Run 快照中的唯一业务 PDF,隔离历史 Unit/Review Case 汇总。
|
||
* 核心逻辑:优先用稳定 documentId 去重;旧快照缺失时才回退 unitId 或文件名。
|
||
*/
|
||
const currentBusinessFileRows = computed(() => {
|
||
const seen = new Set<string>();
|
||
return fileRows.value.filter((row) => {
|
||
if (isEmailRow(row)) return false;
|
||
const key = row.documentId > 0
|
||
? `document:${row.documentId}`
|
||
: row.unitId > 0
|
||
? `unit:${row.unitId}`
|
||
: `filename:${String(row.fileName || '').trim().toLowerCase()}`;
|
||
if (seen.has(key)) return false;
|
||
seen.add(key);
|
||
return true;
|
||
});
|
||
});
|
||
const hasCurrentBusinessFileRows = computed(() => currentBusinessFileRows.value.length > 0);
|
||
const emailRows = computed(() => fileRows.value.filter(isEmailRow));
|
||
const isFailedParseRow = (row: ShippingOrderExtractionFileState) => (
|
||
row.status === 'failed'
|
||
|| row.reasonCode === 'intake_parse_failed'
|
||
|| row.userVisibleStage === 'parse_failed'
|
||
);
|
||
const childRows = (email: ShippingOrderExtractionFileState) => fileRows.value.filter((row) => (
|
||
row.unitId !== email.unitId
|
||
&& row.intakeId != null
|
||
&& row.intakeId === email.intakeId
|
||
&& !isEmailRow(row)
|
||
));
|
||
const emailHasFailedChild = (email: ShippingOrderExtractionFileState) => childRows(email).some(isFailedParseRow);
|
||
const emailIsCompleted = (email: ShippingOrderExtractionFileState) => {
|
||
const children = childRows(email);
|
||
return children.length > 0 && children.every((child) => child.status === 'candidate_ready');
|
||
};
|
||
const activeEmailRows = computed(() => emailRows.value);
|
||
const standaloneRows = computed(() => fileRows.value.filter((row) => (
|
||
!isEmailRow(row)
|
||
&& !isFailedParseRow(row)
|
||
&& !emailRows.value.some((email) => childRows(email).some((child) => child.unitId === row.unitId))
|
||
)));
|
||
const failedRows = computed(() => fileRows.value.filter((row) => (
|
||
isFailedParseRow(row)
|
||
&& !emailRows.value.some((email) => childRows(email).some((child) => child.unitId === row.unitId))
|
||
)));
|
||
const processedCount = computed(() => {
|
||
if (hasConversationStatusGroups.value) {
|
||
const summary = conversationProcessing.value?.summary;
|
||
// [AUTHORITY] “已处理/完成率”只表示已经完成通知生命周期的业务文件。
|
||
// waiting_human / failed 只是后端裁决出的待处理事项,不能借用历史 Run 的
|
||
// “处理过”口径累计为完成,否则会与批次进度中心的 completed_files 冲突。
|
||
return Math.max(0, Number(summary?.completed_files || 0));
|
||
}
|
||
// 当前 Run 仅表达抽取/候选状态,不能把 candidate_ready 或历史复核 Case 伪装成
|
||
// 已完成通知生命周期;生命周期完成数只由会话权威投影下发。
|
||
if (hasCurrentBusinessFileRows.value) return 0;
|
||
return emlAggregate.value?.aggregateSummary?.completed
|
||
?? (props.state.summary.completedDocuments + props.state.summary.reviewRequiredDocuments);
|
||
});
|
||
const progressPercent = computed(() => {
|
||
const total = batchFileCount.value;
|
||
return total > 0 ? Math.min(100, Math.round((processedCount.value / total) * 100)) : 0;
|
||
});
|
||
/** 新版会话批次的业务文件数由后端汇总;旧 Run 卡仍保留历史兼容计数。 */
|
||
const batchFileCount = computed(() => {
|
||
if (hasConversationStatusGroups.value) {
|
||
return Math.max(0, Number(conversationProcessing.value?.summary?.total_files || 0));
|
||
}
|
||
if (hasCurrentBusinessFileRows.value) return currentBusinessFileRows.value.length;
|
||
return Math.max(0, Number(emlAggregate.value?.sourceSummary.documentCount ?? props.state.summary.totalDocuments));
|
||
});
|
||
|
||
/**
|
||
* 是否为「仅重复关联已有任务、无需人工复核」终态通知。
|
||
*/
|
||
const isDuplicateOnlyNotice = computed(() => {
|
||
if (handlingItems.value.length > 0) return false;
|
||
const opened = Math.max(0, Number(displaySummary.value.openedExistingCount || 0));
|
||
if (opened <= 0) return false;
|
||
const review = Math.max(0, Number(displaySummary.value.reviewRequiredDocuments || 0));
|
||
const failed = Math.max(0, Number(displaySummary.value.failedDocuments || 0));
|
||
return review === 0 && failed === 0;
|
||
});
|
||
|
||
/**
|
||
* 是否为纯候选确认场景;优先信任后端 primary_notice。
|
||
*/
|
||
const isCandidateConfirmationNotice = computed(() => (
|
||
props.state.primaryNotice === 'candidate_confirmation'
|
||
|| (
|
||
!props.state.primaryNotice
|
||
&& handlingItems.value.length === 1
|
||
&& handlingItems.value[0]?.category === 'candidate_confirmation'
|
||
)
|
||
));
|
||
|
||
function rowStatusLabel(row: ShippingOrderExtractionFileState): string {
|
||
if (row.status === 'candidate_ready') return t('chat.shippingProcessing.candidateReady');
|
||
if (isFailedParseRow(row)) return t('chat.shippingProcessing.batchException');
|
||
if (row.status === 'review_required') return t('chat.shippingProcessing.waitingReview');
|
||
const stageKey = `chat.shippingOrderExtractionUserStage.${String(row.userVisibleStage || '').trim()}`;
|
||
if (row.userVisibleStage && te(stageKey)) return t(stageKey);
|
||
return t('chat.shippingProcessing.batchProcessing');
|
||
}
|
||
|
||
function rowStatusClass(row: ShippingOrderExtractionFileState): string {
|
||
if (row.status === 'candidate_ready') return 'text-emerald-500';
|
||
if (isFailedParseRow(row)) return 'text-rose-500';
|
||
return 'text-blue-500';
|
||
}
|
||
|
||
/**
|
||
* 将处理事项类别映射为一句过程通知文案。
|
||
* @param category - 后端 primary_notice / handling item category
|
||
*/
|
||
function noticeForCategory(category: string): string {
|
||
const key = `chat.shippingOrderExtractionHandling.primaryNotice.${category}`;
|
||
return te(key) ? t(key) : t('chat.shippingSessionSummary.processNoticeNeedsAction');
|
||
}
|
||
|
||
/**
|
||
* 解析处理事项标题。
|
||
* @param item - 后端 handling item
|
||
*/
|
||
function handlingTitle(item: ShippingOrderExtractionHandlingItemState): string {
|
||
const key = `chat.shippingOrderExtractionHandling.category.${item.category}`;
|
||
return te(key) ? t(key) : item.category;
|
||
}
|
||
|
||
/**
|
||
* 状态短句:排队/处理中仅「系统处理中」;其余用过程通知,不含文件阶段耗时。
|
||
*/
|
||
const statusNotice = computed(() => {
|
||
if (hasConversationStatusGroups.value) {
|
||
const status = String(conversationProcessing.value?.ui_state?.status || '').trim().toLowerCase();
|
||
if (status === 'completed') return t('chat.shippingSessionSummary.processNoticeCompleted');
|
||
if (status === 'failed' || status === 'retryable') return t('chat.shippingSessionSummary.processNoticeFailed');
|
||
if (status === 'waiting_human') return t('chat.shippingSessionSummary.processNoticeNeedsAction');
|
||
return t('chat.shippingProcessing.systemProcessing');
|
||
}
|
||
if (emlAggregate.value) {
|
||
const status = String(emlAggregate.value.userStatus || '').trim().toLowerCase();
|
||
if (status === 'completed') return t('chat.shippingSessionSummary.processNoticeCompleted');
|
||
if (status === 'failed' || status === 'retryable') return t('chat.shippingSessionSummary.processNoticeFailed');
|
||
if (status === 'waiting_human') return t('chat.shippingSessionSummary.processNoticeNeedsAction');
|
||
return t('chat.shippingProcessing.systemProcessing');
|
||
}
|
||
if (props.state.cancellation?.requested && !props.state.cancellation?.completedAt && !props.state.terminal) {
|
||
return t('chat.shippingOrderExtractionUserStage.cancellation_requested');
|
||
}
|
||
if (props.state.status === 'queued' || props.state.status === 'processing') {
|
||
return t('chat.shippingProcessing.systemProcessing');
|
||
}
|
||
if (isDuplicateOnlyNotice.value) {
|
||
return t('chat.shippingSessionSummary.processNoticeDuplicateLinked');
|
||
}
|
||
const notice = String(props.state.primaryNotice || '').trim();
|
||
if (notice) return noticeForCategory(notice);
|
||
if (handlingItems.value[0]?.category) {
|
||
return noticeForCategory(handlingItems.value[0].category);
|
||
}
|
||
switch (props.state.status) {
|
||
case 'completed':
|
||
return t('chat.shippingSessionSummary.processNoticeCompleted');
|
||
case 'partially_completed':
|
||
case 'review_required':
|
||
return t('chat.shippingSessionSummary.processNoticeNeedsAction');
|
||
case 'failed':
|
||
case 'cancelled': {
|
||
const explained = String(props.state.errorExplainability?.message || '').trim();
|
||
if (explained) return explained;
|
||
return t('chat.shippingSessionSummary.processNoticeFailed');
|
||
}
|
||
default:
|
||
return t('chat.shippingSessionSummary.processNoticeProcessing');
|
||
}
|
||
});
|
||
|
||
/**
|
||
* 文件数 + 状态一行:`N 个文件 · 系统处理中`(或终态通知)。
|
||
*/
|
||
const statusLine = computed(() => {
|
||
const count = Math.max(0, Number(displaySummary.value.totalDocuments || 0));
|
||
const status = statusNotice.value;
|
||
if (count <= 0) return status;
|
||
return `${t('chat.shippingProcessing.taskFiles', { count })} · ${status}`;
|
||
});
|
||
|
||
/**
|
||
* 一行 handling 摘要(无操作按钮);无事项时为空。
|
||
*/
|
||
const handlingSummaryLine = computed(() => {
|
||
const items = handlingItems.value;
|
||
if (!items.length) return '';
|
||
const first = items[0];
|
||
if (!first) return '';
|
||
const totalCount = items.reduce((sum, item) => sum + Math.max(0, Number(item.count || 0)), 0);
|
||
const count = totalCount > 0 ? totalCount : items.length;
|
||
// 旧 Run 的 Case 是跨版本历史记录。当前卡片已有 PDF 快照时,数目不一致即说明
|
||
// handling 来自另一集合,不能在“本批文件”标题下误导为当前待复核文件。
|
||
if (hasCurrentBusinessFileRows.value && count !== currentBusinessFileRows.value.length) return '';
|
||
return t('chat.shippingOrderExtractionHandling.summaryLine', {
|
||
title: handlingTitle(first),
|
||
count,
|
||
});
|
||
});
|
||
|
||
/**
|
||
* 唯一主 CTA 只读取服务端明确下发的动作;失败数量和 Run 状态不能自行授权重试。
|
||
*/
|
||
const primaryChatAction = computed((): { kind: 'retry' | 'continue'; label: string } | null => {
|
||
if (props.readonly || hasConversationStatusGroups.value) return null;
|
||
const actions = props.state.availableActions || [];
|
||
const canRetry = actions.includes('retry_failed_attachments')
|
||
|| actions.includes('retry_failed_documents');
|
||
if (canRetry) {
|
||
return {
|
||
kind: 'retry',
|
||
label: t('chat.shippingNoticeRetryParse'),
|
||
};
|
||
}
|
||
const needsContinue = actions.includes('enter_manual_review')
|
||
|| actions.includes('review_candidate')
|
||
|| actions.includes('open_order_review')
|
||
|| actions.includes('open_order_processing')
|
||
|| props.state.status === 'review_required'
|
||
|| props.state.status === 'partially_completed'
|
||
|| isCandidateConfirmationNotice.value;
|
||
if (needsContinue) {
|
||
return {
|
||
kind: 'continue',
|
||
label: t('chat.shippingProcessing.continueProcessing'),
|
||
};
|
||
}
|
||
return null;
|
||
});
|
||
|
||
const healthTips = computed(() => props.state.healthTips || []);
|
||
|
||
/**
|
||
* 打开订单复核工作台(Chat order-review 模式)。
|
||
* @param options.documentId - 可选,定位到具体 PDF
|
||
* @param options.focus - evidence=证据区;draft=草稿复核(默认)
|
||
*/
|
||
async function openOrderReview(options?: {
|
||
documentId?: number;
|
||
focus?: 'evidence' | 'draft';
|
||
}) {
|
||
const runNo = String(props.runNo || '').trim();
|
||
if (!runNo) return;
|
||
const query: Record<string, string> = {
|
||
...Object.fromEntries(
|
||
Object.entries(route.query).filter(([, v]) => typeof v === 'string') as Array<[string, string]>,
|
||
),
|
||
mode: 'order-review',
|
||
run_no: runNo,
|
||
};
|
||
const documentId = Number(options?.documentId || 0);
|
||
if (documentId > 0) query.document_id = String(documentId);
|
||
const focus = options?.focus === 'evidence' || options?.focus === 'draft'
|
||
? options.focus
|
||
: 'draft';
|
||
query.focus = focus;
|
||
await router.push({
|
||
name: 'Chat',
|
||
params: { agentId: String(route.params.agentId || '') },
|
||
query,
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 仅重载详情抽屉的文档结果列表。
|
||
*/
|
||
async function loadDetailsDocuments() {
|
||
const runNo = String(props.runNo || '').trim();
|
||
if (!runNo) {
|
||
detailsDocuments.value = [];
|
||
detailsLoadFailed.value = true;
|
||
return;
|
||
}
|
||
detailsLoading.value = true;
|
||
detailsLoadFailed.value = false;
|
||
try {
|
||
const docsRes = await listWorkspaceShippingOrderExtractionDocuments(runNo, props.state.uploadBatchId).catch(() => null);
|
||
if (docsRes) {
|
||
detailsDocuments.value = Array.isArray(docsRes.items) ? docsRes.items : [];
|
||
} else {
|
||
detailsDocuments.value = [];
|
||
detailsLoadFailed.value = true;
|
||
}
|
||
} finally {
|
||
detailsLoading.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 仅重载详情抽屉的进度时间线。
|
||
*/
|
||
async function loadDetailsProgress() {
|
||
const runNo = String(props.runNo || '').trim();
|
||
if (!runNo) {
|
||
progressEvents.value = [];
|
||
progressLoadFailed.value = true;
|
||
return;
|
||
}
|
||
progressLoading.value = true;
|
||
progressLoadFailed.value = false;
|
||
try {
|
||
const eventsRes = await listWorkspaceShippingOrderExtractionProgressEvents(runNo, props.state.uploadBatchId).catch(() => null);
|
||
if (eventsRes) {
|
||
progressEvents.value = Array.isArray(eventsRes.items) ? eventsRes.items : [];
|
||
} else {
|
||
progressEvents.value = [];
|
||
progressLoadFailed.value = true;
|
||
}
|
||
} finally {
|
||
progressLoading.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 并行加载详情抽屉所需的文档列表与进度事件。
|
||
*/
|
||
async function loadDetailsDrawerData() {
|
||
await Promise.all([loadDetailsDocuments(), loadDetailsProgress()]);
|
||
}
|
||
|
||
/**
|
||
* 打开 Run 级处理详情抽屉(文档结果 + 进度时间线)。
|
||
*/
|
||
async function openDetailsDrawer() {
|
||
detailsOpen.value = true;
|
||
await loadDetailsDrawerData();
|
||
}
|
||
|
||
/**
|
||
* 关闭详情抽屉。
|
||
*/
|
||
function closeDetailsDrawer() {
|
||
detailsOpen.value = false;
|
||
}
|
||
|
||
/**
|
||
* 从详情抽屉进入复核/证据页。
|
||
*/
|
||
async function enterReviewFromDetails(payload?: { focus?: 'evidence' | 'draft'; documentId?: number }) {
|
||
if (props.readonly) return;
|
||
await openOrderReview({
|
||
documentId: payload?.documentId,
|
||
focus: payload?.focus === 'evidence' ? 'evidence' : 'draft',
|
||
});
|
||
closeDetailsDrawer();
|
||
}
|
||
|
||
/**
|
||
* 执行唯一主 CTA:重试解析或进入订单处理。
|
||
*/
|
||
async function onPrimaryChatAction() {
|
||
if (!primaryChatAction.value || props.readonly) return;
|
||
if (primaryChatAction.value.kind === 'retry') {
|
||
emit('retry');
|
||
return;
|
||
}
|
||
await openOrderReview({ focus: 'draft' });
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div
|
||
v-if="conversationProjectionLoading"
|
||
class="mb-3 animate-pulse overflow-hidden rounded-xl border border-slate-200 bg-white/90 shadow-md dark:border-slate-700 dark:bg-slate-900/90"
|
||
data-testid="shipping-order-extraction-projection-loading"
|
||
>
|
||
<!-- 读取权威 Projection 不是业务状态;只显示结构骨架,避免伪造“系统处理中”。 -->
|
||
<div class="border-b border-slate-200 bg-indigo-50/70 px-5 py-4 dark:border-slate-700 dark:bg-indigo-950/30">
|
||
<div class="h-6 w-36 rounded bg-slate-200 dark:bg-slate-700" />
|
||
<div class="mt-3 h-4 w-2/3 rounded bg-slate-200 dark:bg-slate-700" />
|
||
<div class="mt-5 h-2 w-full rounded bg-slate-200 dark:bg-slate-700" />
|
||
</div>
|
||
<div class="space-y-3 p-4">
|
||
<div class="h-12 rounded-lg bg-slate-100 dark:bg-slate-800" />
|
||
<div class="h-12 rounded-lg bg-slate-100 dark:bg-slate-800" />
|
||
</div>
|
||
</div>
|
||
<div
|
||
v-else
|
||
class="mb-3 overflow-hidden rounded-xl border border-slate-200 bg-white/90 text-slate-900 shadow-md backdrop-blur-sm dark:border-slate-700 dark:bg-slate-900/90 dark:text-slate-100"
|
||
data-testid="shipping-order-extraction-card"
|
||
>
|
||
<div class="border-b border-slate-200 bg-indigo-50/70 px-5 py-4 dark:border-slate-700 dark:bg-indigo-950/30">
|
||
<div class="flex items-center justify-between gap-3">
|
||
<div class="flex items-center gap-2 text-lg font-semibold">
|
||
<LoaderCircle v-if="hasConversationStatusGroups ? conversationProcessing?.ui_state?.status === 'running' : emlAggregate ? emlAggregate.userStatus === 'running' : state.status === 'queued' || state.status === 'processing'" class="h-5 w-5 animate-spin text-blue-600" />
|
||
<CheckCircle2 v-else-if="hasConversationStatusGroups ? conversationProcessing?.ui_state?.status === 'completed' : emlAggregate ? emlAggregate.userStatus === 'completed' : state.status === 'completed'" class="h-5 w-5 text-emerald-500" />
|
||
<TriangleAlert v-else class="h-5 w-5 text-amber-500" />
|
||
<span>{{ t('chat.shippingProcessing.multiPdfTaskTitle') }}</span>
|
||
</div>
|
||
<span class="rounded-full bg-slate-200 px-3 py-1 text-xs font-medium text-slate-600 dark:bg-slate-700 dark:text-slate-200">
|
||
{{ t('chat.shippingProcessing.batchFilesTotal', { count: batchFileCount }) }}
|
||
</span>
|
||
</div>
|
||
<p class="mt-1 text-sm text-slate-600 dark:text-slate-300">{{ t('chat.shippingProcessing.batchStatusTitle') }} · {{ statusNotice }}</p>
|
||
<div v-for="tip in healthTips" :key="tip.code" class="mt-1 text-sm font-medium text-amber-600">{{ t(`chat.shippingOrderExtractionHealthTip.${tip.code}`) }}</div>
|
||
<div v-if="handlingSummaryLine" class="mt-1 text-sm text-slate-600 dark:text-slate-300">{{ handlingSummaryLine }}</div>
|
||
<div class="mt-4 flex items-end justify-between">
|
||
<span class="text-lg font-medium text-blue-600">{{ progressPercent }}% {{ t('chat.shippingProcessing.batchComplete') }}</span>
|
||
<span class="text-sm text-slate-600 dark:text-slate-300">{{ processedCount }}/{{ batchFileCount }} {{ t('chat.shippingProcessing.batchProcessed') }}</span>
|
||
</div>
|
||
<div class="mt-3 h-2 overflow-hidden rounded-full bg-slate-200 dark:bg-slate-700">
|
||
<div class="h-full rounded-full bg-blue-600 transition-all" :style="{ width: `${progressPercent}%` }" />
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="hasConversationStatusGroups && !compactProgress" class="flex flex-col gap-2 bg-slate-50 p-2 dark:bg-slate-950/30" data-testid="shipping-order-extraction-status-groups">
|
||
<template v-for="group in statusGroupDefs" :key="group.key">
|
||
<section v-if="statusGroupTasks(group.key).length" class="overflow-hidden rounded-lg border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900">
|
||
<button type="button" class="flex w-full items-center justify-between px-3 py-3 text-left" @click="toggleStatusGroup(group.key)">
|
||
<span class="text-sm font-semibold" :class="group.key === 'failed' ? 'text-rose-600' : group.key === 'waiting_human' ? 'text-amber-700' : group.key === 'completed' ? 'text-emerald-600' : 'text-slate-700 dark:text-slate-200'">{{ statusGroupLabel(group.key) }}</span>
|
||
<ChevronDown class="h-4 w-4 transition-transform" :class="expandedStatusGroups.has(group.key) ? 'rotate-180' : ''" />
|
||
</button>
|
||
<div v-if="expandedStatusGroups.has(group.key)" class="space-y-2 border-t border-slate-200 p-2 dark:border-slate-700">
|
||
<article v-for="task in statusGroupTasks(group.key)" :key="task.user_task_no" class="overflow-hidden rounded-lg border border-slate-300 bg-white shadow-sm dark:border-slate-700 dark:bg-slate-900" :data-testid="`shipping-order-extraction-eml-${group.key}-${task.user_task_no}`">
|
||
<div class="flex items-start gap-3 border-b border-slate-200 bg-blue-50/50 p-3 dark:border-slate-700 dark:bg-blue-950/20">
|
||
<Mail class="mt-0.5 h-5 w-5 text-blue-600" />
|
||
<div class="min-w-0 flex-1">
|
||
<button type="button" class="flex w-full items-center justify-between gap-3 text-left" @click="toggleEmlTask(task.user_task_no)">
|
||
<span class="truncate font-medium">{{ task.title || task.user_task_no }}</span>
|
||
<ChevronDown class="h-4 w-4 shrink-0 transition-transform" :class="expandedEmlTasks.has(task.user_task_no) ? 'rotate-180' : ''" />
|
||
</button>
|
||
<div class="mt-1 text-xs text-slate-600 dark:text-slate-300">{{ t('chat.shippingProcessing.taskFiles', { count: taskFileCount(task) }) }}<span v-if="task.aggregateSummary"> · {{ aggregateStatusLabelFromSummary(task.aggregateSummary) }}</span></div>
|
||
<div v-if="taskReason(task)" class="mt-1 text-xs text-rose-600">{{ displayReason(taskReason(task)) }}</div>
|
||
</div>
|
||
</div>
|
||
<div v-if="expandedEmlTasks.has(task.user_task_no) && taskChildren(task).length" class="mx-4 my-2 space-y-1 border-l-2 border-blue-200 bg-slate-50 p-3 pl-4 dark:border-blue-800 dark:bg-blue-950/30" data-testid="shipping-order-extraction-eml-children">
|
||
<div v-for="child in taskChildren(task).filter((item) => !String(item.sourceSummary?.filename || '').toLowerCase().endsWith('.eml'))" :key="child.workItemNo" class="flex items-start justify-between gap-3 py-1 text-sm">
|
||
<div class="flex min-w-0 items-start gap-2">
|
||
<LoaderCircle v-if="!isFailedProjection(child) && !isWaitingProjection(child) && !isCompletedProjection(child)" class="mt-0.5 h-4 w-4 shrink-0 animate-spin text-blue-500" />
|
||
<AlertCircle v-else-if="isFailedProjection(child)" class="mt-0.5 h-4 w-4 shrink-0 text-rose-500" />
|
||
<CheckCircle2 v-else-if="isCompletedProjection(child)" class="mt-0.5 h-4 w-4 shrink-0 text-emerald-500" />
|
||
<TriangleAlert v-else class="mt-0.5 h-4 w-4 shrink-0 text-amber-500" />
|
||
<div class="min-w-0">
|
||
<div class="truncate">{{ child.sourceSummary.filename || child.workItemNo }}</div>
|
||
<div class="text-xs text-slate-500">{{ childStageLabel(child) }}</div>
|
||
<div v-if="taskReason(child)" class="text-xs text-rose-600">{{ displayReason(taskReason(child)) }}</div>
|
||
</div>
|
||
</div>
|
||
<span :data-testid="`shipping-order-extraction-child-status-${child.workItemNo}`" class="shrink-0" :class="isFailedProjection(child) ? 'text-rose-600' : isWaitingProjection(child) ? 'text-amber-700' : isCompletedProjection(child) ? 'text-emerald-600' : 'text-blue-600'">{{ childStatusLabel(child) }}</span>
|
||
</div>
|
||
</div>
|
||
</article>
|
||
</div>
|
||
</section>
|
||
</template>
|
||
</div>
|
||
<div v-else-if="!compactProgress && emlAggregate" class="flex flex-col gap-2 bg-slate-50 p-2 dark:bg-slate-950/30" data-testid="shipping-order-extraction-eml-aggregate">
|
||
<article class="overflow-hidden rounded-lg border border-slate-300 bg-white shadow-sm dark:border-slate-700 dark:bg-slate-900">
|
||
<div class="flex items-start gap-3 border-b border-slate-200 bg-blue-50/50 p-3 dark:border-slate-700 dark:bg-blue-950/20">
|
||
<Mail class="mt-0.5 h-5 w-5 text-blue-600" />
|
||
<div class="min-w-0 flex-1">
|
||
<div class="flex items-center justify-between gap-3">
|
||
<span class="truncate font-medium">{{ t('chat.shippingProcessing.emailPrefix') }}{{ emlAggregate.sourceSummary.filename || emlAggregate.intakeNo }}</span>
|
||
<span class="rounded border px-2 py-0.5 text-xs" :class="emlAggregate.userStatus === 'failed' || emlAggregate.userStatus === 'retryable' ? 'border-rose-200 bg-rose-100/70 text-rose-600' : emlAggregate.userStatus === 'waiting_human' ? 'border-amber-200 bg-amber-100/70 text-amber-700' : emlAggregate.userStatus === 'completed' ? 'border-emerald-200 bg-emerald-100/70 text-emerald-600' : 'border-blue-200 bg-blue-100/70 text-blue-600'">
|
||
{{ emlAggregate.userStatus === 'completed' ? t('chat.shippingProcessing.aggregate.completed', { count: emlAggregate.aggregateSummary?.completed || 0 }) : emlAggregate.userStatus === 'failed' || emlAggregate.userStatus === 'retryable' ? t('chat.shippingProcessing.batchException') : emlAggregate.userStatus === 'waiting_human' ? t('chat.shippingProcessing.waitingReview') : t('chat.shippingProcessing.systemProcessing') }}
|
||
</span>
|
||
</div>
|
||
<div class="mt-1 text-xs text-slate-600 dark:text-slate-300">{{ aggregateSummaryLabel(emlAggregate) }}</div>
|
||
<div v-if="taskReason(emlAggregate)" class="mt-1 text-xs text-rose-600">{{ displayReason(taskReason(emlAggregate)) }}</div>
|
||
</div>
|
||
</div>
|
||
<button type="button" class="flex w-full items-center justify-between px-3 py-2 text-left text-sm" @click="emlAggregateExpanded = !emlAggregateExpanded">
|
||
<span>{{ t('chat.shippingProcessing.taskFiles', { count: emlAggregate.sourceSummary.documentCount || 0 }) }}</span>
|
||
<ChevronDown class="h-4 w-4 transition-transform" :class="emlAggregateExpanded ? 'rotate-180' : ''" />
|
||
</button>
|
||
<div v-if="emlAggregateExpanded" class="space-y-1 border-t border-slate-200 px-3 py-2 dark:border-slate-700">
|
||
<div v-for="child in emlAggregateChildren" :key="child.workItemNo" class="flex items-center justify-between gap-3 py-1 text-sm">
|
||
<span class="min-w-0 truncate">{{ child.sourceSummary.filename || child.workItemNo }}</span>
|
||
<span class="shrink-0 text-xs" :class="isFailedProjection(child) ? 'text-rose-600' : isWaitingProjection(child) ? 'text-amber-700' : isCompletedProjection(child) ? 'text-emerald-600' : 'text-blue-600'">{{ aggregateChildStatusLabel(child) }} · {{ aggregateStageLabel(child) }}</span>
|
||
</div>
|
||
</div>
|
||
</article>
|
||
</div>
|
||
<div v-else-if="!compactProgress" class="flex flex-col gap-2 bg-slate-50 p-2 dark:bg-slate-950/30">
|
||
<div v-for="row in activeEmailRows" :key="row.unitId" class="overflow-hidden rounded-lg border border-slate-300 bg-white shadow-sm dark:border-slate-700 dark:bg-slate-900">
|
||
<div class="flex items-start gap-3 border-b border-slate-200 bg-blue-50/50 p-3 dark:border-slate-700 dark:bg-blue-950/20"><Mail class="mt-0.5 h-5 w-5 text-blue-600" /><div class="min-w-0 flex-1"><div class="flex items-center justify-between gap-3"><span class="font-medium">{{ t('chat.shippingProcessing.emailPrefix') }}{{ row.fileName }}</span><span class="rounded border px-2 py-0.5 text-xs" :class="isFailedParseRow(row) || emailHasFailedChild(row) ? 'border-rose-200 bg-rose-100/70 text-rose-600' : emailIsCompleted(row) ? 'border-emerald-200 bg-emerald-100/70 text-emerald-600' : 'border-blue-200 bg-blue-100/70 text-blue-600'">{{ isFailedParseRow(row) || emailHasFailedChild(row) ? t('chat.shippingProcessing.batchException') : emailIsCompleted(row) ? t('chat.shippingProcessing.batchExtracted') : t('chat.shippingProcessing.parsingAttachments') }}</span></div><span class="mt-1 block font-mono text-xs text-slate-500">{{ t('chat.shippingProcessing.emailMeta') }}</span></div></div>
|
||
<div class="mx-4 my-2 flex flex-col gap-2 border-l-2 border-blue-200 bg-slate-50 p-3 pl-4 dark:border-blue-800 dark:bg-blue-950/30"><div v-for="child in childRows(row)" :key="`child-${child.unitId}`" class="flex items-center justify-between gap-3 text-sm"><span class="flex min-w-0 items-center gap-2"><CheckCircle2 v-if="child.status === 'candidate_ready'" class="h-4 w-4 text-emerald-500" /><LoaderCircle v-else-if="!isFailedParseRow(child)" class="h-4 w-4 animate-spin text-blue-500" /><AlertCircle v-else class="h-4 w-4 text-rose-500" /><span class="truncate">{{ child.fileName }}</span></span><span :class="rowStatusClass(child)">{{ rowStatusLabel(child) }}</span></div></div>
|
||
</div>
|
||
<div v-for="row in standaloneRows" :key="row.unitId" class="flex items-center justify-between gap-3 rounded-lg border border-slate-200 bg-white p-3 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:bg-slate-900"><span class="flex min-w-0 items-center gap-3"><FileText class="h-5 w-5 text-slate-500" /><span class="truncate">{{ row.fileName }}</span></span><span class="flex items-center gap-2" :class="rowStatusClass(row)">{{ rowStatusLabel(row) }}<RefreshCw v-if="!isFailedParseRow(row)" class="h-4 w-4 animate-spin" /></span></div>
|
||
<div v-if="!fileRows.length" class="rounded-lg border border-slate-200 bg-white p-3 text-sm text-slate-500 dark:border-slate-700 dark:bg-slate-900">{{ t('chat.shippingProcessing.batchFilesUnavailable') }}</div>
|
||
<div v-for="row in failedRows" :key="`failed-${row.unitId}`" class="rounded-lg border border-rose-200 bg-rose-50 p-3 dark:border-rose-800 dark:bg-rose-950/30"><div class="flex items-center justify-between text-rose-600"><span class="flex items-center gap-2 font-medium"><AlertCircle class="h-5 w-5" />{{ row.fileName }}</span><span class="rounded bg-rose-100 px-2 py-0.5 text-xs">{{ t('chat.shippingProcessing.batchException') }}</span></div><p class="mt-2 pl-7 text-sm">{{ row.explainability?.message || t('chat.shippingProcessing.batchManualVerify') }}</p></div>
|
||
</div>
|
||
|
||
<div class="flex justify-end border-t border-slate-200 bg-indigo-50/60 p-3 dark:border-slate-700 dark:bg-indigo-950/20">
|
||
<div class="flex items-center gap-3">
|
||
<button
|
||
v-if="!compactProgress && (hasConversationStatusGroups || String(props.runNo || '').trim())"
|
||
type="button"
|
||
class="inline-flex items-center gap-2 rounded-lg bg-blue-600 px-5 py-2.5 text-sm font-medium text-white shadow-sm hover:bg-blue-700"
|
||
data-testid="shipping-order-extraction-open-batch-workbench"
|
||
@click="emit('open-batch-workbench')"
|
||
>
|
||
{{ t('chat.shippingProcessing.openBatchWorkbench') }}
|
||
<ArrowRight class="h-4 w-4" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div v-if="false" class="flex items-start gap-3">
|
||
<CircleX class="mt-0.5 h-4 w-4 shrink-0" />
|
||
<div class="min-w-0 flex-1">
|
||
<div
|
||
v-if="readonly"
|
||
class="mb-1 text-xs font-medium opacity-80"
|
||
data-testid="shipping-order-extraction-readonly"
|
||
>
|
||
{{ t('chat.shippingOrderExtractionHistory.superseded') }}
|
||
</div>
|
||
|
||
<div
|
||
class="text-sm font-medium"
|
||
data-testid="shipping-order-extraction-title"
|
||
>
|
||
{{ t('chat.shippingProcessing.multiPdfTaskTitle') }}
|
||
</div>
|
||
|
||
<div
|
||
class="mt-0.5 text-xs opacity-90"
|
||
data-testid="shipping-order-extraction-status-line"
|
||
>
|
||
{{ statusLine }}
|
||
</div>
|
||
|
||
<p
|
||
v-if="state.errorExplainability?.request_id"
|
||
class="mt-1 text-[11px] opacity-80"
|
||
data-testid="shipping-order-extraction-error-request-id"
|
||
>
|
||
{{ t('chat.shippingOrderExtractionErrorRequestId', { id: state.errorExplainability?.request_id }) }}
|
||
</p>
|
||
|
||
<div
|
||
v-if="handlingSummaryLine"
|
||
class="mt-1.5 text-xs opacity-90"
|
||
data-testid="shipping-order-extraction-handling-summary"
|
||
>
|
||
{{ handlingSummaryLine }}
|
||
</div>
|
||
|
||
<div
|
||
v-for="tip in healthTips"
|
||
:key="tip.code"
|
||
class="mt-1 text-xs font-medium opacity-90"
|
||
data-testid="shipping-order-extraction-health-tip"
|
||
>
|
||
{{ t(`chat.shippingOrderExtractionHealthTip.${tip.code}`) }}
|
||
</div>
|
||
|
||
<div v-if="state.refreshFailed" class="mt-1 text-xs font-medium opacity-90">
|
||
{{ t('chat.shippingOrderExtractionRefreshFailed') }}
|
||
</div>
|
||
|
||
<div class="mt-2 flex flex-wrap items-center gap-3">
|
||
<button
|
||
v-if="primaryChatAction"
|
||
type="button"
|
||
class="inline-flex items-center rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||
data-testid="shipping-order-extraction-primary-action"
|
||
:disabled="primaryChatAction?.kind === 'retry' && retrying"
|
||
@click="onPrimaryChatAction"
|
||
>
|
||
{{ primaryChatAction?.kind === 'retry' && retrying
|
||
? t('chat.shippingOrderExtractionRetrying')
|
||
: primaryChatAction?.label }}
|
||
</button>
|
||
<button
|
||
v-if="String(props.runNo || '').trim()"
|
||
type="button"
|
||
class="text-xs font-medium underline-offset-2 opacity-80 hover:underline"
|
||
data-testid="shipping-order-extraction-view-details"
|
||
@click="openDetailsDrawer"
|
||
>
|
||
{{ t('chat.shippingProcessing.viewTaskDetails') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<ShippingOrderExtractionDetailsDrawer
|
||
:open="detailsOpen"
|
||
:state="state"
|
||
:documents="detailsDocuments"
|
||
:progress-events="progressEvents"
|
||
:loading="detailsLoading"
|
||
:load-failed="detailsLoadFailed"
|
||
:progress-loading="progressLoading"
|
||
:progress-load-failed="progressLoadFailed"
|
||
@close="closeDetailsDrawer"
|
||
@enter-manual-review="enterReviewFromDetails"
|
||
@retry-documents="loadDetailsDocuments"
|
||
@retry-progress="loadDetailsProgress"
|
||
/>
|
||
</div>
|
||
</template>
|