feat(shipping-notice): 新增订单行与字段冲突管理功能,支持字段冲突查询与解决

This commit is contained in:
hugo committed 2026-07-16 13:03:11 +08:00
1 parent 4fbaed2b4c
commit 9da0481fc3
74 files changed
+4861 -375

No files matched your search

@@ -0,0 +1,210 @@
<!--
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,
ShippingParseIssue,
ShippingParseValidation,
ShippingProcessFieldGate,
ShippingSourceCandidateProjection,
} from '@/features/chat/types/shipping.api.types';
const props = defineProps<{
taskNo?: string | null;
poNumber?: string | null;
lines?: ShippingNoticeLine[] | 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 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 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');
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="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.sku" class="mt-0.5 text-[11px] opacity-80">SKU {{ issue.sku }}</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 class="px-2.5 py-2">{{ t('chat.shippingNoticeUi.sku') }}</th>
<th class="px-2.5 py-2">{{ t('chat.shippingNoticeUi.qty') }}</th>
<th class="px-2.5 py-2">{{ t('chat.shippingNoticeUi.reservationId') }}</th>
<th class="px-2.5 py-2">{{ t('chat.shippingParsedResult.sourceType') }}</th>
<th class="px-2.5 py-2">{{ t('chat.shippingParsedResult.hubCode') }}</th>
</tr>
</thead>
<tbody>
<tr
v-for="(line, index) in orderLines"
:key="`${line.sku}-${index}`"
class="border-t border-default/60 text-xs"
>
<td class="px-2.5 py-2 text-muted">{{ index + 1 }}</td>
<td class="px-2.5 py-2 font-mono">{{ displayValue(line.sku) }}</td>
<td class="px-2.5 py-2">{{ displayValue(line.qty) }}</td>
<td class="px-2.5 py-2 font-mono">{{ displayValue(line.reservation_id) }}</td>
<td class="px-2.5 py-2">{{ displayValue(line.source_type) }}</td>
<td class="px-2.5 py-2 font-mono">{{ displayValue(line.hub_code) }}</td>
</tr>
</tbody>
</table>
</div>
<div v-else class="text-muted">{{ t('chat.shippingParsedResult.noLines') }}</div>
<ShippingFieldEvidencePanel
:evidence="sourceCandidate?.evidence || []"
:compact="compact"
/>
</div>
</section>
</template>