feat(shipping-notice): 添加订单文档 Profile 盲测集和样本管理功能,支持创建、执行和批准盲测,增强订单冻结和库存核验功能

This commit is contained in:
hugo committed 2026-07-23 00:15:34 +08:00
1 parent c35223d49d
commit abd8fc1e16
98 files changed
+4629 -528

No files matched your search

@@ -1,42 +1,29 @@
<script setup lang="ts">
/**
* features/workspace/views/ShippingNoticeView.vue
* 用途:货代发货任务只读工作台,提供任务筛选、详情查看与跳转 Chat 继续处理入口。
* 用途:货代发货任务工作台,提供任务筛选、履约审计与跳转对话入口。
* 依赖:ShippingWorkflowStepper、ShippingMatchResultCard、ShippingTaskParsedResultCard、shipping.api。
* 逻辑:先拉取任务列表与详情,再以只读方式展示步骤、匹配结果、解析行和事件记录;所有写操作回到 Chat 主路径完成。
* 逻辑:先拉取任务列表与详情,再展示步骤、匹配结果、解析行和事件记录;所有用户写操作仅由对话界面执行。
*/
import { computed, onMounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useAuthStore } from '@/features/auth';
import { Archive, ArrowLeft, Download, ExternalLink, RefreshCw, RotateCcw, Trash2 } from 'lucide-vue-next';
import { ArrowLeft, ExternalLink, RefreshCw } from 'lucide-vue-next';
import ShippingWorkflowStepper from '@/features/chat/components/ShippingWorkflowStepper.vue';
import ShippingMatchResultCard from '@/features/chat/components/messages/ShippingMatchResultCard.vue';
import ShippingTaskParsedResultCard from '@/features/chat/components/ShippingTaskParsedResultCard.vue';
import { formatLocalDateTime } from '@/shared/utils/dateTime';
import { useMessage } from '@/shared/composables/useMessage';
import {
getWorkspaceShippingTask,
archiveWorkspaceShippingTasks,
deleteWorkspaceShippingTasks,
downloadWorkspaceShippingExportArchive,
listShippingChatAgents,
listWorkspaceShippingTasks,
purgeWorkspaceShippingTasks,
restoreWorkspaceShippingTasks,
SHIPPING_NOTICE_AGENT_CODE,
workspaceShippingExportUrl,
type ShippingCurrentStepProgress,
type ShippingTaskDetail,
type ShippingTaskSummary,
} from '@/features/chat/api/shipping.api';
import { getAuthHeaders } from '@/shared/utils/auth';
import { resolveShippingWorkflowSteps } from '@/features/chat/shipping';
import { sanitizeShippingRuntimeStatusText } from '@/features/chat/shipping/shippingText';
import {
selectVisibleShippingExports,
updateShippingExportSelection,
} from '@/features/shipping-notice/utils/exportSelection';
import { SHIPPING_TASK_STATUS_FILTERS } from '../shippingTaskStatuses';
const props = defineProps<{
@@ -45,17 +32,10 @@ const props = defineProps<{
const router = useRouter();
const { t, te } = useI18n();
const msg = useMessage();
const authStore = useAuthStore();
const isAdmin = computed(() => authStore.isAdmin);
const loading = ref(false);
const detailLoading = ref(false);
const tasks = ref<ShippingTaskSummary[]>([]);
const selectedTaskNo = ref<string | null>(null);
const selectedTaskNos = ref<string[]>([]);
const archiveDownloading = ref(false);
const dispositionSubmitting = ref(false);
const detail = ref<ShippingTaskDetail | null>(null);
const statusFilter = ref('all');
const lifecycleFilter = ref('active');
@@ -222,7 +202,6 @@ const loadCases = async (resetPage = false) => {
}
tasks.value = result.items;
totalTasks.value = result.total;
selectedTaskNos.value = [];
selectedTaskNo.value = null;
} catch {
tasks.value = [];
@@ -232,7 +211,7 @@ const loadCases = async (resetPage = false) => {
}
};
/** 切换分页时清空仅当前页有效的下载选择,防止跨页误下载。 */
/** 切换页码并重新读取只读任务列表。 */
const changePage = async (page: number) => {
const normalized = Math.max(1, Math.min(page, totalPages.value));
if (normalized === currentPage.value || loading.value) return;
@@ -271,93 +250,6 @@ const openInChat = (taskNo: string, conversationId?: string | null, batchNo?: st
router.push({ path: `/chat/${chatAgentId.value}`, query });
};
const downloadExport = async (taskNo: string) => {
const url = workspaceShippingExportUrl(taskNo);
const res = await fetch(url, { headers: getAuthHeaders() });
if (!res.ok) return;
const blob = await res.blob();
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = detail.value?.export_file_name || `${taskNo}.xlsx`;
a.click();
URL.revokeObjectURL(a.href);
};
/** 下载当前任务所属批次的所有有效 Artifact;缺失票据记录在 ZIP manifest。 */
const downloadBatchExports = async (batchNo: string) => {
await downloadExportArchive({ batch_no: batchNo });
};
/** 下载批次或显式任务集合,并确保临时对象 URL 在点击后释放。 */
const downloadExportArchive = async (payload: { batch_no?: string; task_nos?: string[] }) => {
archiveDownloading.value = true;
try {
const { blob, filename } = await downloadWorkspaceShippingExportArchive(payload);
const a = document.createElement('a');
a.href = URL.createObjectURL(blob); a.download = filename; a.click(); URL.revokeObjectURL(a.href);
} catch {
msg.error(t('workspace.shippingNotice.archiveDownloadFailed'));
} finally {
archiveDownloading.value = false;
}
};
/** 更新单票勾选;数量门禁与后端 100 票限制一致。 */
const toggleTask = (taskNo: string, checked: boolean) => {
selectedTaskNos.value = updateShippingExportSelection(selectedTaskNos.value, taskNo, checked);
};
/** 全选或清空当前页结果,切页后不保留选择。 */
const toggleAllVisibleTasks = (checked: boolean) => {
selectedTaskNos.value = checked
? selectVisibleShippingExports(tasks.value.map((item) => item.task_no))
: [];
};
const allVisibleTasksSelected = computed(() => (
tasks.value.length > 0 && tasks.value.every((item) => selectedTaskNos.value.includes(item.task_no))
));
/** 按用户显式选择下载,后端仍逐票执行权限与 Artifact 当前性校验。 */
const downloadSelectedExports = async () => {
if (!selectedTaskNos.value.length) return;
await downloadExportArchive({ task_nos: selectedTaskNos.value });
};
/** 批量执行回收站、归档或恢复;删除必须显式录入原因,服务端仍逐票重算资格。 */
const applyTaskDisposition = async (action: 'delete' | 'archive' | 'restore' | 'purge') => {
if (!selectedTaskNos.value.length || dispositionSubmitting.value) return;
let reason = '';
if (action === 'delete' || action === 'purge') {
const promptKey = action === 'purge'
? 'workspace.shippingNotice.disposition.purgeReasonPrompt'
: 'workspace.shippingNotice.disposition.reasonPrompt';
reason = window.prompt(t(promptKey))?.trim() || '';
if (!reason) return;
}
if (!window.confirm(t('workspace.shippingNotice.disposition.confirm', {
action: t(`workspace.shippingNotice.disposition.actions.${action}`), count: selectedTaskNos.value.length,
}))) return;
dispositionSubmitting.value = true;
try {
const result = action === 'delete'
? await deleteWorkspaceShippingTasks(selectedTaskNos.value, reason)
: action === 'archive'
? await archiveWorkspaceShippingTasks(selectedTaskNos.value)
: action === 'restore'
? await restoreWorkspaceShippingTasks(selectedTaskNos.value)
: await purgeWorkspaceShippingTasks(selectedTaskNos.value, reason);
const blocked = result.results.filter((item) => item.status === 'blocked').length;
if (blocked) msg.error(t('workspace.shippingNotice.disposition.partial', { success: result.results.length - blocked, blocked }));
else msg.success(t('workspace.shippingNotice.disposition.success', { count: result.results.length }));
await loadCases();
} catch {
msg.error(t('workspace.shippingNotice.disposition.failed'));
} finally {
dispositionSubmitting.value = false;
}
};
const shortageLines = computed(() => detail.value?.shortage?.lines || []);
const hasMatchCard = computed(() =>
!!detail.value && (
@@ -393,14 +285,16 @@ onMounted(async () => {
<p class="text-sm text-muted">{{ $t('workspace.shippingNotice.subtitle') }}</p>
</div>
</div>
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
@click="loadCases(true)"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.refresh') }}
</button>
<div class="flex gap-2">
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
@click="loadCases(true)"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.refresh') }}
</button>
</div>
</div>
<div class="flex flex-wrap items-end gap-3 rounded-2xl border border-default/80 bg-surface/70 px-4 py-3 shadow-sm">
@@ -423,67 +317,6 @@ onMounted(async () => {
>
{{ $t('workspace.shippingNotice.search') }}
</button>
<label class="ml-auto inline-flex items-center gap-2 text-sm text-secondary">
<input
type="checkbox"
:checked="allVisibleTasksSelected"
:disabled="tasks.length === 0"
@change="toggleAllVisibleTasks(($event.target as HTMLInputElement).checked)"
>
{{ $t('workspace.shippingNotice.selectAllVisible') }}
</label>
<span class="text-sm text-muted">
{{ $t('workspace.shippingNotice.selectedCount', { count: selectedTaskNos.length }) }}
</span>
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || archiveDownloading"
@click="downloadSelectedExports"
>
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.downloadSelected') }}
</button>
<button
v-if="lifecycleFilter === 'active'"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || dispositionSubmitting"
@click="applyTaskDisposition('archive')"
>
<Archive class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.disposition.actions.archive') }}
</button>
<button
v-if="lifecycleFilter === 'active'"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-rose-300 px-3 py-2 text-sm font-medium text-rose-700 hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || dispositionSubmitting"
@click="applyTaskDisposition('delete')"
>
<Trash2 class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.disposition.actions.delete') }}
</button>
<button
v-if="lifecycleFilter === 'deleted'"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || dispositionSubmitting"
@click="applyTaskDisposition('restore')"
>
<RotateCcw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.disposition.actions.restore') }}
</button>
<button
v-if="lifecycleFilter === 'deleted' && isAdmin"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-rose-300 px-3 py-2 text-sm font-medium text-rose-700 hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-50"
:disabled="selectedTaskNos.length === 0 || dispositionSubmitting"
@click="applyTaskDisposition('purge')"
>
<Trash2 class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.disposition.actions.purge') }}
</button>
</div>
<div class="grid gap-5 lg:grid-cols-5">
@@ -500,13 +333,6 @@ onMounted(async () => {
class="flex w-full items-start gap-3 rounded-2xl border px-4 py-3 transition-colors"
:class="selectedTaskNo === item.task_no ? 'border-brand-400 bg-brand-50/60' : 'border-default hover:bg-surface-soft/70'"
>
<input
type="checkbox"
class="mt-1"
:aria-label="$t('workspace.shippingNotice.selectForDownload', { taskNo: item.task_no })"
:checked="selectedTaskNos.includes(item.task_no)"
@change="toggleTask(item.task_no, ($event.target as HTMLInputElement).checked)"
>
<button type="button" class="min-w-0 flex-1 text-left" @click="selectedTaskNo = item.task_no">
<div class="flex items-center justify-between gap-2">
<span class="font-mono text-sm font-semibold text-primary">{{ item.task_no }}</span>
@@ -585,25 +411,6 @@ onMounted(async () => {
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.openChat') }}
</button>
<button
v-if="detail.export_file_name"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft"
@click="downloadExport(detail.task_no)"
>
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.download') }}
</button>
<button
v-if="detail.batch_no"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft"
:disabled="archiveDownloading"
@click="downloadBatchExports(detail.batch_no)"
>
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.downloadBatch') }}
</button>
</div>
</div>
@@ -743,6 +550,59 @@ onMounted(async () => {
:action-busy="false"
/>
<section
v-if="detail.inventory_verifications?.length"
class="rounded-2xl border border-default/80 bg-surface px-4 py-3 text-sm"
>
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.fulfillmentTimeline.inventoryTitle') }}</h3>
<div v-for="verification in detail.inventory_verifications" :key="verification.id" class="border-t border-default/70 py-2 first:border-t-0 first:pt-0">
<div class="flex flex-wrap gap-x-3 gap-y-1 text-xs">
<span class="font-medium text-secondary">#{{ verification.id }} · {{ verification.status }}</span>
<span>{{ formatLocalDateTime(verification.created_at) }}</span>
</div>
<div class="mt-1 text-xs text-muted">
<span v-for="line in verification.lines" :key="line.reservation_id" class="mr-3 inline-block">
{{ $t('workspace.shippingNotice.fulfillmentTimeline.verificationLine', { reservationId: line.reservation_id, availableQty: line.available_qty, requiredQty: line.required_qty, status: line.status }) }}
</span>
</div>
</div>
</section>
<section
v-if="detail.export_artifacts?.length"
class="rounded-2xl border border-default/80 bg-surface px-4 py-3 text-sm"
>
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.fulfillmentTimeline.artifactTitle') }}</h3>
<div v-for="artifact in detail.export_artifacts" :key="artifact.id" class="border-t border-default/70 py-2 first:border-t-0 first:pt-0">
<div class="flex flex-wrap gap-x-3 gap-y-1 text-xs">
<span class="font-mono font-medium text-secondary">{{ artifact.artifact_no }}</span>
<span>{{ artifact.status }}</span>
<span>{{ artifact.file_name }}</span>
<span>{{ formatLocalDateTime(artifact.created_at) }}</span>
</div>
<p class="mt-1 text-xs text-muted">{{ $t('workspace.shippingNotice.fulfillmentTimeline.reservationIds', { reservationIds: artifact.reservation_ids.join(', ') || '—' }) }}</p>
</div>
</section>
<section
v-if="detail.upload_attempts?.length"
class="rounded-2xl border border-default/80 bg-surface px-4 py-3 text-sm"
>
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.fulfillmentTimeline.uploadTitle') }}</h3>
<div v-for="attempt in detail.upload_attempts" :key="attempt.id" class="border-t border-default/70 py-2 first:border-t-0 first:pt-0">
<div class="flex flex-wrap gap-x-3 gap-y-1 text-xs">
<span class="font-medium text-secondary">{{ $t('workspace.shippingNotice.fulfillmentTimeline.uploadAttempt', { artifactId: attempt.artifact_id, attemptNo: attempt.attempt_no }) }}</span>
<span>{{ attempt.mode }}</span><span>{{ attempt.status }}</span>
<span>{{ formatLocalDateTime(attempt.finished_at || attempt.created_at) }}</span>
</div>
<p v-if="attempt.freight_ref_no || attempt.error_message || attempt.evidence_asset_id" class="mt-1 text-xs text-muted">
{{ attempt.freight_ref_no ? $t('workspace.shippingNotice.fulfillmentTimeline.freightRef', { freightRefNo: attempt.freight_ref_no }) : '' }}
{{ attempt.error_message ? ` ${attempt.error_message}` : '' }}
{{ attempt.evidence_asset_id ? ` ${$t('workspace.shippingNotice.fulfillmentTimeline.evidenceAsset', { assetId: attempt.evidence_asset_id })}` : '' }}
</p>
</div>
</section>
<ShippingTaskParsedResultCard
v-if="detail.lines?.length || detail.process_field_gate || detail.parse_validation || detail.source_candidate || detail.field_conflicts?.length"
class="mt-3"