331 lines
15 KiB
Vue
331 lines
15 KiB
Vue
<!--
|
||
features/chat/components/shipping-review/ReviewBuildEligibilitySummary.vue
|
||
用途:复核摘要侧栏的建单资格压缩卡(可建单状态、门禁清单、首要阻断)。
|
||
依赖:vue-i18n、ShippingOrderReviewBuildEligibility。
|
||
逻辑:只展示业务结论、具体字段/明细问题与异常导航;隐藏 Gate code、
|
||
can_build/can_auto_create 等实现标识;「查看完整检查」emit open-details。
|
||
-->
|
||
<script setup lang="ts">
|
||
import { computed } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import type { ShippingOrderReviewBuildEligibility } from '@/features/chat/types/shipping.api.types';
|
||
import type { ShippingOrderReviewFieldConflict } from '@/features/chat/types/shipping.api.types';
|
||
|
||
const props = defineProps<{
|
||
eligibility: ShippingOrderReviewBuildEligibility | null;
|
||
fieldConflicts?: ShippingOrderReviewFieldConflict[] | null;
|
||
fieldLabels?: Record<string, string>;
|
||
customerResolved?: boolean;
|
||
/** 可定位异常总数;由工作台统一收集草稿与门禁问题。 */
|
||
exceptionCount?: number;
|
||
/** 当前定位异常序号;未定位时为 0。 */
|
||
exceptionOrdinal?: number;
|
||
/**
|
||
* 兼容旧调用方的展示偏好。当前任务卡只承载动作,建单门禁仍须完整展示,
|
||
* 因此该参数不再隐藏字段级诊断,避免用户只能看到泛化阻断原因。
|
||
*/
|
||
focusBuildability?: boolean;
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
'open-details': [];
|
||
'navigate-exception': [delta: -1 | 1];
|
||
}>();
|
||
|
||
const { t, te } = useI18n();
|
||
|
||
/** 用户可见的关键建单前门禁(与后端 qualification gates 对齐)。 */
|
||
const CHECKLIST_GATES = [
|
||
'customer_confirmed',
|
||
'required_fields_complete',
|
||
'evidence_complete',
|
||
'duplicate_resolved',
|
||
'field_conflicts_resolved',
|
||
] as const;
|
||
|
||
/** 阻断 issue 数量(优先 blocking severity)。 */
|
||
const effectiveIssues = computed(() => {
|
||
const issues = props.eligibility?.issues || [];
|
||
if (props.customerResolved !== true) return issues;
|
||
return issues.filter((item) => {
|
||
const code = String(item.code || '').trim().toLowerCase();
|
||
const reason = String(item.reason_code || '').trim().toLowerCase();
|
||
const gate = String(item.owning_gate_code || '').trim().toLowerCase();
|
||
return !(
|
||
code.startsWith('customer_')
|
||
|| reason.startsWith('customer_')
|
||
|| gate === 'customer_resolution'
|
||
|| gate === 'customer_confirmed'
|
||
);
|
||
});
|
||
});
|
||
|
||
const blockingIssueCount = computed(() => {
|
||
const issues = effectiveIssues.value;
|
||
const blocking = issues.filter((item) => String(item.severity || '') === 'blocking');
|
||
return blocking.length || issues.length;
|
||
});
|
||
|
||
/** 首要阻断文案:仅来自当前未解决业务问题;客户已确认时不得再显示客户确认阻断。 */
|
||
const primaryBlockMessage = computed(() => {
|
||
const issues = effectiveIssues.value;
|
||
const primary = issues.find((item) => String(item.severity || '') === 'blocking') || issues[0];
|
||
if (!primary) {
|
||
const blockedLines = (props.eligibility?.line_projections || []).filter((line) => {
|
||
if (line.can_build !== false) return false;
|
||
if (props.customerResolved !== true) return true;
|
||
const reason = String(line.block_reason || '').trim().toLowerCase();
|
||
return !reason.startsWith('customer_');
|
||
});
|
||
if (!blockedLines.length) {
|
||
const failedGate = (props.eligibility?.failed_gates || []).find((gate) => {
|
||
const code = String(gate || '').trim().toLowerCase();
|
||
if (props.customerResolved === true && (code === 'customer_confirmed' || code === 'customer_resolution')) {
|
||
return false;
|
||
}
|
||
return true;
|
||
});
|
||
if (!failedGate) return '';
|
||
const gateKey = `chat.shippingOrderReview.buildEligibility.gates.${failedGate}`;
|
||
return te(gateKey) ? t(gateKey) : t('chat.shippingOrderReview.issueCodes.unknown');
|
||
}
|
||
const reason = String(blockedLines[0]?.block_reason || '').trim();
|
||
const key = `chat.shippingOrderReview.buildEligibility.blockReasons.${reason}`;
|
||
return reason && te(key) ? t(key) : t('chat.shippingOrderReview.buildEligibility.blockReasons.unknown');
|
||
}
|
||
const code = String(primary.code || '').trim().toLowerCase();
|
||
// Draft 基础校验按冻结 Schema 返回 field_id,资格评估返回 field_code;两者都要映射,
|
||
// 否则会丢失“究竟哪个字段没有值”的事实,只剩笼统的不可建单。
|
||
const field = String(primary.field_code || primary.field_id || '').trim();
|
||
const lineIndex = Number.isFinite(Number(primary.line_index)) ? Number(primary.line_index) : null;
|
||
const candidates = Array.isArray(primary.candidate_inventory_source_codes)
|
||
? primary.candidate_inventory_source_codes.map((item) => {
|
||
const sourceCode = String(item || '').trim();
|
||
return props.eligibility?.inventory_source_labels?.[sourceCode] || sourceCode;
|
||
}).filter(Boolean)
|
||
: [];
|
||
if (code === 'customer_unresolved') {
|
||
return t('chat.shippingOrderReview.workbench.manualReview.customer');
|
||
}
|
||
if (field) {
|
||
return t('chat.shippingOrderReview.workbench.manualReview.field', {
|
||
field: props.fieldLabels?.[field] || field,
|
||
});
|
||
}
|
||
if (lineIndex !== null && (candidates.length || code === 'require_manual_review' || code.includes('inventory_source'))) {
|
||
return t('chat.shippingOrderReview.workbench.manualReview.lineInventory', {
|
||
line: lineIndex + 1,
|
||
candidates: candidates.length ? candidates.join('、') : t('chat.shippingOrderReview.workbench.manualReview.noCandidates'),
|
||
});
|
||
}
|
||
const message = String(primary.explainability?.message || primary.message || '').trim();
|
||
if (message) return message;
|
||
const key = `chat.shippingOrderReview.issueCodes.${code}`;
|
||
if (code && te(key)) return t(key);
|
||
const failedGate = (props.eligibility?.failed_gates || []).find((gate) => {
|
||
const gateCode = String(gate || '').trim().toLowerCase();
|
||
if (props.customerResolved === true && (gateCode === 'customer_confirmed' || gateCode === 'customer_resolution')) {
|
||
return false;
|
||
}
|
||
return true;
|
||
});
|
||
if (failedGate) {
|
||
const gateKey = `chat.shippingOrderReview.buildEligibility.gates.${failedGate}`;
|
||
return te(gateKey) ? t(gateKey) : t('chat.shippingOrderReview.issueCodes.unknown');
|
||
}
|
||
return t('chat.shippingOrderReview.issueCodes.unknown');
|
||
});
|
||
|
||
/** 不可建单的行数。 */
|
||
const blockedLineCount = computed(() =>
|
||
(props.eligibility?.line_projections || []).filter((line) => line.can_build === false).length,
|
||
);
|
||
|
||
const missingRequiredFields = computed(() => (props.eligibility?.assessment?.missing_required_fields || [])
|
||
.map((code) => props.fieldLabels?.[String(code)] || String(code)));
|
||
const conflictFields = computed(() => (props.fieldConflicts || []).map((item) => props.fieldLabels?.[String(item.field_code || '').trim()] || String(item.field_code || '').trim())
|
||
.filter(Boolean));
|
||
const lowConfidenceFields = computed(() => props.eligibility?.issues?.flatMap((issue) =>
|
||
(issue.low_confidence_fields || []).map((item) => ({
|
||
...item,
|
||
label: props.fieldLabels?.[item.field_code] || item.field_code,
|
||
})),
|
||
) || []);
|
||
const unexplainedBlocked = computed(() => Boolean(
|
||
props.eligibility
|
||
&& props.eligibility.can_build === false
|
||
&& !props.eligibility.issues?.length
|
||
&& !props.eligibility.failed_gates?.length
|
||
&& !props.eligibility.assessment?.missing_required_fields?.length
|
||
&& !(props.eligibility.line_projections || []).some((line) => line.can_build === false),
|
||
));
|
||
|
||
/**
|
||
* 门禁勾选列表:优先 gates 映射;客户未确认时强制展示失败项。
|
||
*/
|
||
const gateChecklist = computed(() => {
|
||
const gates = props.eligibility?.gates || {};
|
||
const failed = new Set((props.eligibility?.failed_gates || []).map(String));
|
||
const issues = props.eligibility?.issues || [];
|
||
const customerIssue = issues.some((item) => String(item.code || '').startsWith('customer_'));
|
||
const checks = CHECKLIST_GATES.map((gate) => {
|
||
const known = Object.prototype.hasOwnProperty.call(gates, gate);
|
||
let passed = known ? Boolean(gates[gate]) : !failed.has(gate);
|
||
if (gate === 'customer_confirmed') {
|
||
passed = props.customerResolved === true ? true : (customerIssue ? false : passed);
|
||
}
|
||
if (gate === 'field_conflicts_resolved' && props.fieldConflicts) {
|
||
passed = props.fieldConflicts.length === 0;
|
||
}
|
||
if (gate === 'required_fields_complete' && props.eligibility?.assessment) {
|
||
const missing = props.eligibility.assessment.missing_required_fields || [];
|
||
const invalid = props.eligibility.assessment.invalid_lines || [];
|
||
passed = missing.length === 0 && invalid.length === 0;
|
||
}
|
||
const labelKey = `chat.shippingOrderReview.buildEligibility.gates.${gate}`;
|
||
return {
|
||
gate,
|
||
passed,
|
||
label: te(labelKey) ? t(labelKey) : t('chat.shippingOrderReview.issueCodes.unknown'),
|
||
};
|
||
}).filter((item) => Object.keys(gates).length === 0 || Object.prototype.hasOwnProperty.call(gates, item.gate) || item.gate === 'customer_confirmed');
|
||
return [
|
||
{
|
||
gate: 'overall_build_result',
|
||
passed: props.eligibility?.can_build === true,
|
||
label: props.eligibility?.can_build === true
|
||
? t('chat.shippingOrderReview.buildEligibility.overallPass')
|
||
: t('chat.shippingOrderReview.buildEligibility.overallBlocked'),
|
||
},
|
||
...checks,
|
||
];
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<section
|
||
v-if="eligibility"
|
||
class="rounded-xl border border-slate-200 bg-white p-3 shadow-sm dark:border-slate-800 dark:bg-slate-900"
|
||
data-testid="review-build-eligibility-summary"
|
||
>
|
||
<header class="flex flex-wrap items-center justify-between gap-2">
|
||
<h2 class="text-sm font-semibold">{{ t('chat.shippingOrderReview.buildEligibility.title') }}</h2>
|
||
<span
|
||
class="rounded-full px-2.5 py-1 text-xs font-medium"
|
||
:class="eligibility.can_build
|
||
? '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-build-eligibility-badge"
|
||
>
|
||
{{
|
||
eligibility.can_build
|
||
? t('chat.shippingOrderReview.buildEligibility.canBuildYes')
|
||
: t('chat.shippingOrderReview.buildEligibility.canBuildNo')
|
||
}}
|
||
</span>
|
||
</header>
|
||
|
||
<p
|
||
v-if="eligibility.can_build && eligibility.can_auto_create === false"
|
||
class="mt-2 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-xs text-amber-950 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
|
||
data-testid="review-auto-create-blocked"
|
||
>
|
||
{{ t('chat.shippingOrderReview.buildEligibility.manualConfirmOnly') }}
|
||
</p>
|
||
<ul
|
||
v-if="gateChecklist.length"
|
||
class="mt-2 space-y-1 text-xs"
|
||
data-testid="review-eligibility-gate-checklist"
|
||
>
|
||
<li
|
||
v-for="item in gateChecklist"
|
||
:key="item.gate"
|
||
class="flex items-center gap-2"
|
||
>
|
||
<span :class="item.passed ? 'text-emerald-600' : 'text-rose-600'">{{ item.passed ? '✓' : '×' }}</span>
|
||
<span :class="item.passed ? 'text-secondary' : 'font-medium text-rose-700 dark:text-rose-300'">
|
||
{{ item.label }}
|
||
</span>
|
||
</li>
|
||
</ul>
|
||
<div
|
||
v-if="exceptionCount"
|
||
class="mt-2 flex flex-wrap items-center justify-between gap-2 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-xs text-amber-950 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
|
||
data-testid="review-exception-nav"
|
||
>
|
||
<span>
|
||
{{ t('chat.shippingOrderReview.issues') }}
|
||
<span class="ml-1 text-muted">
|
||
{{ exceptionOrdinal ? `${exceptionOrdinal}/${exceptionCount}` : `0/${exceptionCount}` }}
|
||
</span>
|
||
</span>
|
||
<div class="flex items-center gap-2">
|
||
<button
|
||
type="button"
|
||
class="rounded border border-amber-300 px-2 py-1 text-amber-900 hover:bg-amber-100 dark:border-amber-800 dark:text-amber-100 dark:hover:bg-amber-950"
|
||
data-testid="review-exception-prev"
|
||
:title="t('chat.shippingOrderReview.exceptionNav.prevHint')"
|
||
@click="emit('navigate-exception', -1)"
|
||
>
|
||
{{ t('chat.shippingOrderReview.exceptionNav.prev') }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="rounded border border-amber-300 px-2 py-1 text-amber-900 hover:bg-amber-100 dark:border-amber-800 dark:text-amber-100 dark:hover:bg-amber-950"
|
||
data-testid="review-exception-next"
|
||
:title="t('chat.shippingOrderReview.exceptionNav.nextHint')"
|
||
@click="emit('navigate-exception', 1)"
|
||
>
|
||
{{ t('chat.shippingOrderReview.exceptionNav.next') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div v-if="missingRequiredFields.length || conflictFields.length" class="mt-2 space-y-1 rounded-lg border border-rose-200 bg-rose-50 px-2.5 py-2 text-xs text-rose-900 dark:border-rose-900 dark:bg-rose-950/30 dark:text-rose-100">
|
||
<p v-if="missingRequiredFields.length"><span class="font-semibold">{{ t('chat.shippingOrderReview.workbench.missingRequiredFields') }}:</span>{{ missingRequiredFields.join('、') }}</p>
|
||
<p v-if="conflictFields.length"><span class="font-semibold">{{ t('chat.shippingOrderReview.workbench.conflictFields') }}:</span>{{ [...new Set(conflictFields)].join('、') }}</p>
|
||
</div>
|
||
<div
|
||
v-if="lowConfidenceFields.length"
|
||
class="mt-2 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-xs text-amber-950 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
|
||
data-testid="review-low-confidence-fields"
|
||
>
|
||
<p class="font-semibold">{{ t('chat.shippingOrderReview.workbench.lowConfidenceFields') }}:</p>
|
||
<ul class="mt-1 list-disc pl-4">
|
||
<li v-for="item in lowConfidenceFields" :key="item.field_code">
|
||
{{ item.label }}({{ item.confidence == null ? '—' : `${Math.round(item.confidence * 100)}%` }},{{ t('chat.shippingOrderReview.workbench.confidenceThreshold', { threshold: Math.round(Number(item.minimum_confidence || 0) * 100) }) }})
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div
|
||
v-if="!eligibility.can_build && primaryBlockMessage"
|
||
class="mt-2 rounded-lg border border-amber-200 bg-amber-50 px-2.5 py-2 text-xs text-amber-950 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-100"
|
||
data-testid="review-eligibility-primary-block"
|
||
>
|
||
<div class="font-semibold">{{ t('chat.shippingOrderReview.workbench.primaryBlock') }}</div>
|
||
<p class="mt-0.5">{{ primaryBlockMessage }}</p>
|
||
<p v-if="blockingIssueCount || blockedLineCount" class="mt-1 text-[11px] opacity-80">
|
||
{{ t('chat.shippingOrderReview.workbench.blockCount', {
|
||
count: Math.max(blockingIssueCount, blockedLineCount),
|
||
}) }}
|
||
</p>
|
||
</div>
|
||
<div
|
||
v-if="unexplainedBlocked"
|
||
class="mt-2 rounded-lg border border-rose-200 bg-rose-50 px-2.5 py-2 text-xs text-rose-900 dark:border-rose-900 dark:bg-rose-950/30 dark:text-rose-100"
|
||
data-testid="review-eligibility-unexplained-block"
|
||
>
|
||
{{ t('chat.shippingOrderReview.buildEligibility.unexplainedBlocked') }}
|
||
</div>
|
||
|
||
<button
|
||
type="button"
|
||
class="mt-2 w-full rounded border border-slate-300 px-2 py-1.5 text-xs hover:bg-slate-50 dark:border-slate-600 dark:hover:bg-slate-800"
|
||
data-testid="review-open-eligibility-details"
|
||
@click="emit('open-details')"
|
||
>
|
||
{{ t('chat.shippingOrderReview.workbench.viewFullChecks') }}
|
||
</button>
|
||
</section>
|
||
</template>
|