3975 lines
172 KiB
Vue
3975 lines
172 KiB
Vue
<!--
|
||
features/chat/views/ShippingOrderReviewView.vue
|
||
用途:建单前/正式任务「订单处理工作台」(主编辑区 + 阶段工作台侧栏 + workbenchMode)。
|
||
依赖:路由参数、useShippingOrderReview、ReviewWorkbenchHeader/Footer、ReviewDocumentNavigation、
|
||
ReviewWorkflowProgressPanel、ReviewProcessDetailDrawer、ReviewUnsavedSwitchDialog、
|
||
ReviewWorkbenchModeToggle、ReviewDocumentEvidenceDrawer、ReviewVersionHistoryDrawer、
|
||
ReviewLlmSuggestionDrawer、ReviewActionConfirmDialog、ReviewLineNoOverrideDialog、
|
||
ReviewCustomerResolutionPanel / ReviewCurrentProcessingCard / ReviewCompletedChecksPanel /
|
||
ReviewBuildEligibilitySummary、ReviewInventory*、
|
||
ReviewLineInventoryOps(履约操作并入明细右侧列)、ReviewLineFulfillmentDetail(行内履约摘要)、
|
||
ProcessGateRecoveryCard;formal_task 仅显式动作挂载 TaskTodoPanel(主写在 Footer);
|
||
shipping.api.retryWorkspaceConversationAutoProgress(对话级重试)。
|
||
逻辑:建单前订单检查为主卡;正式 OT 后保持 standard,不自动切 formal_task 空壳;
|
||
对话级「重试自动推进」在顶栏;当前 Case 对象级重试优先右栏 CurrentProcessingCard,
|
||
仅当未挂载该卡时回落到底栏;库存动作仅明细行浮层;写操作仅底栏。
|
||
-->
|
||
<script setup lang="ts">
|
||
import { computed, defineAsyncComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||
import { useRoute, useRouter } from 'vue-router';
|
||
import { Check, CircleX, Crosshair, Plus, RefreshCw, Undo2, Copy, Trash2 } from 'lucide-vue-next';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { BusinessError } from '@/shared/api/client';
|
||
import { useMessage } from '@/shared/composables/useMessage';
|
||
import { useChatPageContext } from '@/features/chat/composables/chat.context';
|
||
import {
|
||
resolveShippingProcessingStatusLabel,
|
||
resolveShippingProcessingStageLabel,
|
||
} from '@/features/chat/shipping/shippingProcessingLabels';
|
||
import {
|
||
auditWorkspaceShippingOrderReviewEligibilityDetails,
|
||
auditWorkspaceShippingOrderReviewVersionHistory,
|
||
attemptWorkspaceShippingOrderReviewFieldLocate,
|
||
getWorkspaceShippingOrderReviewEvidenceItem,
|
||
getWorkspaceShippingTask,
|
||
retryWorkspaceConversationAutoProgress,
|
||
retryWorkspaceShippingOrderStpAutoCreate,
|
||
retryWorkspaceShippingTask,
|
||
viewWorkspaceShippingOrderReviewHighlightDiagnostic,
|
||
} from '../api/shipping.api';
|
||
import type {
|
||
ShippingOrderReviewLineFulfillmentLine,
|
||
} from '../types/shipping.api.types';
|
||
import ReviewActionConfirmDialog, {
|
||
type ReviewConfirmAction,
|
||
type ReviewConfirmPayload,
|
||
} from '../components/shipping-review/ReviewActionConfirmDialog.vue';
|
||
import ReviewBuildEligibilityDetailsDrawer from '../components/shipping-review/ReviewBuildEligibilityDetailsDrawer.vue';
|
||
import ReviewBuildEligibilitySummary from '../components/shipping-review/ReviewBuildEligibilitySummary.vue';
|
||
import ReviewCustomerResolutionPanel from '../components/shipping-review/ReviewCustomerResolutionPanel.vue';
|
||
import ReviewCloseFulfillmentDialog from '../components/shipping-review/ReviewCloseFulfillmentDialog.vue';
|
||
import ReviewLineInventoryOps from '../components/shipping-review/ReviewLineInventoryOps.vue';
|
||
import ReviewLineFulfillmentDetail from '../components/shipping-review/ReviewLineFulfillmentDetail.vue';
|
||
import ReviewInventoryIssueFallbackCard from '../components/shipping-review/ReviewInventoryIssueFallbackCard.vue';
|
||
import ReviewAuditTrailDrawer from '../components/shipping-review/ReviewAuditTrailDrawer.vue';
|
||
import ReviewCompletedChecksPanel from '../components/shipping-review/ReviewCompletedChecksPanel.vue';
|
||
import ReviewCurrentProcessingCard from '../components/shipping-review/ReviewCurrentProcessingCard.vue';
|
||
import ReviewConversationRetryDrawer from '../components/shipping-review/ReviewConversationRetryDrawer.vue';
|
||
import ReviewDocumentNavigation, {
|
||
type ReviewDocumentNavMode,
|
||
} from '../components/shipping-review/ReviewDocumentNavigation.vue';
|
||
import ReviewWorkflowProgressPanel from '../components/shipping-review/ReviewWorkflowProgressPanel.vue';
|
||
import ReviewInventoryCandidatesPanel from '../components/shipping-review/ReviewInventoryCandidatesPanel.vue';
|
||
import ReviewWorkbenchFooter from '../components/shipping-review/ReviewWorkbenchFooter.vue';
|
||
import ReviewWorkbenchHeader from '../components/shipping-review/ReviewWorkbenchHeader.vue';
|
||
import ReviewWorkbenchModeToggle from '../components/shipping-review/ReviewWorkbenchModeToggle.vue';
|
||
import ReviewUnsavedSwitchDialog from '../components/shipping-review/ReviewUnsavedSwitchDialog.vue';
|
||
import ProcessGateRecoveryCard from '@/features/shipping-process-gates/components/ProcessGateRecoveryCard.vue';
|
||
import TaskTodoPanel from '@/features/workspace/shipping-task-center/TaskTodoPanel.vue';
|
||
import ManualUploadEvidenceDialog from '@/features/workspace/shipping-task-center/ManualUploadEvidenceDialog.vue';
|
||
import { downloadWorkspaceShippingExcelFile } from '@/features/workspace/api/shipping-tasks.api';
|
||
import ReviewLineNoOverrideDialog, {
|
||
type LineNoOverridePayload,
|
||
} from '../components/shipping-review/ReviewLineNoOverrideDialog.vue';
|
||
import ReviewLlmSuggestionDrawer from '../components/shipping-review/ReviewLlmSuggestionDrawer.vue';
|
||
import ReviewProfileMatchPanel from '../components/shipping-review/ReviewProfileMatchPanel.vue';
|
||
import ReviewVersionHistoryDrawer from '../components/shipping-review/ReviewVersionHistoryDrawer.vue';
|
||
import ReviewProcessDetailDrawer from '@/features/shipping-progress/components/ReviewProcessDetailDrawer.vue';
|
||
import { useProcessingActionPresentation } from '@/features/shipping-progress/composables/useProcessingActionPresentation';
|
||
import {
|
||
resolveWorkbenchActionItem,
|
||
type WorkbenchPanelAvailability,
|
||
} from '@/features/shipping-progress/workbenchActionRegistry';
|
||
import { parseOrderReviewConfirmResponse } from '../shipping-review/parseOrderReviewConfirmResponse';
|
||
import { buildReviewWorkbenchDisplayCase } from '../shipping-review/reviewWorkbenchDisplayState';
|
||
import { REVIEW_BUILD_ELIGIBILITY_BLOCKED, useShippingOrderReview } from '../shipping-review/useShippingOrderReview';
|
||
import type { ActionPresentationItem } from '@/features/shipping-progress/types';
|
||
import type {
|
||
ReviewWorkbenchMode,
|
||
ReviewWorkbenchPanelState,
|
||
ShippingOrderReviewCase,
|
||
ShippingOrderReviewDraftFieldMeta,
|
||
ShippingOrderReviewEvidence,
|
||
ShippingOrderReviewValueSource,
|
||
ShippingTaskDetail,
|
||
} from '../types/shipping.api.types';
|
||
|
||
/** 证据模式才加载,避免标准复核首屏拉入 pdfjs 预览组件。 */
|
||
const ReviewDocumentEvidenceDrawer = defineAsyncComponent(
|
||
() => import('../components/shipping-review/ReviewDocumentEvidenceDrawer.vue'),
|
||
);
|
||
|
||
const route = useRoute();
|
||
const router = useRouter();
|
||
const page = useChatPageContext();
|
||
const { t, te } = useI18n();
|
||
const {
|
||
reviewRun,
|
||
activeCase,
|
||
caseProjectionVersion,
|
||
caseLoadingContext,
|
||
reviewProgressContext,
|
||
shippingProcessingProjection,
|
||
authoritativeOrderTaskNo,
|
||
refreshShippingProcessing,
|
||
shippingProcessingLoading,
|
||
workflowProgressPolling,
|
||
versions,
|
||
statusMessage,
|
||
draftConflict,
|
||
draftConflictDiffLines,
|
||
buildEligibility,
|
||
canConfirmBuild,
|
||
routingRecoveryLines,
|
||
isViewingHistoricalVersion,
|
||
isReadOnly,
|
||
loading,
|
||
loadFailed,
|
||
caseSwitchLoading,
|
||
caseSwitchFailed,
|
||
saving,
|
||
validationInProgress,
|
||
saveFailed,
|
||
versionsLoading,
|
||
evidence,
|
||
llmSuggestions,
|
||
suggestionLoading,
|
||
focusedFieldId,
|
||
focusedLineKey,
|
||
previewUrl,
|
||
ensurePreviewLoaded,
|
||
load,
|
||
selectCase,
|
||
requestedCaseNo,
|
||
refreshWorkItemContext,
|
||
openCurrentVersion,
|
||
reloadLatestDraft,
|
||
toggleConflictDiff,
|
||
patchHeader,
|
||
patchLine,
|
||
addLine,
|
||
copyLine,
|
||
deleteLine,
|
||
validate,
|
||
setLineInventoryCandidates,
|
||
rerouteInventoryRouting,
|
||
adoptInventoryRoutingSuggestion,
|
||
keepManualInventoryRouting,
|
||
confirm,
|
||
createManualDraft,
|
||
markNonOrder,
|
||
markQualityIssue,
|
||
reparseDocument,
|
||
uploadReplacement,
|
||
focusSuggestionField,
|
||
setEvidenceDrawerFocus,
|
||
clearEvidenceDrawerFocus,
|
||
requestSuggestion,
|
||
decideSuggestion,
|
||
editable,
|
||
isFieldEditable,
|
||
showWorkflowProgress,
|
||
reparseProgressActive,
|
||
reparseProgressPolling,
|
||
reparseProgressRefreshFailed,
|
||
reparseProgressStage,
|
||
reparseLastStableStage,
|
||
reparseRunStatus,
|
||
reparseLastActivityAt,
|
||
reparseLastRefreshedAt,
|
||
reparseStalePolls,
|
||
refreshReparseProgress,
|
||
} = useShippingOrderReview({ onWorkflowRefresh: page.bumpWorkflowRefresh });
|
||
const msg = useMessage();
|
||
|
||
/** 统一投影状态/阶段文案(确认结果区与持续进度条共用)。 */
|
||
const shippingProcessingSummaryLabel = computed(() => {
|
||
const projection = shippingProcessingProjection.value;
|
||
if (!projection) return '';
|
||
const status = resolveShippingProcessingStatusLabel(projection.status, te, t);
|
||
const stage = resolveShippingProcessingStageLabel(
|
||
projection.stage,
|
||
te,
|
||
t,
|
||
projection.stageLabelKey,
|
||
);
|
||
return [status, stage].filter(Boolean).join(' · ');
|
||
});
|
||
|
||
/**
|
||
* 右侧主卡阶段:优先 Progress 投影(与顶部同源);Case current_stage 仅降级。
|
||
* 无论哪一路都带 label_key,禁止把 code 当用户文案。
|
||
*/
|
||
const currentProcessingStageDisplay = computed(() => {
|
||
const projection = shippingProcessingProjection.value;
|
||
if (projection?.stage) {
|
||
return {
|
||
code: projection.stage,
|
||
labelKey: projection.stageLabelKey
|
||
|| (projection.stage === 'order_creating' ? 'waiting_system_start' : projection.stage),
|
||
inconsistent: false,
|
||
};
|
||
}
|
||
const caseStage = activeCase.value?.current_stage;
|
||
const code = String(caseStage?.code || '').trim() || null;
|
||
return {
|
||
code,
|
||
labelKey: caseStage?.label_key
|
||
|| (code === 'order_creating' ? 'waiting_system_start' : code),
|
||
inconsistent: Boolean(caseStage?.inconsistent),
|
||
};
|
||
});
|
||
|
||
/** 复核页始终可见的统一进度条:有投影、权威 OT 或确认成功即展示。 */
|
||
const showUnifiedProcessingStrip = computed(() => (
|
||
Boolean(shippingProcessingProjection.value)
|
||
|| Boolean(shippingProcessingSummaryLabel.value)
|
||
|| Boolean(authoritativeOrderTaskNo.value)
|
||
|| Boolean(confirmSuccess.value)
|
||
));
|
||
|
||
const runNo = computed(() => String(route.query.run_no || route.params.runNo || ''));
|
||
const agentId = computed(() => String(route.params.agentId || ''));
|
||
const conversationId = computed(() => String(page.conversationId || route.query.conversation_id || ''));
|
||
const itemNoFromQuery = computed(() => String(route.query.item_no || ''));
|
||
const reviewFocus = computed(() => String(route.query.focus || '').trim());
|
||
/** Gate 恢复卡片导航上下文(复核台深链)。 */
|
||
const reviewGateNavigationContext = computed(() => ({
|
||
agentId: agentId.value,
|
||
conversationId: conversationId.value,
|
||
}));
|
||
const focusedEvidenceRef = ref<{ fieldId: string; lineIndex?: number } | null>(null);
|
||
|
||
const workbenchMode = ref<ReviewWorkbenchMode>('standard');
|
||
const panelState = ref<ReviewWorkbenchPanelState>({
|
||
pdfOpen: false,
|
||
pdfPinned: false,
|
||
pdfExpanded: false,
|
||
pdfDocked: false,
|
||
pdfFloatSide: 'right',
|
||
eligibilityDetailsOpen: false,
|
||
llmSuggestionOpen: false,
|
||
versionHistoryOpen: false,
|
||
scrollRestoreKey: null,
|
||
});
|
||
const auditTrailOpen = ref(false);
|
||
const lastResolvedCase = ref<ShippingOrderReviewCase | null>(null);
|
||
/** 当前展开履约摘要的行键;null 表示全部收起。 */
|
||
const fulfillmentDetailLineKey = ref<string | null>(null);
|
||
const processDetailOpen = ref(false);
|
||
const unsavedSwitchOpen = ref(false);
|
||
const pendingSwitchCaseNo = ref<string | null>(null);
|
||
const otNavMode = ref<ReviewDocumentNavMode>('hidden');
|
||
const closeFulfillmentOpen = ref(false);
|
||
const closeFulfillmentLineKeys = ref<string[]>([]);
|
||
/** focus=evidence 深链只消费一次,切换 PDF 后不得再次自动打开。 */
|
||
const evidenceFocusConsumed = ref(false);
|
||
|
||
watch(activeCase, (value) => {
|
||
if (value) {
|
||
lastResolvedCase.value = value;
|
||
}
|
||
}, { immediate: true });
|
||
|
||
const displayCase = computed(() => buildReviewWorkbenchDisplayCase({
|
||
activeCase: activeCase.value,
|
||
lastResolvedCase: lastResolvedCase.value,
|
||
reviewRun: reviewRun.value,
|
||
requestedCaseNo: requestedCaseNo.value,
|
||
}));
|
||
|
||
const displayHeaderValues = computed(() => (
|
||
(displayCase.value?.draft?.header_values as Record<string, unknown> | undefined) || {}
|
||
));
|
||
|
||
const displayDraftLines = computed(() => displayCase.value?.draft?.lines || []);
|
||
|
||
const showWorkbenchCaseShell = computed(() => Boolean(displayCase.value));
|
||
/** 切换期间和失败回退均保留旧快照;无稳定 Case 时才进入空状态骨架。 */
|
||
const caseContentSkeleton = computed(() => caseSwitchFailed.value && !activeCase.value);
|
||
|
||
/** can_build && can_auto_create 时底栏隐藏「确认建单」;文案仅表示资格达标等待入队,不等于正在推进。 */
|
||
/** queued|running|已有正式 OT|task_missing 时隐藏「确认并创建任务」。 */
|
||
const hideConfirmBecauseAutoGate = computed(() => {
|
||
if (hasFormalOt.value || Boolean(activeCase.value?.task_missing)) return true;
|
||
if (activeCase.value?.confirmed_task_id) return true;
|
||
const automationStatus = String(activeCase.value?.automation?.status || '').trim().toLowerCase();
|
||
if (['queued', 'running'].includes(automationStatus)) return true;
|
||
if (String(activeCase.value?.status || '') === 'confirmed') return true;
|
||
if (String(activeCase.value?.confirmed_task_no || '').trim()) return true;
|
||
return false;
|
||
});
|
||
|
||
/** 底栏是否展示自动建单/推进提示(等待 / 推进中)。 */
|
||
const showAutoGateHint = computed(() => {
|
||
if (validationInProgress.value) return false;
|
||
if (hasFormalOt.value || Boolean(activeCase.value?.task_missing)) return true;
|
||
const automationStatus = String(activeCase.value?.automation?.status || '').trim().toLowerCase();
|
||
return ['waiting_to_start', 'queued', 'running'].includes(automationStatus);
|
||
});
|
||
|
||
/**
|
||
* 正式 OT 主卡/底栏重试:failed+retryable 且有 task_no;task_missing 不渲染重试。
|
||
*/
|
||
const formalOtRetryTaskNo = computed(() => {
|
||
if (Boolean(activeCase.value?.task_missing)) return '';
|
||
return String(
|
||
activeCase.value?.confirmed_task_no
|
||
|| activeCase.value?.post_confirm_auto_progress?.task_no
|
||
|| '',
|
||
).trim();
|
||
});
|
||
|
||
/** failed / manual_fallback 时展示「重试自动推进」(含正式 OT 后推进失败)。 */
|
||
const showStpRetry = computed(() => {
|
||
const automation = activeCase.value?.automation;
|
||
const status = String(automation?.status || '').trim().toLowerCase();
|
||
if (!['failed', 'manual_fallback'].includes(status)) return false;
|
||
if (Boolean(activeCase.value?.task_missing)) return false;
|
||
if (hasFormalOt.value) {
|
||
return Boolean(automation?.retryable) && Boolean(formalOtRetryTaskNo.value);
|
||
}
|
||
if (String(activeCase.value?.status || '') === 'confirmed') return false;
|
||
if (String(activeCase.value?.confirmed_task_no || '').trim()) return false;
|
||
return Boolean(automation?.retryable) || (activeCase.value?.available_actions || []).includes('retry_stp_auto_create');
|
||
});
|
||
|
||
/**
|
||
* 对话级重试动作:后端 conversation_allowed_actions 中 retry_auto_progress 且 eligible_count>0。
|
||
*/
|
||
const conversationRetryAction = computed(() => {
|
||
const actions = activeCase.value?.conversation_allowed_actions || [];
|
||
return actions.find((item) => (
|
||
item.code === 'retry_auto_progress' && Number(item.eligible_count || 0) > 0
|
||
)) || null;
|
||
});
|
||
|
||
/** 顶栏是否展示对话级「重试自动推进」。 */
|
||
const showConversationRetry = computed(() => (
|
||
Boolean(conversationRetryAction.value) && Boolean(String(conversationId.value || '').trim())
|
||
));
|
||
|
||
/** 对话级可重试对象数量(徽标)。 */
|
||
const conversationRetryEligibleCount = computed(() => (
|
||
Number(conversationRetryAction.value?.eligible_count || 0)
|
||
));
|
||
|
||
/**
|
||
* 是否挂载右侧/窄屏「当前处理」卡:task_missing、正式 OT、或自动化进行中/失败态。
|
||
* 核心逻辑:对象级重试优先挂在此卡上,未挂载时才回落底栏。
|
||
*/
|
||
const mountCurrentProcessingCard = computed(() => {
|
||
if (!displayCase.value) return false;
|
||
if (caseContentSkeleton.value) return true;
|
||
if (Boolean(displayCase.value.task_missing)) return true;
|
||
if (hasFormalOt.value) return true;
|
||
const status = String(displayCase.value.automation?.status || '').trim().toLowerCase();
|
||
return ['waiting_to_start', 'queued', 'running', 'failed', 'manual_fallback'].includes(status);
|
||
});
|
||
|
||
/** 对象级重试:有当前处理卡时放右栏/窄屏主卡;否则回落底栏。 */
|
||
const showObjectRetryOnRail = computed(() => showStpRetry.value && mountCurrentProcessingCard.value);
|
||
const showObjectRetryOnFooter = computed(() => showStpRetry.value && !mountCurrentProcessingCard.value);
|
||
|
||
/** 管理员诊断:后端 technical_progress / automation.technical 仅 admin 投影。 */
|
||
const showAdminTaskMissingDiagnosis = computed(() => (
|
||
Boolean(displayCase.value?.task_missing)
|
||
&& (
|
||
Boolean(displayCase.value?.technical_progress)
|
||
|| Boolean((displayCase.value?.automation as { technical?: unknown } | undefined)?.technical)
|
||
)
|
||
));
|
||
|
||
/**
|
||
* 是否存在已确认的自动建单/推进 Job(queued|running)。
|
||
* 核心逻辑:仅 post_confirm 或投影 status 明确入队/运行时为 true;资格达标不算。
|
||
*/
|
||
const hasConfirmedAutomationJob = computed(() => {
|
||
const automationStatus = String(activeCase.value?.automation?.status || '').trim().toLowerCase();
|
||
if (['queued', 'running', 'completed'].includes(automationStatus)) return true;
|
||
const progress = activeCase.value?.post_confirm_auto_progress;
|
||
const progressStatus = String(progress?.status || '').trim().toLowerCase();
|
||
if (['queued', 'running', 'started', 'in_progress'].includes(progressStatus)) return true;
|
||
const projStatus = String(shippingProcessingProjection.value?.status || '').trim().toLowerCase();
|
||
const hasTask = Boolean(
|
||
String(activeCase.value?.confirmed_task_no || '').trim()
|
||
|| String(authoritativeOrderTaskNo.value || '').trim(),
|
||
);
|
||
return hasTask && ['processing', 'automating', 'queued'].includes(projStatus);
|
||
});
|
||
|
||
/**
|
||
* 底栏自动资格提示:消费 automation.phase,禁止前端猜「建单/推进」文案。
|
||
*/
|
||
const autoGateHintKey = computed(() => {
|
||
const phase = String(activeCase.value?.automation?.phase || '').trim();
|
||
const status = String(activeCase.value?.automation?.status || '').trim().toLowerCase();
|
||
if (displayCase.value?.task_missing) {
|
||
return 'chat.shippingOrderReview.currentProcessing.taskMissingHint';
|
||
}
|
||
if (status === 'waiting_to_start') {
|
||
return phase === 'pre_ot_stp'
|
||
? 'chat.shippingOrderReview.automation.waitingPreOt'
|
||
: 'chat.shippingOrderReview.automation.waitingPostOt';
|
||
}
|
||
return hasConfirmedAutomationJob.value
|
||
? 'chat.shippingOrderReview.buildEligibility.autoGateRunningHint'
|
||
: 'chat.shippingOrderReview.buildEligibility.autoGateWaitingHint';
|
||
});
|
||
|
||
/** 是否展示人工阻断卡:必须后端 owner_type=human 且非 technical_auto_only。 */
|
||
const showHumanBlockingGate = computed(() => {
|
||
const gate = activeCase.value?.process_gate;
|
||
if (!gate?.current_blocking_gate) return false;
|
||
if (gate.technical_auto_only) return false;
|
||
if (String(gate.owner_type || '') === 'system') return false;
|
||
return true;
|
||
});
|
||
|
||
/** 正式 OT 后是否将订单检查降级折叠。 */
|
||
const showEligibilityAsPrimary = computed(() => !hasFormalOt.value && !displayCase.value?.task_missing);
|
||
|
||
/** 证据浮窗是否以浮动方式展示(打开且未固定为侧栏)。 */
|
||
const evidenceFloating = computed(
|
||
() => workbenchMode.value === 'evidence' && panelState.value.pdfOpen && !panelState.value.pdfDocked,
|
||
);
|
||
|
||
/** 证据是否以双栏侧栏方式展示。 */
|
||
const evidenceDocked = computed(
|
||
() => workbenchMode.value === 'evidence' && panelState.value.pdfOpen && panelState.value.pdfDocked,
|
||
);
|
||
|
||
const mainEditorScrollEl = ref<HTMLElement | null>(null);
|
||
const savedScrollTop = ref(0);
|
||
|
||
const confirmSuccess = ref<{
|
||
taskNo: string;
|
||
/** Candidate 一对一 OT;返回对话聚焦用。 */
|
||
orderTaskNo: string;
|
||
/** 建单已成功 */
|
||
confirmOk: boolean;
|
||
/** 自动推进已入队/启动 */
|
||
autoProgress: boolean;
|
||
/** 入队失败或同步执行失败,需用户可见告警 */
|
||
progressFailed: boolean;
|
||
progressStatus: string;
|
||
progressMessage: string;
|
||
checkpoint: string;
|
||
/** 来自 Case 投影的刷新恢复(非本次确认即时响应) */
|
||
restoredFromProjection?: boolean;
|
||
} | null>(null);
|
||
const progressRetrying = ref(false);
|
||
const conversationRetrying = ref(false);
|
||
const conversationRetryDrawerOpen = ref(false);
|
||
const conversationRetryToastOpen = ref(false);
|
||
let conversationRetryToastTimer: ReturnType<typeof window.setTimeout> | undefined;
|
||
const conversationRetryError = ref('');
|
||
const conversationRetryResult = ref<{
|
||
summary: { total: number; retried: number; skipped: number; failed: number; blocked?: number };
|
||
items: Array<{
|
||
object_type: string;
|
||
object_ref: string;
|
||
action?: string | null;
|
||
outcome: string;
|
||
reason_code?: string | null;
|
||
}>;
|
||
} | null>(null);
|
||
|
||
const hasConversationRetryAttention = computed(() => (
|
||
Number(conversationRetryResult.value?.summary.failed || 0) > 0
|
||
|| Number(conversationRetryResult.value?.summary.blocked || 0) > 0
|
||
));
|
||
|
||
function showConversationRetryToast() {
|
||
if (conversationRetryToastTimer) window.clearTimeout(conversationRetryToastTimer);
|
||
conversationRetryToastOpen.value = true;
|
||
conversationRetryToastTimer = window.setTimeout(() => {
|
||
conversationRetryToastOpen.value = false;
|
||
}, 5000);
|
||
}
|
||
|
||
/**
|
||
* 题9A:already_running 响应本地冷却(任务号 → 过期毫秒时间戳)。
|
||
* 当服务端返回 noop.already_running 时写对应 task 条目;按钮禁用在此有效期内叠加,避免「投影 refresh 有 2-3s 滞后期间用户再次点击」。
|
||
* 10 秒后自动过期。
|
||
*/
|
||
const taskRunningCooldownUntilMs = ref<Record<string, number>>({});
|
||
|
||
const TASK_RUNNING_COOLDOWN_MS = 10000;
|
||
|
||
function markTaskRunningCooldown(taskNo: string | null | undefined, durationMs: number = TASK_RUNNING_COOLDOWN_MS) {
|
||
const key = String(taskNo || '').trim();
|
||
if (!key) return;
|
||
taskRunningCooldownUntilMs.value = {
|
||
...taskRunningCooldownUntilMs.value,
|
||
[key]: Date.now() + durationMs,
|
||
};
|
||
}
|
||
|
||
function isTaskRunningCooldownActive(taskNo: string | null | undefined): boolean {
|
||
const key = String(taskNo || '').trim();
|
||
if (!key) return false;
|
||
const until = Number(taskRunningCooldownUntilMs.value[key] || 0) || 0;
|
||
return until > Date.now();
|
||
}
|
||
|
||
/**
|
||
* 题9A:任务级 inventory_preparation running 判定(非请求中)。
|
||
* true → 后端投影层即已确认 Attempt 在跑 / Gate 在活动 / 冷却期内。
|
||
*/
|
||
const taskInventoryPreparationRunning = computed(() => {
|
||
const taskNo = String(
|
||
formalOtRetryTaskNo.value
|
||
|| confirmSuccess.value?.taskNo
|
||
|| shippingProcessingProjection.value?.shippingNoticeNo
|
||
|| '',
|
||
).trim();
|
||
const inv = shippingProcessingProjection.value?.inventoryPreparation;
|
||
if (inv) {
|
||
if (Number(inv.activeAttemptCount || 0) > 0) return true;
|
||
if (Boolean(inv.gateAttemptActive)) return true;
|
||
if ((inv.pendingSources || []).length > 0) return true;
|
||
}
|
||
return isTaskRunningCooldownActive(taskNo);
|
||
});
|
||
|
||
/**
|
||
* 题9A:任务级三重禁用总开关。
|
||
* 优先级:① 请求中 progressRetrying/caseSwitchLoading → ② inventoryPreparation running → ③ retryable !== true(需确认投影层折叠到位)。
|
||
*/
|
||
const taskRetryButtonDisabled = computed(() => {
|
||
if (Boolean(activeCase.value?.task_missing)) return true;
|
||
if (progressRetrying.value || caseSwitchLoading.value) return true;
|
||
const inv = shippingProcessingProjection.value?.inventoryPreparation;
|
||
if (inv) {
|
||
if (Number(inv.activeAttemptCount || 0) > 0) return true;
|
||
if (Boolean(inv.gateAttemptActive)) return true;
|
||
if ((inv.pendingSources || []).length > 0) return true;
|
||
}
|
||
const taskNo = String(
|
||
formalOtRetryTaskNo.value
|
||
|| confirmSuccess.value?.taskNo
|
||
|| shippingProcessingProjection.value?.shippingNoticeNo
|
||
|| '',
|
||
).trim();
|
||
if (isTaskRunningCooldownActive(taskNo)) return true;
|
||
if (shippingProcessingProjection.value != null) {
|
||
const retryableFlag = shippingProcessingProjection.value.retryable;
|
||
if (retryableFlag === false) return true;
|
||
}
|
||
return false;
|
||
});
|
||
|
||
/**
|
||
* 题7A:是否有自动次数 exhausted 的源。
|
||
* true 时按钮显示「人工继续」语义,同时 tooltip 提示 source_codes。
|
||
*/
|
||
const taskInventoryExhaustedSources = computed((): string[] => {
|
||
const inv = shippingProcessingProjection.value?.inventoryPreparation;
|
||
if (!inv) return [];
|
||
return Array.isArray(inv.exhaustedSources) ? inv.exhaustedSources : [];
|
||
});
|
||
|
||
/**
|
||
* 从 Case 投影恢复「已建单但仍待推进」琥珀色重试条(覆盖页面刷新场景)。
|
||
* 核心逻辑:仅当 post_confirm_auto_progress.needs_retry 时写入;不覆盖同会话即时 confirm 结果。
|
||
* 注:确认成功琥珀色 UI 已移除(避免与对话级/对象级重试重复);本 hydrate 仍供内部状态与流程动作使用。
|
||
*/
|
||
function hydrateConfirmProgressFromCase() {
|
||
const caseRow = activeCase.value;
|
||
if (!caseRow || String(caseRow.status || '') !== 'confirmed') return;
|
||
if (confirmSuccess.value && !confirmSuccess.value.restoredFromProjection) return;
|
||
const progress = caseRow.post_confirm_auto_progress;
|
||
if (!progress?.needs_retry) {
|
||
if (confirmSuccess.value?.restoredFromProjection && !progress?.needs_retry) {
|
||
confirmSuccess.value = null;
|
||
}
|
||
return;
|
||
}
|
||
const taskNo = String(progress.task_no || caseRow.confirmed_task_no || '').trim();
|
||
if (!taskNo) return;
|
||
confirmSuccess.value = {
|
||
taskNo,
|
||
orderTaskNo: String(caseRow.order_task_no || '').trim(),
|
||
confirmOk: true,
|
||
autoProgress: false,
|
||
progressFailed: true,
|
||
progressStatus: String(progress.status || 'needs_retry'),
|
||
progressMessage: String(progress.message || ''),
|
||
checkpoint: '',
|
||
restoredFromProjection: true,
|
||
};
|
||
}
|
||
|
||
/**
|
||
* 深链 focus=evidence:仅首次进入且尚未消费时打开证据模式;消费后立即从 URL 清除 focus。
|
||
* 切换 PDF/Case 不得因残留 query 或新 evidence 加载再次自动打开。
|
||
*/
|
||
watch(
|
||
() => [evidence.value, reviewFocus.value, activeCase.value?.case_no] as const,
|
||
([items, focus]) => {
|
||
if (focus !== 'evidence' || evidenceFocusConsumed.value || !items?.length) return;
|
||
const first = items.find((item) => item.bbox) || items[0];
|
||
if (!first) return;
|
||
evidenceFocusConsumed.value = true;
|
||
focusedEvidenceRef.value = {
|
||
fieldId: String(first.field_id || '').trim(),
|
||
lineIndex: first.line_index == null ? undefined : Number(first.line_index),
|
||
};
|
||
workbenchMode.value = 'evidence';
|
||
panelState.value = { ...panelState.value, pdfOpen: true };
|
||
void ensurePreviewLoaded();
|
||
const nextQuery = { ...route.query };
|
||
delete nextQuery.focus;
|
||
void router.replace({ query: nextQuery });
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
/** PDF 打开且 Case 切换时按需拉取预览,避免导航时预取。 */
|
||
watch(
|
||
() => [activeCase.value?.case_no, panelState.value.pdfOpen] as const,
|
||
([caseNo, pdfOpen]) => {
|
||
if (!pdfOpen || !caseNo) return;
|
||
void ensurePreviewLoaded(caseNo);
|
||
},
|
||
);
|
||
|
||
/**
|
||
* 当前用于 PDF 证据高亮的条目:明细同时按字段与行号匹配,避免多行同字段定位错位。
|
||
*/
|
||
const selectedEvidence = computed((): ShippingOrderReviewEvidence | null => {
|
||
const items = evidence.value || [];
|
||
const fieldId = String(focusedEvidenceRef.value?.fieldId || '').trim();
|
||
if (fieldId) {
|
||
const lineIndex = focusedEvidenceRef.value?.lineIndex;
|
||
// 有聚焦字段时按质量优选,不回退到其他字段证据。
|
||
return findFieldEvidence(fieldId, lineIndex) || null;
|
||
}
|
||
if (!items.length) return null;
|
||
return items.find((item) => item.highlight_bbox || item.bbox) || items[0] || null;
|
||
});
|
||
|
||
/** 多 evidence 优选顺序:verified > candidate > unavailable > invalid;同级优先有 highlight_bbox。 */
|
||
const HIGHLIGHT_QUALITY_RANK: Record<string, number> = {
|
||
verified: 0,
|
||
candidate: 1,
|
||
unavailable: 2,
|
||
invalid: 3,
|
||
};
|
||
|
||
/**
|
||
* 选择字段最佳证据:多 Observation 时按质量与可绘制 bbox 优选,禁止盲取首条。
|
||
*/
|
||
const findFieldEvidence = (fieldId: string, lineIndex?: number) => {
|
||
const matches = (evidence.value || []).filter((item) =>
|
||
String(item.field_id || '') === String(fieldId || '').trim()
|
||
&& (lineIndex === undefined || Number(item.line_index) === lineIndex),
|
||
);
|
||
if (!matches.length) return undefined;
|
||
return [...matches].sort((left, right) => {
|
||
const leftRank = HIGHLIGHT_QUALITY_RANK[String(left.highlight_quality || '')] ?? 9;
|
||
const rightRank = HIGHLIGHT_QUALITY_RANK[String(right.highlight_quality || '')] ?? 9;
|
||
if (leftRank !== rightRank) return leftRank - rightRank;
|
||
const leftDrawable = left.highlight_bbox || left.bbox ? 0 : 1;
|
||
const rightDrawable = right.highlight_bbox || right.bbox ? 0 : 1;
|
||
return leftDrawable - rightDrawable;
|
||
})[0];
|
||
};
|
||
|
||
/**
|
||
* 读取字段高亮质量(与自动确认状态独立,仅用于展示)。
|
||
* 无 Observation / 无证据时默认 unavailable,避免与「前端未加载」混淆。
|
||
*/
|
||
const fieldHighlightQuality = (fieldId: string, lineIndex?: number) => {
|
||
const quality = String(findFieldEvidence(fieldId, lineIndex)?.highlight_quality || '').trim();
|
||
return quality || 'unavailable';
|
||
};
|
||
|
||
/**
|
||
* 是否仅诊断、不可精确高亮(红色入口)。
|
||
*/
|
||
const isLocateDiagnoseOnly = (quality: string) => quality === 'unavailable' || quality === 'invalid';
|
||
|
||
/**
|
||
* 定位图标颜色:绿=verified,橙=candidate,红=unavailable/invalid。
|
||
* 不得仅依赖颜色:调用方须同步设置 title / aria-label。
|
||
*/
|
||
const locateIconButtonClass = (quality: string) => {
|
||
if (quality === 'verified') {
|
||
return 'rounded p-1 text-emerald-600 hover:bg-emerald-50 dark:text-emerald-400 dark:hover:bg-emerald-950/40';
|
||
}
|
||
if (quality === 'candidate') {
|
||
return 'rounded p-1 text-orange-600 hover:bg-orange-50 dark:text-orange-400 dark:hover:bg-orange-950/40';
|
||
}
|
||
return (
|
||
'rounded p-1 text-rose-600 hover:bg-rose-50 dark:text-rose-400 dark:hover:bg-rose-950/40'
|
||
);
|
||
};
|
||
|
||
/**
|
||
* 定位控件可访问文案:含字段名、质量状态与无坐标/候选说明。
|
||
*/
|
||
const locateControlLabel = (fieldDisplayName: string, fieldId: string, lineIndex?: number) => {
|
||
const quality = fieldHighlightQuality(fieldId, lineIndex);
|
||
const qualityLabel = t(`chat.shippingOrderReview.highlightQuality.${quality}`);
|
||
const base = t('chat.shippingOrderReview.locateSource', { field: fieldDisplayName });
|
||
if (quality === 'unavailable' || quality === 'invalid') {
|
||
return `${base} — ${qualityLabel}. ${t('chat.shippingOrderReview.locateUnavailableHint')}`;
|
||
}
|
||
if (quality === 'candidate') {
|
||
return `${base} — ${qualityLabel}. ${t('chat.shippingOrderReview.locateCandidateHint')}`;
|
||
}
|
||
return `${base} — ${qualityLabel}`;
|
||
};
|
||
|
||
/**
|
||
* 写定位点击审计;无 evidence 也记录,失败不阻断 UI。
|
||
*/
|
||
const auditFieldLocateAttempt = (
|
||
fieldId: string,
|
||
lineIndex: number | undefined,
|
||
matched: ShippingOrderReviewEvidence | null | undefined,
|
||
) => {
|
||
const caseNo = String(activeCase.value?.case_no || '').trim();
|
||
if (!caseNo) return;
|
||
const quality = String(matched?.highlight_quality || fieldHighlightQuality(fieldId, lineIndex));
|
||
const pdfLocated = Boolean(
|
||
matched
|
||
&& (matched.highlight_quality === 'verified' || matched.highlight_quality === 'candidate')
|
||
&& (matched.highlight_bbox || matched.bbox),
|
||
);
|
||
void attemptWorkspaceShippingOrderReviewFieldLocate(caseNo, {
|
||
field_id: fieldId,
|
||
line_index: lineIndex ?? null,
|
||
highlight_quality: quality,
|
||
has_evidence: Boolean(matched?.evidence_id),
|
||
evidence_id: matched?.evidence_id || null,
|
||
pdf_located: pdfLocated,
|
||
coordinate_issue_codes: matched?.coordinate_issue_codes || [],
|
||
}).catch(() => undefined);
|
||
};
|
||
|
||
/**
|
||
* 同步当前编辑字段焦点(不切换工作台模式)。
|
||
* 用途:输入框 focus 时更新 AI 建议焦点与证据引用,避免误开 PDF 抽屉。
|
||
*/
|
||
const syncFieldFocus = (fieldId: string, lineIndex?: number) => {
|
||
const lineKey = lineIndex != null ? activeCase.value?.draft?.lines?.[lineIndex]?.line_key : undefined;
|
||
focusSuggestionField(String(fieldId || '').trim(), typeof lineKey === 'string' ? lineKey : null);
|
||
focusedEvidenceRef.value = findFieldEvidence(fieldId, lineIndex)
|
||
? { fieldId: String(fieldId || '').trim(), lineIndex }
|
||
: null;
|
||
};
|
||
|
||
/**
|
||
* 当前证据模式下是否与 PDF 联动的字段输入(用于边框高亮)。
|
||
*/
|
||
const isEvidenceLinkedField = (fieldId: string, lineIndex?: number) => {
|
||
if (workbenchMode.value !== 'evidence' || !panelState.value.pdfOpen) return false;
|
||
const focused = focusedEvidenceRef.value;
|
||
if (!focused) return false;
|
||
if (String(focused.fieldId || '') !== String(fieldId || '').trim()) return false;
|
||
if (lineIndex === undefined) return focused.lineIndex == null;
|
||
return Number(focused.lineIndex) === Number(lineIndex);
|
||
};
|
||
|
||
/**
|
||
* 从草稿问题与建单门禁问题收集可跳转的异常字段目标(去重保序)。
|
||
*/
|
||
const exceptionTargets = computed(() => {
|
||
type Target = { fieldId: string; lineIndex?: number; key: string };
|
||
const seen = new Set<string>();
|
||
const out: Target[] = [];
|
||
const push = (fieldIdRaw: unknown, lineIndexRaw: unknown) => {
|
||
const fieldId = String(fieldIdRaw || '').trim();
|
||
if (!fieldId) return;
|
||
const lineIndex = lineIndexRaw == null || lineIndexRaw === ''
|
||
? undefined
|
||
: Number(lineIndexRaw);
|
||
const key = lineIndex == null || !Number.isFinite(lineIndex)
|
||
? fieldId
|
||
: `${fieldId}:${lineIndex}`;
|
||
if (seen.has(key)) return;
|
||
seen.add(key);
|
||
out.push({
|
||
fieldId,
|
||
lineIndex: lineIndex == null || !Number.isFinite(lineIndex) ? undefined : lineIndex,
|
||
key,
|
||
});
|
||
};
|
||
for (const issue of activeCase.value?.draft?.issues || []) {
|
||
push(issue.field_id, issue.line_index);
|
||
}
|
||
const schemaFields = activeCase.value?.schema?.fields || [];
|
||
for (const issue of buildEligibility.value?.issues || []) {
|
||
const rawFieldId = String((issue as { field_id?: string | null }).field_id || '').trim();
|
||
const fieldCode = String(issue.field_code || '').trim();
|
||
const byCode = fieldCode
|
||
? schemaFields.find((field) => field.field_code === fieldCode)?.field_id
|
||
: '';
|
||
push(rawFieldId || byCode, issue.line_index);
|
||
}
|
||
return out;
|
||
});
|
||
|
||
const exceptionOrdinal = computed(() => {
|
||
const targets = exceptionTargets.value;
|
||
if (!targets.length) return 0;
|
||
const fieldId = String(focusedEvidenceRef.value?.fieldId || focusedFieldId.value || '').trim();
|
||
if (!fieldId) return 0;
|
||
const lineIndex = focusedEvidenceRef.value?.lineIndex;
|
||
const idx = targets.findIndex((item) => (
|
||
item.fieldId === fieldId
|
||
&& (item.lineIndex == null ? lineIndex == null : Number(item.lineIndex) === Number(lineIndex))
|
||
));
|
||
return idx >= 0 ? idx + 1 : 0;
|
||
});
|
||
|
||
/**
|
||
* 跳转到上一个/下一个异常字段并定位 PDF。
|
||
* @param delta - -1 上一异常,+1 下一异常
|
||
*/
|
||
const navigateExceptionField = (delta: number) => {
|
||
const targets = exceptionTargets.value;
|
||
if (!targets.length) return;
|
||
let idx = exceptionOrdinal.value > 0 ? exceptionOrdinal.value - 1 : -1;
|
||
if (idx < 0) idx = delta > 0 ? -1 : 0;
|
||
const next = targets[Math.min(Math.max(idx + delta, 0), targets.length - 1)];
|
||
if (!next) return;
|
||
focusFieldEvidence(next.fieldId, next.lineIndex);
|
||
if (next.lineIndex != null) focusOrderLine(next.lineIndex);
|
||
};
|
||
|
||
/**
|
||
* Alt+[ / Alt+]:上一个 / 下一个异常字段(输入框内同样生效,避免与文本输入冲突)。
|
||
*/
|
||
const onExceptionNavKeydown = (event: KeyboardEvent) => {
|
||
if (!(event.altKey) || event.ctrlKey || event.metaKey) return;
|
||
if (event.key !== '[' && event.key !== ']') return;
|
||
if (!exceptionTargets.value.length) return;
|
||
event.preventDefault();
|
||
navigateExceptionField(event.key === '[' ? -1 : 1);
|
||
};
|
||
|
||
onMounted(() => {
|
||
document.addEventListener('keydown', onExceptionNavKeydown, true);
|
||
});
|
||
|
||
onBeforeUnmount(() => {
|
||
document.removeEventListener('keydown', onExceptionNavKeydown, true);
|
||
});
|
||
|
||
/**
|
||
* 定位字段证据:保存滚动、进入 evidence 模式并打开 PDF 浮窗(默认不挤占主编辑区)。
|
||
* 由「定位原文」按钮或字段双击触发;无 Observation 时仍可点击(红色),打开诊断说明。
|
||
*/
|
||
const focusFieldEvidence = (fieldId: string, lineIndex?: number) => {
|
||
if (mainEditorScrollEl.value) {
|
||
savedScrollTop.value = mainEditorScrollEl.value.scrollTop;
|
||
}
|
||
const normalizedFieldId = String(fieldId || '').trim();
|
||
const lineKey = lineIndex != null ? activeCase.value?.draft?.lines?.[lineIndex]?.line_key : undefined;
|
||
focusSuggestionField(normalizedFieldId, typeof lineKey === 'string' ? lineKey : null);
|
||
// 无证据也保留字段焦点,供抽屉展示「无坐标」诊断,禁止回退到其他字段。
|
||
focusedEvidenceRef.value = { fieldId: normalizedFieldId, lineIndex };
|
||
const matched = findFieldEvidence(fieldId, lineIndex);
|
||
setEvidenceDrawerFocus({
|
||
fieldId: normalizedFieldId,
|
||
lineKey: typeof lineKey === 'string' ? lineKey : null,
|
||
lineIndex: lineIndex ?? null,
|
||
pageNo: matched?.page_no ?? null,
|
||
evidenceId: matched?.evidence_id ?? null,
|
||
});
|
||
workbenchMode.value = 'evidence';
|
||
panelState.value = {
|
||
...panelState.value,
|
||
pdfOpen: true,
|
||
// 定位证据默认浮窗;保留用户已选的 docked/expanded/side。
|
||
scrollRestoreKey: typeof lineKey === 'string' ? `${fieldId}:${lineKey}` : normalizedFieldId,
|
||
};
|
||
void ensurePreviewLoaded();
|
||
// [STEP] 所有定位点击写 locate 审计(含无 evidence);有 evidence_id 再写 focus/诊断。
|
||
auditFieldLocateAttempt(normalizedFieldId, lineIndex, matched);
|
||
const quality = String(matched?.highlight_quality || fieldHighlightQuality(fieldId, lineIndex));
|
||
const caseNo = String(activeCase.value?.case_no || '').trim();
|
||
if (caseNo && matched?.evidence_id) {
|
||
void getWorkspaceShippingOrderReviewEvidenceItem(caseNo, matched.evidence_id)
|
||
.catch(() => undefined);
|
||
if (quality === 'unavailable' || quality === 'invalid') {
|
||
void viewWorkspaceShippingOrderReviewHighlightDiagnostic(
|
||
caseNo,
|
||
matched.evidence_id,
|
||
).catch(() => undefined);
|
||
}
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 退出证据核对模式:恢复滚动;未勾选「退出后保留」时关闭面板。
|
||
*/
|
||
const closeEvidenceMode = () => {
|
||
workbenchMode.value = 'standard';
|
||
if (!panelState.value.pdfPinned) {
|
||
panelState.value = { ...panelState.value, pdfOpen: false };
|
||
}
|
||
panelState.value = { ...panelState.value, scrollRestoreKey: null };
|
||
clearEvidenceDrawerFocus();
|
||
void nextTick(() => {
|
||
if (mainEditorScrollEl.value) {
|
||
mainEditorScrollEl.value.scrollTop = savedScrollTop.value;
|
||
}
|
||
});
|
||
};
|
||
|
||
/** 切换浮窗紧凑/展开尺寸(不改变主布局)。 */
|
||
const togglePdfExpanded = () => {
|
||
panelState.value = { ...panelState.value, pdfExpanded: !panelState.value.pdfExpanded };
|
||
};
|
||
|
||
/** 切换浮动面板 ↔ 固定侧栏双栏。 */
|
||
const togglePdfDocked = () => {
|
||
const nextDocked = !panelState.value.pdfDocked;
|
||
panelState.value = {
|
||
...panelState.value,
|
||
pdfDocked: nextDocked,
|
||
pdfOpen: true,
|
||
// 固定侧栏时收起「展开」态,避免语义混淆。
|
||
pdfExpanded: nextDocked ? false : panelState.value.pdfExpanded,
|
||
};
|
||
void ensurePreviewLoaded();
|
||
};
|
||
|
||
/** 浮窗左右切换,减轻对当前字段的遮挡。 */
|
||
const togglePdfFloatSide = () => {
|
||
panelState.value = {
|
||
...panelState.value,
|
||
pdfFloatSide: panelState.value.pdfFloatSide === 'right' ? 'left' : 'right',
|
||
};
|
||
};
|
||
|
||
/** 进入库存处理模式,突出库存候选面板。 */
|
||
const enterInventoryMode = () => {
|
||
// 正式 OT 后禁止完整库存工作台;行级动作走明细浮层 / Case 兜底卡。
|
||
if (hasFormalOt.value) return;
|
||
workbenchMode.value = 'inventory';
|
||
};
|
||
|
||
/** 退出库存处理模式,回到标准复核布局。 */
|
||
const exitInventoryMode = () => {
|
||
workbenchMode.value = 'standard';
|
||
};
|
||
|
||
/**
|
||
* 处理模式切换条事件;evidence/inventory 返回 standard 时走专用清理逻辑。
|
||
*/
|
||
const onWorkbenchModeChange = (mode: ReviewWorkbenchMode) => {
|
||
if (mode === 'standard') {
|
||
if (workbenchMode.value === 'evidence') {
|
||
closeEvidenceMode();
|
||
return;
|
||
}
|
||
if (workbenchMode.value === 'inventory') {
|
||
exitInventoryMode();
|
||
return;
|
||
}
|
||
}
|
||
if (mode === 'inventory') {
|
||
enterInventoryMode();
|
||
return;
|
||
}
|
||
workbenchMode.value = mode;
|
||
};
|
||
|
||
/** 切换「退出后保留」:离开证据模式时是否保留 pdfOpen(≠ 固定侧栏)。 */
|
||
const togglePdfPinned = () => {
|
||
panelState.value = { ...panelState.value, pdfPinned: !panelState.value.pdfPinned };
|
||
if (panelState.value.pdfPinned) {
|
||
panelState.value = { ...panelState.value, pdfOpen: true };
|
||
void ensurePreviewLoaded();
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 在证据列表中移动到上一项/下一项,并同步字段焦点。
|
||
* @param delta - -1 上一证据,+1 下一证据
|
||
*/
|
||
const navigateEvidence = (delta: number) => {
|
||
const items = evidence.value || [];
|
||
if (!items.length) return;
|
||
const currentId = String(selectedEvidence.value?.evidence_id || '');
|
||
let idx = items.findIndex((item) => item.evidence_id === currentId);
|
||
if (idx < 0) idx = 0;
|
||
const next = items[Math.min(Math.max(idx + delta, 0), items.length - 1)];
|
||
if (!next) return;
|
||
const lineIndex = next.line_index == null ? undefined : Number(next.line_index);
|
||
const lineKey = lineIndex != null
|
||
? activeCase.value?.draft?.lines?.[lineIndex]?.line_key
|
||
: undefined;
|
||
syncFieldFocus(String(next.field_id || ''), lineIndex);
|
||
focusedEvidenceRef.value = {
|
||
fieldId: String(next.field_id || '').trim(),
|
||
lineIndex,
|
||
};
|
||
setEvidenceDrawerFocus({
|
||
fieldId: String(next.field_id || '').trim(),
|
||
lineKey: typeof lineKey === 'string' ? lineKey : null,
|
||
lineIndex: lineIndex ?? null,
|
||
pageNo: next.page_no ?? null,
|
||
evidenceId: next.evidence_id,
|
||
});
|
||
panelState.value = { ...panelState.value, pdfOpen: true };
|
||
};
|
||
|
||
/** 打开版本历史抽屉。 */
|
||
/**
|
||
* 打开版本历史抽屉:先写入访问审计,失败则告警并拒绝展示(硬性可追溯)。
|
||
*/
|
||
const openVersionHistory = async () => {
|
||
const caseNo = String(activeCase.value?.case_no || '').trim();
|
||
if (!caseNo) return;
|
||
try {
|
||
await auditWorkspaceShippingOrderReviewVersionHistory(caseNo);
|
||
panelState.value = { ...panelState.value, versionHistoryOpen: true };
|
||
} catch {
|
||
msg.warning(t('chat.shippingOrderReview.workbench.auditFailed'));
|
||
}
|
||
};
|
||
|
||
/** 关闭版本历史抽屉。 */
|
||
const closeVersionHistory = () => {
|
||
panelState.value = { ...panelState.value, versionHistoryOpen: false };
|
||
};
|
||
|
||
/** 打开审计时间线抽屉(按需加载 timeline)。 */
|
||
const openAuditTrail = () => {
|
||
auditTrailOpen.value = true;
|
||
};
|
||
|
||
/**
|
||
* 收起行内履约摘要。
|
||
*/
|
||
function closeFulfillmentDetail() {
|
||
fulfillmentDetailLineKey.value = null;
|
||
}
|
||
|
||
/** 关闭审计时间线抽屉。 */
|
||
const closeAuditTrail = () => {
|
||
auditTrailOpen.value = false;
|
||
};
|
||
|
||
/**
|
||
* 打开关闭履约行对话框。
|
||
* @param lineKeys - 待关闭行键;空数组表示全部剩余开放行
|
||
*/
|
||
const openCloseFulfillmentDialog = (lineKeys: string[]) => {
|
||
closeFulfillmentLineKeys.value = [...lineKeys];
|
||
closeFulfillmentOpen.value = true;
|
||
};
|
||
|
||
/** 是否在明细表展示库存列(正式 OT 或库存模式)。 */
|
||
const showLineInventoryColumns = computed(() => (
|
||
hasFormalOt.value || workbenchMode.value === 'inventory'
|
||
));
|
||
|
||
/**
|
||
* 按 line_key 取履约投影行。
|
||
*/
|
||
function lineFulfillmentFor(lineKey: string): ShippingOrderReviewLineFulfillmentLine | null {
|
||
const rows = displayCase.value?.line_fulfillment?.lines || [];
|
||
return rows.find((item) => String(item.line_key) === String(lineKey)) || null;
|
||
}
|
||
|
||
/**
|
||
* 是否为行 Schema 数量字段(qty/quantity)。
|
||
*/
|
||
function isQtySchemaField(field: { field_code?: string }): boolean {
|
||
const code = String(field.field_code || '').trim().toLowerCase();
|
||
return code === 'qty' || code === 'quantity';
|
||
}
|
||
|
||
/**
|
||
* 是否为行 Schema 库存源线索字段(inventory_source_hint,按 field_code 或 fulfillment_role 判定)。
|
||
*/
|
||
function isInventorySourceHintField(field: {
|
||
field_code?: string;
|
||
fulfillment_role?: string;
|
||
}): boolean {
|
||
const code = String(field.field_code || '').trim();
|
||
const role = String(field.fulfillment_role || '').trim();
|
||
return code === 'inventory_source_hint' || role === 'inventory_source_hint';
|
||
}
|
||
|
||
/** 可见行字段中是否已有数量列(用于决定库存列插入点)。 */
|
||
const hasVisibleQtyField = computed(() => (
|
||
visibleLineSchemaFields.value.some((field) => isQtySchemaField(field))
|
||
));
|
||
|
||
/**
|
||
* 缺口展示:库存未就绪时不得显示数字(避免把「待确认」误当成短缺 30)。
|
||
*/
|
||
function displayShortageQty(line: ShippingOrderReviewLineFulfillmentLine | null): string {
|
||
if (!line) return '—';
|
||
if (
|
||
line.display_available === 'pending'
|
||
|| ['preparing', 'mapping_failed', 'source_conflict', 'unavailable', 'invalid_key'].includes(
|
||
String(line.inventory_status || ''),
|
||
)
|
||
|| ['inventory_pending', 'source_conflict', 'invalid', 'auto_fulfill_failed'].includes(
|
||
String(line.user_line_status || ''),
|
||
)
|
||
) {
|
||
return '—';
|
||
}
|
||
if (line.shortage_qty == null || line.shortage_qty === '') return '—';
|
||
return String(line.shortage_qty);
|
||
}
|
||
|
||
/**
|
||
* 只读库存源展示(严格消费后端 inventory_source;禁止前端读取 Case/Task/Gate 或数量推断)。
|
||
* 展示优先级:candidates_frozen 列表 → 非 resolved 的 i18n 状态 → label+code / label / code → 解析中。
|
||
*/
|
||
function displayInventorySource(line: ShippingOrderReviewLineFulfillmentLine | null): string {
|
||
if (!line) return '解析中';
|
||
const source = line?.inventory_source;
|
||
if (!source) return '解析中';
|
||
const status = String(source.status || '').trim();
|
||
// [A1] candidates_frozen 最高优先:跳过 i18n,直接用候选列表拼接(后端已保证三源全空时才回落 resolving)
|
||
if (status === 'candidates_frozen') {
|
||
const candidates = (source as { candidates?: Array<string | { code?: string | null; label?: string | null }> }).candidates ?? [];
|
||
const codes = candidates
|
||
.map((item: string | { code?: string | null; label?: string | null }) => {
|
||
if (typeof item === 'string') return item.trim();
|
||
return String(item?.code ?? item?.label ?? '').trim();
|
||
})
|
||
.filter(Boolean);
|
||
return codes.length ? codes.join('、') : '候选源已冻结';
|
||
}
|
||
// [A2] 其余非 resolved 状态:走 i18n 文案(仅为 resolving/conflict/unrecognized/unavailable 等保留翻译分支)
|
||
if (status && status !== 'resolved') {
|
||
const key = `chat.shippingOrderReview.lineOps.inventorySourceStatus.${status}`;
|
||
if (te(key)) return t(key);
|
||
}
|
||
const label = String(source.label || '').trim();
|
||
const code = String(source?.code || '').trim();
|
||
if (label && code) return `${label}(${code})`;
|
||
if (label) return label;
|
||
if (code) return code;
|
||
return '解析中';
|
||
}
|
||
|
||
/**
|
||
* 可用数量展示:pending → 待确认;短缺标红由模板 class 处理。
|
||
*/
|
||
function displayAvailableQty(line: ShippingOrderReviewLineFulfillmentLine | null): string {
|
||
if (!line) return '—';
|
||
if (line.display_available === 'pending' || line.available_qty == null || line.available_qty === '') {
|
||
return t('chat.shippingOrderReview.lineOps.availablePending');
|
||
}
|
||
return String(line.available_qty);
|
||
}
|
||
|
||
/** Case 级库存兜底卡:统一由当前 Gate 卡提供精确动作。 */
|
||
async function retryCaseInventoryFallback() {
|
||
await retryFormalOtAutoProgress();
|
||
}
|
||
|
||
/**
|
||
* 右侧主卡「定位明细」:滚动到订单行(0-based lineIndex)或字段冲突证据。
|
||
* 优先处理 line_key(从 line_key 解析行索引并滚动),无行号时回滚到字段冲突视图。
|
||
*/
|
||
function handleCurrentTaskLocate(
|
||
lineKey: string | null | undefined,
|
||
fieldId: string | null | undefined,
|
||
) {
|
||
if (lineKey) {
|
||
const draftLines = (activeCase.value?.draft?.lines || []) as Array<{
|
||
line_key?: string | null;
|
||
line_index?: number | null;
|
||
}>;
|
||
const draftLine = draftLines.find(
|
||
(row) => String(row.line_key || '') === String(lineKey),
|
||
);
|
||
if (draftLine?.line_index != null) {
|
||
focusOrderLine(draftLine.line_index);
|
||
return;
|
||
}
|
||
const m = /line[-_:\s]*([0-9]+)$/i.exec(String(lineKey));
|
||
if (m) {
|
||
focusOrderLine(Math.max(0, Number(m[1]) - 1));
|
||
return;
|
||
}
|
||
}
|
||
if (fieldId) {
|
||
const fieldCode = String(fieldId).split('.').pop() || String(fieldId);
|
||
focusFieldConflict({ fieldCode, lineIndex: null, lineKey: null });
|
||
return;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 正式 OT 货代上传 RPA 重试:统一复用任务级 retry 决策器。
|
||
* 核心逻辑:当前前端没有独立 freight-upload-rpa retry API,先走 task retry,
|
||
* 保持按钮可用且给出明确反馈。
|
||
* @param taskNo - 正式 OT 任务号
|
||
*/
|
||
async function retryFormalUploadRpa(taskNo: string) {
|
||
await retryFormalOtAutoProgress(taskNo);
|
||
}
|
||
|
||
/**
|
||
* 右侧主卡「业务动作」分派:禁止自建新动作码,统一按后端 primary_action.code 执行。
|
||
* 动作目标完全映射到现有模式切换与滚动锚点:
|
||
* - open_inventory_source_review → 库存源候选面板
|
||
* - open_inventory_match_review → 库存匹配问题列表
|
||
* - open_order_review → 订单复核(草稿/建单前标准模式)
|
||
* - confirm_customer → 打开客户确认对话框
|
||
* - retry_freight_upload_rpa → 行级货代上传 RPA 重试(正式 OT)
|
||
*/
|
||
async function handleCurrentTaskAction(
|
||
code: string,
|
||
parameters?: Record<string, unknown> | null,
|
||
) {
|
||
const params = (parameters || {}) as Record<string, unknown>;
|
||
switch (code) {
|
||
case 'download_excel': {
|
||
const taskNo = (params.task_no as string | undefined) || confirmedNoticeTaskNo.value;
|
||
if (!taskNo) {
|
||
msg.warning(t('chat.shippingOrderReview.workbench.resultNotReady'));
|
||
return;
|
||
}
|
||
await downloadWorkspaceShippingExcelFile(taskNo);
|
||
msg.success(t('chat.shippingOrderReview.workbench.actionSuccess'));
|
||
break;
|
||
}
|
||
case 'view_result':
|
||
case 'open_fulfillment':
|
||
case 'view_details':
|
||
workbenchMode.value = 'formal_task';
|
||
if (!(await ensureFormalTaskDetailReady())) return;
|
||
await nextTick();
|
||
scrollWorkbenchAnchor('review-formal-task-result-region');
|
||
break;
|
||
case 'open_inventory_source_review':
|
||
if (hasCreatedShippingTask.value) {
|
||
workbenchMode.value = 'formal_task';
|
||
scrollWorkbenchAnchor('review-formal-task-todo-panel');
|
||
await formalTodoPanelRef.value?.invokeActionByCode('confirm_inventory_source');
|
||
} else {
|
||
workbenchMode.value = 'inventory';
|
||
await nextTick();
|
||
scrollWorkbenchAnchor('review-inventory-candidates-panel');
|
||
}
|
||
break;
|
||
case 'open_inventory_match_review':
|
||
if (hasFormalOt.value) {
|
||
scrollWorkbenchAnchor('review-order-lines-table');
|
||
} else {
|
||
workbenchMode.value = 'inventory';
|
||
scrollWorkbenchAnchor('review-inventory-issue-list');
|
||
}
|
||
break;
|
||
case 'open_order_review':
|
||
workbenchMode.value = 'standard';
|
||
scrollWorkbenchAnchor('review-order-lines-table');
|
||
break;
|
||
case 'confirm_customer': {
|
||
const taskNo = (params.task_no as string | undefined)
|
||
|| confirmedNoticeTaskNo.value
|
||
|| authoritativeOrderTaskNo.value;
|
||
if (taskNo && typeof page.openShippingCustomerDialog === 'function') {
|
||
await page.openShippingCustomerDialog(taskNo);
|
||
}
|
||
break;
|
||
}
|
||
case 'retry_freight_upload_rpa': {
|
||
const taskNo = (params.task_no as string | undefined) || confirmedNoticeTaskNo.value;
|
||
if (taskNo) {
|
||
await retryFormalUploadRpa(taskNo);
|
||
}
|
||
break;
|
||
}
|
||
case 'mark_manual_uploaded':
|
||
await formalTodoPanelRef.value?.invokeActionByCode('mark_manual_uploaded');
|
||
break;
|
||
default:
|
||
msg.info(t('chat.shippingOrderReview.currentTask.actionUnknown', { code }));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 行是否允许删除(已入波次/已履约则禁用)。
|
||
*/
|
||
function canDeleteDraftLine(lineKey: string): boolean {
|
||
const lf = lineFulfillmentFor(lineKey);
|
||
if (!lf) return true;
|
||
const status = String(lf.line_status || lf.user_line_status || '');
|
||
return !['task_created', 'fulfilled', 'wave_created'].includes(status);
|
||
}
|
||
|
||
/** 关闭履约成功后刷新 Case。 */
|
||
const onCloseFulfillmentConfirmed = () => {
|
||
closeFulfillmentOpen.value = false;
|
||
closeFulfillmentLineKeys.value = [];
|
||
void reloadLatestDraft();
|
||
};
|
||
|
||
/** 关闭 AI 建议抽屉。 */
|
||
const closeLlmSuggestionDrawer = () => {
|
||
panelState.value = { ...panelState.value, llmSuggestionOpen: false };
|
||
};
|
||
|
||
/** 打开完整建单检查抽屉。 */
|
||
/**
|
||
* 打开完整建单检查抽屉:先写入访问审计,失败则告警并拒绝展示。
|
||
*/
|
||
const openEligibilityDetails = async () => {
|
||
const caseNo = String(activeCase.value?.case_no || '').trim();
|
||
if (!caseNo) return;
|
||
try {
|
||
await auditWorkspaceShippingOrderReviewEligibilityDetails(caseNo);
|
||
panelState.value = { ...panelState.value, eligibilityDetailsOpen: true };
|
||
} catch {
|
||
msg.warning(t('chat.shippingOrderReview.workbench.auditFailed'));
|
||
}
|
||
};
|
||
|
||
/** 关闭完整建单检查抽屉。 */
|
||
const closeEligibilityDetails = () => {
|
||
panelState.value = { ...panelState.value, eligibilityDetailsOpen: false };
|
||
};
|
||
|
||
/**
|
||
* 将视口滚动到订单明细指定行(0-based)。
|
||
*/
|
||
const focusOrderLine = (lineIndex: number) => {
|
||
void nextTick(() => {
|
||
const root = mainEditorScrollEl.value;
|
||
if (!root) return;
|
||
const target = root.querySelector(`[data-review-line-index="${lineIndex}"]`) as HTMLElement | null;
|
||
target?.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 从字段冲突面板定位到对应草稿字段与证据。
|
||
* 核心逻辑:field_code → schema.field_id,再复用 focusFieldEvidence。
|
||
*/
|
||
const focusFieldConflict = (payload: {
|
||
fieldCode: string;
|
||
lineIndex: number | null;
|
||
lineKey: string | null;
|
||
}) => {
|
||
const code = String(payload.fieldCode || '').trim();
|
||
if (!code) return;
|
||
const field = (activeCase.value?.schema.fields || []).find(
|
||
(item) => String(item.field_code || '') === code,
|
||
);
|
||
const fieldId = String(field?.field_id || '').trim();
|
||
if (!fieldId) {
|
||
if (payload.lineIndex != null) focusOrderLine(payload.lineIndex);
|
||
return;
|
||
}
|
||
focusFieldEvidence(fieldId, payload.lineIndex ?? undefined);
|
||
if (payload.lineIndex != null) focusOrderLine(payload.lineIndex);
|
||
};
|
||
|
||
/**
|
||
* 当前证据抽屉字段展示名。
|
||
*/
|
||
const evidenceFieldLabel = computed(() => {
|
||
const fieldId = String(focusedEvidenceRef.value?.fieldId || focusedFieldId.value || '');
|
||
if (!fieldId) return '';
|
||
const field = (activeCase.value?.schema.fields || []).find((item) => item.field_id === fieldId);
|
||
return field?.display_name || fieldId;
|
||
});
|
||
|
||
/**
|
||
* 当前证据对应机器识别值。
|
||
*/
|
||
const evidenceMachineValue = computed(() => {
|
||
const fieldId = String(focusedEvidenceRef.value?.fieldId || focusedFieldId.value || '');
|
||
if (!fieldId || !activeCase.value?.draft) return '';
|
||
const lineIndex = focusedEvidenceRef.value?.lineIndex;
|
||
if (lineIndex != null) {
|
||
const line = activeCase.value.draft.lines?.[lineIndex] as Record<string, unknown> | undefined;
|
||
const machine = Array.isArray(line?.machine_fields) ? line.machine_fields as Array<Record<string, unknown>> : [];
|
||
return machineValueByIdFor(machine, fieldId);
|
||
}
|
||
const headerMachine = Array.isArray(activeCase.value.draft.header_values?.machine_fields)
|
||
? activeCase.value.draft.header_values.machine_fields as Array<Record<string, unknown>>
|
||
: [];
|
||
return machineValueByIdFor(headerMachine, fieldId);
|
||
});
|
||
|
||
/**
|
||
* 当前证据字段来源标签。
|
||
*/
|
||
const evidenceValueSourceLabel = computed(() => {
|
||
const fieldId = String(focusedEvidenceRef.value?.fieldId || focusedFieldId.value || '');
|
||
if (!fieldId || !activeCase.value?.draft) return '';
|
||
const lineIndex = focusedEvidenceRef.value?.lineIndex;
|
||
if (lineIndex != null) {
|
||
const line = activeCase.value.draft.lines?.[lineIndex] as Record<string, unknown> | undefined;
|
||
return valueSourceLabel(draftFieldMeta(line, fieldId).value_source);
|
||
}
|
||
return valueSourceLabel(
|
||
draftFieldMeta(activeCase.value.draft.header_values as Record<string, unknown>, fieldId).value_source,
|
||
);
|
||
});
|
||
|
||
/**
|
||
* 证据抽屉「恢复机器值」:按当前焦点字段写回。
|
||
*/
|
||
const restoreEvidenceMachineValue = () => {
|
||
const fieldId = String(focusedEvidenceRef.value?.fieldId || focusedFieldId.value || '');
|
||
if (!fieldId || !editable.value) return;
|
||
const lineIndex = focusedEvidenceRef.value?.lineIndex;
|
||
if (lineIndex != null) {
|
||
const lineKey = String(activeCase.value?.draft?.lines?.[lineIndex]?.line_key || '');
|
||
if (!lineKey) return;
|
||
void reportSave(() => patchLine(lineKey, fieldId, null, true));
|
||
return;
|
||
}
|
||
void reportSave(() => patchHeader(fieldId, null, true));
|
||
};
|
||
|
||
const canEnterInventory = computed(() => {
|
||
// 正式 OT 后库存动作只在明细行 / Case 兜底卡,禁止切换完整库存工作台。
|
||
if (hasFormalOt.value) return false;
|
||
return (
|
||
(routingRecoveryLines.value?.length ?? 0) > 0
|
||
|| Boolean(activeCase.value?.line_fulfillment?.has_shortage)
|
||
|| Boolean(activeCase.value?.line_fulfillment?.has_open_lines)
|
||
|| Number(activeCase.value?.line_fulfillment?.open_count || 0) > 0
|
||
);
|
||
});
|
||
const availableActions = computed(() => activeCase.value?.available_actions || []);
|
||
|
||
/** 订单处理工作台写权限(只读查看 / Case 切换中为 false)。 */
|
||
const workbenchActionsExecutable = computed(() => (
|
||
!isReadOnly.value
|
||
&& !caseSwitchLoading.value
|
||
&& !progressRetrying.value
|
||
&& !conversationRetrying.value
|
||
));
|
||
|
||
/** 当前 Case 面板可用性,供注册表 requiresPanel 守卫。 */
|
||
const workbenchPanelAvailability = computed((): WorkbenchPanelAvailability => {
|
||
const c = activeCase.value;
|
||
return {
|
||
customerUnresolved: Boolean(c && !c.customer_resolution?.resolved),
|
||
hasFieldConflicts: Boolean((c?.field_conflicts || []).length),
|
||
hasDuplicateAdjudication: Boolean(c?.duplicate?.needs_adjudication),
|
||
hasProfileMatch: Boolean(c?.profile_match?.available),
|
||
hasInventoryCandidates: Boolean((routingRecoveryLines.value || []).length),
|
||
hasInventoryIssues: Boolean(
|
||
(routingRecoveryLines.value || []).length
|
||
|| c?.line_fulfillment?.has_shortage,
|
||
),
|
||
};
|
||
});
|
||
|
||
/** 底栏流程写操作:与原进度条 ActionBar 同源,surface=review。 */
|
||
const flowProjectionRef = computed(() => shippingProcessingProjection.value);
|
||
const flowPresentationOptions = computed(() => ({
|
||
surface: 'review' as const,
|
||
actionsExecutable: workbenchActionsExecutable.value,
|
||
panels: workbenchPanelAvailability.value,
|
||
}));
|
||
const flowPresentation = useProcessingActionPresentation(flowProjectionRef, flowPresentationOptions);
|
||
const flowActionBusy = ref(false);
|
||
const viewResultLoading = ref(false);
|
||
|
||
const customerResolutionPanelRef = ref<{ openSelectDialog: () => Promise<void> } | null>(null);
|
||
const customerResolutionWideRef = ref<{ openSelectDialog: () => Promise<void> } | null>(null);
|
||
const fieldConflictPanelRef = ref<{ focusFirstConflict: () => void } | null>(null);
|
||
const duplicatePanelRef = ref<{ focusAdjudication: () => void } | null>(null);
|
||
|
||
/** 系统自动推进中:仅当存在确认 Job 时隐藏主写按钮;资格达标不算 automating。 */
|
||
const isProcessingAutomating = computed(() => {
|
||
if (!hasConfirmedAutomationJob.value) return false;
|
||
const status = String(shippingProcessingProjection.value?.status || '').trim().toLowerCase();
|
||
return ['processing', 'automating', 'queued'].includes(status)
|
||
&& !shippingProcessingProjection.value?.currentGate?.nextActionCode;
|
||
});
|
||
|
||
/** OT 导航侧栏模式(≥5)时主区并排。 */
|
||
const otNavUsesSidebar = computed(() => (
|
||
otNavMode.value === 'sidebar' || otNavMode.value === 'sidebar_search'
|
||
));
|
||
|
||
/**
|
||
* 导航项:一 PDF 一 Case;当前 Case 附带 PO/客户/阶段(摘要列表无跨 Case 草稿字段)。
|
||
*/
|
||
const documentNavItems = computed(() => {
|
||
const items = reviewRun.value?.items || [];
|
||
const header = activeCase.value?.draft?.header_values as Record<string, unknown> | undefined;
|
||
const activeNo = activeCase.value?.case_no;
|
||
const stage = shippingProcessingProjection.value?.stage;
|
||
const stageLabel = stage
|
||
? resolveShippingProcessingStageLabel(
|
||
stage,
|
||
te,
|
||
t,
|
||
shippingProcessingProjection.value?.stageLabelKey,
|
||
)
|
||
: null;
|
||
return items.map((item) => {
|
||
const isActive = item.case_no === activeNo;
|
||
return {
|
||
...item,
|
||
po_number: isActive ? (String(header?.po_number || '').trim() || null) : null,
|
||
customer_name: isActive ? (String(header?.customer_name || '').trim() || null) : null,
|
||
stage_label: isActive ? stageLabel : null,
|
||
};
|
||
});
|
||
});
|
||
|
||
/** 流程详情标题用 PO。 */
|
||
const processDetailPoNumber = computed(() => {
|
||
const header = activeCase.value?.draft?.header_values as Record<string, unknown> | undefined;
|
||
return String(header?.po_number || shippingProcessingProjection.value?.sourceSummary?.poNumber || '').trim() || null;
|
||
});
|
||
|
||
const isReparsePrimary = computed(() => workbenchMode.value === 'reparse' && reparseProgressActive.value);
|
||
/** 重识别任务存在时常驻展示轨道;轮询结束后保留最终状态,避免用户失去进度上下文。 */
|
||
const hasReparseProgressContext = computed(() => Boolean(
|
||
isReparsePrimary.value
|
||
|| reparseProgressStage.value !== 'submitted'
|
||
|| ['extracting', 'layout_parsing', 'routing', 'matching_profile', 'reparse_failed', 'failed'].includes(String(reviewProgressContext.value?.lifecycle_status || '').trim()),
|
||
));
|
||
const isConfirmProgressPrimary = computed(
|
||
() => workbenchMode.value === 'confirm_progress' && (Boolean(confirmSuccess.value) || showWorkflowProgress.value),
|
||
);
|
||
const showWorkbenchGrid = computed(
|
||
// 重识别:保留原订单上下文。确认后 formal_task 仍展示字段区;仅旧 confirm_progress 隐藏网格。
|
||
() => workbenchMode.value === 'formal_task' || !isConfirmProgressPrimary.value,
|
||
);
|
||
|
||
const headerSchemaFields = computed(() => (displayCase.value?.schema.fields || []).filter((field) => field.scope === 'header'));
|
||
const lineSchemaFields = computed(() => (displayCase.value?.schema.fields || []).filter((field) => field.scope === 'line'));
|
||
|
||
/** Gate 卡片正在表达当前业务阻断时,资格卡只保留建单结论,避免重复叙事。 */
|
||
const hasActiveBusinessGate = computed(() => showHumanBlockingGate.value);
|
||
|
||
/** 正式 OT 已创建(以后端 has_formal_ot 为准;confirmed_task_id 仅作短期展示兜底)。 */
|
||
const hasFormalOt = computed(() => Boolean(
|
||
displayCase.value?.has_formal_ot
|
||
|| (
|
||
displayCase.value?.confirmed_task_id
|
||
&& String(displayCase.value?.confirmed_task_no || '').trim()
|
||
&& !displayCase.value?.task_missing
|
||
),
|
||
));
|
||
|
||
/** 只有 ShippingTask 已实际创建后,才进入库存履约与自动推进展示阶段。 */
|
||
const hasCreatedShippingTask = computed(() => Boolean(
|
||
hasFormalOt.value
|
||
|| displayCase.value?.confirmed_task_id
|
||
|| String(displayCase.value?.confirmed_task_no || '').trim()
|
||
|| String(reviewProgressContext.value?.current_task_no || '').trim(),
|
||
));
|
||
|
||
/** 正式 Notice 编号(SN),供履约写 API / TaskTodoPanel。 */
|
||
const confirmedNoticeTaskNo = computed(() => String(
|
||
displayCase.value?.confirmed_task_no
|
||
|| reviewProgressContext.value?.current_task_no
|
||
|| '',
|
||
).trim());
|
||
|
||
/** 确认后履约待办详情;任务中心不再挂工作台,由本工作台承接。 */
|
||
const formalTaskDetail = ref<ShippingTaskDetail | null>(null);
|
||
const formalTaskDetailLoading = ref(false);
|
||
const manualUploadRegistrationOpen = ref(false);
|
||
|
||
/** 完成态结果摘要:与正式 ShippingTask 详情同源,禁止从进度条重新推导业务结果。 */
|
||
const formalResultLineResults = computed(() => formalTaskDetail.value?.line_results || []);
|
||
const formalResultShortageCount = computed(() => formalResultLineResults.value.filter(
|
||
(line) => Number(line.shortage_qty || 0) > 0 || String(line.line_status || '').toLowerCase() === 'shortage',
|
||
).length);
|
||
const formalResultMatchedCount = computed(() => formalResultLineResults.value.filter(
|
||
(line) => Number(line.shortage_qty || 0) <= 0 && String(line.line_status || '').toLowerCase() !== 'shortage',
|
||
).length);
|
||
const formalResultArtifact = computed(() => formalTaskDetail.value?.export_artifacts?.[0] || null);
|
||
const formalResultCompletedAt = computed(() => (
|
||
formalTaskDetail.value?.upload_attempts?.find((attempt) => String(attempt.status || '').toLowerCase() === 'succeeded')?.finished_at
|
||
|| formalTaskDetail.value?.updated_at
|
||
|| formalTaskDetail.value?.created_at
|
||
|| null
|
||
));
|
||
const formalResultIsCompleted = computed(() => {
|
||
const status = String(formalTaskDetail.value?.process_status || '').toLowerCase();
|
||
return ['completed', 'uploaded', 'closed'].includes(status)
|
||
|| String(formalTaskDetail.value?.upload_status || '').toLowerCase() === 'uploaded';
|
||
});
|
||
|
||
/** 直接在订单复核页打开人工上传登记,避免依赖仅在 formal_task 模式挂载的 TaskTodoPanel ref。 */
|
||
function openManualUploadRegistration() {
|
||
if (!confirmedNoticeTaskNo.value) {
|
||
msg.warning(t('chat.shippingOrderReview.workbench.resultNotReady'));
|
||
return;
|
||
}
|
||
manualUploadRegistrationOpen.value = true;
|
||
}
|
||
|
||
/**
|
||
* 人工上传登记成功后刷新完整工作台状态。
|
||
* 先重新拉取 Review Case(顶部阶段与 Gate 的权威投影),再刷新任务详情和统一处理投影;
|
||
* 不能只刷新 OT 详情,否则登记已落库但页面仍会显示旧的人工上传阻断状态。
|
||
*/
|
||
async function handleManualUploadSuccess() {
|
||
manualUploadRegistrationOpen.value = false;
|
||
await reloadLatestDraft();
|
||
await Promise.all([
|
||
loadFormalTaskDetail(),
|
||
refreshShippingProcessing(),
|
||
]);
|
||
}
|
||
const formalTodoPanelRef = ref<{
|
||
invokeActionByCode: (actionId: string) => Promise<void>;
|
||
openCustomerDialog: () => Promise<void>;
|
||
} | null>(null);
|
||
|
||
/**
|
||
* 拉取确认后的 Notice 履约详情,供 TaskTodoPanel 使用。
|
||
*/
|
||
async function loadFormalTaskDetail() {
|
||
const taskNo = confirmedNoticeTaskNo.value;
|
||
if (!taskNo) {
|
||
formalTaskDetail.value = null;
|
||
return;
|
||
}
|
||
formalTaskDetailLoading.value = true;
|
||
try {
|
||
formalTaskDetail.value = await getWorkspaceShippingTask(taskNo);
|
||
} catch {
|
||
formalTaskDetail.value = null;
|
||
} finally {
|
||
formalTaskDetailLoading.value = false;
|
||
}
|
||
}
|
||
|
||
watch(
|
||
[confirmedNoticeTaskNo, workbenchMode, hasCreatedShippingTask],
|
||
([taskNo, mode, created]) => {
|
||
const completed = String(displayCase.value?.current_stage?.code || '').trim().toLowerCase() === 'completed'
|
||
|| String(displayCase.value?.user_status || '').trim().toLowerCase() === 'completed';
|
||
if (taskNo && created && (mode === 'formal_task' || mode === 'confirm_progress' || completed)) {
|
||
void loadFormalTaskDetail();
|
||
return;
|
||
}
|
||
if (!taskNo) formalTaskDetail.value = null;
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
/** Schema 字段显示名同时按 field_code / field_id 建索引,避免阻断只显示内部标识。 */
|
||
const reviewFieldLabels = computed(() => Object.fromEntries(
|
||
(displayCase.value?.schema.fields || []).flatMap((field) => [
|
||
[field.field_code, field.display_name],
|
||
[field.field_id, field.display_name],
|
||
]),
|
||
));
|
||
|
||
const showAllHeaderFields = ref(false);
|
||
const showAllLineFields = ref(false);
|
||
|
||
/**
|
||
* 判断字段是否应默认展示(必填 / 异常 / 有值 / 人工修改)。
|
||
* @param field - Schema 字段
|
||
* @param scope - header | line
|
||
* @param line - 行容器(行级判断时传入)
|
||
*/
|
||
function isPrimarySchemaField(
|
||
field: { field_id: string; required?: boolean },
|
||
scope: 'header' | 'line',
|
||
line?: Record<string, unknown>,
|
||
): boolean {
|
||
if (field.required) return true;
|
||
const fieldId = String(field.field_id || '').trim();
|
||
if (!fieldId) return false;
|
||
if (exceptionTargets.value.some((item) => item.fieldId === fieldId)) return true;
|
||
if (scope === 'header') {
|
||
const header = displayCase.value?.draft?.header_values as Record<string, unknown> | undefined;
|
||
const value = String(draftValue(header || {}, fieldId) || '').trim();
|
||
if (value) return true;
|
||
const meta = draftFieldMeta(header, fieldId);
|
||
return String(meta.value_source || '') === 'manual';
|
||
}
|
||
const container = (line || {}) as Record<string, unknown>;
|
||
const value = String(draftValue(container, fieldId) || '').trim();
|
||
if (value) return true;
|
||
return String(draftFieldMeta(container, fieldId).value_source || '') === 'manual';
|
||
}
|
||
|
||
const visibleHeaderSchemaFields = computed(() => {
|
||
const all = headerSchemaFields.value;
|
||
if (showAllHeaderFields.value) return all;
|
||
const primary = all.filter((field) => isPrimarySchemaField(field, 'header'));
|
||
return primary.length ? primary : all.slice(0, Math.min(4, all.length));
|
||
});
|
||
|
||
const hiddenHeaderFieldCount = computed(
|
||
() => Math.max(0, headerSchemaFields.value.length - visibleHeaderSchemaFields.value.length),
|
||
);
|
||
|
||
const visibleLineSchemaFields = computed(() => {
|
||
const all = lineSchemaFields.value;
|
||
if (showAllLineFields.value) return all;
|
||
const lines = displayDraftLines.value as Array<Record<string, unknown>>;
|
||
const primary = all.filter((field) => (
|
||
lines.some((line) => isPrimarySchemaField(field, 'line', line))
|
||
|| isPrimarySchemaField(field, 'line')
|
||
));
|
||
return primary.length ? primary : all.slice(0, Math.min(4, all.length));
|
||
});
|
||
|
||
const hiddenLineFieldCount = computed(
|
||
() => Math.max(0, lineSchemaFields.value.length - visibleLineSchemaFields.value.length),
|
||
);
|
||
|
||
const linesTableMinWidthClass = computed(() => {
|
||
const cols = visibleLineSchemaFields.value.length;
|
||
if (cols <= 3) return 'min-w-[36rem]';
|
||
if (cols <= 5) return 'min-w-[48rem]';
|
||
return 'min-w-[56rem]';
|
||
});
|
||
|
||
/** 明细表列数(含库存插入列与操作列),供履约摘要 rowspan/colspan。 */
|
||
const linesTableColumnCount = computed(() => {
|
||
let count = 1 + visibleLineSchemaFields.value.length + 1; // # + schema + ops
|
||
if (!showLineInventoryColumns.value) return count;
|
||
count += 1; // inventory source only(available/shortage 已由 qty 字段计入)
|
||
if (hasVisibleQtyField.value) {
|
||
count += visibleLineSchemaFields.value.filter((field) => isQtySchemaField(field)).length * 2;
|
||
} else {
|
||
count += 2;
|
||
}
|
||
return count;
|
||
});
|
||
|
||
/**
|
||
* 履约摘要展示用正式任务号。
|
||
*/
|
||
const fulfillmentDetailTaskNo = computed(() => String(
|
||
activeCase.value?.confirmed_task_no
|
||
|| authoritativeOrderTaskNo.value
|
||
|| reviewProgressContext.value?.current_task_no
|
||
|| '',
|
||
).trim());
|
||
const machineValue = (field: Record<string, unknown>) => {
|
||
const observations = Array.isArray(field.observations) ? field.observations as Array<Record<string, unknown>> : [];
|
||
return String(observations[0]?.value || t('chat.shippingOrderReview.emptyValue'));
|
||
};
|
||
const draftValue = (container: Record<string, unknown>, fieldId: string) => {
|
||
const values = container.values as Record<string, { value?: unknown }> | undefined;
|
||
if (values?.[fieldId] && 'value' in values[fieldId]) return String(values[fieldId].value ?? '');
|
||
const machine = Array.isArray(container.machine_fields) ? container.machine_fields as Array<Record<string, unknown>> : [];
|
||
return machineValueByIdFor(machine, fieldId);
|
||
};
|
||
|
||
/**
|
||
* 当前聚焦字段的草稿值,供 LLM 建议面板做三方对比。
|
||
*/
|
||
const focusedLlmDraftValue = computed(() => {
|
||
const fieldId = String(focusedFieldId.value || '');
|
||
if (!fieldId || !activeCase.value?.draft) return null;
|
||
const lineKey = focusedLineKey.value;
|
||
if (lineKey) {
|
||
const line = (activeCase.value.draft.lines || []).find(
|
||
(item) => String((item as { line_key?: string }).line_key || '') === String(lineKey),
|
||
);
|
||
if (!line) return null;
|
||
return draftValue(line as Record<string, unknown>, fieldId);
|
||
}
|
||
const header = activeCase.value.draft.header_values as Record<string, unknown> | undefined;
|
||
return header ? draftValue(header, fieldId) : null;
|
||
});
|
||
|
||
/**
|
||
* 读取投影字段元数据(值来源 / 锁定 / 覆盖原因)。
|
||
* @param container - 表头或明细草稿容器
|
||
* @param fieldId - Schema field_id
|
||
*/
|
||
const draftFieldMeta = (
|
||
container: Record<string, unknown> | undefined,
|
||
fieldId: string,
|
||
): ShippingOrderReviewDraftFieldMeta => {
|
||
const metaMap = container?.field_meta as Record<string, ShippingOrderReviewDraftFieldMeta> | undefined;
|
||
if (metaMap?.[fieldId]) return metaMap[fieldId];
|
||
const values = container?.values as Record<string, { source?: string; locked?: boolean }> | undefined;
|
||
const entry = values?.[fieldId];
|
||
if (entry && typeof entry === 'object') {
|
||
const source = String(entry.source || 'manual') as ShippingOrderReviewValueSource;
|
||
return { value_source: source, locked: Boolean(entry.locked) };
|
||
}
|
||
return { value_source: 'machine', locked: false };
|
||
};
|
||
|
||
/**
|
||
* 将 value_source 映射为复核页来源文案。
|
||
* @param source - 后端投影来源枚举
|
||
*/
|
||
const valueSourceLabel = (source?: ShippingOrderReviewValueSource | string) => {
|
||
const normalized = String(source || 'machine');
|
||
const key = `chat.shippingOrderReview.valueSources.${normalized}`;
|
||
return te(key) ? t(key) : t('chat.shippingOrderReview.valueSources.machine');
|
||
};
|
||
|
||
/**
|
||
* 组装字段血缘/覆盖详情说明,供来源徽章 title 与无障碍文案。
|
||
* @param meta - 投影字段元数据
|
||
*/
|
||
const fieldMetaDetail = (meta: ShippingOrderReviewDraftFieldMeta) => {
|
||
return fieldMetaLineageRows(meta)
|
||
.map((row) => `${row.label}: ${row.value}`)
|
||
.join(' · ');
|
||
};
|
||
|
||
/**
|
||
* 将 field_meta 拆成结构化血缘行,供 line_no 来源徽章浮层展示。
|
||
* @param meta - 投影字段元数据
|
||
*/
|
||
const fieldMetaLineageRows = (meta: ShippingOrderReviewDraftFieldMeta) => {
|
||
const rows: Array<{ label: string; value: string }> = [
|
||
{
|
||
label: t('chat.shippingOrderReview.lineage.source'),
|
||
value: valueSourceLabel(meta.value_source),
|
||
},
|
||
];
|
||
if (meta.locked) {
|
||
rows.push({
|
||
label: t('chat.shippingOrderReview.lineage.locked'),
|
||
value: t('chat.shippingOrderReview.lockedHint'),
|
||
});
|
||
}
|
||
if (meta.override_reason_code) {
|
||
const reasonKey = `chat.shippingOrderReview.lineNoOverrideDialog.reasons.${meta.override_reason_code}`;
|
||
rows.push({
|
||
label: t('chat.shippingOrderReview.lineage.overrideReason'),
|
||
value: te(reasonKey) ? t(reasonKey) : meta.override_reason_code,
|
||
});
|
||
}
|
||
if (meta.override_reason_text) {
|
||
rows.push({
|
||
label: t('chat.shippingOrderReview.lineage.overrideNote'),
|
||
value: meta.override_reason_text,
|
||
});
|
||
}
|
||
if (meta.derivation?.source_field_code) {
|
||
rows.push({
|
||
label: t('chat.shippingOrderReview.lineage.derivedFrom'),
|
||
value: String(meta.derivation.source_field_code),
|
||
});
|
||
}
|
||
if (meta.derivation?.rule_id) {
|
||
rows.push({
|
||
label: t('chat.shippingOrderReview.lineage.ruleId'),
|
||
value: String(meta.derivation.rule_id),
|
||
});
|
||
}
|
||
if (meta.derivation?.skip_reason) {
|
||
rows.push({
|
||
label: t('chat.shippingOrderReview.lineage.skipReason'),
|
||
value: String(meta.derivation.skip_reason),
|
||
});
|
||
}
|
||
return rows;
|
||
};
|
||
|
||
const machineValueByIdFor = (fields: Array<Record<string, unknown>>, fieldId: string) => {
|
||
const field = fields.find((item) => String(item.field_id || '') === fieldId);
|
||
return field ? machineValue(field) : '';
|
||
};
|
||
const statusBannerText = computed(() => {
|
||
if (!statusMessage.value) return '';
|
||
const key = `chat.shippingOrderReview.statusBanner.${statusMessage.value}`;
|
||
return te(key) ? t(key) : t('chat.shippingOrderReview.statusBanner.unknown');
|
||
});
|
||
|
||
/** 重识别阶段顺序;仅展示后端状态,不推算虚假百分比。 */
|
||
const reparseProgressStages = [
|
||
'submitted', 'layout_parsing', 'routing', 'extracting', 'validating',
|
||
'draft_ready', 'auto_confirming', 'building_order', 'inventory_matching',
|
||
'generating_excel', 'awaiting_manual_action', 'completed',
|
||
] as const;
|
||
const reparseProgressIndex = computed(() => (
|
||
reparseProgressStage.value === 'failed' || reparseProgressStage.value === 'interrupted'
|
||
? reparseProgressStages.indexOf(reparseLastStableStage.value)
|
||
: reparseProgressStages.indexOf(reparseProgressStage.value)
|
||
));
|
||
/** 已经完成的节点边界;草稿已生成/终态时当前节点也应显示勾号。 */
|
||
const reparseCompletedIndex = computed(() => {
|
||
const terminalStage = ['draft_ready', 'completed'].includes(reparseProgressStage.value);
|
||
return reparseProgressIndex.value + (terminalStage ? 1 : 0);
|
||
});
|
||
const reparseFailed = computed(() => ['failed', 'interrupted'].includes(reparseProgressStage.value));
|
||
const reparseStatusLabel = computed(() => {
|
||
const key = `chat.shippingOrderReview.reparseProgress.status.${reparseRunStatus.value}`;
|
||
if (te(key)) return t(key);
|
||
const fallback: Record<string, string> = {
|
||
queued: '排队中',
|
||
processing: '正在处理',
|
||
completed: '已完成',
|
||
partially_completed: '部分文件需要处理',
|
||
review_required: '识别完成,等待处理',
|
||
failed: '处理失败',
|
||
cancelled: '已取消',
|
||
};
|
||
return fallback[reparseRunStatus.value] || '处理中';
|
||
});
|
||
const reparseStageLabel = (stage: string) => {
|
||
const key = `chat.shippingOrderReview.reparseProgress.stages.${stage}`;
|
||
if (te(key)) return t(key);
|
||
if (stage === 'interrupted') return t('chat.shippingOrderReview.reparseProgress.interrupted');
|
||
if (stage === 'failed') return t('chat.shippingOrderReview.reparseProgress.failed');
|
||
return stage;
|
||
};
|
||
const reparseInterruptionReason = computed(() => {
|
||
if (reparseProgressRefreshFailed.value) return t('chat.shippingOrderReview.reparseProgress.interruptionReasons.refreshFailed');
|
||
if (reparseRunStatus.value === 'cancelled') return t('chat.shippingOrderReview.reparseProgress.interruptionReasons.cancelled');
|
||
if (reparseRunStatus.value === 'failed') return t('chat.shippingOrderReview.reparseProgress.interruptionReasons.runFailed');
|
||
return t('chat.shippingOrderReview.reparseProgress.interruptionReasons.noProgress');
|
||
});
|
||
const reparseLastActivityLabel = computed(() => {
|
||
const value = reparseLastActivityAt.value;
|
||
if (!value) return '';
|
||
const date = new Date(value);
|
||
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
||
});
|
||
const reparseLastRefreshedLabel = computed(() => {
|
||
const value = reparseLastRefreshedAt.value;
|
||
if (!value) return '';
|
||
const date = new Date(value);
|
||
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
||
});
|
||
const reviewProgressVersionLabel = computed(() => {
|
||
const versionNo = reviewProgressContext.value?.displayed_version?.version_no
|
||
?? reviewProgressContext.value?.current_version_no;
|
||
if (!versionNo) return '';
|
||
return t('chat.shippingSessionWorkItem.versionLabel', { version: versionNo });
|
||
});
|
||
const reparseFailedVersionNotice = computed(() => {
|
||
const item = reviewProgressContext.value;
|
||
const displayed = item?.displayed_version;
|
||
const latest = item?.latest_attempt;
|
||
if (item?.lifecycle_status !== 'reparse_failed' || !displayed || !latest) return '';
|
||
const stageKey = `chat.shippingOrderReview.reparseFailedVersion.stages.${latest.failure_stage}`;
|
||
const stage = latest.failure_stage && te(stageKey)
|
||
? t(stageKey)
|
||
: (latest.failure_stage || t('chat.shippingOrderReview.reparseFailedVersion.unknownStage'));
|
||
return t('chat.shippingOrderReview.reparseFailedVersion.notice', {
|
||
failedVersion: latest.version_no,
|
||
stage,
|
||
displayedVersion: displayed.version_no,
|
||
});
|
||
});
|
||
|
||
const pendingAction = ref<ReviewConfirmAction | null>(null);
|
||
const pendingReplaceFile = ref<File | null>(null);
|
||
const actionDialogOpen = ref(false);
|
||
const lineNoOverrideOpen = ref(false);
|
||
const pendingLineNoEdit = ref<{ lineKey: string; fieldId: string; value: string } | null>(null);
|
||
|
||
/**
|
||
* 正式 OT 用户侧重试:POST /shipping-tasks/<taskNo>/retry(统一决策器)。
|
||
* 核心逻辑:禁止再调 auto-progress;task_missing 或无 task_no 时不请求。
|
||
* 题9A:响应 reason_code == already_running → 写本地冷却 + 琥珀提示而不是 success,避免「投影 refresh 延迟期间重复点击」。
|
||
* @param preferredTaskNo - 可选任务号覆盖
|
||
*/
|
||
const retryFormalOtAutoProgress = async (preferredTaskNo?: string | null) => {
|
||
if (
|
||
Boolean(activeCase.value?.task_missing)
|
||
|| progressRetrying.value
|
||
|| caseSwitchLoading.value
|
||
) return;
|
||
const taskNo = String(
|
||
preferredTaskNo
|
||
|| formalOtRetryTaskNo.value
|
||
|| confirmSuccess.value?.taskNo
|
||
|| '',
|
||
).trim();
|
||
if (!taskNo) return;
|
||
// 题9A:请求前再次确认投影层 already_running(或冷却期内),直接拦截不发请求。
|
||
if (taskRetryButtonDisabled.value) {
|
||
if (taskInventoryPreparationRunning.value || isTaskRunningCooldownActive(taskNo)) {
|
||
msg.warning(t('chat.shippingOrderReview.autoProgress.alreadyRunning', { taskNo }));
|
||
}
|
||
return;
|
||
}
|
||
progressRetrying.value = true;
|
||
try {
|
||
const result = await retryWorkspaceShippingTask(taskNo);
|
||
const status = String(result?.status || 'ok');
|
||
const reasonCode = String(result?.reason_code || '').trim().toLowerCase();
|
||
// 题9A:no-op already_running 专用分支:不写 progressFailed=false(失败/成功都不是),写冷却 10s
|
||
if (status === 'noop' && reasonCode === 'already_running') {
|
||
markTaskRunningCooldown(taskNo, TASK_RUNNING_COOLDOWN_MS);
|
||
msg.warning(String(result?.message || t('chat.shippingOrderReview.autoProgress.alreadyRunning', { taskNo })));
|
||
void refreshShippingProcessing();
|
||
return;
|
||
}
|
||
const progressFailed = ['failed', 'enqueue_failed', 'sync_execution_failed'].includes(status);
|
||
if (confirmSuccess.value?.taskNo === taskNo || confirmSuccess.value) {
|
||
const outcome = confirmSuccess.value;
|
||
if (outcome) {
|
||
confirmSuccess.value = {
|
||
...outcome,
|
||
taskNo: outcome.taskNo || taskNo,
|
||
autoProgress: true,
|
||
progressFailed,
|
||
progressStatus: status,
|
||
progressMessage: String(result?.message || ''),
|
||
checkpoint: String(result?.checkpoint || outcome.checkpoint || ''),
|
||
};
|
||
}
|
||
}
|
||
if (progressFailed) {
|
||
msg.warning(t('chat.shippingOrderReview.confirmProgressFailed', { taskNo }));
|
||
} else if (status === 'needs_human') {
|
||
msg.warning(String(result?.message || t('chat.shippingOrderReview.autoProgress.status.needs_human')));
|
||
} else {
|
||
msg.success(
|
||
taskInventoryExhaustedSources.value.length > 0
|
||
? t('chat.shippingOrderReview.autoProgress.retrySuccessWithExhausted', {
|
||
taskNo,
|
||
sources: taskInventoryExhaustedSources.value.join(', '),
|
||
})
|
||
: t('chat.shippingOrderReview.autoProgress.retrySuccess'),
|
||
);
|
||
}
|
||
await reloadLatestDraft();
|
||
await refreshShippingProcessing();
|
||
} catch (error) {
|
||
msg.error(resolveReviewErrorMessage(error));
|
||
} finally {
|
||
progressRetrying.value = false;
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 底栏对象级「重试」兜底:正式 OT 走统一 /retry;建单前走 STP。
|
||
*/
|
||
const onFooterRetryAutomation = async () => {
|
||
if (hasFormalOt.value) {
|
||
await retryFormalOtAutoProgress();
|
||
return;
|
||
}
|
||
await retryStpAutoCreate();
|
||
};
|
||
|
||
/**
|
||
* STP 自动建单失败 / manual_fallback:调用专用 retry API 重新入队。
|
||
* 核心逻辑:与确认后 auto_progress 重试分离;成功后刷新 Case 投影。
|
||
*/
|
||
const retryStpAutoCreate = async () => {
|
||
const caseNo = String(activeCase.value?.case_no || '').trim();
|
||
if (!caseNo || progressRetrying.value || caseSwitchLoading.value) return;
|
||
progressRetrying.value = true;
|
||
try {
|
||
const result = await retryWorkspaceShippingOrderStpAutoCreate(caseNo);
|
||
if (result.case) {
|
||
activeCase.value = result.case;
|
||
} else {
|
||
await reloadLatestDraft();
|
||
}
|
||
msg.success(t('chat.shippingOrderReview.autoProgress.retryStpSuccess'));
|
||
} catch (error) {
|
||
msg.error(resolveReviewErrorMessage(error));
|
||
} finally {
|
||
progressRetrying.value = false;
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 对话级「重试自动推进」:扫描会话下可恢复 Case/正式 OT。
|
||
* 核心逻辑:调用 retryWorkspaceConversationAutoProgress;以内嵌摘要展示逐项结果;刷新草稿与处理投影。
|
||
*/
|
||
const retryConversationAutoProgress = async () => {
|
||
const id = String(conversationId.value || '').trim();
|
||
if (!id || conversationRetrying.value || !showConversationRetry.value) return;
|
||
if (caseSwitchLoading.value || progressRetrying.value) return;
|
||
conversationRetrying.value = true;
|
||
conversationRetryError.value = '';
|
||
try {
|
||
const result = await retryWorkspaceConversationAutoProgress(id);
|
||
conversationRetryResult.value = {
|
||
summary: result.summary,
|
||
items: result.items || [],
|
||
};
|
||
// 结果只以短暂提示反馈;逐项详情由用户主动打开右侧抽屉,避免占用复核主内容。
|
||
showConversationRetryToast();
|
||
await reloadLatestDraft();
|
||
await refreshShippingProcessing();
|
||
} catch (error) {
|
||
// 批量动作失败只影响本次扫描;错误以内嵌提示展示,避免 toast 遮挡并允许继续切换任务。
|
||
conversationRetryError.value = resolveReviewErrorMessage(error);
|
||
showConversationRetryToast();
|
||
} finally {
|
||
conversationRetrying.value = false;
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 滚动到工作台锚点(data-testid)。
|
||
*/
|
||
function scrollWorkbenchAnchor(testId: string | null | undefined) {
|
||
const id = String(testId || '').trim();
|
||
if (!id) return;
|
||
void nextTick(() => {
|
||
document
|
||
.querySelector(`[data-testid="${id}"]`)
|
||
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 确保正式任务详情已加载且身份一致,再委托 TaskTodoPanel。
|
||
*
|
||
* @returns 是否可继续 invoke
|
||
*/
|
||
async function ensureFormalTaskDetailReady(): Promise<boolean> {
|
||
const taskNo = confirmedNoticeTaskNo.value;
|
||
if (!taskNo) {
|
||
msg.warning(t('chat.shippingOrderReview.workbench.resultNotReady'));
|
||
return false;
|
||
}
|
||
if (!formalTaskDetail.value || formalTaskDetail.value.task_no !== taskNo) {
|
||
await loadFormalTaskDetail();
|
||
}
|
||
if (!formalTaskDetail.value || formalTaskDetail.value.task_no !== taskNo) {
|
||
msg.warning(t('chat.shippingOrderReview.workbench.resultNotReady'));
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 统一动作栏点击:经注册表派发到显式执行器(禁止散落 if / Gate POST / 盲调 API)。
|
||
*/
|
||
const onUnifiedProcessingAction = async (item: ActionPresentationItem) => {
|
||
if (flowActionBusy.value) return;
|
||
// 建单后库存源别名须解析为 todo_panel,禁止再走候选面板。
|
||
const entry = resolveWorkbenchActionItem(item, {
|
||
postCreate: hasCreatedShippingTask.value,
|
||
});
|
||
if (!entry) {
|
||
return;
|
||
}
|
||
if (entry.isWrite && !workbenchActionsExecutable.value) {
|
||
return;
|
||
}
|
||
|
||
flowActionBusy.value = true;
|
||
try {
|
||
const behavior = entry.reviewBehavior;
|
||
|
||
if (behavior === 'hidden_on_review' || behavior === 'refresh_strip_only') {
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'open_customer_dialog') {
|
||
// [A1] 先滚动客户面板,再打开既有确认弹窗;禁止直调确认 API。
|
||
scrollWorkbenchAnchor(entry.scrollTestId || 'review-customer-resolution-panel');
|
||
const taskNo = String(
|
||
confirmedNoticeTaskNo.value
|
||
|| activeCase.value?.confirmed_task_no
|
||
|| activeCase.value?.order_task_no
|
||
|| authoritativeOrderTaskNo.value
|
||
|| '',
|
||
).trim();
|
||
if (taskNo && typeof page.openShippingCustomerDialog === 'function') {
|
||
await page.openShippingCustomerDialog(taskNo);
|
||
return;
|
||
}
|
||
const panel = customerResolutionWideRef.value || customerResolutionPanelRef.value;
|
||
if (panel?.openSelectDialog) {
|
||
await panel.openSelectDialog();
|
||
return;
|
||
}
|
||
msg.warning(t('chat.shippingOrderReview.workbench.resultNotReady'));
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'focus_field_conflicts') {
|
||
scrollWorkbenchAnchor(entry.scrollTestId || 'review-field-conflict-panel');
|
||
if (fieldConflictPanelRef.value?.focusFirstConflict) {
|
||
fieldConflictPanelRef.value.focusFirstConflict();
|
||
} else {
|
||
const first = activeCase.value?.field_conflicts?.[0];
|
||
if (first) {
|
||
focusFieldConflict({
|
||
fieldCode: first.field_code,
|
||
lineIndex: first.line_index ?? null,
|
||
lineKey: first.line_key ?? null,
|
||
});
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'focus_duplicate_panel') {
|
||
scrollWorkbenchAnchor(entry.scrollTestId || 'review-duplicate-panel');
|
||
duplicatePanelRef.value?.focusAdjudication?.();
|
||
void nextTick(() => {
|
||
document
|
||
.querySelector('[data-testid="review-duplicate-actions"]')
|
||
?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||
});
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'focus_profile_panel') {
|
||
void router.replace({ query: { ...route.query, focus: 'profile' } });
|
||
scrollWorkbenchAnchor(entry.scrollTestId || 'review-profile-match-panel');
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'open_inventory_candidates') {
|
||
// [B1] 仅建单前:进入库存模式并定位候选面板;禁止 TaskTodoPanel / 正式 OT API。
|
||
// 建单后由 resolveWorkbenchActionItem(postCreate) 改写为 todo_panel。
|
||
if (hasCreatedShippingTask.value) {
|
||
workbenchMode.value = 'formal_task';
|
||
if (!(await ensureFormalTaskDetailReady())) return;
|
||
scrollWorkbenchAnchor('review-formal-task-todo-panel');
|
||
await formalTodoPanelRef.value?.invokeActionByCode('confirm_inventory_source');
|
||
return;
|
||
}
|
||
workbenchMode.value = 'inventory';
|
||
await nextTick();
|
||
scrollWorkbenchAnchor(entry.scrollTestId || 'review-inventory-candidates-panel');
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'focus_inventory_issues') {
|
||
// 正式 OT 后禁止切完整库存工作台;仅滚动到明细 / 兜底卡。
|
||
if (hasFormalOt.value) {
|
||
scrollWorkbenchAnchor(entry.scrollTestId || 'review-order-lines-table');
|
||
return;
|
||
}
|
||
workbenchMode.value = 'inventory';
|
||
scrollWorkbenchAnchor(entry.scrollTestId || 'review-inventory-issue-list');
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'view_result') {
|
||
// [C1] 详情未返回时先 loading + loadFormalTaskDetail,身份匹配后再定位结果区。
|
||
viewResultLoading.value = true;
|
||
try {
|
||
workbenchMode.value = 'formal_task';
|
||
const expectedTaskNo = String(confirmedNoticeTaskNo.value || '').trim();
|
||
if (expectedTaskNo) {
|
||
const ready = await ensureFormalTaskDetailReady();
|
||
if (!ready) return;
|
||
if (String(formalTaskDetail.value?.task_no || '').trim() !== expectedTaskNo) {
|
||
msg.warning(t('chat.shippingOrderReview.workbench.resultNotReady'));
|
||
return;
|
||
}
|
||
}
|
||
await nextTick();
|
||
const resultEl = document.querySelector('[data-testid="review-formal-task-result-region"]');
|
||
if (resultEl) {
|
||
resultEl.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||
msg.info(t('chat.shippingOrderReview.workbench.actionSuccess'));
|
||
} else {
|
||
scrollWorkbenchAnchor('review-formal-task-todo-panel');
|
||
msg.info(t('chat.shippingOrderReview.workbench.resultNotReady'));
|
||
}
|
||
} finally {
|
||
viewResultLoading.value = false;
|
||
}
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'view_record') {
|
||
openAuditTrail();
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'download') {
|
||
if (!confirmedNoticeTaskNo.value) {
|
||
msg.warning(t('chat.shippingOrderReview.workbench.resultNotReady'));
|
||
return;
|
||
}
|
||
await downloadWorkspaceShippingExcelFile(confirmedNoticeTaskNo.value);
|
||
await loadFormalTaskDetail();
|
||
await refreshShippingProcessing();
|
||
msg.success(t('chat.shippingOrderReview.workbench.actionSuccess'));
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'retry') {
|
||
await retryFormalOtAutoProgress();
|
||
await refreshShippingProcessing();
|
||
return;
|
||
}
|
||
|
||
if (behavior === 'todo_panel') {
|
||
const todoCode = entry.todoActionCode || item.actionCode;
|
||
if (todoCode === 'mark_manual_uploaded') {
|
||
openManualUploadRegistration();
|
||
return;
|
||
}
|
||
workbenchMode.value = 'formal_task';
|
||
if (!(await ensureFormalTaskDetailReady())) return;
|
||
scrollWorkbenchAnchor(entry.scrollTestId || 'review-formal-task-todo-panel');
|
||
await formalTodoPanelRef.value?.invokeActionByCode(todoCode);
|
||
return;
|
||
}
|
||
} catch (error: unknown) {
|
||
msg.warning(error instanceof Error ? error.message : t('errors.generic'));
|
||
} finally {
|
||
flowActionBusy.value = false;
|
||
}
|
||
};
|
||
|
||
const reportSave = async (action: () => Promise<unknown> | null) => {
|
||
try { await action(); }
|
||
catch (error) {
|
||
const message = resolveReviewErrorMessage(error);
|
||
msg.error(message);
|
||
}
|
||
};
|
||
const reportDisposition = async (action: () => Promise<unknown> | null) => {
|
||
try { await action(); }
|
||
catch (error) {
|
||
const message = resolveReviewErrorMessage(error);
|
||
msg.error(message);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 将复核写路径错误映射为用户可见文案;建单资格阻断使用专用 i18n。
|
||
*/
|
||
const resolveReviewErrorMessage = (error: unknown) => {
|
||
if (error instanceof BusinessError && error.code === REVIEW_BUILD_ELIGIBILITY_BLOCKED) {
|
||
return t('chat.shippingOrderReview.buildEligibility.confirmBlocked');
|
||
}
|
||
return error instanceof BusinessError ? error.message : t('errors.generic');
|
||
};
|
||
|
||
/**
|
||
* 提交行级人工库存源候选并刷新 build_eligibility。
|
||
*/
|
||
const submitInventoryCandidates = async (payload: { lineKey: string; sourceCodes: string[]; reason: string }) => {
|
||
await reportSave(() => setLineInventoryCandidates(payload.lineKey, payload.sourceCodes, payload.reason));
|
||
};
|
||
|
||
/**
|
||
* 重新匹配库存路由(行级或整单);进度复用 saving。
|
||
*/
|
||
const onInventoryRoutingReroute = async (lineKey?: string) => {
|
||
await reportSave(() => rerouteInventoryRouting(lineKey));
|
||
};
|
||
|
||
/**
|
||
* 采纳待决规则建议。
|
||
*/
|
||
const onInventoryRoutingAdopt = async (payload: { lineKey: string; reason?: string }) => {
|
||
await reportSave(() => adoptInventoryRoutingSuggestion(payload.lineKey, payload.reason));
|
||
};
|
||
|
||
/**
|
||
* 保留当前人工库存路由结果。
|
||
*/
|
||
const onInventoryRoutingKeep = async (payload: { lineKey: string; reason?: string }) => {
|
||
await reportSave(() => keepManualInventoryRouting(payload.lineKey, payload.reason));
|
||
};
|
||
|
||
/** 打开指定类型的二次确认弹窗。 */
|
||
const openActionDialog = (action: ReviewConfirmAction) => {
|
||
pendingAction.value = action;
|
||
actionDialogOpen.value = true;
|
||
};
|
||
|
||
/**
|
||
* 明细字段变更:内部项次 line_no 走覆盖原因弹窗,其余字段直接 patch。
|
||
* @param line - 当前明细行
|
||
* @param field - Schema 字段
|
||
* @param value - 输入框新值
|
||
*/
|
||
const onLineFieldChange = (
|
||
line: Record<string, unknown>,
|
||
field: { field_id: string; field_code: string },
|
||
value: string,
|
||
) => {
|
||
const lineKey = String(line.line_key || '');
|
||
if (!lineKey) return;
|
||
if (field.field_code === 'line_no') {
|
||
pendingLineNoEdit.value = { lineKey, fieldId: field.field_id, value };
|
||
lineNoOverrideOpen.value = true;
|
||
return;
|
||
}
|
||
void reportSave(() => patchLine(lineKey, field.field_id, value));
|
||
};
|
||
|
||
/**
|
||
* 内部项次输入中:立即记录待提交值,提示尚未保存,失焦后再弹覆盖原因。
|
||
* @param line - 当前明细行
|
||
* @param field - Schema 字段
|
||
* @param value - 当前输入
|
||
*/
|
||
const onLineNoInput = (
|
||
line: Record<string, unknown>,
|
||
field: { field_id: string; field_code: string },
|
||
value: string,
|
||
) => {
|
||
const lineKey = String(line.line_key || '');
|
||
if (!lineKey) return;
|
||
const committed = draftValue(line, field.field_id);
|
||
if (value === committed && !lineNoOverrideOpen.value) {
|
||
if (pendingLineNoEdit.value?.lineKey === lineKey && pendingLineNoEdit.value.fieldId === field.field_id) {
|
||
pendingLineNoEdit.value = null;
|
||
}
|
||
return;
|
||
}
|
||
pendingLineNoEdit.value = { lineKey, fieldId: field.field_id, value };
|
||
};
|
||
|
||
/**
|
||
* 明细输入过程回调;仅内部项次需要即时未保存提示。
|
||
*/
|
||
const onLineFieldInput = (
|
||
line: Record<string, unknown>,
|
||
field: { field_id: string; field_code: string },
|
||
value: string,
|
||
) => {
|
||
if (field.field_code === 'line_no') {
|
||
onLineNoInput(line, field, value);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 明细单元格展示值:覆盖弹窗打开或编辑中时优先显示待提交值,避免与草稿真值漂移。
|
||
*/
|
||
const lineFieldDisplayValue = (
|
||
line: Record<string, unknown>,
|
||
field: { field_id: string; field_code: string },
|
||
) => {
|
||
const lineKey = String(line.line_key || '');
|
||
if (
|
||
field.field_code === 'line_no'
|
||
&& pendingLineNoEdit.value
|
||
&& pendingLineNoEdit.value.lineKey === lineKey
|
||
&& pendingLineNoEdit.value.fieldId === field.field_id
|
||
) {
|
||
return pendingLineNoEdit.value.value;
|
||
}
|
||
return draftValue(line, field.field_id);
|
||
};
|
||
|
||
/**
|
||
* 确认内部项次覆盖:携带原因码写入 manual_override 并锁定。
|
||
* 核心逻辑:仅成功后关闭弹窗并清空 pending;失败保留原因表单与输入框待提交值。
|
||
* @param payload - 弹窗确认载荷
|
||
*/
|
||
const submitLineNoOverride = async (payload: LineNoOverridePayload) => {
|
||
const pending = pendingLineNoEdit.value;
|
||
if (!pending) return;
|
||
try {
|
||
await patchLine(pending.lineKey, pending.fieldId, payload.value, false, {
|
||
override_reason_code: payload.reasonCode,
|
||
override_reason_text: payload.reasonText,
|
||
});
|
||
pendingLineNoEdit.value = null;
|
||
lineNoOverrideOpen.value = false;
|
||
} catch (error) {
|
||
msg.error(resolveReviewErrorMessage(error));
|
||
}
|
||
};
|
||
|
||
/** 取消项次覆盖时丢弃待提交值,输入框回退为草稿真值。 */
|
||
const cancelLineNoOverride = () => {
|
||
pendingLineNoEdit.value = null;
|
||
lineNoOverrideOpen.value = false;
|
||
};
|
||
|
||
/**
|
||
* 确认弹窗提交:按 action 分发至对应写操作。
|
||
* 核心逻辑:质量异常/非订单/重识别携带 reasonCode + comment,供后端统一审计复盘。
|
||
* @param payload - 弹窗确认载荷
|
||
*/
|
||
const submitPendingAction = async (payload: ReviewConfirmPayload) => {
|
||
const action = pendingAction.value;
|
||
if (!action) return;
|
||
try {
|
||
if (action === 'confirm') {
|
||
if (!canConfirmBuild.value) {
|
||
msg.error(t('chat.shippingOrderReview.buildEligibility.confirmBlocked'));
|
||
return;
|
||
}
|
||
const response = await confirm();
|
||
// [STEP] 统一解析器:禁止仅凭 HTTP/confirm_ok 判定推进成功。
|
||
const parsed = parseOrderReviewConfirmResponse(response);
|
||
if (parsed) {
|
||
confirmSuccess.value = {
|
||
taskNo: parsed.taskNo,
|
||
orderTaskNo: parsed.orderTaskNo,
|
||
confirmOk: parsed.confirmOk,
|
||
autoProgress: parsed.autoProgressStarted,
|
||
progressFailed: parsed.progressFailed,
|
||
progressStatus: parsed.progressStatus,
|
||
progressMessage: parsed.progressMessage,
|
||
checkpoint: parsed.checkpoint,
|
||
restoredFromProjection: false,
|
||
};
|
||
if (parsed.progressFailed) {
|
||
msg.warning(t('chat.shippingOrderReview.confirmProgressFailed', { taskNo: parsed.taskNo }));
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
if (action === 'reparse') {
|
||
// 重识别是当前复核工作台内的异步子流程:保留旧 Case/字段快照,
|
||
// 由 composable 轮询到新 Case 后原位刷新,不切换路由或清空页面上下文。
|
||
await reparseDocument(payload.reasonCode || 'document_quality', payload.comment);
|
||
return;
|
||
}
|
||
if (action === 'non_order') {
|
||
await markNonOrder(payload.reasonCode || 'non_order', payload.comment);
|
||
return;
|
||
}
|
||
if (action === 'quality_issue') {
|
||
await markQualityIssue(payload.reasonCode || 'other', payload.comment);
|
||
return;
|
||
}
|
||
if (action === 'replace' && pendingReplaceFile.value) {
|
||
await uploadReplacement(pendingReplaceFile.value);
|
||
pendingReplaceFile.value = null;
|
||
}
|
||
} catch (error) {
|
||
const message = resolveReviewErrorMessage(error);
|
||
msg.error(message);
|
||
} finally {
|
||
pendingAction.value = null;
|
||
}
|
||
};
|
||
|
||
const selectReplacement = (event: Event) => {
|
||
const file = (event.target as HTMLInputElement).files?.[0];
|
||
if (!file) return;
|
||
pendingReplaceFile.value = file;
|
||
pendingAction.value = 'replace';
|
||
actionDialogOpen.value = true;
|
||
(event.target as HTMLInputElement).value = '';
|
||
};
|
||
|
||
/**
|
||
* 切换 Case 前统一关闭附属面板,避免旧 Case 侧栏内容残留。
|
||
*/
|
||
const closeAuxiliaryPanelsForCaseSwitch = () => {
|
||
auditTrailOpen.value = false;
|
||
processDetailOpen.value = false;
|
||
fulfillmentDetailLineKey.value = null;
|
||
closeFulfillmentOpen.value = false;
|
||
closeFulfillmentLineKeys.value = [];
|
||
panelState.value = {
|
||
...panelState.value,
|
||
eligibilityDetailsOpen: false,
|
||
llmSuggestionOpen: false,
|
||
versionHistoryOpen: false,
|
||
};
|
||
};
|
||
|
||
/**
|
||
* 实际切换 Case(无未保存拦截)。
|
||
* 核心逻辑:清理证据焦点与确认成功条;非 dock 关闭证据模式;只更新 URL,
|
||
* 由 run/case watch 在同 Run 内走轻量 selectCase,避免整页 load 误报历史版与加载中。
|
||
*/
|
||
const select = async (caseNo: string) => {
|
||
const wasDocked = panelState.value.pdfDocked && panelState.value.pdfOpen;
|
||
const switchingToCurrent = Boolean(
|
||
reviewProgressContext.value?.current_case_no
|
||
&& caseNo === reviewProgressContext.value.current_case_no
|
||
&& isViewingHistoricalVersion.value,
|
||
);
|
||
|
||
focusedEvidenceRef.value = null;
|
||
confirmSuccess.value = null;
|
||
closeAuxiliaryPanelsForCaseSwitch();
|
||
|
||
// [STEP 1] 浮窗模式关闭;dock 保留布局。切到当前版本强制关浮窗(G19)。
|
||
if (!wasDocked || switchingToCurrent) {
|
||
if (workbenchMode.value === 'evidence') {
|
||
workbenchMode.value = 'standard';
|
||
}
|
||
panelState.value = {
|
||
...panelState.value,
|
||
pdfOpen: wasDocked && !switchingToCurrent,
|
||
pdfExpanded: false,
|
||
pdfDocked: wasDocked && !switchingToCurrent ? panelState.value.pdfDocked : false,
|
||
eligibilityDetailsOpen: false,
|
||
};
|
||
}
|
||
|
||
// [STEP 2] 先轻量加载目标 Case,再同步 URL;watch 见已是当前 Case 则跳过二次 load。
|
||
await selectCase(caseNo);
|
||
const docId = activeCase.value?.document?.id;
|
||
const nextQuery: Record<string, unknown> = { ...route.query, case: caseNo };
|
||
delete nextQuery.focus;
|
||
delete nextQuery.candidate;
|
||
if (docId != null) nextQuery.document_id = String(docId);
|
||
else delete nextQuery.document_id;
|
||
await router.replace({ query: nextQuery as typeof route.query });
|
||
|
||
if (wasDocked && !switchingToCurrent && panelState.value.pdfOpen) {
|
||
void ensurePreviewLoaded(caseNo);
|
||
}
|
||
};
|
||
|
||
/** 未保存本地修改数(与底栏提示、切换拦截同源)。 */
|
||
const unsavedEditCount = computed(() => (pendingLineNoEdit.value ? 1 : 0));
|
||
const hasUnsavedEdits = computed(() => unsavedEditCount.value > 0);
|
||
|
||
/**
|
||
* 请求切换 OT:有未保存修改时硬拦截。
|
||
*/
|
||
const requestSelectCase = async (caseNo: string) => {
|
||
if (caseNo === activeCase.value?.case_no) return;
|
||
if (hasUnsavedEdits.value) {
|
||
pendingSwitchCaseNo.value = caseNo;
|
||
unsavedSwitchOpen.value = true;
|
||
return;
|
||
}
|
||
await select(caseNo);
|
||
};
|
||
|
||
/**
|
||
* 放弃本地未保存修改并切换。
|
||
*/
|
||
const discardAndSwitchCase = async () => {
|
||
const target = pendingSwitchCaseNo.value;
|
||
pendingLineNoEdit.value = null;
|
||
unsavedSwitchOpen.value = false;
|
||
pendingSwitchCaseNo.value = null;
|
||
if (target) await select(target);
|
||
};
|
||
|
||
/**
|
||
* 保存校验后切换(丢弃无法单独落库的行号 pending,再走 validate)。
|
||
*/
|
||
const saveAndSwitchCase = async () => {
|
||
const target = pendingSwitchCaseNo.value;
|
||
pendingLineNoEdit.value = null;
|
||
await reportSave(() => validate());
|
||
unsavedSwitchOpen.value = false;
|
||
pendingSwitchCaseNo.value = null;
|
||
if (target) await select(target);
|
||
};
|
||
|
||
/**
|
||
* 版本历史面板选择:历史版本只读打开,当前版本正常编辑。
|
||
*/
|
||
const selectVersionFromHistory = async (caseNo: string) => {
|
||
await select(caseNo);
|
||
await refreshWorkItemContext(conversationId.value, reviewProgressContext.value?.item_no || itemNoFromQuery.value);
|
||
};
|
||
|
||
/**
|
||
* 跳转至工作项当前版本 Case。
|
||
*/
|
||
const jumpToCurrentVersion = async () => {
|
||
const target = await openCurrentVersion();
|
||
if (!target) {
|
||
msg.warning(t('chat.shippingOrderReview.currentVersionUnavailable'));
|
||
return;
|
||
}
|
||
await router.replace({
|
||
query: {
|
||
...route.query,
|
||
run_no: target.runNo,
|
||
case: target.caseNo,
|
||
case_no: undefined,
|
||
item_no: reviewProgressContext.value?.item_no || itemNoFromQuery.value || undefined,
|
||
},
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 草稿版本冲突后重新加载服务端最新 Case,丢弃本地过期编辑。
|
||
*/
|
||
const onReloadLatestDraft = async () => {
|
||
try {
|
||
await reloadLatestDraft();
|
||
msg.success(t('chat.shippingOrderReview.versionConflict.reloaded'));
|
||
} catch (error) {
|
||
const message = error instanceof BusinessError ? error.message : t('errors.generic');
|
||
msg.error(message);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 退出复核模式回到普通对话,并携带一次性任务焦点。
|
||
* 核心逻辑:普通对话不绑定 Run/Case/文档;仅保留 conversation_id 与
|
||
* focus_task_no,供右侧任务卡聚焦后立即消费。
|
||
*/
|
||
const back = () => {
|
||
const activeConversationId = String(route.query.conversation_id || conversationId.value || '').trim();
|
||
const focusTask = String(
|
||
route.query.focus_task_no
|
||
|| confirmSuccess.value?.orderTaskNo
|
||
|| '',
|
||
).trim();
|
||
const nextQuery: Record<string, string> = {};
|
||
if (activeConversationId) nextQuery.conversation_id = activeConversationId;
|
||
if (focusTask) {
|
||
nextQuery.focus_task_no = focusTask;
|
||
nextQuery.focus_notice = '1';
|
||
}
|
||
void router.replace({
|
||
name: 'Chat',
|
||
params: { agentId: agentId.value },
|
||
query: nextQuery,
|
||
});
|
||
};
|
||
|
||
/**
|
||
* 就地重试加载复核 Run/Case(不依赖整页刷新)。
|
||
*/
|
||
function retryLoad() {
|
||
const nextRun = runNo.value;
|
||
if (!nextRun) return;
|
||
void load(nextRun, String(route.query.case || route.query.case_no || '') || undefined, {
|
||
conversationId: conversationId.value || undefined,
|
||
itemNo: itemNoFromQuery.value || undefined,
|
||
});
|
||
}
|
||
|
||
watch(
|
||
() => activeCase.value,
|
||
() => {
|
||
hydrateConfirmProgressFromCase();
|
||
},
|
||
{ immediate: true, deep: true },
|
||
);
|
||
|
||
watch(
|
||
[reparseProgressActive, () => confirmSuccess.value, showWorkflowProgress, hasCreatedShippingTask],
|
||
([reparse, confirm, workflow, hasTask]) => {
|
||
if (reparse) {
|
||
workbenchMode.value = 'reparse';
|
||
return;
|
||
}
|
||
// [STEP] 确认建单/正式 OT 后保持 standard 主编辑面,禁止自动切 formal_task 空壳。
|
||
// formal_task 仅由 Footer/registry 显式动作(如查看处理结果)进入。
|
||
if (confirm || workflow || hasTask) {
|
||
if (
|
||
workbenchMode.value === 'reparse'
|
||
|| workbenchMode.value === 'confirm_progress'
|
||
) {
|
||
workbenchMode.value = 'standard';
|
||
}
|
||
return;
|
||
}
|
||
if (
|
||
workbenchMode.value === 'reparse'
|
||
|| workbenchMode.value === 'confirm_progress'
|
||
|| workbenchMode.value === 'formal_task'
|
||
) {
|
||
workbenchMode.value = 'standard';
|
||
}
|
||
},
|
||
);
|
||
|
||
watch(
|
||
[runNo, () => String(route.query.case || route.query.case_no || ''), conversationId, itemNoFromQuery],
|
||
([nextRun, nextCase, nextConversationId, nextItemNo], previous) => {
|
||
if (!nextRun) return;
|
||
const prevRun = previous?.[0] ? String(previous[0]) : '';
|
||
const activeNo = String(activeCase.value?.case_no || '').trim();
|
||
const sameRunLoaded = Boolean(
|
||
reviewRun.value?.run_no
|
||
&& String(reviewRun.value.run_no) === String(nextRun)
|
||
&& prevRun === String(nextRun),
|
||
);
|
||
// [STEP] 同 Run 仅切换 PDF/Case:走轻量 selectCase,禁止整页 load 清空进度与闪「正在加载」。
|
||
if (sameRunLoaded && nextCase) {
|
||
if (nextCase === activeNo) return;
|
||
void selectCase(nextCase);
|
||
return;
|
||
}
|
||
void load(nextRun, nextCase || undefined, {
|
||
conversationId: nextConversationId || undefined,
|
||
itemNo: nextItemNo || undefined,
|
||
});
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
watch(
|
||
() => reviewRun.value?.run_no,
|
||
(resolvedRunNo) => {
|
||
if (resolvedRunNo && resolvedRunNo !== runNo.value) {
|
||
void router.replace({
|
||
query: {
|
||
...route.query,
|
||
run_no: resolvedRunNo,
|
||
case: undefined,
|
||
case_no: undefined,
|
||
},
|
||
});
|
||
}
|
||
},
|
||
);
|
||
</script>
|
||
|
||
<template>
|
||
<main
|
||
class="flex h-full min-h-0 flex-1 flex-col overflow-hidden bg-slate-50 text-slate-900 dark:bg-slate-950 dark:text-slate-100"
|
||
data-testid="shipping-order-review-view"
|
||
:data-readonly="isReadOnly ? 'true' : 'false'"
|
||
:data-workbench-mode="workbenchMode"
|
||
>
|
||
<ReviewWorkbenchHeader
|
||
:run-no="runNo"
|
||
:item-no="reviewProgressContext?.item_no"
|
||
:version-label="reviewProgressVersionLabel"
|
||
:saving="saving"
|
||
:save-failed="saveFailed"
|
||
:draft-conflict="Boolean(draftConflict)"
|
||
:is-read-only="isReadOnly"
|
||
:show-version-history="Boolean(activeCase)"
|
||
:show-audit-trail="Boolean(activeCase)"
|
||
:show-conversation-retry="showConversationRetry"
|
||
:conversation-retry-eligible-count="conversationRetryEligibleCount"
|
||
:conversation-retrying="conversationRetrying"
|
||
:conversation-retry-disabled="caseSwitchLoading || progressRetrying"
|
||
:has-conversation-retry-result="hasConversationRetryAttention"
|
||
@back="back"
|
||
@open-version-history="openVersionHistory"
|
||
@open-audit-trail="openAuditTrail"
|
||
@retry-conversation-auto-progress="() => void retryConversationAutoProgress()"
|
||
@open-conversation-retry-result="conversationRetryDrawerOpen = true"
|
||
/>
|
||
|
||
<div
|
||
v-if="reparseFailedVersionNotice"
|
||
class="mx-4 mt-3 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100"
|
||
data-testid="review-reparse-failed-version-notice"
|
||
>
|
||
{{ reparseFailedVersionNotice }}
|
||
</div>
|
||
|
||
<div
|
||
v-if="statusBannerText && !isReparsePrimary"
|
||
class="mx-4 mt-3 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100"
|
||
data-testid="review-status-banner"
|
||
>
|
||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||
<div class="min-w-0 flex-1 space-y-1">
|
||
<span>{{ statusBannerText }}</span>
|
||
<p
|
||
v-if="draftConflict"
|
||
class="text-xs text-amber-800 dark:text-amber-200"
|
||
data-testid="review-version-conflict-hint"
|
||
>
|
||
{{ t('chat.shippingOrderReview.versionConflict.hint', {
|
||
local: draftConflict.localVersion,
|
||
server: draftConflict.serverVersion ?? t('chat.shippingOrderReview.versionConflict.unknownServer'),
|
||
}) }}
|
||
</p>
|
||
</div>
|
||
<div class="flex flex-wrap items-center gap-2">
|
||
<button
|
||
v-if="draftConflict"
|
||
type="button"
|
||
class="rounded border border-amber-400 px-2 py-1 text-xs font-medium hover:bg-amber-100 dark:hover:bg-amber-900"
|
||
data-testid="reload-latest-draft"
|
||
:disabled="saving"
|
||
@click="onReloadLatestDraft"
|
||
>
|
||
{{ t('chat.shippingOrderReview.versionConflict.reload') }}
|
||
</button>
|
||
<button
|
||
v-if="draftConflict"
|
||
type="button"
|
||
class="rounded border border-amber-400 px-2 py-1 text-xs font-medium hover:bg-amber-100 dark:hover:bg-amber-900"
|
||
data-testid="toggle-draft-conflict-diff"
|
||
@click="toggleConflictDiff"
|
||
>
|
||
{{ draftConflict.showDiff
|
||
? t('chat.shippingOrderReview.versionConflict.hideDiff')
|
||
: t('chat.shippingOrderReview.versionConflict.viewDiff') }}
|
||
</button>
|
||
<button
|
||
v-if="isViewingHistoricalVersion"
|
||
type="button"
|
||
class="rounded border border-amber-400 px-2 py-1 text-xs font-medium hover:bg-amber-100 dark:hover:bg-amber-900"
|
||
data-testid="jump-to-current-version"
|
||
@click="jumpToCurrentVersion"
|
||
>
|
||
{{ t('chat.shippingOrderReview.jumpToCurrentVersion') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<ul
|
||
v-if="draftConflict?.showDiff && draftConflictDiffLines.length"
|
||
class="mt-2 list-disc space-y-0.5 pl-5 text-xs"
|
||
data-testid="review-version-conflict-diff"
|
||
>
|
||
<li v-for="line in draftConflictDiffLines" :key="line">{{ line }}</li>
|
||
</ul>
|
||
<p
|
||
v-else-if="draftConflict?.showDiff"
|
||
class="mt-2 text-xs"
|
||
data-testid="review-version-conflict-diff-empty"
|
||
>
|
||
{{ t('chat.shippingOrderReview.versionConflict.diffUnavailable') }}
|
||
</p>
|
||
</div>
|
||
|
||
<!-- 确认后统一进度主路径留在本页;返回对话仅作次要聚焦链接。 -->
|
||
|
||
<div v-if="loading" class="p-8 text-sm text-slate-600 dark:text-slate-300">{{ t('chat.shippingOrderReview.loading') }}</div>
|
||
<div
|
||
v-else-if="loadFailed"
|
||
class="m-4 rounded-lg border border-rose-300 bg-rose-50 p-4 text-sm text-rose-900 dark:border-rose-800 dark:bg-rose-950/30 dark:text-rose-100"
|
||
data-testid="shipping-order-review-load-failed"
|
||
>
|
||
<p>{{ t('chat.shippingOrderReview.unavailable') }}</p>
|
||
<button
|
||
type="button"
|
||
class="mt-3 inline-flex items-center gap-1 rounded border border-current/30 px-3 py-1.5 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5"
|
||
data-testid="shipping-order-review-retry-load"
|
||
@click="retryLoad"
|
||
>
|
||
<RefreshCw class="h-3.5 w-3.5" />
|
||
{{ t('chat.shippingOrderReview.retryLoad') }}
|
||
</button>
|
||
</div>
|
||
<div v-else class="min-h-0 flex-1 overflow-y-auto" data-testid="review-workbench-scroll">
|
||
<section class="flex flex-col gap-2 p-3 pb-5 lg:p-4">
|
||
<div
|
||
:class="hasReparseProgressContext
|
||
? 'sticky top-0 z-30 -mx-3 flex flex-col gap-2 border-b border-slate-200 bg-slate-50/95 px-3 py-2 shadow-sm backdrop-blur lg:-mx-4 lg:px-4 dark:border-slate-800 dark:bg-slate-950/95'
|
||
: 'flex flex-col gap-2'"
|
||
data-testid="review-workbench-status-region"
|
||
>
|
||
<ReviewWorkflowProgressPanel
|
||
v-if="showUnifiedProcessingStrip"
|
||
:item="reviewProgressContext"
|
||
:task-no="authoritativeOrderTaskNo"
|
||
:polling="workflowProgressPolling"
|
||
:refreshing="shippingProcessingLoading"
|
||
:processing-projection="shippingProcessingProjection"
|
||
:has-formal-ot="hasFormalOt"
|
||
data-testid="review-shipping-processing-strip"
|
||
@open-process-details="processDetailOpen = true"
|
||
@refresh="() => { void refreshShippingProcessing(); }"
|
||
/>
|
||
|
||
<section
|
||
v-if="hasCreatedShippingTask && formalTaskDetail && (workbenchMode === 'formal_task' || formalResultIsCompleted)"
|
||
class="rounded-xl border border-default bg-surface p-3"
|
||
data-testid="review-formal-task-todo-panel"
|
||
>
|
||
<div
|
||
data-testid="review-formal-task-result-region"
|
||
:data-view-result-loading="viewResultLoading ? '1' : '0'"
|
||
>
|
||
<div v-if="formalTaskDetailLoading" class="py-4 text-center text-xs text-muted">
|
||
{{ t('workspace.shippingNotice.loading') }}
|
||
</div>
|
||
<section
|
||
v-else-if="formalResultIsCompleted"
|
||
class="mb-3 rounded-xl border border-emerald-200 bg-emerald-50/60 p-3 dark:border-emerald-900 dark:bg-emerald-950/20"
|
||
data-testid="review-formal-task-result-panel"
|
||
>
|
||
<div class="flex items-center justify-between gap-2">
|
||
<h3 class="text-sm font-semibold text-emerald-900 dark:text-emerald-100">
|
||
{{ t('chat.shippingOrderReview.workbench.resultTitle') }}
|
||
</h3>
|
||
<span class="rounded-full bg-emerald-600 px-2 py-0.5 text-[11px] font-medium text-white">
|
||
{{ t('chat.shippingOrderReview.workbench.resultCompleted') }}
|
||
</span>
|
||
</div>
|
||
<div class="mt-3 grid gap-2 text-xs text-emerald-950 dark:text-emerald-50 sm:grid-cols-3">
|
||
<div>
|
||
<div class="text-emerald-700/80 dark:text-emerald-200/80">{{ t('chat.shippingOrderReview.workbench.resultLines') }}</div>
|
||
<div class="mt-0.5 font-semibold">{{ formalResultLineResults.length }}</div>
|
||
</div>
|
||
<div>
|
||
<div class="text-emerald-700/80 dark:text-emerald-200/80">{{ t('chat.shippingOrderReview.workbench.resultMatched') }}</div>
|
||
<div class="mt-0.5 font-semibold">{{ formalResultMatchedCount }}</div>
|
||
</div>
|
||
<div>
|
||
<div class="text-emerald-700/80 dark:text-emerald-200/80">{{ t('chat.shippingOrderReview.workbench.resultShortage') }}</div>
|
||
<div class="mt-0.5 font-semibold">{{ formalResultShortageCount }}</div>
|
||
</div>
|
||
</div>
|
||
<div v-if="formalResultLineResults.length" class="mt-3 overflow-x-auto rounded-lg border border-emerald-200/80 bg-white/70 dark:border-emerald-900 dark:bg-slate-950/30">
|
||
<table class="min-w-full text-xs">
|
||
<thead class="border-b border-emerald-200/80 text-left dark:border-emerald-900">
|
||
<tr>
|
||
<th class="px-2 py-1.5 font-medium">{{ t('chat.shippingOrderReview.workbench.resultPartNumber') }}</th>
|
||
<th class="px-2 py-1.5 font-medium">{{ t('chat.shippingOrderReview.workbench.resultReservation') }}</th>
|
||
<th class="px-2 py-1.5 font-medium">{{ t('chat.shippingOrderReview.workbench.resultStatus') }}</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-for="line in formalResultLineResults" :key="`${line.reservation_id || ''}-${line.part_number}`" class="border-b border-emerald-100 last:border-0 dark:border-emerald-950">
|
||
<td class="px-2 py-1.5">{{ line.part_number || '-' }}</td>
|
||
<td class="px-2 py-1.5">{{ line.reservation_id || '-' }}</td>
|
||
<td class="px-2 py-1.5">{{ Number(line.shortage_qty || 0) > 0 ? t('chat.shippingOrderReview.workbench.resultShortage') : t('chat.shippingOrderReview.workbench.resultMatched') }}</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="mt-3 flex flex-wrap items-center justify-between gap-2 text-xs">
|
||
<span>{{ t('chat.shippingOrderReview.workbench.resultArtifact', { file: formalResultArtifact?.file_name || formalTaskDetail.export_file_name || '-' }) }}</span>
|
||
<button v-if="formalResultArtifact || formalTaskDetail.export_file_name" type="button" class="rounded-lg border border-emerald-300 bg-white px-2.5 py-1.5 font-medium text-emerald-800 hover:bg-emerald-100 dark:border-emerald-800 dark:bg-slate-900 dark:text-emerald-100" data-testid="review-formal-task-result-download" @click="() => void downloadWorkspaceShippingExcelFile(confirmedNoticeTaskNo)">
|
||
{{ t('workspace.shippingNotice.todo.downloadExcel') }}
|
||
</button>
|
||
</div>
|
||
<div v-if="formalResultCompletedAt" class="mt-2 text-[11px] text-emerald-700/80 dark:text-emerald-200/80">
|
||
{{ t('chat.shippingOrderReview.workbench.resultCompletedAt', { time: formalResultCompletedAt }) }}
|
||
</div>
|
||
</section>
|
||
<TaskTodoPanel
|
||
v-else
|
||
ref="formalTodoPanelRef"
|
||
:detail="formalTaskDetail"
|
||
:gate-can-handle="workbenchActionsExecutable"
|
||
:actions-executable="workbenchActionsExecutable"
|
||
:hide-primary-actions="true"
|
||
:hide-gate-card="true"
|
||
:expected-notice-task-no="confirmedNoticeTaskNo"
|
||
:expected-order-task-no="authoritativeOrderTaskNo"
|
||
:expected-review-case-no="activeCase?.case_no || null"
|
||
:expected-run-no="runNo || null"
|
||
@refreshed="() => {
|
||
void loadFormalTaskDetail();
|
||
void refreshShippingProcessing();
|
||
msg.success(t('chat.shippingOrderReview.workbench.actionSuccess'));
|
||
}"
|
||
/>
|
||
</div>
|
||
</section>
|
||
|
||
<section
|
||
v-if="hasReparseProgressContext"
|
||
class="rounded-xl border border-sky-200 bg-white/95 p-3 shadow-[0_-8px_24px_rgba(15,23,42,0.08)] backdrop-blur dark:border-sky-900 dark:bg-slate-900/95"
|
||
data-testid="review-reparse-progress"
|
||
>
|
||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||
<div>
|
||
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.reparseProgress.title') }}</h2>
|
||
<p class="mt-0.5 text-xs text-slate-500 dark:text-slate-400">
|
||
{{ t('chat.shippingOrderReview.reparseProgress.subtitle') }}
|
||
</p>
|
||
</div>
|
||
<span v-if="reparseProgressPolling" class="text-xs text-sky-700 dark:text-sky-300">
|
||
{{ t('chat.shippingOrderReview.reparseProgress.polling') }}
|
||
</span>
|
||
<span v-else-if="reparseProgressStage === 'draft_ready'" class="text-xs text-emerald-700 dark:text-emerald-300">
|
||
{{ t('chat.shippingOrderReview.reparseProgress.stages.draft_ready') }}
|
||
</span>
|
||
<span v-else-if="reparseFailed" class="text-xs font-medium text-rose-700 dark:text-rose-300">
|
||
{{ reparseProgressStage === 'interrupted'
|
||
? t('chat.shippingOrderReview.reparseProgress.interrupted')
|
||
: t('chat.shippingOrderReview.reparseProgress.failed') }}
|
||
</span>
|
||
</div>
|
||
<p class="mt-2 text-xs text-slate-600 dark:text-slate-300">
|
||
{{ t('chat.shippingOrderReview.reparseProgress.currentStage', {
|
||
stage: reparseStageLabel(reparseProgressStage),
|
||
}) }}
|
||
</p>
|
||
<p v-if="reparseProgressStage === 'failed' || reparseProgressStage === 'interrupted'" class="mt-1 text-xs font-medium text-rose-700 dark:text-rose-300">
|
||
{{ t('chat.shippingOrderReview.reparseProgress.interruptedAt', {
|
||
stage: reparseStageLabel(reparseLastStableStage),
|
||
}) }}
|
||
</p>
|
||
<div class="mt-1 flex flex-wrap gap-x-4 gap-y-1 text-xs text-slate-500 dark:text-slate-400">
|
||
<span>{{ t('chat.shippingOrderReview.reparseProgress.runStatus', { status: reparseStatusLabel }) }}</span>
|
||
<span v-if="reparseLastActivityLabel">{{ t('chat.shippingOrderReview.reparseProgress.lastActivity', { time: reparseLastActivityLabel }) }}</span>
|
||
<span v-if="reparseLastRefreshedLabel" data-testid="review-reparse-last-refreshed">
|
||
{{ t('chat.shippingOrderReview.reparseProgress.lastRefreshed', { time: reparseLastRefreshedLabel }) }}
|
||
</span>
|
||
</div>
|
||
<div v-if="reparseStalePolls >= 8" class="mt-2 flex flex-wrap items-center justify-between gap-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-200">
|
||
<span>{{ reparseProgressPolling ? t('chat.shippingOrderReview.reparseProgress.stalled') : t('chat.shippingOrderReview.reparseProgress.monitoringPaused') }}</span>
|
||
<button
|
||
type="button"
|
||
class="rounded border border-amber-300 px-2 py-1 font-medium hover:bg-amber-100 dark:border-amber-800 dark:hover:bg-amber-950"
|
||
data-testid="review-reparse-refresh-now"
|
||
@click="refreshReparseProgress"
|
||
>
|
||
{{ t('chat.shippingOrderReview.reparseProgress.refreshNow') }}
|
||
</button>
|
||
</div>
|
||
<ol
|
||
class="mt-4 flex items-start overflow-x-auto pb-1"
|
||
data-testid="review-reparse-progress-rail"
|
||
>
|
||
<li
|
||
v-for="(stage, index) in reparseProgressStages"
|
||
:key="stage"
|
||
class="flex min-w-[7rem] flex-1 items-start"
|
||
:data-testid="`review-reparse-stage-${stage}`"
|
||
>
|
||
<span class="flex min-w-0 flex-1 flex-col items-center gap-1.5 text-center text-[11px]">
|
||
<span
|
||
class="relative z-10 flex h-7 w-7 items-center justify-center rounded-full border-2 bg-white font-semibold transition-colors dark:bg-slate-900"
|
||
:class="reparseFailed && index === reparseProgressIndex
|
||
? 'border-rose-500 bg-white text-rose-600 dark:border-rose-400 dark:bg-slate-900 dark:text-rose-300'
|
||
: index < reparseCompletedIndex
|
||
? 'border-emerald-500 bg-white text-emerald-600 dark:border-emerald-400 dark:bg-slate-900 dark:text-emerald-300'
|
||
: index === reparseProgressIndex && !(['draft_ready', 'completed', 'failed', 'interrupted'].includes(reparseProgressStage))
|
||
? 'border-sky-500 text-sky-700 ring-4 ring-sky-100 dark:border-sky-400 dark:text-sky-200 dark:ring-sky-950'
|
||
: 'border-slate-300 text-slate-400 dark:border-slate-700 dark:text-slate-500'"
|
||
>
|
||
<CircleX
|
||
v-if="reparseFailed && index === reparseProgressIndex"
|
||
class="h-4 w-4 shrink-0 stroke-[2.5]"
|
||
aria-label="异常中断"
|
||
aria-hidden="false"
|
||
/>
|
||
<Check
|
||
v-else-if="index < reparseCompletedIndex"
|
||
class="h-4 w-4 shrink-0 stroke-[3]"
|
||
aria-label="已完成"
|
||
aria-hidden="false"
|
||
/>
|
||
<span v-else>{{ index + 1 }}</span>
|
||
</span>
|
||
<span
|
||
class="max-w-[7rem] truncate"
|
||
:class="reparseFailed && index === reparseProgressIndex
|
||
? 'font-semibold text-rose-700 dark:text-rose-300'
|
||
: index === reparseProgressIndex && !(['draft_ready', 'completed', 'failed', 'interrupted'].includes(reparseProgressStage)) ? 'font-semibold text-sky-800 dark:text-sky-200' : index < reparseCompletedIndex ? 'text-slate-600 dark:text-slate-300' : 'text-slate-400 dark:text-slate-500'"
|
||
:title="reparseStageLabel(stage)"
|
||
>
|
||
{{ reparseStageLabel(stage) }}
|
||
</span>
|
||
</span>
|
||
<span
|
||
v-if="index < reparseProgressStages.length - 1"
|
||
class="mt-3 h-0.5 min-w-4 flex-1 bg-slate-200 dark:bg-slate-700"
|
||
:class="index < reparseCompletedIndex ? 'bg-emerald-400 dark:bg-emerald-700' : ''"
|
||
aria-hidden="true"
|
||
/>
|
||
</li>
|
||
</ol>
|
||
<p
|
||
v-if="reparseProgressRefreshFailed"
|
||
class="mt-3 text-xs text-amber-700 dark:text-amber-300"
|
||
data-testid="review-reparse-refresh-failed"
|
||
>
|
||
{{ t('chat.shippingOrderReview.reparseProgress.refreshFailed') }}
|
||
</p>
|
||
<p
|
||
v-if="reparseProgressStage === 'failed' || reparseProgressStage === 'interrupted'"
|
||
class="mt-3 flex flex-wrap items-center justify-between gap-2 rounded-lg border border-rose-200 bg-rose-50 px-3 py-2 text-xs text-rose-800 dark:border-rose-900 dark:bg-rose-950/40 dark:text-rose-200"
|
||
data-testid="review-reparse-failed"
|
||
>
|
||
<span>{{ reparseProgressStage === 'interrupted'
|
||
? t('chat.shippingOrderReview.reparseProgress.interruptedMessage')
|
||
: t('chat.shippingOrderReview.reparseProgress.failed') }}
|
||
<span v-if="reparseProgressStage === 'interrupted'" class="mt-1 block">{{ reparseInterruptionReason }}</span>
|
||
</span>
|
||
<button
|
||
v-if="displayCase?.available_actions.includes('reparse')"
|
||
type="button"
|
||
class="rounded border border-rose-300 px-2.5 py-1 font-medium hover:bg-rose-100 disabled:opacity-50 dark:border-rose-800 dark:hover:bg-rose-900/50"
|
||
:disabled="saving"
|
||
data-testid="review-reparse-retry"
|
||
@click="openActionDialog('reparse')"
|
||
>
|
||
{{ t('chat.shippingOrderReview.reparseProgress.retry') }}
|
||
</button>
|
||
</p>
|
||
</section>
|
||
</div>
|
||
|
||
<div
|
||
v-if="showWorkbenchGrid"
|
||
:class="otNavUsesSidebar ? 'lg:flex lg:items-start lg:gap-4' : 'contents'"
|
||
data-testid="review-workbench-ot-shell"
|
||
>
|
||
<ReviewDocumentNavigation
|
||
:items="documentNavItems"
|
||
:active-case-no="requestedCaseNo || displayCase?.case_no"
|
||
:nav-aria-label="t('chat.shippingOrderReview.documentNavigation')"
|
||
@mode-change="(mode) => { otNavMode = mode; }"
|
||
@select="(caseNo) => { void requestSelectCase(caseNo); }"
|
||
/>
|
||
<div
|
||
class="min-w-0 flex-1 space-y-2"
|
||
:class="otNavUsesSidebar ? '' : 'contents'"
|
||
>
|
||
<template v-if="showWorkbenchGrid">
|
||
<div
|
||
v-if="caseSwitchFailed"
|
||
class="rounded-xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-900 dark:border-rose-900 dark:bg-rose-950/40 dark:text-rose-100"
|
||
data-testid="review-case-switch-failed"
|
||
>
|
||
<p>{{ t('chat.shippingOrderReview.caseSwitchFailed') }}</p>
|
||
<div
|
||
class="mt-3 space-y-2"
|
||
aria-hidden="true"
|
||
data-testid="review-case-switch-failed-skeleton"
|
||
>
|
||
<div class="h-4 w-2/5 animate-pulse rounded bg-rose-200/70 dark:bg-rose-900/50" />
|
||
<div class="h-10 w-full animate-pulse rounded bg-rose-200/70 dark:bg-rose-900/50" />
|
||
<div class="h-24 w-full animate-pulse rounded bg-rose-200/70 dark:bg-rose-900/50" />
|
||
</div>
|
||
<button
|
||
type="button"
|
||
class="mt-3 rounded border border-rose-300 px-2 py-1 text-xs hover:bg-rose-100 dark:border-rose-800 dark:hover:bg-rose-950"
|
||
data-testid="review-case-switch-retry"
|
||
@click="() => { const target = requestedCaseNo; if (target) void selectCase(target); }"
|
||
>
|
||
{{ t('chat.shippingOrderReview.caseSwitchRetry') }}
|
||
</button>
|
||
</div>
|
||
<div
|
||
v-if="caseSwitchLoading"
|
||
class="space-y-3 rounded-xl border border-dashed border-slate-300 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-900/40"
|
||
data-testid="review-case-switch-loading"
|
||
>
|
||
<p class="text-sm text-slate-600 dark:text-slate-300">
|
||
{{ caseLoadingContext?.message || t('chat.shippingOrderReview.caseSwitchLoading') }}
|
||
</p>
|
||
<div class="space-y-2" aria-hidden="true">
|
||
<div class="h-4 w-2/5 animate-pulse rounded bg-slate-200 dark:bg-slate-700" />
|
||
<div class="h-10 w-full animate-pulse rounded bg-slate-200 dark:bg-slate-700" />
|
||
<div class="h-10 w-full animate-pulse rounded bg-slate-200 dark:bg-slate-700" />
|
||
<div class="h-24 w-full animate-pulse rounded bg-slate-200 dark:bg-slate-700" />
|
||
</div>
|
||
</div>
|
||
<div
|
||
v-if="showWorkbenchCaseShell"
|
||
class="relative space-y-2 transition-opacity duration-150"
|
||
:class="caseSwitchLoading ? 'pointer-events-none opacity-70' : ''"
|
||
data-testid="review-case-workbench-shell"
|
||
:data-case-switching="caseSwitchLoading ? '1' : '0'"
|
||
:data-case-switch-failed="caseSwitchFailed ? '1' : '0'"
|
||
:data-case-projection-version="caseProjectionVersion ?? ''"
|
||
:aria-busy="caseSwitchLoading ? 'true' : 'false'"
|
||
>
|
||
<ReviewWorkbenchModeToggle
|
||
v-if="workbenchMode === 'inventory'"
|
||
:mode="workbenchMode"
|
||
:can-enter-inventory="canEnterInventory"
|
||
@set-mode="onWorkbenchModeChange"
|
||
/>
|
||
|
||
<!-- 窄屏:阻断卡 + 当前处理卡(对象级重试优先于此) -->
|
||
<div
|
||
class="space-y-2 xl:hidden"
|
||
data-testid="review-primary-blockers-narrow"
|
||
>
|
||
<ReviewCurrentProcessingCard
|
||
v-if="mountCurrentProcessingCard"
|
||
:stage-code="currentProcessingStageDisplay.code"
|
||
:stage-label-key="currentProcessingStageDisplay.labelKey"
|
||
:stage-inconsistent="currentProcessingStageDisplay.inconsistent"
|
||
:task-missing="Boolean(displayCase?.task_missing)"
|
||
:task-no="displayCase?.confirmed_task_no || displayCase?.post_confirm_auto_progress?.task_no"
|
||
:confirmed-task-id="displayCase?.confirmed_task_id"
|
||
:show-admin-diagnosis="showAdminTaskMissingDiagnosis"
|
||
:automation="displayCase?.automation"
|
||
:show-retry="showObjectRetryOnRail"
|
||
:user-status="shippingProcessingProjection?.userStatus ?? displayCase?.user_status"
|
||
:retryable="displayCase?.process_gate?.current_blocking_gate ? false : (shippingProcessingProjection?.retryable ?? showObjectRetryOnRail)"
|
||
:blocking-reason="shippingProcessingProjection?.blockingReason ?? displayCase?.blocking_reason"
|
||
:primary-action="displayCase?.process_gate?.current_blocking_gate ? null : (shippingProcessingProjection?.primaryAction ?? displayCase?.primary_action)"
|
||
:retrying="displayCase?.process_gate?.current_blocking_gate
|
||
? (progressRetrying || caseSwitchLoading)
|
||
: (taskRetryButtonDisabled || progressRetrying || caseSwitchLoading)"
|
||
:retry-exhausted-sources="taskInventoryExhaustedSources"
|
||
:loading="caseContentSkeleton"
|
||
@retry="() => void (hasFormalOt ? retryFormalOtAutoProgress() : retryStpAutoCreate())"
|
||
/>
|
||
<ReviewCustomerResolutionPanel
|
||
v-if="activeCase && !activeCase.customer_resolution?.resolved && showEligibilityAsPrimary"
|
||
ref="customerResolutionPanelRef"
|
||
:case-no="activeCase.case_no"
|
||
:resolution="activeCase.customer_resolution"
|
||
:editable="editable"
|
||
@refreshed="reloadLatestDraft"
|
||
/>
|
||
<ReviewBuildEligibilitySummary
|
||
v-if="showEligibilityAsPrimary"
|
||
:eligibility="buildEligibility"
|
||
:field-conflicts="displayCase?.field_conflicts"
|
||
:customer-resolved="Boolean(displayCase?.customer_resolution?.resolved)"
|
||
:field-labels="reviewFieldLabels"
|
||
:exception-count="exceptionTargets.length"
|
||
:exception-ordinal="exceptionOrdinal"
|
||
:focus-buildability="hasActiveBusinessGate"
|
||
@open-details="openEligibilityDetails"
|
||
@navigate-exception="navigateExceptionField"
|
||
/>
|
||
<ReviewCompletedChecksPanel
|
||
:items="displayCase?.completed_checks"
|
||
/>
|
||
<ReviewProfileMatchPanel
|
||
:profile-match="displayCase?.profile_match"
|
||
/>
|
||
</div>
|
||
|
||
<div
|
||
class="grid gap-3 xl:grid-cols-[minmax(0,1fr)_minmax(260px,0.35fr)]"
|
||
data-testid="review-workbench-grid"
|
||
>
|
||
<div
|
||
ref="mainEditorScrollEl"
|
||
class="min-h-0 min-w-0 space-y-3"
|
||
data-testid="review-main-editor"
|
||
>
|
||
<!-- 仅「固定为侧栏」时 PDF 占网格列;默认浮窗挂在根节点,不挤压订单区。 -->
|
||
<div
|
||
:class="evidenceDocked
|
||
? 'grid gap-4 min-[1440px]:grid-cols-[minmax(280px,0.38fr)_minmax(420px,1fr)]'
|
||
: 'space-y-4'"
|
||
data-testid="review-editor-body"
|
||
:data-evidence-docked="evidenceDocked ? 'true' : 'false'"
|
||
>
|
||
<ReviewDocumentEvidenceDrawer
|
||
v-if="evidenceDocked"
|
||
:open="panelState.pdfOpen"
|
||
:pinned="panelState.pdfPinned"
|
||
:expanded="panelState.pdfExpanded"
|
||
:docked="true"
|
||
:float-side="panelState.pdfFloatSide"
|
||
:src="previewUrl"
|
||
:evidence="selectedEvidence"
|
||
:evidence-list="evidence || []"
|
||
:field-label="evidenceFieldLabel"
|
||
:draft-value="focusedLlmDraftValue"
|
||
:machine-value="evidenceMachineValue"
|
||
:value-source-label="evidenceValueSourceLabel"
|
||
:show-ai-actions="editable"
|
||
:reset-key="displayCase?.case_no || null"
|
||
@close="closeEvidenceMode"
|
||
@toggle-pin="togglePdfPinned"
|
||
@toggle-expand="togglePdfExpanded"
|
||
@toggle-dock="togglePdfDocked"
|
||
@toggle-side="togglePdfFloatSide"
|
||
@prev-evidence="navigateEvidence(-1)"
|
||
@next-evidence="navigateEvidence(1)"
|
||
@request-ai="requestSuggestion()"
|
||
@restore-machine="restoreEvidenceMachineValue"
|
||
/>
|
||
|
||
<div class="min-w-0 space-y-3" data-testid="review-order-form">
|
||
<section class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||
<div class="flex items-center justify-between gap-3">
|
||
<div>
|
||
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.orderFields') }}</h2>
|
||
<p class="mt-1 text-xs text-slate-500">{{ t('chat.shippingOrderReview.schemaVersion', { version: displayCase?.schema.schema_version_id || '-' }) }}</p>
|
||
</div>
|
||
<span v-if="isReadOnly" class="rounded-full bg-slate-100 px-2 py-0.5 text-xs text-slate-600 dark:bg-slate-800 dark:text-slate-300">
|
||
{{ t('chat.shippingOrderReview.readOnly') }}
|
||
</span>
|
||
</div>
|
||
<div v-if="headerSchemaFields.length" class="mt-4 grid gap-3 md:grid-cols-2 2xl:grid-cols-3">
|
||
<div v-for="field in visibleHeaderSchemaFields" :key="field.field_id" class="min-w-0">
|
||
<div class="flex items-center justify-between gap-2 text-xs font-medium text-slate-600 dark:text-slate-300">
|
||
<span class="truncate">{{ field.display_name }}<span v-if="field.required"> *</span></span>
|
||
<button
|
||
type="button"
|
||
class="shrink-0"
|
||
data-testid="review-field-locate"
|
||
:data-highlight-quality="fieldHighlightQuality(field.field_id)"
|
||
:data-locate-mode="isLocateDiagnoseOnly(fieldHighlightQuality(field.field_id)) ? 'diagnose' : 'locate'"
|
||
:class="locateIconButtonClass(fieldHighlightQuality(field.field_id))"
|
||
:aria-label="locateControlLabel(field.display_name, field.field_id)"
|
||
:title="locateControlLabel(field.display_name, field.field_id)"
|
||
@click="focusFieldEvidence(field.field_id)"
|
||
>
|
||
<Crosshair class="h-3.5 w-3.5" aria-hidden="true" />
|
||
</button>
|
||
</div>
|
||
<input
|
||
:value="draftValue(displayHeaderValues, field.field_id)"
|
||
:disabled="caseContentSkeleton || !isFieldEditable(field.field_id) || saving"
|
||
class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2.5 py-2 text-sm dark:border-slate-600 dark:bg-slate-950"
|
||
:class="{
|
||
'border-sky-400 ring-2 ring-sky-300 dark:border-sky-500 dark:ring-sky-700': isEvidenceLinkedField(field.field_id),
|
||
}"
|
||
data-testid="review-header-field-input"
|
||
:data-evidence-active="isEvidenceLinkedField(field.field_id) ? 'true' : 'false'"
|
||
:title="t('chat.shippingOrderReview.dblclickLocateHint')"
|
||
@focus="syncFieldFocus(field.field_id)"
|
||
@dblclick="focusFieldEvidence(field.field_id)"
|
||
@change="reportSave(() => patchHeader(field.field_id, ($event.target as HTMLInputElement).value))"
|
||
>
|
||
<div class="mt-1 flex items-center justify-between gap-2 text-[11px] text-slate-500">
|
||
<span>{{ valueSourceLabel(draftFieldMeta(displayHeaderValues as Record<string, unknown> | undefined, field.field_id).value_source) }}</span>
|
||
<button v-if="!caseContentSkeleton && isFieldEditable(field.field_id)" type="button" class="hover:text-sky-600" @click="reportSave(() => patchHeader(field.field_id, null, true))">
|
||
<Undo2 class="mr-1 inline h-3 w-3" />{{ t('chat.shippingOrderReview.restoreMachine') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div v-if="hiddenHeaderFieldCount > 0 || showAllHeaderFields" class="mt-3">
|
||
<button
|
||
type="button"
|
||
class="rounded border border-slate-300 px-2.5 py-1 text-xs hover:bg-slate-50 dark:border-slate-600 dark:hover:bg-slate-800"
|
||
data-testid="review-toggle-header-fields"
|
||
@click="showAllHeaderFields = !showAllHeaderFields"
|
||
>
|
||
{{ showAllHeaderFields
|
||
? t('chat.shippingOrderReview.collapseFields')
|
||
: t('chat.shippingOrderReview.moreFields', { count: hiddenHeaderFieldCount }) }}
|
||
</button>
|
||
</div>
|
||
<div v-else class="mt-4 rounded-lg border border-dashed border-slate-300 p-3 text-sm text-slate-500 dark:border-slate-700">
|
||
<p>{{ t('chat.shippingOrderReview.noMachineOrder') }}</p>
|
||
<div v-if="editable && displayCase?.available_actions.includes('create_draft')" class="mt-3 flex flex-wrap gap-2">
|
||
<button type="button" class="rounded border px-2 py-1 text-xs" :disabled="saving" @click="reportDisposition(() => createManualDraft())">{{ t('chat.shippingOrderReview.createManualDraft') }}</button>
|
||
<button type="button" class="rounded border px-2 py-1 text-xs" :disabled="saving" @click="openActionDialog('non_order')">{{ t('chat.shippingOrderReview.markNonOrder') }}</button>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="rounded-xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
|
||
<div class="flex items-center justify-between gap-3 border-b border-slate-200 px-4 py-3 dark:border-slate-800">
|
||
<div>
|
||
<h3 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.lines') }}</h3>
|
||
<p class="mt-1 text-xs text-slate-500">{{ displayDraftLines.length }} {{ t('chat.shippingOrderReview.lines') }}</p>
|
||
</div>
|
||
<div class="flex flex-wrap items-center gap-2">
|
||
<button
|
||
v-if="hiddenLineFieldCount > 0 || showAllLineFields"
|
||
type="button"
|
||
class="rounded border border-slate-300 px-2 py-1 text-xs hover:bg-slate-50 dark:border-slate-600 dark:hover:bg-slate-800"
|
||
data-testid="review-toggle-line-fields"
|
||
@click="showAllLineFields = !showAllLineFields"
|
||
>
|
||
{{ showAllLineFields
|
||
? t('chat.shippingOrderReview.collapseFields')
|
||
: t('chat.shippingOrderReview.moreLineFields', { count: hiddenLineFieldCount }) }}
|
||
</button>
|
||
<button v-if="editable" type="button" :disabled="saving" class="inline-flex items-center gap-1 rounded border px-2 py-1 text-xs disabled:opacity-50" data-testid="review-add-line" @click="reportSave(() => addLine())">
|
||
<Plus class="h-3.5 w-3.5" />{{ t('chat.shippingOrderReview.addLine') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div v-if="displayDraftLines.length" class="overflow-x-auto overscroll-x-contain" data-testid="review-lines-scroll">
|
||
<table :class="[linesTableMinWidthClass, 'w-full border-collapse text-left text-xs']">
|
||
<thead class="bg-slate-50 text-slate-500 dark:bg-slate-950/40 dark:text-slate-400">
|
||
<tr>
|
||
<th class="sticky left-0 z-10 min-w-10 border-b border-slate-200 bg-slate-50 px-2 py-1.5 font-medium dark:border-slate-800 dark:bg-slate-950">#</th>
|
||
<template v-for="field in visibleLineSchemaFields" :key="field.field_id">
|
||
<th class="min-w-36 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800">
|
||
{{ field.display_name }}<span v-if="field.required"> *</span>
|
||
</th>
|
||
<th
|
||
v-if="showLineInventoryColumns && isInventorySourceHintField(field)"
|
||
class="min-w-28 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800"
|
||
>
|
||
{{ t('chat.shippingOrderReview.lineOps.inventorySource') }}
|
||
</th>
|
||
<th
|
||
v-if="showLineInventoryColumns && isQtySchemaField(field)"
|
||
class="min-w-20 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800"
|
||
>
|
||
{{ t('chat.shippingOrderReview.fulfillmentDecision.availableQty') }}
|
||
</th>
|
||
<th
|
||
v-if="showLineInventoryColumns && isQtySchemaField(field)"
|
||
class="min-w-16 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800"
|
||
>
|
||
{{ t('chat.shippingOrderReview.fulfillmentDecision.shortage') }}
|
||
</th>
|
||
</template>
|
||
<template v-if="showLineInventoryColumns && !hasVisibleQtyField">
|
||
<th class="min-w-20 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800">
|
||
{{ t('chat.shippingOrderReview.fulfillmentDecision.availableQty') }}
|
||
</th>
|
||
<th class="min-w-16 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800">
|
||
{{ t('chat.shippingOrderReview.fulfillmentDecision.shortage') }}
|
||
</th>
|
||
</template>
|
||
<th class="sticky right-0 z-10 min-w-28 border-b border-slate-200 bg-slate-50 px-2 py-1.5 dark:border-slate-800 dark:bg-slate-950">
|
||
<span class="sr-only">{{ t('chat.shippingOrderReview.fulfillmentDecision.actions') }}</span>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<template
|
||
v-for="(line, index) in displayDraftLines"
|
||
:key="String(line.line_key || index)"
|
||
>
|
||
<tr
|
||
class="border-b border-slate-100 last:border-0 dark:border-slate-800"
|
||
:data-review-line-index="index"
|
||
>
|
||
<td class="sticky left-0 z-10 bg-white px-2 py-1.5 font-medium dark:bg-slate-900">{{ index + 1 }}</td>
|
||
<template v-for="field in visibleLineSchemaFields" :key="field.field_id">
|
||
<td class="min-w-36 px-2 py-1.5 align-top">
|
||
<div class="flex min-w-[8.5rem] flex-col gap-0.5">
|
||
<div class="relative flex min-w-0 items-center gap-1">
|
||
<input
|
||
:value="lineFieldDisplayValue(line, field)"
|
||
:disabled="!isFieldEditable(field.field_id) || saving || (field.field_code === 'line_no' && Boolean(draftFieldMeta(line, field.field_id).locked))"
|
||
class="min-w-0 flex-1 rounded border border-slate-300 bg-white px-1.5 py-1 text-xs dark:border-slate-600 dark:bg-slate-950"
|
||
:class="{
|
||
'border-amber-400 ring-1 ring-amber-300 dark:border-amber-500': field.field_code === 'line_no'
|
||
&& pendingLineNoEdit?.lineKey === String(line.line_key || '')
|
||
&& pendingLineNoEdit.fieldId === field.field_id
|
||
&& !lineNoOverrideOpen,
|
||
'border-sky-400 ring-2 ring-sky-300 dark:border-sky-500 dark:ring-sky-700': isEvidenceLinkedField(field.field_id, index),
|
||
}"
|
||
data-testid="review-line-field-input"
|
||
:data-evidence-active="isEvidenceLinkedField(field.field_id, index) ? 'true' : 'false'"
|
||
:title="t('chat.shippingOrderReview.dblclickLocateHint')"
|
||
@focus="syncFieldFocus(field.field_id, index)"
|
||
@dblclick="focusFieldEvidence(field.field_id, index)"
|
||
@input="onLineFieldInput(line, field, ($event.target as HTMLInputElement).value)"
|
||
@change="onLineFieldChange(line, field, ($event.target as HTMLInputElement).value)"
|
||
>
|
||
<button
|
||
type="button"
|
||
class="shrink-0"
|
||
data-testid="review-line-field-locate"
|
||
:data-highlight-quality="fieldHighlightQuality(field.field_id, index)"
|
||
:data-locate-mode="isLocateDiagnoseOnly(fieldHighlightQuality(field.field_id, index)) ? 'diagnose' : 'locate'"
|
||
:class="locateIconButtonClass(fieldHighlightQuality(field.field_id, index))"
|
||
:aria-label="locateControlLabel(field.display_name, field.field_id, index)"
|
||
:title="locateControlLabel(field.display_name, field.field_id, index)"
|
||
@click="focusFieldEvidence(field.field_id, index)"
|
||
>
|
||
<Crosshair class="h-3.5 w-3.5" aria-hidden="true" />
|
||
</button>
|
||
<details
|
||
v-if="field.field_code === 'line_no' || draftFieldMeta(line, field.field_id).value_source !== 'machine'"
|
||
class="relative shrink-0 min-w-0"
|
||
data-testid="review-field-lineage"
|
||
>
|
||
<summary
|
||
class="cursor-pointer list-none truncate whitespace-nowrap rounded bg-slate-100 px-1.5 py-0.5 text-[10px] text-slate-600 marker:content-none dark:bg-slate-800 dark:text-slate-300 [&::-webkit-details-marker]:hidden"
|
||
:title="fieldMetaDetail(draftFieldMeta(line, field.field_id))"
|
||
:aria-label="fieldMetaDetail(draftFieldMeta(line, field.field_id))"
|
||
>
|
||
{{ valueSourceLabel(draftFieldMeta(line, field.field_id).value_source) }}
|
||
</summary>
|
||
<div
|
||
class="absolute right-0 top-full z-30 mt-1 w-56 rounded-md border border-slate-200 bg-white p-2 shadow-md dark:border-slate-700 dark:bg-slate-900"
|
||
role="tooltip"
|
||
>
|
||
<dl class="grid gap-1.5">
|
||
<div
|
||
v-for="row in fieldMetaLineageRows(draftFieldMeta(line, field.field_id))"
|
||
:key="`${row.label}:${row.value}`"
|
||
class="min-w-0"
|
||
>
|
||
<dt class="text-[10px] font-medium text-slate-500 dark:text-slate-400">{{ row.label }}</dt>
|
||
<dd class="break-words text-[11px] text-slate-700 dark:text-slate-200">{{ row.value }}</dd>
|
||
</div>
|
||
</dl>
|
||
</div>
|
||
</details>
|
||
</div>
|
||
<p
|
||
v-if="field.field_code === 'line_no'
|
||
&& pendingLineNoEdit?.lineKey === String(line.line_key || '')
|
||
&& pendingLineNoEdit.fieldId === field.field_id
|
||
&& !lineNoOverrideOpen"
|
||
class="mt-0 text-[10px] text-amber-600 dark:text-amber-400"
|
||
>
|
||
{{ t('chat.shippingOrderReview.lineNoUnsavedHint') }}
|
||
</p>
|
||
</div>
|
||
<button
|
||
v-if="editable && field.field_code === 'line_no' && draftFieldMeta(line, field.field_id).locked"
|
||
type="button"
|
||
class="mt-0.5 text-[10px] text-sky-600 hover:underline"
|
||
@click="reportSave(() => patchLine(String(line.line_key), field.field_id, null, true))"
|
||
>
|
||
<Undo2 class="mr-0.5 inline h-2.5 w-2.5" />{{ t('chat.shippingOrderReview.restorePriorProjection') }}
|
||
</button>
|
||
</td>
|
||
<td
|
||
v-if="showLineInventoryColumns && isInventorySourceHintField(field)"
|
||
class="px-2 py-1.5 align-middle text-xs"
|
||
data-testid="review-line-inventory-source"
|
||
>
|
||
{{ displayInventorySource(lineFulfillmentFor(String(line.line_key || ''))) }}
|
||
</td>
|
||
<td
|
||
v-if="showLineInventoryColumns && isQtySchemaField(field)"
|
||
class="px-2 py-1.5 align-middle tabular-nums"
|
||
:class="lineFulfillmentFor(String(line.line_key || ''))?.is_shortage ? 'font-medium text-rose-600 dark:text-rose-400' : ''"
|
||
>
|
||
{{ displayAvailableQty(lineFulfillmentFor(String(line.line_key || ''))) }}
|
||
</td>
|
||
<td
|
||
v-if="showLineInventoryColumns && isQtySchemaField(field)"
|
||
class="px-2 py-1.5 align-middle tabular-nums"
|
||
:class="lineFulfillmentFor(String(line.line_key || ''))?.is_shortage ? 'font-medium text-rose-600 dark:text-rose-400' : ''"
|
||
>
|
||
{{ displayShortageQty(lineFulfillmentFor(String(line.line_key || ''))) }}
|
||
</td>
|
||
</template>
|
||
<template v-if="showLineInventoryColumns && !hasVisibleQtyField">
|
||
<td
|
||
class="px-2 py-1.5 align-middle tabular-nums"
|
||
:class="lineFulfillmentFor(String(line.line_key || ''))?.is_shortage ? 'font-medium text-rose-600 dark:text-rose-400' : ''"
|
||
>
|
||
{{ displayAvailableQty(lineFulfillmentFor(String(line.line_key || ''))) }}
|
||
</td>
|
||
<td
|
||
class="px-2 py-1.5 align-middle tabular-nums"
|
||
:class="lineFulfillmentFor(String(line.line_key || ''))?.is_shortage ? 'font-medium text-rose-600 dark:text-rose-400' : ''"
|
||
>
|
||
{{ displayShortageQty(lineFulfillmentFor(String(line.line_key || ''))) }}
|
||
</td>
|
||
</template>
|
||
<td class="sticky right-0 z-10 min-w-28 whitespace-nowrap bg-white px-2 py-1.5 dark:bg-slate-900">
|
||
<div class="flex items-center justify-end gap-0.5">
|
||
<button
|
||
type="button"
|
||
:disabled="!editable || saving"
|
||
class="rounded p-1.5 hover:bg-slate-100 disabled:opacity-50 dark:hover:bg-slate-800"
|
||
data-testid="review-copy-line"
|
||
:aria-label="t('chat.shippingOrderReview.copyLine')"
|
||
:title="t('chat.shippingOrderReview.copyLine')"
|
||
@click="reportSave(() => copyLine(String(line.line_key)))"
|
||
>
|
||
<Copy class="h-3.5 w-3.5" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
:disabled="!editable || saving || !canDeleteDraftLine(String(line.line_key || ''))"
|
||
class="rounded p-1.5 hover:bg-slate-100 disabled:opacity-50 dark:hover:bg-slate-800"
|
||
data-testid="review-delete-line"
|
||
:aria-label="t('chat.shippingOrderReview.deleteLine')"
|
||
:title="t('chat.shippingOrderReview.deleteLine')"
|
||
@click="reportSave(() => deleteLine(String(line.line_key)))"
|
||
>
|
||
<Trash2 class="h-3.5 w-3.5" />
|
||
</button>
|
||
<ReviewLineInventoryOps
|
||
:line="lineFulfillmentFor(String(line.line_key || ''))"
|
||
:editable="editable"
|
||
:busy="saving"
|
||
@close-line="openCloseFulfillmentDialog([String(line.line_key || '')])"
|
||
/>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<tr
|
||
v-if="fulfillmentDetailLineKey && fulfillmentDetailLineKey === String(line.line_key || '')"
|
||
class="border-b border-slate-100 bg-slate-50/40 dark:border-slate-800 dark:bg-slate-950/30"
|
||
data-testid="review-line-fulfillment-detail-row"
|
||
>
|
||
<td :colspan="linesTableColumnCount" class="px-2 py-2">
|
||
<ReviewLineFulfillmentDetail
|
||
:line="lineFulfillmentFor(String(line.line_key || ''))"
|
||
:task-no="fulfillmentDetailTaskNo"
|
||
@open-audit="openAuditTrail"
|
||
@close="closeFulfillmentDetail"
|
||
/>
|
||
</td>
|
||
</tr>
|
||
</template>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div v-else-if="caseContentSkeleton" class="overflow-x-auto overscroll-x-contain p-4" data-testid="review-lines-skeleton">
|
||
<table :class="[linesTableMinWidthClass, 'w-full border-collapse text-left text-xs']">
|
||
<thead class="bg-slate-50 text-slate-500 dark:bg-slate-950/40 dark:text-slate-400">
|
||
<tr>
|
||
<th class="sticky left-0 z-10 min-w-10 border-b border-slate-200 bg-slate-50 px-2 py-1.5 font-medium dark:border-slate-800 dark:bg-slate-950">#</th>
|
||
<template v-for="field in visibleLineSchemaFields" :key="`skeleton-${field.field_id}`">
|
||
<th class="min-w-36 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800">
|
||
{{ field.display_name }}<span v-if="field.required"> *</span>
|
||
</th>
|
||
<th
|
||
v-if="showLineInventoryColumns && isInventorySourceHintField(field)"
|
||
class="min-w-28 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800"
|
||
>
|
||
{{ t('chat.shippingOrderReview.lineOps.inventorySource') }}
|
||
</th>
|
||
<th
|
||
v-if="showLineInventoryColumns && isQtySchemaField(field)"
|
||
class="min-w-20 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800"
|
||
>
|
||
{{ t('chat.shippingOrderReview.fulfillmentDecision.availableQty') }}
|
||
</th>
|
||
<th
|
||
v-if="showLineInventoryColumns && isQtySchemaField(field)"
|
||
class="min-w-16 border-b border-slate-200 px-2 py-1.5 font-medium dark:border-slate-800"
|
||
>
|
||
{{ t('chat.shippingOrderReview.fulfillmentDecision.shortage') }}
|
||
</th>
|
||
</template>
|
||
<th class="sticky right-0 z-10 min-w-28 border-b border-slate-200 bg-slate-50 px-2 py-1.5 dark:border-slate-800 dark:bg-slate-950">
|
||
<span class="sr-only">{{ t('chat.shippingOrderReview.fulfillmentDecision.actions') }}</span>
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr v-for="index in 3" :key="`line-skeleton-${index}`" class="border-b border-slate-100 last:border-0 dark:border-slate-800">
|
||
<td class="sticky left-0 z-10 bg-white px-2 py-2 dark:bg-slate-900">
|
||
<div class="h-4 w-4 animate-pulse rounded bg-slate-200 dark:bg-slate-700" />
|
||
</td>
|
||
<td v-for="column in Math.max(visibleLineSchemaFields.length + 1, 3)" :key="`line-skeleton-${index}-${column}`" class="px-2 py-2">
|
||
<div class="h-8 w-full animate-pulse rounded bg-slate-200 dark:bg-slate-700" />
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div v-else class="p-4 text-sm text-slate-500">{{ t('chat.shippingOrderReview.noLines') }}</div>
|
||
</section>
|
||
|
||
<ReviewInventoryCandidatesPanel
|
||
v-if="workbenchMode === 'inventory'"
|
||
:lines="routingRecoveryLines"
|
||
:enabled-source-codes="buildEligibility?.enabled_inventory_source_codes || []"
|
||
:source-labels="buildEligibility?.inventory_source_labels || {}"
|
||
:editable="editable"
|
||
:saving="saving"
|
||
@submit="submitInventoryCandidates"
|
||
@reroute="onInventoryRoutingReroute"
|
||
@adopt="onInventoryRoutingAdopt"
|
||
@keep="onInventoryRoutingKeep"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<aside
|
||
class="min-w-0 space-y-2 xl:sticky xl:top-4"
|
||
data-testid="review-build-gate-rail"
|
||
:aria-label="t('chat.shippingOrderReview.workbench.summaryRail')"
|
||
>
|
||
<!-- T9+T18 精简:宽屏与窄屏均只保留单一「当前任务」主卡,历史检查与资格卡片移除。 -->
|
||
<ReviewCurrentProcessingCard
|
||
v-if="mountCurrentProcessingCard"
|
||
:stage-code="currentProcessingStageDisplay.code"
|
||
:stage-label-key="currentProcessingStageDisplay.labelKey"
|
||
:stage-inconsistent="currentProcessingStageDisplay.inconsistent"
|
||
:task-missing="Boolean(displayCase?.task_missing)"
|
||
:task-no="displayCase?.confirmed_task_no || displayCase?.post_confirm_auto_progress?.task_no"
|
||
:confirmed-task-id="displayCase?.confirmed_task_id"
|
||
:show-admin-diagnosis="showAdminTaskMissingDiagnosis"
|
||
:has-formal-ot="shippingProcessingProjection?.hasFormalOt ?? hasFormalOt"
|
||
:shipping-notice-no="shippingProcessingProjection?.shippingNoticeNo ?? confirmedNoticeTaskNo"
|
||
:user-status="shippingProcessingProjection?.userStatus ?? displayCase?.user_status"
|
||
:retryable="displayCase?.process_gate?.current_blocking_gate ? false : (shippingProcessingProjection?.retryable ?? showObjectRetryOnRail)"
|
||
:blocking-reason="shippingProcessingProjection?.blockingReason ?? displayCase?.blocking_reason"
|
||
:primary-action="displayCase?.process_gate?.current_blocking_gate ? null : (shippingProcessingProjection?.primaryAction ?? displayCase?.primary_action)"
|
||
:retrying="displayCase?.process_gate?.current_blocking_gate
|
||
? (progressRetrying || caseSwitchLoading)
|
||
: (taskRetryButtonDisabled || progressRetrying || caseSwitchLoading)"
|
||
:retry-exhausted-sources="taskInventoryExhaustedSources"
|
||
:loading="caseContentSkeleton"
|
||
@retry="() => void (hasFormalOt ? retryFormalOtAutoProgress() : retryStpAutoCreate())"
|
||
@locate="(lineKey, fieldId) => handleCurrentTaskLocate(lineKey, fieldId)"
|
||
@action="(code, params) => void handleCurrentTaskAction(code, params)"
|
||
/>
|
||
<ReviewInventoryIssueFallbackCard
|
||
v-if="hasFormalOt && displayCase?.inventory_issue_fallback && !displayCase?.line_fulfillment?.has_line_inventory_projection"
|
||
:fallback="displayCase.inventory_issue_fallback"
|
||
:busy="false"
|
||
@retry-preparation="() => void retryCaseInventoryFallback()"
|
||
/>
|
||
<ProcessGateRecoveryCard
|
||
v-if="!reparseProgressActive && showHumanBlockingGate && displayCase?.process_gate && hasCreatedShippingTask"
|
||
:summary="displayCase.process_gate"
|
||
:can-handle="workbenchActionsExecutable"
|
||
:navigation-context="reviewGateNavigationContext"
|
||
inventory-upload-mode="local"
|
||
:field-labels="reviewFieldLabels"
|
||
@refreshed="reloadLatestDraft"
|
||
@refresh-needed="reloadLatestDraft"
|
||
@confirm-customer="(taskNo) => void page.openShippingCustomerDialog?.(taskNo)"
|
||
@manual-upload="() => void openManualUploadRegistration()"
|
||
/>
|
||
<ReviewProfileMatchPanel
|
||
:profile-match="displayCase?.profile_match"
|
||
/>
|
||
</aside>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
|
||
<!-- 默认浮动证据面板:fixed 叠加,不参与主网格,底栏上方留白。 -->
|
||
<ReviewDocumentEvidenceDrawer
|
||
v-if="evidenceFloating"
|
||
:open="panelState.pdfOpen"
|
||
:pinned="panelState.pdfPinned"
|
||
:expanded="panelState.pdfExpanded"
|
||
:docked="false"
|
||
:float-side="panelState.pdfFloatSide"
|
||
:src="previewUrl"
|
||
:evidence="selectedEvidence"
|
||
:evidence-list="evidence || []"
|
||
:field-label="evidenceFieldLabel"
|
||
:draft-value="focusedLlmDraftValue"
|
||
:machine-value="evidenceMachineValue"
|
||
:value-source-label="evidenceValueSourceLabel"
|
||
:show-ai-actions="editable"
|
||
:reset-key="displayCase?.case_no || null"
|
||
@close="closeEvidenceMode"
|
||
@toggle-pin="togglePdfPinned"
|
||
@toggle-expand="togglePdfExpanded"
|
||
@toggle-dock="togglePdfDocked"
|
||
@toggle-side="togglePdfFloatSide"
|
||
@prev-evidence="navigateEvidence(-1)"
|
||
@next-evidence="navigateEvidence(1)"
|
||
@request-ai="requestSuggestion()"
|
||
@restore-machine="restoreEvidenceMachineValue"
|
||
/>
|
||
|
||
<ReviewBuildEligibilityDetailsDrawer
|
||
:open="panelState.eligibilityDetailsOpen"
|
||
:eligibility="buildEligibility"
|
||
:field-conflicts="displayCase?.field_conflicts"
|
||
:field-labels="Object.fromEntries((displayCase?.schema.fields || []).map((field) => [field.field_code, field.display_name]))"
|
||
:customer-resolved="Boolean(displayCase?.customer_resolution?.resolved)"
|
||
@close="closeEligibilityDetails"
|
||
@focus-line="(lineIndex) => { closeEligibilityDetails(); focusOrderLine(lineIndex); }"
|
||
/>
|
||
|
||
<ReviewVersionHistoryDrawer
|
||
:open="panelState.versionHistoryOpen"
|
||
:item-no="reviewProgressContext?.item_no || itemNoFromQuery"
|
||
:versions="versions"
|
||
:loading="versionsLoading"
|
||
:active-case-no="requestedCaseNo || displayCase?.case_no"
|
||
@close="closeVersionHistory"
|
||
@select="(caseNo) => { closeVersionHistory(); void selectVersionFromHistory(caseNo); }"
|
||
/>
|
||
|
||
<ReviewAuditTrailDrawer
|
||
:open="auditTrailOpen"
|
||
:case-no="activeCase?.case_no || ''"
|
||
@close="closeAuditTrail"
|
||
/>
|
||
|
||
<ReviewCloseFulfillmentDialog
|
||
v-model:open="closeFulfillmentOpen"
|
||
:case-no="activeCase?.case_no || ''"
|
||
:draft-version="activeCase?.draft?.draft_version"
|
||
:line-keys="closeFulfillmentLineKeys"
|
||
@confirmed="onCloseFulfillmentConfirmed"
|
||
/>
|
||
|
||
<ReviewLlmSuggestionDrawer
|
||
:open="panelState.llmSuggestionOpen"
|
||
:active-case="activeCase"
|
||
:evidence="evidence"
|
||
:editable="editable"
|
||
:saving="saving"
|
||
:suggestions="llmSuggestions"
|
||
:suggestion-loading="suggestionLoading"
|
||
:focused-field-id="focusedFieldId"
|
||
:focused-line-key="focusedLineKey"
|
||
:draft-value="focusedLlmDraftValue"
|
||
@close="closeLlmSuggestionDrawer"
|
||
@request-suggestion="requestSuggestion()"
|
||
@adjudicate="({ suggestion, body }) => decideSuggestion(suggestion.suggestion_no, body)"
|
||
/>
|
||
|
||
<ReviewWorkbenchFooter
|
||
:available-actions="availableActions"
|
||
:can-confirm-build="canConfirmBuild"
|
||
:hide-confirm-because-auto-gate="hideConfirmBecauseAutoGate"
|
||
:show-auto-gate-hint="showAutoGateHint"
|
||
:show-stp-retry="showObjectRetryOnFooter"
|
||
:auto-gate-hint="t(autoGateHintKey)"
|
||
:saving="saving"
|
||
:is-read-only="isReadOnly"
|
||
:has-draft="Boolean(displayCase?.draft)"
|
||
:unsaved-count="unsavedEditCount"
|
||
:flow-presentation="flowPresentation"
|
||
:automating="isProcessingAutomating"
|
||
:actions-executable="workbenchActionsExecutable"
|
||
:flow-busy="flowActionBusy"
|
||
@mark-non-order="openActionDialog('non_order')"
|
||
@mark-quality-issue="openActionDialog('quality_issue')"
|
||
@reparse="openActionDialog('reparse')"
|
||
@upload-replacement="selectReplacement"
|
||
@validate="reportSave(() => validate())"
|
||
@confirm="openActionDialog('confirm')"
|
||
@retry-stp="() => void onFooterRetryAutomation()"
|
||
@flow-action="(item) => { void onUnifiedProcessingAction(item); }"
|
||
/>
|
||
|
||
<ReviewProcessDetailDrawer
|
||
:open="processDetailOpen"
|
||
:projection="shippingProcessingProjection"
|
||
:po-number="processDetailPoNumber"
|
||
:order-task-no="authoritativeOrderTaskNo"
|
||
:audit-available="Boolean(activeCase?.case_no)"
|
||
@close="processDetailOpen = false"
|
||
@open-audit="() => { processDetailOpen = false; auditTrailOpen = true; }"
|
||
/>
|
||
|
||
<ManualUploadEvidenceDialog
|
||
v-model:open="manualUploadRegistrationOpen"
|
||
:task-no="confirmedNoticeTaskNo"
|
||
:artifact-id="formalTaskDetail?.export_artifacts?.[0]?.id || null"
|
||
:disabled="!workbenchActionsExecutable"
|
||
@success="() => { void handleManualUploadSuccess(); }"
|
||
/>
|
||
|
||
<ReviewConversationRetryDrawer
|
||
:open="conversationRetryDrawerOpen"
|
||
:result="conversationRetryResult"
|
||
@close="conversationRetryDrawerOpen = false"
|
||
/>
|
||
|
||
<ReviewUnsavedSwitchDialog
|
||
:open="unsavedSwitchOpen"
|
||
:unsaved-count="unsavedEditCount"
|
||
:saving="saving"
|
||
@cancel="() => { unsavedSwitchOpen = false; pendingSwitchCaseNo = null; }"
|
||
@discard="() => { void discardAndSwitchCase(); }"
|
||
@save-and-switch="() => { void saveAndSwitchCase(); }"
|
||
/>
|
||
|
||
<div
|
||
v-if="conversationRetryToastOpen"
|
||
class="fixed right-4 top-16 z-50 max-w-xs rounded-full border border-slate-200 bg-white px-3 py-1.5 text-[11px] shadow-md dark:border-slate-700 dark:bg-slate-900"
|
||
data-testid="review-conversation-retry-toast"
|
||
role="status"
|
||
>
|
||
<div class="flex items-center gap-2">
|
||
<RefreshCw class="h-3.5 w-3.5 shrink-0 text-amber-600" />
|
||
<p v-if="conversationRetryError" class="text-rose-700 dark:text-rose-300">{{ conversationRetryError }}</p>
|
||
<p v-else class="text-slate-700 dark:text-slate-200">
|
||
{{ conversationRetryError || t('chat.shippingOrderReview.conversationRetry.toast', { retried: conversationRetryResult?.summary.retried || 0 }) }}
|
||
<button
|
||
v-if="hasConversationRetryAttention"
|
||
type="button"
|
||
class="ml-2 font-medium text-sky-700 hover:underline dark:text-sky-300"
|
||
data-testid="review-conversation-retry-toast-open"
|
||
@click="conversationRetryDrawerOpen = true"
|
||
>
|
||
{{ t('chat.shippingOrderReview.conversationRetry.viewResult') }}
|
||
</button>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<ReviewActionConfirmDialog
|
||
v-if="actionDialogOpen && pendingAction"
|
||
v-model="actionDialogOpen"
|
||
:action="pendingAction"
|
||
:confirm-loading="saving"
|
||
@confirm="submitPendingAction"
|
||
@cancel="pendingReplaceFile = null"
|
||
/>
|
||
<ReviewLineNoOverrideDialog
|
||
v-model="lineNoOverrideOpen"
|
||
:pending-value="pendingLineNoEdit?.value || ''"
|
||
:confirm-loading="saving"
|
||
@confirm="submitLineNoOverride"
|
||
@cancel="cancelLineNoOverride"
|
||
/>
|
||
</main>
|
||
</template>
|