148 lines
6.2 KiB
Vue
148 lines
6.2 KiB
Vue
/**
|
|
* features/chat/components/messages/ShippingMatchResultCard.vue
|
|
* 用途:出货 Agent 对话区与工作台共用的库存匹配/缺口结果卡片。
|
|
* 依赖:shipping.api.types、vue-i18n。
|
|
* 逻辑:由 Chat 消息区和 ShippingNoticeView 传入匹配结果;本组件只负责结构化展示状态、缺口与操作按钮。
|
|
*/
|
|
<script setup lang="ts">
|
|
import { useI18n } from 'vue-i18n';
|
|
import type {
|
|
ShippingChatAction,
|
|
ShippingMatchLineResult,
|
|
} from '../../types/shipping.api.types';
|
|
|
|
const props = defineProps<{
|
|
taskId: string;
|
|
matchStatus?: string | null;
|
|
lineResults?: ShippingMatchLineResult[] | null;
|
|
shortageLines?: ShippingMatchLineResult[] | null;
|
|
actionButtons?: ShippingChatAction[] | null;
|
|
actionBusy?: boolean;
|
|
onActionClick?: (action: ShippingChatAction) => void;
|
|
actionButtonClass?: (variant?: string) => string;
|
|
}>();
|
|
|
|
const { t } = useI18n();
|
|
const formatQty = (value: unknown) => {
|
|
const num = Number(value ?? 0);
|
|
if (!Number.isFinite(num)) return '-';
|
|
return Number.isInteger(num) ? String(num) : String(num);
|
|
};
|
|
|
|
const rowStatusLabel = (status?: string | null) => {
|
|
if (status === 'ok') return t('chat.shippingNoticeUi.rowStatus.ok');
|
|
if (status === 'partial') return t('chat.shippingNoticeUi.rowStatus.partial');
|
|
if (status === 'shortage') return t('chat.shippingNoticeUi.rowStatus.shortage');
|
|
return status || '-';
|
|
};
|
|
|
|
const matchStatusLabel = (status?: string | null) => {
|
|
if (status === 'fulfillable') return t('chat.shippingNoticeUi.matchStatus.fulfillable');
|
|
if (status === 'partial') return t('chat.shippingNoticeUi.matchStatus.partial');
|
|
if (status === 'unfulfillable') return t('chat.shippingNoticeUi.matchStatus.unfulfillable');
|
|
return status || t('chat.shippingNoticeUi.matchStatus.pending');
|
|
};
|
|
|
|
const hasShortage = () => Array.isArray(props.shortageLines) && props.shortageLines.length > 0;
|
|
</script>
|
|
|
|
<template>
|
|
<section class="space-y-4 rounded-2xl border border-default bg-surface-soft/90 p-4">
|
|
<div class="flex flex-wrap items-start justify-between gap-3">
|
|
<div>
|
|
<div class="text-xs font-bold uppercase tracking-wider text-muted">{{ t('chat.shippingNoticeUi.matchResult') }}</div>
|
|
<div class="mt-1 text-xs text-muted">{{ t('chat.shippingNoticeUi.taskId', { taskId }) }}</div>
|
|
</div>
|
|
<span
|
|
class="rounded-full px-2.5 py-1 text-xs font-semibold"
|
|
:class="hasShortage()
|
|
? 'bg-rose-100 text-rose-700'
|
|
: 'bg-emerald-100 text-emerald-700'"
|
|
>
|
|
{{ matchStatusLabel(matchStatus) }}
|
|
</span>
|
|
</div>
|
|
|
|
<div
|
|
v-if="hasShortage()"
|
|
class="rounded-xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700"
|
|
>
|
|
{{ t('chat.shippingNoticeUi.shortageBanner') }}
|
|
</div>
|
|
|
|
<div v-if="lineResults?.length" class="overflow-x-auto rounded-xl border border-default">
|
|
<table class="min-w-full text-sm">
|
|
<thead class="bg-surface text-left text-xs text-muted">
|
|
<tr>
|
|
<th class="px-3 py-2">#</th>
|
|
<th class="px-3 py-2">{{ t('chat.shippingNoticeUi.reservationId') }}</th>
|
|
<th class="px-3 py-2">{{ t('chat.shippingNoticeUi.sku') }}</th>
|
|
<th class="px-3 py-2">{{ t('chat.shippingNoticeUi.orderDemand') }}</th>
|
|
<th class="px-3 py-2">{{ t('chat.shippingNoticeUi.inventoryAvailable') }}</th>
|
|
<th class="px-3 py-2">{{ t('chat.shippingNoticeUi.shortageQty') }}</th>
|
|
<th class="px-3 py-2">{{ t('chat.shippingNoticeUi.statusLabel') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr
|
|
v-for="(line, index) in lineResults"
|
|
:key="`${taskId}-match-${index}`"
|
|
class="border-t border-default/70"
|
|
>
|
|
<td class="px-3 py-2 text-secondary">{{ index + 1 }}</td>
|
|
<td class="px-3 py-2 text-secondary">{{ line.reservation_id || '-' }}</td>
|
|
<td class="px-3 py-2 font-mono text-secondary">{{ line.sku || '-' }}</td>
|
|
<td class="px-3 py-2 text-secondary">{{ formatQty(line.required_qty) }}</td>
|
|
<td class="px-3 py-2 text-secondary">{{ formatQty(line.available_qty) }}</td>
|
|
<td class="px-3 py-2" :class="Number(line.shortage_qty || 0) > 0 ? 'font-semibold text-rose-700' : 'text-secondary'">
|
|
{{ Number(line.shortage_qty || 0) > 0 ? formatQty(line.shortage_qty) : '-' }}
|
|
</td>
|
|
<td class="px-3 py-2">
|
|
<span
|
|
class="rounded-full px-2 py-0.5 text-xs font-medium"
|
|
:class="line.line_status === 'ok'
|
|
? 'bg-emerald-100 text-emerald-700'
|
|
: line.line_status === 'partial'
|
|
? 'bg-amber-100 text-amber-700'
|
|
: 'bg-rose-100 text-rose-700'"
|
|
>
|
|
{{ rowStatusLabel(line.line_status) }}
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div v-if="shortageLines?.length" class="space-y-2">
|
|
<div class="text-xs font-bold uppercase tracking-wider text-muted">{{ t('chat.shippingNoticeUi.shortageDetails') }}</div>
|
|
<ul class="space-y-2 rounded-xl border border-rose-200 bg-rose-50/70 p-3 text-sm text-rose-700">
|
|
<li
|
|
v-for="(line, index) in shortageLines"
|
|
:key="`${taskId}-shortage-${index}`"
|
|
>
|
|
{{ t('chat.shippingNoticeUi.shortageRowDetail', { index: index + 1, reservationId: line.reservation_id || '-', sku: line.sku || '-', shortage: formatQty(line.shortage_qty) }) }}
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div v-if="actionButtons?.length" class="space-y-2 border-t border-default pt-4">
|
|
<div class="text-xs font-bold uppercase tracking-wider text-muted">{{ t('chat.shippingNoticeUi.availableActions') }}</div>
|
|
<div class="flex flex-wrap gap-2">
|
|
<button
|
|
v-for="(action, index) in actionButtons"
|
|
:key="`${taskId}-action-${action.id}-${index}`"
|
|
type="button"
|
|
:class="actionButtonClass
|
|
? actionButtonClass(action.variant)
|
|
: 'rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary hover:bg-surface'"
|
|
:disabled="actionBusy"
|
|
@click="onActionClick?.(action)"
|
|
>
|
|
{{ action.label }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</template>
|