253 lines
9.4 KiB
Vue
253 lines
9.4 KiB
Vue
<!--
|
||
features/chat/components/shipping-review/ReviewDuplicatePanel.vue
|
||
用途:复核工作台建单前重复订单对比与裁决区。
|
||
依赖:vue-i18n、shipping.api 重复裁决/刷新、useMessage。
|
||
逻辑:needs_adjudication 时展示匹配任务与动作;裁决成功后 emit refreshed。
|
||
-->
|
||
<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 {
|
||
refreshWorkspaceShippingOrderReviewDuplicate,
|
||
resolveWorkspaceShippingOrderReviewDuplicate,
|
||
} from '@/features/chat/api/shipping.api';
|
||
import { showReviewResumeOutcome } from '@/features/chat/shipping-review/showReviewResumeOutcome';
|
||
import type {
|
||
ShippingDuplicateAction,
|
||
ShippingOrderReviewDuplicate,
|
||
} from '@/features/chat/types/shipping.api.types';
|
||
|
||
const props = defineProps<{
|
||
caseNo: string;
|
||
duplicate: ShippingOrderReviewDuplicate | null | undefined;
|
||
editable: boolean;
|
||
canForceCreate: boolean;
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
refreshed: [];
|
||
}>();
|
||
|
||
const { t, te } = useI18n();
|
||
const msg = useMessage();
|
||
const busy = ref(false);
|
||
const forceReason = ref('');
|
||
const selectedAction = ref<ShippingDuplicateAction | ''>('');
|
||
|
||
const visible = computed(() => Boolean(props.duplicate?.needs_adjudication || props.duplicate?.blocking));
|
||
const allowed = computed(() => new Set(props.duplicate?.allowed_actions || []));
|
||
const primaryMatch = computed(() => props.duplicate?.matches?.[0] || null);
|
||
const resolved = computed(() => Boolean(props.duplicate?.resolved));
|
||
|
||
/**
|
||
* 重复状态本地化文案。
|
||
*/
|
||
const statusLabel = computed(() => {
|
||
const status = String(props.duplicate?.status || '').trim();
|
||
const key = `chat.shippingOrderReview.duplicate.status.${status}`;
|
||
if (status && te(key)) return t(key);
|
||
if (props.duplicate?.blocking) return t('chat.shippingNoticeDuplicateNeedsResolution');
|
||
return t('chat.shippingOrderReview.duplicate.status.none');
|
||
});
|
||
|
||
/**
|
||
* 提交重复裁决。
|
||
*/
|
||
async function resolve(action: ShippingDuplicateAction) {
|
||
if (!props.editable || !props.caseNo || busy.value) return;
|
||
if (!allowed.value.has(action)) {
|
||
msg.warning(t('chat.shippingNoticeDuplicateActionUnavailable'));
|
||
return;
|
||
}
|
||
const target = String(primaryMatch.value?.task_no || '').trim();
|
||
if (!target) {
|
||
msg.warning(t('chat.shippingNoticeDuplicateActionUnavailable'));
|
||
return;
|
||
}
|
||
if (action === 'force_create') {
|
||
if (!props.canForceCreate) {
|
||
msg.warning(t('chat.shippingNoticeDuplicateForceForbidden'));
|
||
return;
|
||
}
|
||
if (!forceReason.value.trim()) {
|
||
msg.warning(t('chat.shippingNoticeDuplicateReasonRequired'));
|
||
return;
|
||
}
|
||
}
|
||
busy.value = true;
|
||
selectedAction.value = action;
|
||
try {
|
||
const result = await resolveWorkspaceShippingOrderReviewDuplicate(props.caseNo, {
|
||
action,
|
||
target_task_no: target,
|
||
reason: action === 'force_create' ? forceReason.value.trim() : undefined,
|
||
});
|
||
forceReason.value = '';
|
||
showReviewResumeOutcome(result.resume_outcome, msg, t, t('chat.shippingOrderReview.duplicate.resolveSuccess'));
|
||
emit('refreshed');
|
||
} catch (error: unknown) {
|
||
const message = error instanceof BusinessError
|
||
? resolveLocalizedErrorMessage(error.code, error.message)
|
||
: (error instanceof Error ? error.message : t('chat.shippingOrderReview.duplicate.resolveFailed'));
|
||
msg.warning(message);
|
||
} finally {
|
||
busy.value = false;
|
||
selectedAction.value = '';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 重新检测重复(清除陈旧决议)。
|
||
*/
|
||
async function onRefresh() {
|
||
if (!props.editable || !props.caseNo || busy.value) return;
|
||
busy.value = true;
|
||
try {
|
||
const result = await refreshWorkspaceShippingOrderReviewDuplicate(props.caseNo);
|
||
showReviewResumeOutcome(result.resume_outcome, msg, t, t('chat.shippingOrderReview.duplicate.refreshDone'));
|
||
emit('refreshed');
|
||
} catch (error: unknown) {
|
||
const message = error instanceof BusinessError
|
||
? resolveLocalizedErrorMessage(error.code, error.message)
|
||
: (error instanceof Error ? error.message : t('chat.shippingOrderReview.duplicate.refreshFailed'));
|
||
msg.warning(message);
|
||
} finally {
|
||
busy.value = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 聚焦裁决区并短暂高亮动作按钮(Footer / Resolver 委托)。
|
||
*/
|
||
function focusAdjudication() {
|
||
const root = document.querySelector('[data-testid="review-duplicate-panel"]');
|
||
root?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||
const actions = document.querySelector('[data-testid="review-duplicate-actions"]');
|
||
if (!(actions instanceof HTMLElement)) return;
|
||
actions.classList.add('ring-2', 'ring-amber-400');
|
||
window.setTimeout(() => {
|
||
actions.classList.remove('ring-2', 'ring-amber-400');
|
||
}, 1600);
|
||
}
|
||
|
||
defineExpose({
|
||
focusAdjudication,
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<section
|
||
v-if="visible"
|
||
class="rounded-xl border border-amber-200 bg-amber-50/70 p-3 shadow-sm dark:border-amber-900 dark:bg-amber-950/40"
|
||
data-testid="review-duplicate-panel"
|
||
>
|
||
<header class="flex flex-wrap items-start justify-between gap-2">
|
||
<div>
|
||
<h2 class="text-sm font-semibold text-amber-950 dark:text-amber-50">
|
||
{{ t('chat.shippingOrderReview.duplicate.title') }}
|
||
</h2>
|
||
<p class="mt-0.5 text-xs text-amber-900 dark:text-amber-200">
|
||
{{ t('chat.shippingOrderReview.duplicate.subtitle') }}
|
||
</p>
|
||
</div>
|
||
<span
|
||
class="rounded-full px-2.5 py-1 text-xs font-medium"
|
||
:class="resolved
|
||
? 'bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-100'
|
||
: 'bg-amber-100 text-amber-900 dark:bg-amber-950 dark:text-amber-100'"
|
||
data-testid="review-duplicate-badge"
|
||
>
|
||
{{ resolved ? t('chat.shippingOrderReview.duplicate.resolvedBadge') : statusLabel }}
|
||
</span>
|
||
</header>
|
||
|
||
<div
|
||
v-if="primaryMatch"
|
||
class="mt-2 rounded-lg border border-amber-200 bg-white/90 px-2.5 py-2 text-xs text-secondary dark:border-amber-900"
|
||
data-testid="review-duplicate-match"
|
||
>
|
||
<div class="font-medium text-primary">
|
||
{{ t('chat.shippingNoticeDuplicateMatchTask', { taskNo: primaryMatch.task_no }) }}
|
||
</div>
|
||
<div class="mt-0.5 text-muted">
|
||
{{ t('chat.shippingNoticeDuplicateMatchStatus', { status: primaryMatch.lifecycle || 'active' }) }}
|
||
</div>
|
||
<div v-if="primaryMatch.matched_fields?.length" class="mt-0.5 text-muted">
|
||
{{ t('chat.shippingNoticeDuplicateMatchFields', { fields: primaryMatch.matched_fields.join(', ') }) }}
|
||
</div>
|
||
</div>
|
||
|
||
<p v-if="duplicate?.resolution?.action" class="mt-2 text-xs text-secondary">
|
||
{{ t('chat.shippingOrderReview.duplicate.resolutionLabel', { action: duplicate.resolution.action }) }}
|
||
<span v-if="duplicate.resolution.target_task_no" class="font-mono">
|
||
→ {{ duplicate.resolution.target_task_no }}
|
||
</span>
|
||
</p>
|
||
|
||
<div
|
||
v-if="editable && duplicate?.needs_adjudication"
|
||
class="mt-3 space-y-2 rounded-lg transition-shadow"
|
||
data-testid="review-duplicate-actions"
|
||
>
|
||
<div class="flex flex-wrap gap-2">
|
||
<button
|
||
v-if="allowed.has('open_existing')"
|
||
type="button"
|
||
class="rounded-xl border border-default bg-surface px-3 py-1.5 text-sm text-secondary hover:bg-surface-soft disabled:opacity-60"
|
||
data-testid="review-duplicate-open-existing"
|
||
:disabled="busy"
|
||
@click="resolve('open_existing')"
|
||
>
|
||
{{ t('chat.shippingNoticeDuplicateOpenExisting') }}
|
||
</button>
|
||
<button
|
||
v-if="allowed.has('create_revision')"
|
||
type="button"
|
||
class="rounded-xl border border-amber-300 bg-amber-100 px-3 py-1.5 text-sm font-medium text-amber-950 hover:bg-amber-200 disabled:opacity-60 dark:border-amber-800 dark:bg-amber-950 dark:text-amber-100"
|
||
data-testid="review-duplicate-create-revision"
|
||
:disabled="busy"
|
||
@click="resolve('create_revision')"
|
||
>
|
||
{{ t('chat.shippingNoticeDuplicateCreateRevision') }}
|
||
</button>
|
||
</div>
|
||
|
||
<div v-if="allowed.has('force_create') && canForceCreate" class="space-y-1.5">
|
||
<input
|
||
v-model="forceReason"
|
||
type="text"
|
||
class="w-full rounded border border-default bg-surface px-2 py-1.5 text-xs"
|
||
data-testid="review-duplicate-force-reason"
|
||
:placeholder="t('chat.shippingNoticeDuplicateReasonPlaceholder')"
|
||
:disabled="busy"
|
||
>
|
||
<button
|
||
type="button"
|
||
class="rounded-xl bg-rose-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-rose-700 disabled:opacity-60"
|
||
data-testid="review-duplicate-force-create"
|
||
:disabled="busy || !forceReason.trim()"
|
||
@click="resolve('force_create')"
|
||
>
|
||
{{ selectedAction === 'force_create' && busy
|
||
? t('chat.shippingOrderReview.duplicate.resolving')
|
||
: t('chat.shippingNoticeDuplicateForceCreate') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="editable" class="mt-3">
|
||
<button
|
||
type="button"
|
||
class="text-[11px] text-secondary underline-offset-2 hover:underline disabled:opacity-60"
|
||
data-testid="review-duplicate-refresh"
|
||
:disabled="busy"
|
||
@click="onRefresh"
|
||
>
|
||
{{ busy ? t('chat.shippingOrderReview.duplicate.refreshing') : t('chat.shippingOrderReview.duplicate.refresh') }}
|
||
</button>
|
||
</div>
|
||
</section>
|
||
</template>
|