feat(shipping_notice): 支持客户 ODM 白名单与整单 ODM 选择收敛导出

- 客户主数据新增 odm_ids 白名单字段(含 Alembic 迁移),表单与管理端支持维护
- 导出库存命中行按客户白名单与整单 ODM 裁决收敛,新增 notice_odm_choice_service
- 工作台新增 odm-options / odm-choice 接口,投影行级候选并持久化用户选择
- 修复复核工作台跨 Run 切换时接收解析上下文残留
- 同步四语言 i18n、测试用例、funclist 与 shipping-notice 技术文档
This commit is contained in:
hugo committed 2026-09-16 19:50:12 +08:00
1 parent a032354cb9
commit d396371020
51 files changed
+2717 -109

No files matched your search

@@ -166,6 +166,16 @@ export const getWorkspaceShippingFreightNoticeGroups = (taskNo: string) =>
{ priority: 'low' },
);
/** 整单 ODM 裁决:保存行级选择(同快照文件行后端同步),随后可重试生成 Excel。 */
export const setWorkspaceShippingTaskOdmChoice = (
taskNo: string,
payload: { snapshot_line_id: string | number; odm_id: string },
) =>
requestJson<{ task_id: number; odm_id: string; synced_line_count: number; odm_values: string[] }>(
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/odm-choice`,
jsonPost(payload),
);
/**
* 分页拉取任务工作台统一审计时间线(ShippingAuditEvent 单源)。
*/
@@ -173,3 +173,64 @@ describe('ReviewDocumentNavigation', () => {
narrow.unmount();
});
});
describe('ReviewDocumentNavigation queue row status icons', () => {
/**
* 以指定字段挂载单行侧栏队列,返回该行按钮包装器。
*/
function mountRow(item: Partial<ReviewDocumentNavItem>) {
return mount(ReviewDocumentNavigation, {
props: {
items: [{ case_no: 'C-1', file_name: 'f1.pdf', status: 'draft', ...item }],
activeCaseNo: 'C-1',
navAriaLabel: 'nav',
forceMode: 'sidebar',
},
global: { plugins: [i18n] },
}).get('[data-testid="review-doc-nav-C-1"]');
}
it('renders confirmed cases as in-progress spinner instead of done check', () => {
const row = mountRow({ status: 'confirmed' });
// 关键断言:已创建任务是系统在办中间态,必须转圈而非绿勾。
expect(row.find('svg.animate-spin').exists()).toBe(true);
expect(row.find('svg.text-emerald-500').exists()).toBe(false);
});
it('renders ready-to-confirm cases as amber attention icon', () => {
const row = mountRow({ status: 'ready' });
// 关键断言:可确认是等人操作,属于待办而非完成。
expect(row.find('svg.text-amber-500').exists()).toBe(true);
});
it('renders backend gate-blocked cases as amber attention icon', () => {
const row = mountRow({ status: 'confirmed', needs_attention: true });
// 关键断言:needs_attention 是后端门禁裁决,优先于中间态转圈。
expect(row.find('svg.text-amber-500').exists()).toBe(true);
expect(row.find('svg.animate-spin').exists()).toBe(false);
});
it('reserves the green check for terminal upload_complete', () => {
const row = mountRow({ status: 'confirmed', lifecycle_stage: 'upload_complete' });
expect(row.find('svg.text-emerald-500').exists()).toBe(true);
expect(row.find('svg.animate-spin').exists()).toBe(false);
});
it('renders failed and neutral states as before', () => {
expect(mountRow({ status: 'failed' }).find('svg.text-rose-500').exists()).toBe(true);
const idle = mountRow({ status: 'non_order' });
expect(idle.find('svg.text-muted').exists()).toBe(true);
expect(idle.find('svg.animate-spin').exists()).toBe(false);
});
it('keeps the truthful state icon on the selected row', () => {
const row = mountRow({ status: 'draft' });
// 关键断言:选中态由行高亮表达,图标不再被 active 覆盖成灰圈。
expect(row.find('svg.text-amber-500').exists()).toBe(true);
});
it('treats missing needs_attention as false for old queue payloads', () => {
const row = mountRow({ status: 'confirmed', needs_attention: undefined });
expect(row.find('svg.animate-spin').exists()).toBe(true);
});
});
@@ -11,6 +11,7 @@ import {
ChevronLeft,
ChevronRight,
Circle,
LoaderCircle,
Search,
TriangleAlert,
X,
@@ -23,10 +24,12 @@ export type ReviewDocumentNavItem = {
file_name?: string | null;
status: string;
issue_count?: number;
/** 队列接口按当前门禁裁决的"需人工"标志(blocked_manual/blocked_retryable/failed_terminal);前端禁止自行推断阻塞。 */
needs_attention?: boolean | null;
po_number?: string | null;
customer_name?: string | null;
stage_label?: string | null;
/** 队列接口下发的生命周期码;仅用于本地化展示,不参与阶段裁决。 */
/** 队列接口下发的生命周期码;用于阶段文字展示与终态(upload_complete)绿勾判定,不参与阶段裁决。 */
lifecycle_stage?: ReviewLifecycleStageCode | null;
};
@@ -118,17 +121,20 @@ function lifecycleStageLabel(item: ReviewDocumentNavItem): string | null {
}
/**
* 导航状态图标语义。
* 队列状态图标语义,按优先级命中即停:
* 失败 → 需人工(草稿问题数 / needs_attention 门禁阻塞)→ 终态绿勾
* → 等人状态 ⚠ → 系统在办转圈 → 中性灰圈 → 兜底转圈。
* 绿勾只属于终态(upload_complete / closed / completed);选中态由行高亮表达,
* 本函数不感知选中,图标永远如实反映状态。
*/
function navIconKind(item: ReviewDocumentNavItem): 'active' | 'alert' | 'processing' | 'done' | 'failed' | 'idle' {
if (props.activeCaseNo === item.case_no) return 'active';
function navIconKind(item: ReviewDocumentNavItem): 'alert' | 'done' | 'failed' | 'processing' | 'idle' {
const status = String(item.status || '').toLowerCase();
if (item.issue_count && item.issue_count > 0) return 'alert';
if (status === 'failed' || status === 'error') return 'failed';
if (status === 'confirmed' || status === 'completed' || status === 'ready' || status === 'closed') return 'done';
if (status === 'processing' || status === 'reparse_pending' || status === 'queued') return 'processing';
if (status === 'non_order' || status === 'cancelled' || status === 'superseded') return 'idle';
if (status === 'draft' || status === 'pending_review' || status === 'waiting_review') return 'alert';
if ((item.issue_count && item.issue_count > 0) || item.needs_attention === true) return 'alert';
if (item.lifecycle_stage === 'upload_complete' || status === 'completed' || status === 'closed') return 'done';
if (['draft', 'ready', 'unreviewed', 'quality_issue', 'pending_review', 'waiting_review'].includes(status)) return 'alert';
if (['confirmed', 'confirming', 'processing', 'reparse_pending', 'queued'].includes(status)) return 'processing';
if (['non_order', 'cancelled', 'superseded'].includes(status)) return 'idle';
return 'processing';
}
@@ -139,7 +145,7 @@ function matchesStatusFilter(item: ReviewDocumentNavItem): boolean {
if (statusFilter.value === 'all') return true;
const kind = navIconKind(item);
if (statusFilter.value === 'needs_action') return kind === 'alert';
if (statusFilter.value === 'processing') return kind === 'processing' || kind === 'active';
if (statusFilter.value === 'processing') return kind === 'processing';
if (statusFilter.value === 'done') return kind === 'done';
if (statusFilter.value === 'failed') return kind === 'failed';
return true;
@@ -218,6 +224,11 @@ function onSelect(caseNo: string) {
class="h-3.5 w-3.5 shrink-0 text-rose-500"
aria-hidden="true"
/>
<LoaderCircle
v-else-if="navIconKind(item) === 'processing'"
class="h-3.5 w-3.5 shrink-0 animate-spin text-brand-600"
aria-hidden="true"
/>
<Circle
v-else
class="h-3 w-3 shrink-0 text-muted"
@@ -329,6 +340,10 @@ function onSelect(caseNo: string) {
v-else-if="navIconKind(item) === 'failed'"
class="mt-0.5 h-3.5 w-3.5 shrink-0 text-rose-500"
/>
<LoaderCircle
v-else-if="navIconKind(item) === 'processing'"
class="mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin text-brand-600"
/>
<Circle
v-else
class="mt-0.5 h-3 w-3 shrink-0 text-muted"
@@ -771,6 +771,48 @@ describe('useShippingOrderReview build eligibility writes', () => {
expect(review.reviewProgressContext.value?.user_task_authoritative).toBe(false);
});
it('beginCrossRunSwitch drops the previous file intake context and rejects its stale success', async () => {
// 关键断言:跨 Run 切文件(如 PO_6075309 → PO_6075316)切换即清空接收解析上下文,
// 迟到的旧 Case 上下文成功响应也不得把旧附件名/邮件正文写回新文件工作面。
const review = useShippingOrderReview();
await review.load('RUN-1', 'CASE-1');
await review.ensureIntakeParseContextLoaded('CASE-1');
expect(review.intakeParseContext.value?.attachment.filename).toBe('order.pdf');
let resolveStale: ((value: Record<string, unknown>) => void) | null = null;
api.getIntakeParseContext.mockImplementationOnce(
() => new Promise((resolve) => { resolveStale = resolve; }),
);
const pendingStale = review.ensureIntakeParseContextLoaded('CASE-1');
review.beginCrossRunSwitch('CASE-2');
expect(review.intakeParseContext.value).toBeNull();
expect(review.intakeParseLoading.value).toBe(false);
expect(review.intakeParseLoadFailed.value).toBe(false);
resolveStale?.({
case_no: 'CASE-1',
attachment: { document_id: 1, filename: 'order.pdf', mime_type: 'application/pdf', preview_kind: 'pdf' },
email: null,
});
await pendingStale;
expect(review.intakeParseContext.value).toBeNull();
});
it('load fast path drops the stale intake context when the target Case changes', async () => {
// 关键断言:稳定工作台直达 load 换 Case(重解析落位/重试等入口)同样撤销旧上下文。
const review = useShippingOrderReview();
await review.load('RUN-1', 'CASE-1');
await review.ensureIntakeParseContextLoaded('CASE-1');
expect(review.intakeParseContext.value?.case_no).toBe('CASE-1');
api.getCase.mockResolvedValue(buildCase({ case_no: 'CASE-2', document: { id: 2, file_name: 'second.pdf' } }));
await review.load('RUN-1', 'CASE-2');
expect(review.activeCase.value?.case_no).toBe('CASE-2');
expect(review.intakeParseContext.value).toBeNull();
expect(review.intakeParseLoading.value).toBe(false);
});
it('discards stale selectCase responses when switching PDFs quickly', async () => {
// 关键断言:A 后发先至不得覆盖后选的 B;切换时先清空瞬态。
let resolveA: ((value: ShippingOrderReviewCase) => void) | null = null;
@@ -1096,6 +1096,13 @@ export function useShippingOrderReview(options: {
// 已有稳定工作台且路由明确目标 PDF 时,目标详情是用户切换的关键路径;
// Run/Queue 只负责后续更新导航和阶段摘要,不能用其慢投影阻塞当前文件显示。
if (hasStableWorkbench && preferredCaseNo) {
// 稳定工作台直达 load 换 Case 时(如重解析落位/重试),同样必须撤销旧文件的
// 接收解析上下文;新上下文由视图层 Case 变化 watcher 按目标 Case 重载。
if (String(preferredCaseNo || '').trim() !== String(activeCase.value?.case_no || '').trim()) {
intakeParseContext.value = null;
intakeParseLoading.value = false;
intakeParseLoadFailed.value = false;
}
const [caseSnapshot, caseEvidence] = await Promise.all([
getWorkspaceShippingOrderReviewCase(preferredCaseNo),
getWorkspaceShippingOrderReviewEvidence(preferredCaseNo),
@@ -1189,6 +1196,8 @@ export function useShippingOrderReview(options: {
* 核心逻辑:保留 activeCase/工作台壳(避免大骨架闪动),但清空 user_task_no,
* 让 shippingProcessingProjection 立即丢弃上一份 PDF 的右卡/库存态;目标 Case
* 仍由随后的 load(preferredCaseNo) 目标优先路径写入。
* 接收解析上下文必须与预览一并撤销:Run 变更即 Case 变更,旧文件的附件名/邮件正文
* 不得残留在新文件工作面(新上下文由视图层 Case 变化 watcher 重载)。
* @param caseNo - 目标复核 Case 编号
*/
const beginCrossRunSwitch = (caseNo: string) => {
@@ -1212,6 +1221,9 @@ export function useShippingOrderReview(options: {
};
}
clearPreview();
intakeParseContext.value = null;
intakeParseLoading.value = false;
intakeParseLoadFailed.value = false;
};
/**
@@ -1498,6 +1498,15 @@ export interface ShippingTaskUiState {
}>;
/** 人工覆写库存源(方案 3·放开):全部已启用源,供行级下拉人工指定。 */
source_options?: Array<{ source_code?: string | null; display_name?: string | null }>;
/**
* 整单 ODM 裁决摘要:conflict=true 表示范围限定后仍有多行存在多值,
* 由行内 odm 下发候选,用户改任一行后同一快照文件的其他行同步。
*/
odm_options?: {
conflict?: boolean;
customer_odm_ids?: Array<string>;
whitelist_applied?: boolean;
};
/** 阶段能力(Task 2 下发);prep 工作台能力工具条消费,scope=task 级。 */
capabilities?: ShippingStageCapability[];
/** 仅当前任务活动关联的库存快照才可下载。 */
@@ -1523,6 +1532,10 @@ export interface ShippingTaskUiState {
/** 多文件冲突行(D5):候选源列表供行内下拉,选定后走 override_line_inventory_source。 */
source_ambiguous?: boolean;
source_candidates?: Array<string>;
/** 整单 ODM 裁决:本行候选(经客户范围过滤);同快照文件行同步同一 chosen 值。 */
odm_values?: Array<string>;
chosen_odm_id?: string | null;
odm_conflict?: boolean;
}>;
artifact?: { file_name?: string | null; status?: string | null } | null;
} | null;
@@ -2307,6 +2320,8 @@ export interface ShippingOrderReviewCaseSummary {
intake_parse_authorized?: boolean;
draft_version?: number | null;
issue_count: number;
/** 队列后端按当前门禁裁决:blocked_manual/blocked_retryable/failed_terminal 为 true;前端禁止自行推断阻塞。 */
needs_attention?: boolean;
available_actions: string[];
/** 仅 parse_failed 时由后端下发,供当前阶段卡调用原 Intake retry API。 */
intake_no?: string | null;
@@ -38,6 +38,7 @@ import {
retryShippingNoticeIntake,
decideWorkspaceShippingOrderReviewLineFulfillment,
waveWorkspaceShippingOrderReviewLineFulfillment,
setWorkspaceShippingTaskOdmChoice,
viewWorkspaceShippingOrderReviewHighlightDiagnostic,
} from '../api/shipping.api';
import type {
@@ -2643,6 +2644,38 @@ async function submitOverrideSource(line: { snapshot_line_id?: number | null; li
}
}
/** 整单 ODM 裁决列可见性:任一行候选多于一个时展示(候选已经客户范围过滤)。 */
const formalPreparationOdmColumnVisible = computed(() =>
(formalPreparationContext.value?.lines || []).some((line) => (line.odm_values?.length || 0) > 1),
);
const lineOdmSelections = ref<Record<string, string>>({});
const lineOdmBusy = ref(false);
/**
* 提交行级 ODM 选择:后端把同一快照文件的全部当前匹配行同步为同一值,
* 刷新详情后其他行回显同步结果,并在门禁仍授权时自动重试生成 Excel。
*/
async function submitLineOdmChoice(line: { snapshot_line_id?: number | null }) {
const selectionKey = String(line.snapshot_line_id ?? '');
const odmId = String(lineOdmSelections.value[selectionKey] || '').trim();
const taskNo = String(confirmedNoticeTaskNo.value || '').trim();
if (!odmId || !taskNo || lineOdmBusy.value) return;
lineOdmBusy.value = true;
try {
await setWorkspaceShippingTaskOdmChoice(taskNo, { snapshot_line_id: selectionKey, odm_id: odmId });
delete lineOdmSelections.value[selectionKey];
await loadFormalTaskDetail();
const canRegenerate = formalTaskActions.value.some(
(action) => action.enabled && String(action.code || '').trim() === 'regenerate_excel_artifact',
);
if (canRegenerate) await submitFormalGateAction('regenerate_excel_artifact');
} catch (error) {
msg.error(resolveReviewErrorMessage(error));
} finally {
lineOdmBusy.value = false;
}
}
function formalPreparationLineAllows(
line: { snapshot_line_id?: number | null },
action: 'retry_inventory_preparation' | 'retry_inventory_matching' | 'close_unfulfillable' | 'release_inventory_shortage',
@@ -4397,7 +4430,14 @@ watch(
);
watch(
[lifecycleActiveStageCode, hasFormalOt, intakeParseContextAuthorized],
[
lifecycleActiveStageCode,
hasFormalOt,
intakeParseContextAuthorized,
// 接收解析文件互切时 stage/授权通常不变;必须以 Case 变化触发新附件/邮件上下文重载,
// 否则接收解析工作面停留上一份 PDF 的附件名且预览不再自动加载。
() => String(activeCase.value?.case_no || '').trim(),
],
([code, , intakeAuthorized]) => {
// 确认进度是当前阶段内的短暂辅助视图,不由生命周期页签覆盖。
if (workbenchMode.value === 'confirm_progress') return;
@@ -4857,12 +4897,12 @@ watch(
class="rounded-full bg-brand-50 px-2.5 py-1 text-xs font-medium text-brand-700 dark:bg-brand-950/30 dark:text-brand-300"
>{{ formalPreparationStatusLabel(formalPreparationContext?.status) }}</span>
</div>
<div v-if="formalPreparationDisplayLines.length" class="review-fulfillment-prep-workspace mt-4 rounded-lg border border-default" data-testid="review-fulfillment-prep-workspace">
<!-- 标题与选行操作条固定不参与横向滚动,仅表头/表体横向滑动。 -->
<div class="flex items-center justify-between gap-3 border-b border-default bg-surface-muted/30 px-3 py-2">
<div class="text-xs font-semibold text-primary">{{ t('chat.shippingOrderReview.lifecycle.prepare.matchWorkspace') }}</div>
<span class="text-xs text-secondary">{{ t('chat.shippingOrderReview.lifecycle.prepare.lineCount', { count: formalPreparationDisplayLines.length }) }}</span>
</div>
<div v-if="formalPreparationDisplayLines.length" class="review-fulfillment-prep-workspace mt-4 rounded-lg border border-default" data-testid="review-fulfillment-prep-workspace">
<!-- 标题与选行操作条固定不参与横向滚动,仅表头/表体横向滑动。 -->
<div class="flex items-center justify-between gap-3 border-b border-default bg-surface-muted/30 px-3 py-2">
<div class="text-xs font-semibold text-primary">{{ t('chat.shippingOrderReview.lifecycle.prepare.matchWorkspace') }}</div>
<span class="text-xs text-secondary">{{ t('chat.shippingOrderReview.lifecycle.prepare.lineCount', { count: formalPreparationDisplayLines.length }) }}</span>
</div>
<div v-if="preparationEditable && formalHeaderEditable()" class="flex flex-wrap items-center justify-between gap-2 border-b border-default bg-brand-50/50 px-3 py-2 text-xs dark:bg-brand-950/20">
<div class="flex items-center gap-3 text-secondary">
<span class="font-medium">{{ t('chat.shippingOrderReview.fulfillmentDecision.selectReady') }}</span>
@@ -4872,8 +4912,8 @@ watch(
</div>
<div class="overflow-x-auto overscroll-x-contain" data-testid="review-fulfillment-prep-table-scroll">
<table class="review-fulfillment-prep-table min-w-[1060px] text-xs">
<thead class="border-b border-default bg-surface-muted/50 text-left"><tr><th v-if="preparationEditable" class="w-10 px-3 py-2"><input type="checkbox" class="rounded border-default" :checked="allPreparationWaveSelected" :disabled="!preparationWaveSelectableLines.length || preparationWaveBusy" :aria-label="t('chat.shippingOrderReview.fulfillmentDecision.selectReady')" @change="toggleAllPreparationLineSelection(($event.target as HTMLInputElement).checked)"></th><th v-if="preparationCustomerPoLineVisible" class="whitespace-nowrap px-3 py-2">{{ preparationCustomerPoLineLabel() }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.workbench.resultReservation') }}</th><th class="px-3 py-2">{{ t('chat.shippingOrderReview.workbench.resultPartNumber') }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.lifecycle.prepare.requiredQty') }}</th><th class="px-3 py-2">{{ t('chat.shippingOrderReview.lifecycle.prepare.inventorySource') }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.fulfillmentDecision.availableQty') }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.fulfillmentDecision.shortage') }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.lifecycle.prepare.lineStatus') }}</th><th class="review-fulfillment-sticky-action-head whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.lineOps.moreActions') }}</th></tr></thead>
<tbody><tr v-for="(line, lineIndex) in formalPreparationDisplayLines" :key="line.snapshot_line_id || `${line.reservation_id}-${line.part_number}`" :class="Number(line.shortage_qty || 0) > 0 ? 'border-b border-amber-100 bg-amber-50/40 last:border-0 dark:border-amber-950 dark:bg-amber-950/10' : 'border-b border-default last:border-0'"><td v-if="preparationEditable" class="w-10 px-3 py-2"><input type="checkbox" class="rounded border-default" :checked="selectedPreparationSnapshotLineIds.includes(String(line.snapshot_line_id))" :disabled="preparationWaveBusy || !preparationWaveSelectableLines.some((item) => String(item.snapshot_line_id) === String(line.snapshot_line_id))" :aria-label="`${t('chat.shippingOrderReview.fulfillmentDecision.selectReady')}: ${preparationLineCustomerPoLine(line)}`" :data-testid="`review-fulfillment-line-select-${line.snapshot_line_id || lineIndex}`" @change="togglePreparationLineSelection(String(line.snapshot_line_id || lineIndex), ($event.target as HTMLInputElement).checked)"></td><td v-if="preparationCustomerPoLineVisible" class="whitespace-nowrap px-3 py-2">{{ preparationLineCustomerPoLine(line) }}</td><td class="whitespace-nowrap px-3 py-2 font-medium text-primary">{{ line.reservation_id || '—' }}</td><td class="max-w-[220px] truncate px-3 py-2" :title="line.part_number || '—'">{{ line.part_number || '—' }}</td><td class="whitespace-nowrap px-3 py-2">{{ line.required_qty ?? '—' }}</td><td class="max-w-[220px] px-3 py-2"><div v-if="line.source_ambiguous && !formalPreparationSourceLocked" class="flex items-center gap-1" :data-testid="`review-line-source-ambiguous-${line.snapshot_line_id || lineIndex}`" :title="t('chat.shippingOrderReview.lifecycle.prepare.sourceAmbiguous')"><select class="min-w-0 flex-1 rounded border border-default bg-surface px-1.5 py-1 text-xs" :data-testid="`review-line-source-select-${line.snapshot_line_id || lineIndex}`" :aria-label="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')" :value="lineSourceSelections[String(line.snapshot_line_id || lineIndex)] || line.source_code || ''" @change="lineSourceSelections[String(line.snapshot_line_id || lineIndex)] = ($event.target as HTMLSelectElement).value"><option value="" disabled>{{ t('chat.shippingOrderReview.lifecycle.prepare.selectSource') }}</option><option v-for="code in line.source_candidates || []" :key="code" :value="code">{{ lineSourceOptionLabel(code) }}</option></select><button type="button" class="rounded bg-brand-600 px-2 py-1 text-xs font-medium text-white disabled:opacity-50" :data-testid="`review-line-source-confirm-${line.snapshot_line_id || lineIndex}`" :disabled="!lineSourceSelections[String(line.snapshot_line_id || lineIndex)] || lineSourceBusy || !preparationEditable" :aria-label="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')" @click="submitLineSourceSelection(line)"><Check class="h-3.5 w-3.5" /></button></div><span v-else-if="line.source_ambiguous && formalPreparationSourceLocked" class="text-xs text-secondary" :title="t('chat.shippingOrderReview.lifecycle.prepare.sourceLocked')">{{ t('chat.shippingOrderReview.lifecycle.prepare.sourceLocked') }}</span><span v-else-if="!formalPreparationSourceLocked && formSourceOptions.length" class="flex items-center gap-1" :data-testid="`review-line-source-override-${line.snapshot_line_id || lineIndex}`" :title="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')"><select class="min-w-0 flex-1 rounded border border-default bg-surface px-1.5 py-1 text-xs" :data-testid="`review-line-source-override-select-${line.snapshot_line_id || lineIndex}`" :aria-label="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')" :value="overrideSourceSelections[String(line.snapshot_line_id || lineIndex)] || line.selected_source_code || line.source_code || ''" @change="overrideSourceSelections[String(line.snapshot_line_id || lineIndex)] = ($event.target as HTMLSelectElement).value"><option value="" disabled>{{ t('chat.shippingOrderReview.lifecycle.prepare.selectSource') }}</option><option v-for="s in formSourceOptions" :key="String(s.source_code)" :value="String(s.source_code)">{{ overrideSourceOptionLabel(String(s.source_code)) }}</option></select><button type="button" class="rounded bg-brand-600 px-2 py-1 text-xs font-medium text-white disabled:opacity-50" :data-testid="`review-line-source-override-confirm-${line.snapshot_line_id || lineIndex}`" :disabled="!overrideSourceSelections[String(line.snapshot_line_id || lineIndex)] || overrideSourceBusy" :aria-label="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')" :data-line-index="lineIndex" @click="submitOverrideSource(line)"><Check class="h-3.5 w-3.5" /></button></span><span v-else class="block max-w-[220px] truncate" :title="formalPreparationLineSource(line)">{{ formalPreparationLineSource(line) }}</span></td><td class="whitespace-nowrap px-3 py-2">{{ line.available_qty ?? '—' }}</td><td class="whitespace-nowrap px-3 py-2 font-medium" :class=Line truncated
<thead class="border-b border-default bg-surface-muted/50 text-left"><tr><th v-if="preparationEditable" class="w-10 px-3 py-2"><input type="checkbox" class="rounded border-default" :checked="allPreparationWaveSelected" :disabled="!preparationWaveSelectableLines.length || preparationWaveBusy" :aria-label="t('chat.shippingOrderReview.fulfillmentDecision.selectReady')" @change="toggleAllPreparationLineSelection(($event.target as HTMLInputElement).checked)"></th><th v-if="preparationCustomerPoLineVisible" class="whitespace-nowrap px-3 py-2">{{ preparationCustomerPoLineLabel() }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.workbench.resultReservation') }}</th><th class="px-3 py-2">{{ t('chat.shippingOrderReview.workbench.resultPartNumber') }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.lifecycle.prepare.requiredQty') }}</th><th class="px-3 py-2">{{ t('chat.shippingOrderReview.lifecycle.prepare.inventorySource') }}</th><th v-if="formalPreparationOdmColumnVisible" class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.odmConflict.column') }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.fulfillmentDecision.availableQty') }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.fulfillmentDecision.shortage') }}</th><th class="whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.lifecycle.prepare.lineStatus') }}</th><th class="review-fulfillment-sticky-action-head whitespace-nowrap px-3 py-2">{{ t('chat.shippingOrderReview.lineOps.moreActions') }}</th></tr></thead>
<tbody><tr v-for="(line, lineIndex) in formalPreparationDisplayLines" :key="line.snapshot_line_id || `${line.reservation_id}-${line.part_number}`" :class="Number(line.shortage_qty || 0) > 0 ? 'border-b border-amber-100 bg-amber-50/40 last:border-0 dark:border-amber-950 dark:bg-amber-950/10' : 'border-b border-default last:border-0'"><td v-if="preparationEditable" class="w-10 px-3 py-2"><input type="checkbox" class="rounded border-default" :checked="selectedPreparationSnapshotLineIds.includes(String(line.snapshot_line_id))" :disabled="preparationWaveBusy || !preparationWaveSelectableLines.some((item) => String(item.snapshot_line_id) === String(line.snapshot_line_id))" :aria-label="`${t('chat.shippingOrderReview.fulfillmentDecision.selectReady')}: ${preparationLineCustomerPoLine(line)}`" :data-testid="`review-fulfillment-line-select-${line.snapshot_line_id || lineIndex}`" @change="togglePreparationLineSelection(String(line.snapshot_line_id || lineIndex), ($event.target as HTMLInputElement).checked)"></td><td v-if="preparationCustomerPoLineVisible" class="whitespace-nowrap px-3 py-2">{{ preparationLineCustomerPoLine(line) }}</td><td class="whitespace-nowrap px-3 py-2 font-medium text-primary">{{ line.reservation_id || '—' }}</td><td class="max-w-[220px] truncate px-3 py-2" :title="line.part_number || '—'">{{ line.part_number || '—' }}</td><td class="whitespace-nowrap px-3 py-2">{{ line.required_qty ?? '—' }}</td><td class="max-w-[220px] px-3 py-2"><div v-if="line.source_ambiguous && !formalPreparationSourceLocked" class="flex items-center gap-1" :data-testid="`review-line-source-ambiguous-${line.snapshot_line_id || lineIndex}`" :title="t('chat.shippingOrderReview.lifecycle.prepare.sourceAmbiguous')"><select class="min-w-0 flex-1 rounded border border-default bg-surface px-1.5 py-1 text-xs" :data-testid="`review-line-source-select-${line.snapshot_line_id || lineIndex}`" :aria-label="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')" :value="lineSourceSelections[String(line.snapshot_line_id || lineIndex)] || line.source_code || ''" @change="lineSourceSelections[String(line.snapshot_line_id || lineIndex)] = ($event.target as HTMLSelectElement).value"><option value="" disabled>{{ t('chat.shippingOrderReview.lifecycle.prepare.selectSource') }}</option><option v-for="code in line.source_candidates || []" :key="code" :value="code">{{ lineSourceOptionLabel(code) }}</option></select><button type="button" class="rounded bg-brand-600 px-2 py-1 text-xs font-medium text-white disabled:opacity-50" :data-testid="`review-line-source-confirm-${line.snapshot_line_id || lineIndex}`" :disabled="!lineSourceSelections[String(line.snapshot_line_id || lineIndex)] || lineSourceBusy || !preparationEditable" :aria-label="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')" @click="submitLineSourceSelection(line)"><Check class="h-3.5 w-3.5" /></button></div><span v-else-if="line.source_ambiguous && formalPreparationSourceLocked" class="text-xs text-secondary" :title="t('chat.shippingOrderReview.lifecycle.prepare.sourceLocked')">{{ t('chat.shippingOrderReview.lifecycle.prepare.sourceLocked') }}</span><span v-else-if="!formalPreparationSourceLocked && formSourceOptions.length" class="flex items-center gap-1" :data-testid="`review-line-source-override-${line.snapshot_line_id || lineIndex}`" :title="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')"><select class="min-w-0 flex-1 rounded border border-default bg-surface px-1.5 py-1 text-xs" :data-testid="`review-line-source-override-select-${line.snapshot_line_id || lineIndex}`" :aria-label="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')" :value="overrideSourceSelections[String(line.snapshot_line_id || lineIndex)] || line.selected_source_code || line.source_code || ''" @change="overrideSourceSelections[String(line.snapshot_line_id || lineIndex)] = ($event.target as HTMLSelectElement).value"><option value="" disabled>{{ t('chat.shippingOrderReview.lifecycle.prepare.selectSource') }}</option><option v-for="s in formSourceOptions" :key="String(s.source_code)" :value="String(s.source_code)">{{ overrideSourceOptionLabel(String(s.source_code)) }}</option></select><button type="button" class="rounded bg-brand-600 px-2 py-1 text-xs font-medium text-white disabled:opacity-50" :data-testid="`review-line-source-override-confirm-${line.snapshot_line_id || lineIndex}`" :disabled="!overrideSourceSelections[String(line.snapshot_line_id || lineIndex)] || overrideSourceBusy" :aria-label="t('chat.shippingOrderReview.lifecycle.prepare.selectSource')" :data-line-index="lineIndex" @click="submitOverrideSource(line)"><Check class="h-3.5 w-3.5" /></button></span><span v-else class="block max-w-[220px] truncate" :title="formalPreparationLineSource(line)">{{ formalPreparationLineSource(line) }}</span></td><td v-if="formalPreparationOdmColumnVisible" class="whitespace-nowrap px-3 py-2"><div v-if="(line.odm_values?.length || 0) > 1 && !formalLine truncated
</table>
</div>
</div>
@@ -58,16 +58,21 @@ onMounted(() => { void Promise.all([admin.loadCustomers(), admin.loadShadowRepor
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.name') }}</th>
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.shortCode') }}</th>
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.status') }}</th>
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.odmIds') }}</th>
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.identityEvidences') }}</th>
<th class="px-5 py-4 text-left">{{ t('admin.shippingCustomers.headers.notices') }}</th>
<th class="px-5 py-4 text-right">{{ t('admin.shippingCustomers.headers.actions') }}</th>
</tr></thead>
<tbody>
<tr v-if="admin.customers.value.length === 0"><td colspan="6" class="admin-table-empty px-5">{{ t('admin.shippingCustomers.empty') }}</td></tr>
<tr v-if="admin.customers.value.length === 0"><td colspan="7" class="admin-table-empty px-5">{{ t('admin.shippingCustomers.empty') }}</td></tr>
<tr v-for="customer in admin.customers.value" :key="customer.id">
<td class="px-5 py-4"><div class="font-medium text-primary">{{ customer.standard_name }}</div><div v-if="customer.remark" class="text-xs text-muted truncate max-w-sm">{{ customer.remark }}</div></td>
<td class="px-5 py-4 font-mono text-sm">{{ customer.short_code }}</td>
<td class="px-5 py-4"><span class="text-sm" :class="customer.status === 'active' ? 'text-emerald-600' : 'text-muted'">{{ t(`admin.shippingCustomers.status.${customer.status}`) }}</span></td>
<td class="px-5 py-4 text-sm">
<span v-if="customer.odm_ids?.length" class="font-mono text-xs">{{ customer.odm_ids.join(', ') }}</span>
<span v-else class="text-xs text-muted">{{ t('admin.shippingCustomers.fields.odmIdsUnlimited') }}</span>
</td>
<td class="px-5 py-4 text-sm">{{ customer.identity_evidence_count || 0 }}</td>
<td class="px-5 py-4 text-sm">{{ customer.notice_count }}</td>
<td class="px-5 py-4"><div class="flex justify-end gap-1">
@@ -42,6 +42,16 @@ const { t } = useI18n();
<span class="label-field">{{ t('admin.shippingCustomers.fields.remark') }}</span>
<textarea v-model="form.remark" rows="3" class="input-field text-sm resize-y" />
</label>
<label class="block space-y-1.5">
<span class="label-field">{{ t('admin.shippingCustomers.fields.odmIds') }}</span>
<textarea
v-model="form.odm_ids_text"
rows="3"
class="input-field text-sm resize-y font-mono"
:placeholder="t('admin.shippingCustomers.fields.odmIdsHint')"
/>
<span class="text-xs text-muted">{{ t('admin.shippingCustomers.fields.odmIdsHint') }}</span>
</label>
<label v-if="form.id" class="block space-y-1.5">
<span class="label-field">{{ t('admin.shippingCustomers.fields.changeReason') }}</span>
<textarea v-model="form.reason" rows="2" class="input-field text-sm resize-y" :placeholder="t('admin.shippingCustomers.fields.changeReasonHint')" />
@@ -158,11 +158,21 @@ export function useShippingCustomersAdmin() {
}
isSaving.value = true;
try {
// ODM ID 清单:文本域逐行解析,去空去重;整体为空提交 null 表示不限定。
const odmIds = Array.from(
new Set(
form.odm_ids_text
.split(/\r?\n/)
.map((item) => item.trim())
.filter(Boolean),
),
);
const payload = {
standard_name: form.standard_name.trim(),
short_code: form.short_code.trim().toUpperCase(),
status: form.status,
remark: form.remark.trim(),
odm_ids: odmIds.length ? odmIds : null,
reason: form.reason.trim(),
};
if (form.id) await updateShippingCustomer(form.id, payload);
@@ -29,6 +29,8 @@ export interface ShippingCustomerRow {
status: ShippingCustomerStatus;
merged_into_customer_id?: number | null;
remark?: string | null;
/** 客户可用的 ODM ID 清单;null/空数组表示不限定。 */
odm_ids?: string[] | null;
notice_count: number;
identifier_count: number;
identity_evidence_count?: number;
@@ -282,6 +284,8 @@ export interface ShippingCustomerFormState {
short_code: string;
status: ShippingCustomerStatus;
remark: string;
/** 文本域原文:每行一个 ODM ID;保存时解析为 odm_ids 数组。 */
odm_ids_text: string;
reason: string;
}
@@ -309,6 +313,7 @@ export const createEmptyShippingCustomerForm = (): ShippingCustomerFormState =>
short_code: '',
status: 'active',
remark: '',
odm_ids_text: '',
reason: '',
});
@@ -319,6 +324,7 @@ export const shippingCustomerToForm = (customer: ShippingCustomerRow): ShippingC
short_code: customer.short_code,
status: customer.status,
remark: customer.remark || '',
odm_ids_text: (customer.odm_ids || []).join('\n'),
reason: '',
});