244 lines
10 KiB
Vue
244 lines
10 KiB
Vue
<!--
|
||
features/chat/components/ShippingTaskParsedResultCard.vue
|
||
用途:任务详情持久只读展示订单解析行、流转门禁、字段冲突与来源证据。
|
||
依赖:ShippingFieldEvidencePanel、ShippingTaskFieldConflictPanel、shipping.api.types、vue-i18n。
|
||
逻辑:Drawer / ShippingNoticeView 共用;只解释后端 Gate,不自行推导可继续状态。
|
||
-->
|
||
<script setup lang="ts">
|
||
import { computed, ref, watch } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import ShippingFieldEvidencePanel from '@/features/chat/components/ShippingFieldEvidencePanel.vue';
|
||
import ShippingTaskFieldConflictPanel from '@/features/chat/components/ShippingTaskFieldConflictPanel.vue';
|
||
import type {
|
||
ShippingFieldConflict,
|
||
ShippingNoticeLine,
|
||
ShippingOrderDisplayField,
|
||
ShippingParseIssue,
|
||
ShippingParseValidation,
|
||
ShippingProcessFieldGate,
|
||
ShippingSourceCandidateProjection,
|
||
} from '@/features/chat/types/shipping.api.types';
|
||
|
||
const props = defineProps<{
|
||
taskNo?: string | null;
|
||
poNumber?: string | null;
|
||
lines?: ShippingNoticeLine[] | null;
|
||
orderHeader?: Record<string, unknown> | null;
|
||
orderHeaderFields?: ShippingOrderDisplayField[] | null;
|
||
orderLineFields?: ShippingOrderDisplayField[] | null;
|
||
parseValidation?: ShippingParseValidation | null;
|
||
processFieldGate?: ShippingProcessFieldGate | null;
|
||
sourceCandidate?: ShippingSourceCandidateProjection | null;
|
||
fieldConflicts?: ShippingFieldConflict[] | null;
|
||
orderDataVersion?: number | null;
|
||
/** 阻断时默认展开;非阻断可折叠。 */
|
||
defaultExpanded?: boolean;
|
||
compact?: boolean;
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
refreshed: [];
|
||
}>();
|
||
|
||
const { t } = useI18n();
|
||
const expanded = ref(true);
|
||
|
||
watch(
|
||
() => props.defaultExpanded,
|
||
(value) => {
|
||
if (typeof value === 'boolean') expanded.value = value;
|
||
},
|
||
{ immediate: true },
|
||
);
|
||
|
||
const orderLines = computed(() => (props.lines || []).filter((line) => line && typeof line === 'object'));
|
||
const orderedHeaderFields = computed(() => [...(props.orderHeaderFields || [])].sort((a, b) => a.sequence - b.sequence));
|
||
const orderedLineFields = computed(() => [...(props.orderLineFields || [])].sort((a, b) => a.sequence - b.sequence));
|
||
|
||
const gateIssues = computed(() => {
|
||
const fromGate = Array.isArray(props.processFieldGate?.issues) ? props.processFieldGate?.issues : [];
|
||
const fromValidation = Array.isArray(props.parseValidation?.issues) ? props.parseValidation?.issues : [];
|
||
return [...fromGate, ...fromValidation] as ShippingParseIssue[];
|
||
});
|
||
|
||
const missingFields = computed(() => {
|
||
const gateMissing = Array.isArray(props.processFieldGate?.missing_fields)
|
||
? props.processFieldGate?.missing_fields || []
|
||
: [];
|
||
const candidateMissing = Array.isArray(props.sourceCandidate?.missing_fields)
|
||
? props.sourceCandidate?.missing_fields || []
|
||
: [];
|
||
return Array.from(new Set([...gateMissing, ...candidateMissing].map((item) => String(item)).filter(Boolean)));
|
||
});
|
||
|
||
const adjudicationDecisions = computed(() => (
|
||
props.sourceCandidate?.field_adjudication?.decisions || []
|
||
).filter((item) => item && typeof item === 'object'));
|
||
|
||
const hasBlocking = computed(() =>
|
||
gateIssues.value.some((issue) => String(issue.severity || '') === 'blocking')
|
||
|| missingFields.value.includes('reservation_id')
|
||
|| String(props.processFieldGate?.status || '') === 'needs_enrichment'
|
||
|| String(props.parseValidation?.status || '') === 'needs_review'
|
||
|| (props.fieldConflicts || []).some((item) => String(item.status || '') === 'open'),
|
||
);
|
||
|
||
const statusLabel = computed(() => {
|
||
if (hasBlocking.value) return t('chat.shippingParsedResult.statusBlocked');
|
||
if (orderLines.value.length) return t('chat.shippingParsedResult.statusReady');
|
||
return t('chat.shippingParsedResult.statusEmpty');
|
||
});
|
||
|
||
const displayValue = (value: unknown) => {
|
||
const text = String(value ?? '').trim();
|
||
return text || '—';
|
||
};
|
||
|
||
/**
|
||
* 将门禁 reason 映射为用户可读文案。
|
||
* @param reason - 后端 issue.reason
|
||
*/
|
||
function issueReasonLabel(reason?: string | null): string {
|
||
const key = String(reason || '').trim();
|
||
if (key === 'missing') return t('chat.shippingParsedResult.issueMissing');
|
||
if (key === 'invalid_format') return t('chat.shippingParsedResult.issueInvalid');
|
||
if (key === 'source_conflict' || key === 'field_conflict') return t('chat.shippingParsedResult.issueConflict');
|
||
if (key === 'value_corrected') return t('chat.shippingParsedResult.issueCorrected');
|
||
if (key === 'plain_text_table_has_no_cell_evidence') return t('chat.shippingParsedResult.issueNoCellEvidence');
|
||
if (key === 'layout_table_needs_review') return t('chat.shippingParsedResult.issueLayoutNeedsReview');
|
||
if (key === 'layout_candidate_document_mismatch') return t('chat.shippingParsedResult.issueLayoutDocumentMismatch');
|
||
return key || t('chat.shippingParsedResult.issueUnknown');
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<section
|
||
class="rounded-xl border p-3 text-xs"
|
||
:class="hasBlocking
|
||
? 'border-amber-200 bg-amber-50/70'
|
||
: 'border-slate-200 bg-surface-soft/80'"
|
||
>
|
||
<button
|
||
type="button"
|
||
class="flex w-full items-start justify-between gap-2 text-left"
|
||
@click="expanded = !expanded"
|
||
>
|
||
<div>
|
||
<div class="text-[11px] font-bold uppercase tracking-wider text-muted">
|
||
{{ t('chat.shippingParsedResult.title') }}
|
||
</div>
|
||
<div v-if="taskNo" class="mt-0.5 font-mono text-[11px] text-secondary">{{ taskNo }}</div>
|
||
<div v-if="poNumber" class="mt-0.5 text-muted">PO {{ poNumber }}</div>
|
||
</div>
|
||
<span
|
||
class="rounded-full px-2 py-0.5 text-[10px] font-semibold"
|
||
:class="hasBlocking ? 'bg-amber-100 text-amber-800' : 'bg-emerald-100 text-emerald-700'"
|
||
>
|
||
{{ statusLabel }}
|
||
</span>
|
||
</button>
|
||
|
||
<div v-if="expanded" class="mt-3 space-y-3">
|
||
<div class="rounded-lg border border-slate-200/80 bg-white/80 px-2.5 py-2 text-[11px] leading-5 text-slate-700">
|
||
{{ t('chat.shippingParsedResult.impactHint') }}
|
||
</div>
|
||
|
||
<ShippingTaskFieldConflictPanel
|
||
v-if="taskNo"
|
||
:task-no="taskNo"
|
||
:conflicts="fieldConflicts || []"
|
||
:order-data-version="orderDataVersion"
|
||
@refreshed="emit('refreshed')"
|
||
/>
|
||
|
||
<div v-if="orderedHeaderFields.length" class="rounded-xl border border-default bg-white/90 p-2.5">
|
||
<div class="mb-2 font-semibold text-slate-700">{{ t('chat.shippingParsedResult.orderInformation') }}</div>
|
||
<dl class="grid gap-2 sm:grid-cols-2">
|
||
<div v-for="field in orderedHeaderFields" :key="field.field_code" class="rounded-lg bg-slate-50 px-2.5 py-2">
|
||
<dt class="text-[10px] text-muted">{{ field.display_name }}</dt>
|
||
<dd class="mt-0.5 break-words text-xs text-slate-800">{{ displayValue(orderHeader?.[field.field_code]) }}</dd>
|
||
</div>
|
||
</dl>
|
||
</div>
|
||
|
||
<div v-if="missingFields.length" class="space-y-1">
|
||
<div class="font-semibold text-amber-800">{{ t('chat.shippingParsedResult.missingFields') }}</div>
|
||
<div class="flex flex-wrap gap-1">
|
||
<span
|
||
v-for="field in missingFields"
|
||
:key="field"
|
||
class="rounded border border-amber-200 bg-amber-100 px-1.5 py-0.5 font-mono text-[10px] text-amber-900"
|
||
>
|
||
{{ field }}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
|
||
<ul v-if="gateIssues.length" class="space-y-1.5">
|
||
<li
|
||
v-for="(issue, index) in gateIssues"
|
||
:key="`${issue.field}-${issue.line_index ?? index}`"
|
||
class="rounded-lg border px-2.5 py-2"
|
||
:class="String(issue.severity) === 'blocking'
|
||
? 'border-rose-200 bg-rose-50 text-rose-800'
|
||
: String(issue.reason) === 'value_corrected'
|
||
? 'border-sky-200 bg-sky-50 text-sky-800'
|
||
: 'border-amber-200 bg-amber-50 text-amber-800'"
|
||
>
|
||
<div class="font-medium">
|
||
<span v-if="issue.line_index != null">#{{ Number(issue.line_index) + 1 }} · </span>
|
||
<span class="font-mono">{{ issue.field }}</span>
|
||
<span class="ml-1">{{ issueReasonLabel(issue.reason) }}</span>
|
||
</div>
|
||
<div v-if="issue.part_number" class="mt-0.5 text-[11px] opacity-80">
|
||
{{ t('chat.shippingNoticeUi.partNumber') }} {{ issue.part_number }}
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
|
||
<div v-if="orderLines.length" class="overflow-x-auto rounded-xl border border-default bg-white/90">
|
||
<table class="min-w-full text-sm">
|
||
<thead class="bg-surface text-left text-[11px] text-muted">
|
||
<tr>
|
||
<th class="px-2.5 py-2">#</th>
|
||
<th v-for="field in orderedLineFields" :key="field.field_code" class="px-2.5 py-2">{{ field.display_name }}</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr
|
||
v-for="(line, index) in orderLines"
|
||
:key="`${line.part_number}-${index}`"
|
||
class="border-t border-default/60 text-xs"
|
||
>
|
||
<td class="px-2.5 py-2 text-muted">{{ index + 1 }}</td>
|
||
<td v-for="field in orderedLineFields" :key="field.field_code" class="px-2.5 py-2" :class="{ 'font-mono': field.value_type === 'string' }">{{ displayValue((line as unknown as Record<string, unknown>)[field.field_code]) }}</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div v-else class="text-muted">{{ t('chat.shippingParsedResult.noLines') }}</div>
|
||
|
||
<div v-if="adjudicationDecisions.length" class="rounded-xl border border-sky-200 bg-sky-50/70 p-2.5">
|
||
<div class="font-semibold text-sky-900">{{ t('chat.shippingParsedResult.adjudicationTitle') }}</div>
|
||
<div class="mt-2 grid gap-1.5 md:grid-cols-2">
|
||
<div
|
||
v-for="decision in adjudicationDecisions"
|
||
:key="`${decision.line_index}-${decision.field}`"
|
||
class="rounded border border-sky-100 bg-white/80 px-2 py-1.5 text-[11px]"
|
||
>
|
||
<span class="font-mono">#{{ Number(decision.line_index) + 1 }} {{ decision.field }}</span>
|
||
<span class="ml-1 font-semibold text-sky-800">{{ decision.status }}</span>
|
||
<span v-if="decision.score != null" class="ml-1 text-muted">{{ t('chat.shippingParsedResult.score', { score: decision.score }) }}</span>
|
||
<div class="mt-0.5 truncate text-secondary">{{ displayValue(decision.value) }}</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<ShippingFieldEvidencePanel
|
||
:evidence="sourceCandidate?.evidence || []"
|
||
:compact="compact"
|
||
/>
|
||
</div>
|
||
</section>
|
||
</template>
|