feat(shipping-notice): 增强发货通知候选管理功能,支持候选选择、重复检测与业务摘要修订

This commit is contained in:
hugo committed 2026-07-15 11:57:04 +08:00
1 parent 70f684b94a
commit b595e157e9
83 files changed
+5857 -200

No files matched your search

@@ -21,6 +21,7 @@ import {
X,
} from 'lucide-vue-next';
import type { PendingAttachment, ShippingNoticePendingAttachment } from '../types/shipping.types';
import ShippingNoticeCandidateReview from './ShippingNoticeCandidateReview.vue';
import {
isBlockingWarning,
isShippingNoticeAttachmentParseIncomplete,
@@ -49,6 +50,7 @@ const props = defineProps<{
isShippingNoticeAgent: boolean;
isMaintenanceAgent?: boolean;
canManageMaintenance?: boolean;
canForceCreateShippingDuplicate?: boolean;
shippingSuggestedPrompt: string;
shippingFocusTaskNo?: string;
shippingFocusReason?: string;
@@ -65,6 +67,9 @@ const emit = defineEmits<{
'remove-attachment': [id: string];
'retry-shipping-notice-attachment': [id: string];
'resolve-shipping-notice-duplicate': [id: string];
'select-shipping-candidate': [candidateNo: string, selected: boolean];
'update-shipping-candidate': [candidateNo: string, businessSummary: Record<string, unknown>, done: (success: boolean) => void];
'resolve-shipping-candidate-duplicate': [candidateNo: string, action: import('../types/shipping.types').ShippingDuplicateAction, targetTaskNo: string | undefined, reason: string | undefined, done: (success: boolean) => void];
'local-files-selected': [event: Event];
'add-remote-url': [url: string];
'shipping-inventory-selected': [event: Event];
@@ -276,6 +281,18 @@ watch(
<X class="h-3.5 w-3.5" />
</button>
</div>
<div v-if="isShippingNoticeAgent" class="space-y-2 px-3 pb-1">
<ShippingNoticeCandidateReview
v-for="a in attachments.filter((item): item is ShippingNoticePendingAttachment => item.kind === 'shipping_notice' && !!item.candidates?.length)"
:key="`candidate-${a.id}`"
:attachment="a"
:can-force-create="!!canForceCreateShippingDuplicate"
@select="(candidateNo, selected) => emit('select-shipping-candidate', candidateNo, selected)"
@update="(candidateNo, summary, done) => emit('update-shipping-candidate', candidateNo, summary, done)"
@resolve-duplicate="(candidateNo, action, targetTaskNo, reason, done) => emit('resolve-shipping-candidate-duplicate', candidateNo, action, targetTaskNo, reason, done)"
/>
</div>
<textarea
ref="textareaRef"
v-model="inputValue"
@@ -319,11 +336,11 @@ watch(
<span v-if="a.uploadStatus === 'uploading'" class="text-muted"> · {{ t('chat.shippingNoticeUploading') }}</span>
<span v-else-if="a.parseStatus === 'queued' || a.parseStatus === 'parsing'" class="text-muted"> · {{ t('chat.shippingNoticeParsing') }}</span>
<span
v-else-if="a.parseStatus === 'parsed' && a.duplicate?.status === 'possible_duplicate' && !a.duplicateResolution?.action"
v-else-if="a.parseStatus === 'parsed' && !a.candidates?.length && a.duplicate?.status === 'possible_duplicate' && !a.duplicateResolution?.action"
class="font-medium text-amber-700"
> · {{ t('chat.shippingNoticeDuplicatePossibleBadge') }}</span>
<span
v-else-if="a.parseStatus === 'parsed' && a.duplicate?.blocking && !a.duplicateResolution?.action"
v-else-if="a.parseStatus === 'parsed' && !a.candidates?.length && a.duplicate?.blocking && !a.duplicateResolution?.action"
class="font-medium text-amber-700"
> · {{ t('chat.shippingNoticeDuplicateBlockingBadge') }}</span>
<span
@@ -355,7 +372,7 @@ watch(
</template>
</span>
<button
v-if="a.kind === 'shipping_notice' && a.duplicate?.blocking && !a.duplicateResolution?.action"
v-if="a.kind === 'shipping_notice' && !a.candidates?.length && a.duplicate?.blocking && !a.duplicateResolution?.action"
type="button"
class="text-amber-700 hover:text-amber-800"
:title="t('chat.shippingNoticeDuplicateHandle')"
@@ -276,6 +276,7 @@ watch(() => page.currentAgentId, () => {
:is-shipping-notice-agent="page.isShippingNoticeAgent"
:is-maintenance-agent="isMaintenanceAgentPage"
:can-manage-maintenance="canManageMaintenance"
:can-force-create-shipping-duplicate="page.canForceCreateShippingDuplicate"
:shipping-suggested-prompt="page.shippingSuggestedPrompt"
:shipping-focus-task-no="page.focusedShippingTaskNo"
:shipping-focus-reason="page.shippingFocusReason"
@@ -288,6 +289,9 @@ watch(() => page.currentAgentId, () => {
@remove-attachment="page.removeAttachment"
@retry-shipping-notice-attachment="page.retryShippingNoticeAttachment"
@resolve-shipping-notice-duplicate="page.openShippingDuplicateDialog"
@select-shipping-candidate="page.setShippingCandidateSelected"
@update-shipping-candidate="page.updateShippingCandidateSummary"
@resolve-shipping-candidate-duplicate="page.resolveShippingCandidateDuplicate"
@local-files-selected="page.handleLocalFilesSelected"
@add-remote-url="page.addRemoteUrlAttachment"
@shipping-inventory-selected="page.handleShippingInventorySelected"
@@ -0,0 +1,218 @@
<!--
features/chat/components/ShippingNoticeCandidateReview.vue
用途:展示一封 EML 下的订单候选,并提供选择、结构化修订与重复决策入口。
依赖:shipping.types、Vue I18n。
逻辑:组件维护 PO 与订单行编辑草稿,持久化操作通过事件交给 useShippingNoticeIntakes。
-->
<script setup lang="ts">
import { computed, reactive, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import type { ShippingDuplicateAction, ShippingNoticePendingAttachment } from '../types/shipping.types';
interface EditableCandidateLine {
source: Record<string, unknown>;
sku: string;
qty: string;
reservation_id: string;
hub_code: string;
uom: string;
}
const props = defineProps<{
attachment: ShippingNoticePendingAttachment;
canForceCreate: boolean;
}>();
const emit = defineEmits<{
select: [candidateNo: string, selected: boolean];
update: [candidateNo: string, businessSummary: Record<string, unknown>, done: (success: boolean) => void];
resolveDuplicate: [candidateNo: string, action: ShippingDuplicateAction, targetTaskNo: string | undefined, reason: string | undefined, done: (success: boolean) => void];
}>();
const { t } = useI18n();
const editingCandidateNo = ref('');
const editError = ref('');
const editPoNumber = ref('');
const editLines = reactive<EditableCandidateLine[]>([]);
const forceReasonCandidateNo = ref('');
const forceReason = ref('');
const submittingCandidateNo = ref('');
const candidates = computed(() => props.attachment.candidates || []);
watch(() => props.attachment.candidates, () => {
if (editingCandidateNo.value && !candidates.value.some((item) => item.candidateNo === editingCandidateNo.value)) {
editingCandidateNo.value = '';
}
});
/** 将 Candidate 摘要投影为业务用户可编辑的 PO、SKU、Qty、Reservation 与 Hub 字段。 */
function startEdit(candidateNo: string): void {
const candidate = candidates.value.find((item) => item.candidateNo === candidateNo);
if (!candidate) return;
const sourceLines = Array.isArray(candidate.businessSummary.lines)
? candidate.businessSummary.lines.filter((item): item is Record<string, unknown> => !!item && typeof item === 'object')
: [];
editingCandidateNo.value = candidateNo;
editPoNumber.value = String(candidate.businessSummary.po_number || candidate.poNumber || '');
editLines.splice(0, editLines.length, ...sourceLines.map((line) => ({
source: { ...line },
sku: String(line.sku || ''),
qty: String(line.qty ?? ''),
reservation_id: String(line.reservation_id || ''),
hub_code: String(line.hub_code || ''),
uom: String(line.uom || 'EA'),
})));
if (!editLines.length) addLine();
editError.value = '';
}
/** 新增一条待修订订单行。 */
function addLine(): void {
editLines.push({ source: {}, sku: '', qty: '', reservation_id: '', hub_code: '', uom: 'EA' });
}
/** 校验所有订单行后提交,不允许空 SKU、非正数数量或空行静默通过。 */
function saveEdit(): void {
const candidate = candidates.value.find((item) => item.candidateNo === editingCandidateNo.value);
if (!candidate || !editLines.length) return;
const normalizedLines = editLines.map((line) => ({
...line.source,
sku: line.sku.trim(),
qty: Number(line.qty),
reservation_id: line.reservation_id.trim() || undefined,
hub_code: line.hub_code.trim() || undefined,
uom: line.uom.trim() || 'EA',
}));
if (normalizedLines.some((line) => !line.sku || !Number.isFinite(line.qty) || line.qty <= 0)) {
editError.value = t('chat.shippingCandidateInvalidLine');
return;
}
submittingCandidateNo.value = candidate.candidateNo;
emit('update', candidate.candidateNo, {
...candidate.businessSummary,
po_number: editPoNumber.value.trim() || null,
lines: normalizedLines,
}, (success) => {
submittingCandidateNo.value = '';
if (success) {
editingCandidateNo.value = '';
editError.value = '';
}
});
}
/** 对当前首个重复目标应用决策;强制新建时要求填写原因。 */
function resolveDuplicate(candidateNo: string, action: ShippingDuplicateAction): void {
const candidate = candidates.value.find((item) => item.candidateNo === candidateNo);
const target = candidate?.duplicate?.matches?.[0]?.taskNo;
if (action === 'force_create') {
forceReasonCandidateNo.value = candidateNo;
forceReason.value = '';
return;
}
submittingCandidateNo.value = candidateNo;
emit('resolveDuplicate', candidateNo, action, target, undefined, () => {
submittingCandidateNo.value = '';
});
}
/** 提交内联强制新建原因,避免浏览器 prompt 丢失上下文或不可访问。 */
function submitForceCreate(candidateNo: string): void {
const candidate = candidates.value.find((item) => item.candidateNo === candidateNo);
const reason = forceReason.value.trim();
if (!candidate || !reason) return;
submittingCandidateNo.value = candidateNo;
emit(
'resolveDuplicate',
candidateNo,
'force_create',
candidate.duplicate?.matches?.[0]?.taskNo,
reason,
(success) => {
submittingCandidateNo.value = '';
if (success) forceReasonCandidateNo.value = '';
},
);
}
</script>
<template>
<div v-if="candidates.length" class="w-full space-y-2 rounded-xl border border-default bg-surface px-3 py-2">
<div class="flex items-center justify-between text-xs">
<span class="font-semibold text-primary">{{ t('chat.shippingCandidateTitle') }}</span>
<span class="text-muted">{{ t('chat.shippingCandidateCount', { count: candidates.length }) }}</span>
</div>
<div v-for="candidate in candidates" :key="candidate.candidateNo" class="rounded-lg border border-default bg-surface-soft p-2 text-xs">
<div class="flex flex-wrap items-center gap-2">
<input
type="checkbox"
:checked="candidate.selected"
:disabled="!!candidate.consumedTaskId"
@change="emit('select', candidate.candidateNo, ($event.target as HTMLInputElement).checked)"
/>
<span class="font-mono text-primary">{{ candidate.candidateNo }}</span>
<span class="font-medium text-secondary">PO {{ candidate.poNumber || '-' }}</span>
<span v-if="candidate.documentFilename" class="max-w-40 truncate text-muted">{{ candidate.documentFilename }}</span>
<span :class="candidate.validationStatus === 'ready' ? 'text-emerald-700' : 'text-amber-700'">
{{ candidate.validationStatus === 'ready' ? t('chat.shippingCandidateReady') : t('chat.shippingCandidateNeedsReview') }}
</span>
<button type="button" class="ml-auto text-brand-700 hover:underline" @click="startEdit(candidate.candidateNo)">
{{ t('chat.shippingCandidateEdit') }}
</button>
</div>
<div v-if="candidate.conflicts.length" class="mt-1 text-amber-700">
{{ t('chat.shippingCandidateConflictCount', { count: candidate.conflicts.length }) }}
</div>
<div v-if="candidate.duplicate?.blocking && !candidate.duplicateResolution" class="mt-2 flex flex-wrap items-center gap-2 text-amber-700">
<span>{{ t('chat.shippingCandidateDuplicate', { task: candidate.duplicate.matches[0]?.taskNo || '-' }) }}</span>
<button
v-if="candidate.duplicate.allowedActions.includes('open_existing')"
type="button"
class="rounded border border-default bg-surface px-2 py-0.5"
@click="resolveDuplicate(candidate.candidateNo, 'open_existing')"
>{{ t('chat.shippingNoticeDuplicateOpenExisting') }}</button>
<button
v-if="candidate.duplicate.allowedActions.includes('create_revision')"
type="button"
class="rounded border border-default bg-surface px-2 py-0.5"
@click="resolveDuplicate(candidate.candidateNo, 'create_revision')"
>{{ t('chat.shippingNoticeDuplicateCreateRevision') }}</button>
<button
v-if="canForceCreate && candidate.duplicate.allowedActions.includes('force_create')"
type="button"
class="rounded border border-amber-300 bg-surface px-2 py-0.5"
@click="resolveDuplicate(candidate.candidateNo, 'force_create')"
>{{ t('chat.shippingNoticeDuplicateForceCreate') }}</button>
</div>
<div v-if="forceReasonCandidateNo === candidate.candidateNo" class="mt-2 flex gap-2">
<input v-model="forceReason" :placeholder="t('chat.shippingCandidateForceReasonPrompt')" class="min-w-0 flex-1 rounded border border-default bg-surface px-2 py-1" />
<button type="button" class="rounded bg-amber-600 px-2 py-1 text-white disabled:opacity-50" :disabled="!forceReason.trim() || submittingCandidateNo === candidate.candidateNo" @click="submitForceCreate(candidate.candidateNo)">{{ t('chat.shippingNoticeDuplicateConfirm') }}</button>
<button type="button" class="text-muted" @click="forceReasonCandidateNo = ''">{{ t('common.cancel') }}</button>
</div>
<div v-else-if="candidate.duplicateResolution" class="mt-1 text-muted">
{{ t('chat.shippingCandidateDuplicateResolved', { action: candidate.duplicateResolution.action }) }}
</div>
<div v-if="editingCandidateNo === candidate.candidateNo" class="mt-2 space-y-2">
<label class="block">
<span class="text-muted">{{ t('chat.shippingCandidatePoNumber') }}</span>
<input v-model="editPoNumber" class="mt-1 w-full rounded border border-default bg-surface px-2 py-1 text-primary" />
</label>
<div v-for="(line, index) in editLines" :key="index" class="grid grid-cols-2 gap-2 rounded border border-default bg-surface p-2 md:grid-cols-5">
<input v-model="line.sku" :placeholder="t('chat.shippingCandidateSku')" class="rounded border border-default px-2 py-1" />
<input v-model="line.qty" type="number" min="0.0001" step="any" :placeholder="t('chat.shippingCandidateQty')" class="rounded border border-default px-2 py-1" />
<input v-model="line.reservation_id" :placeholder="t('chat.shippingCandidateReservation')" class="rounded border border-default px-2 py-1" />
<input v-model="line.hub_code" :placeholder="t('chat.shippingCandidateHubCode')" class="rounded border border-default px-2 py-1" />
<div class="flex gap-1">
<input v-model="line.uom" :placeholder="t('chat.shippingCandidateUom')" class="min-w-0 flex-1 rounded border border-default px-2 py-1" />
<button v-if="editLines.length > 1" type="button" class="text-red-600" @click="editLines.splice(index, 1)">×</button>
</div>
</div>
<button type="button" class="text-brand-700 hover:underline" @click="addLine">{{ t('chat.shippingCandidateAddLine') }}</button>
<div v-if="editError" class="text-red-600">{{ editError }}</div>
<div class="flex justify-end gap-2">
<button type="button" class="rounded px-2 py-1 text-secondary" @click="editingCandidateNo = ''">{{ t('common.cancel') }}</button>
<button type="button" class="rounded bg-brand-600 px-2 py-1 text-white disabled:opacity-50" :disabled="submittingCandidateNo === candidate.candidateNo" @click="saveEdit">{{ t('chat.shippingCandidateSave') }}</button>
</div>
</div>
</div>
</div>
</template>