Files
syops/frontend/src/features/chat/components/shipping-review/ReviewFulfillmentDecisionPanel.vue
T
hugoandCursor fd6a23f870 feat(shipping-notice): 收敛复核阶段同源投影与 OT 后履约推进
统一 Case/Progress 阶段 label_key、修复 Job 成功未推进 OT 的可重试失败投影与写路径,并落地 OT 后行级匹配/波次履约与版面诊断开关。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 13:11:14 +08:00

276 lines
11 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
features/chat/components/shipping-review/ReviewFulfillmentDecisionPanel.vue
用途:复核工作台行级履约决定(等待补货 / 完整行先行 / 关闭)。
依赖:vue-i18n、decide/wave line-fulfillment API、showReviewResumeOutcome。
逻辑:分列展示料号/需求数量/可用数量/预约单号/状态;禁止 part_number 回退预约单号;
逐行决定;选中 fulfill 行可确认波次;关闭 emit open-close-dialog。
-->
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { BusinessError, resolveLocalizedErrorMessage } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import {
decideWorkspaceShippingOrderReviewLineFulfillment,
waveWorkspaceShippingOrderReviewLineFulfillment,
} from '@/features/chat/api/shipping.api';
import { showReviewResumeOutcome } from '@/features/chat/shipping-review/showReviewResumeOutcome';
import type {
ShippingOrderReviewLineFulfillment,
ShippingOrderReviewLineFulfillmentDecisionCode,
ShippingOrderReviewLineFulfillmentLine,
} from '@/features/chat/types/shipping.api.types';
const props = defineProps<{
caseNo: string;
draftVersion: number | null | undefined;
lineFulfillment: ShippingOrderReviewLineFulfillment | null | undefined;
editable: boolean;
}>();
const emit = defineEmits<{
refreshed: [];
'open-close-dialog': [lineKeys: string[]];
}>();
const { t, te } = useI18n();
const msg = useMessage();
const busyKey = ref<string | null>(null);
const selectedFulfillKeys = ref<string[]>([]);
const waveBusy = ref(false);
const TERMINAL_STATUSES = new Set(['task_created', 'fulfilled', 'closed_unfulfillable']);
const visible = computed(() => Boolean(
props.lineFulfillment?.has_open_lines
|| props.lineFulfillment?.has_shortage,
));
const openLines = computed(() => (props.lineFulfillment?.lines || []).filter(
(line) => !TERMINAL_STATUSES.has(String(line.line_status || '')),
));
/**
* 行状态本地化。
*/
function lineStatusLabel(status: string | null | undefined): string {
const normalized = String(status || 'pending_decision').trim();
const key = `chat.shippingOrderReview.fulfillmentDecision.lineStatus.${normalized}`;
return te(key) ? t(key) : normalized;
}
/**
* 切换 fulfill 波次选中行。
*/
function toggleFulfillSelection(lineKey: string, checked: boolean) {
const set = new Set(selectedFulfillKeys.value);
if (checked) set.add(lineKey);
else set.delete(lineKey);
selectedFulfillKeys.value = [...set];
}
/**
* 行是否可选入 fulfill 波次。
*/
function canSelectForWave(line: ShippingOrderReviewLineFulfillmentLine): boolean {
if (TERMINAL_STATUSES.has(String(line.line_status || ''))) return false;
return Boolean(line.can_fulfill_complete_line);
}
/**
* 写入单行履约决定。
*/
async function onDecide(
line: ShippingOrderReviewLineFulfillmentLine,
decisionCode: ShippingOrderReviewLineFulfillmentDecisionCode,
) {
if (!props.caseNo || !props.editable || busyKey.value) return;
if (decisionCode === 'close_unfulfillable') {
emit('open-close-dialog', [line.line_key]);
return;
}
busyKey.value = line.line_key;
try {
const result = await decideWorkspaceShippingOrderReviewLineFulfillment(props.caseNo, {
line_key: line.line_key,
decision_code: decisionCode,
expected_draft_version: props.draftVersion ?? undefined,
});
showReviewResumeOutcome(
result.resume_outcome,
msg,
t,
t('chat.shippingOrderReview.fulfillmentDecision.decideSuccess'),
);
emit('refreshed');
} catch (error: unknown) {
const message = error instanceof BusinessError
? resolveLocalizedErrorMessage(error.code, error.message)
: (error instanceof Error ? error.message : t('chat.shippingOrderReview.fulfillmentDecision.decideFailed'));
msg.warning(message);
} finally {
busyKey.value = null;
}
}
/**
* 为选中完整行创建履约波次 Task。
*/
async function onConfirmWave() {
if (!props.caseNo || props.draftVersion == null || waveBusy.value || !selectedFulfillKeys.value.length) return;
waveBusy.value = true;
try {
const idempotencyKey = `review-wave-${props.caseNo}-${Date.now()}-${selectedFulfillKeys.value.sort().join(',')}`;
const result = await waveWorkspaceShippingOrderReviewLineFulfillment(props.caseNo, {
line_keys: [...selectedFulfillKeys.value],
expected_draft_version: props.draftVersion,
idempotency_key: idempotencyKey,
});
showReviewResumeOutcome(
result.resume_outcome,
msg,
t,
t('chat.shippingOrderReview.fulfillmentDecision.waveSuccess', {
taskNo: result.task_no || '',
}),
);
selectedFulfillKeys.value = [];
emit('refreshed');
} catch (error: unknown) {
const message = error instanceof BusinessError
? resolveLocalizedErrorMessage(error.code, error.message)
: (error instanceof Error ? error.message : t('chat.shippingOrderReview.fulfillmentDecision.waveFailed'));
msg.warning(message);
} finally {
waveBusy.value = false;
}
}
/**
* 打开关闭剩余行对话框(全部开放行)。
*/
function onCloseRemaining() {
const keys = openLines.value.map((line) => line.line_key);
emit('open-close-dialog', keys);
}
</script>
<template>
<section
v-if="visible"
class="rounded-xl border border-sky-200 bg-sky-50/70 p-3 shadow-sm dark:border-sky-900 dark:bg-sky-950/40"
data-testid="review-fulfillment-decision-panel"
>
<header class="flex flex-wrap items-start justify-between gap-2">
<div>
<h2 class="text-sm font-semibold text-sky-950 dark:text-sky-50">
{{ t('chat.shippingOrderReview.fulfillmentDecision.title') }}
</h2>
<p class="mt-0.5 text-xs text-sky-900 dark:text-sky-200">
{{ t('chat.shippingOrderReview.fulfillmentDecision.subtitle') }}
</p>
</div>
<span class="rounded-full bg-sky-100 px-2.5 py-1 text-xs font-medium text-sky-900 dark:bg-sky-950 dark:text-sky-100">
{{ t('chat.shippingOrderReview.fulfillmentDecision.openCount', { count: lineFulfillment?.open_count ?? openLines.length }) }}
</span>
</header>
<div class="mt-2 overflow-x-auto">
<table class="min-w-full text-left text-xs">
<thead class="text-muted">
<tr>
<th v-if="editable" class="px-1 py-1 font-medium">{{ t('chat.shippingOrderReview.fulfillmentDecision.waveSelect') }}</th>
<th class="px-1 py-1 font-medium">#</th>
<th class="px-1 py-1 font-medium">{{ t('chat.shippingOrderReview.fulfillmentDecision.partNumber') }}</th>
<th class="px-1 py-1 font-medium">{{ t('chat.shippingOrderReview.fulfillmentDecision.requiredQty') }}</th>
<th class="px-1 py-1 font-medium">{{ t('chat.shippingOrderReview.fulfillmentDecision.availableQty') }}</th>
<th class="px-1 py-1 font-medium">{{ t('chat.shippingOrderReview.fulfillmentDecision.reservationId') }}</th>
<th class="px-1 py-1 font-medium">{{ t('chat.shippingOrderReview.fulfillmentDecision.status') }}</th>
<th v-if="editable" class="px-1 py-1 font-medium">{{ t('chat.shippingOrderReview.fulfillmentDecision.actions') }}</th>
</tr>
</thead>
<tbody>
<tr
v-for="line in lineFulfillment?.lines || []"
:key="line.line_key"
class="border-t border-sky-100 dark:border-sky-900"
>
<td v-if="editable" class="px-1 py-1">
<input
v-if="canSelectForWave(line)"
type="checkbox"
class="rounded border-default"
:checked="selectedFulfillKeys.includes(line.line_key)"
:data-testid="`review-fulfill-select-${line.line_key}`"
@change="toggleFulfillSelection(line.line_key, ($event.target as HTMLInputElement).checked)"
>
</td>
<td class="px-1 py-1">{{ (line.line_index ?? 0) + 1 }}</td>
<td class="px-1 py-1 font-mono" data-testid="review-fulfill-part-number">
{{ line.part_number || t('chat.shippingOrderReview.fulfillmentDecision.partUnrecognized') }}
</td>
<td class="px-1 py-1">{{ line.required_qty ?? '—' }}</td>
<td class="px-1 py-1">{{ line.available_qty ?? '—' }}</td>
<td class="px-1 py-1 font-mono">{{ line.reservation_id || '—' }}</td>
<td class="px-1 py-1">{{ lineStatusLabel(line.line_status) }}</td>
<td v-if="editable && !TERMINAL_STATUSES.has(String(line.line_status || ''))" class="px-1 py-1">
<div class="flex flex-wrap gap-1">
<button
type="button"
class="rounded border border-sky-300 px-2 py-1 text-xs hover:bg-sky-100 disabled:opacity-50 dark:border-sky-800 dark:hover:bg-sky-950"
:disabled="busyKey != null"
@click="onDecide(line, 'wait_inventory')"
>
{{ t('chat.shippingOrderReview.fulfillmentDecision.waitInventory') }}
</button>
<button
v-if="line.can_fulfill_complete_line"
type="button"
class="rounded border border-emerald-300 px-2 py-1 text-xs hover:bg-emerald-50 disabled:opacity-50 dark:border-emerald-800 dark:hover:bg-emerald-950"
:disabled="busyKey != null"
@click="onDecide(line, 'fulfill_complete_line_now')"
>
{{ t('chat.shippingOrderReview.fulfillmentDecision.fulfillNow') }}
</button>
<button
type="button"
class="rounded border border-rose-300 px-2 py-1 text-xs text-rose-800 hover:bg-rose-50 disabled:opacity-50 dark:border-rose-800 dark:text-rose-200 dark:hover:bg-rose-950"
:disabled="busyKey != null"
@click="onDecide(line, 'close_unfulfillable')"
>
{{ t('chat.shippingOrderReview.fulfillmentDecision.closeLine') }}
</button>
</div>
</td>
<td v-else-if="editable" class="px-1 py-1 text-muted">—</td>
</tr>
</tbody>
</table>
</div>
<div v-if="editable" class="mt-3 flex flex-wrap gap-2">
<button
type="button"
class="rounded-xl bg-emerald-600 px-3 py-1.5 text-sm font-medium text-white disabled:opacity-60"
data-testid="review-fulfillment-confirm-wave"
:disabled="waveBusy || !selectedFulfillKeys.length || draftVersion == null"
@click="onConfirmWave"
>
{{ waveBusy
? t('chat.shippingOrderReview.fulfillmentDecision.waving')
: t('chat.shippingOrderReview.fulfillmentDecision.confirmWave', { count: selectedFulfillKeys.length }) }}
</button>
<button
v-if="openLines.length"
type="button"
class="rounded-xl border border-rose-300 bg-white px-3 py-1.5 text-sm text-rose-800 hover:bg-rose-50 disabled:opacity-60 dark:border-rose-800 dark:bg-slate-900 dark:text-rose-200"
data-testid="review-fulfillment-close-remaining"
:disabled="waveBusy || busyKey != null"
@click="onCloseRemaining"
>
{{ t('chat.shippingOrderReview.fulfillmentDecision.closeRemaining') }}
</button>
</div>
</section>
</template>