Files
syops/frontend/src/features/chat/components/messages/TransferSourceSelectCard.vue
T
hugo 386f93108c feat(shipping-notice): 库存缺口料号兜底自动放行并新增料号可用量列
- 匹配器按料号二次汇总 part_available_qty 随行级匹配事实持久化(新列,迁移 0a575f3a)
- 缺口行料号总库存满足需求时系统自动放行,复用人工放行同一落库/审计/门禁链路,证据按预约优先→料号兜底自动带出
- 前端库存匹配表原「可用数量」列改为「预约数量」,其后新增「可用数量」(料号总库存)列
- DSV 连接器防误点「忘记密码」链接并参数化料号报表取数,库存 worker 按料号查询配套
- 收料就绪与来源状态联动调整;casdoor 未识别认证错误日志保留原始异常堆栈
- 同步门禁/投影/持久化测试、调拨卡片文案四语言与文档
2026-10-11 17:42:55 +08:00

484 lines
23 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/messages/TransferSourceSelectCard.vue
用途:来源实例选择卡(决策 2/3/4:手工两步第一步)——按平台 DBS/Crane 分组勾选实例,
选择调拨类型后“确认范围并匹配”发起匹配。
依赖:props.sources、i18n chat.transfer.*。
逻辑:匹配参数区(调拨类型 + 收料日期,确认时一并提交)→ 选择辅助/上下文操作条
(有选中时原位替换辅助区,承载批量重试/下载/清空选择)→ 平台分组来源列表
(平台仅分组不可直接执行)→ 底部唯一实心主按钮「确认范围并匹配」(未选禁用);
确认只提交具备 ready 文件的来源:混合选择(含非就绪项)先披露范围再确认
(知情部分确认 2026-10-09,替代历史静默剔除),全就绪直达;
门禁「至少一 ready」保留为兜底告警;重试除抓取中(fetching)外均可触发
(ready 亦可强制重抓,2026-09-29 去管控),徽标独立文案;
调拨类型决定收料数据范围(类型 1 仅纳入 INVOICE 前缀 HOM/HOX/WTP),
类型 2/3 一期占位(禁用,后端同样 fail-closed)。
-->
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useMessage } from '@/shared/composables/useMessage';
import { eligibleReceiptDateTo } from './transferDate';
import type { TransferSourceOption, TransferType } from '../../types/transfer.types';
const props = defineProps<{
sources: TransferSourceOption[];
busy?: boolean;
/** 正在重试收料 RPA 的来源编码集合 */
retrying?: Set<string>;
}>();
const emit = defineEmits<{
confirm: [sourceCodes: string[], dateRange?: { from?: string; to?: string }, transferType?: TransferType];
/** 批量重试收料 RPA:传来源编码列表 */
retry: [sourceCodes: string[]];
download: [sourceCodes: string[]];
}>();
const { warning: notifyWarning } = useMessage();
const { t } = useI18n();
const selected = ref<Set<string>>(new Set());
/** 收料日期范围(匹配查询范围):默认 D+1 规则日期(T-1),上限同(输入期限制,
* 不等提交报错);后端 RECEIPT_DATE_RANGE_INVALID 卡控保留为双保险。 */
const maxReceiptDate = eligibleReceiptDateTo();
const dateFrom = ref(maxReceiptDate);
const dateTo = ref(maxReceiptDate);
/** 起始不得晚于截止(清空视为不限,提交 undefined)。 */
const dateRangeInvalid = computed(() => {
const from = dateFrom.value || null;
const to = dateTo.value || null;
return from !== null && to !== null && from > to;
});
/** 调拨业务类型:决定本次匹配纳入哪些收料数据;一期仅类型 1 开放。 */
const transferType = ref<TransferType>('in_transit_to_hub');
/** 类型选项元数据;enabled=false 为占位类型(UI 禁用 + 后端 fail-closed 双保险)。 */
const transferTypeOptions: Array<{ value: TransferType; enabled: boolean }> = [
{ value: 'in_transit_to_hub', enabled: true },
{ value: 'hub_repair_out', enabled: false },
{ value: 'hub_to_hub', enabled: false },
];
function transferTypeLabel(value: TransferType): string {
return t(`chat.transfer.transferType.${value}`);
}
const platforms = computed(() => [...new Set(props.sources.map((source) => source.platform))]);
const selectedCount = computed(() => selected.value.size);
/** 可重试判定:除抓取中(fetching)外均可重试(2026-09-29 去管控:ready 亦可强制重抓,
* 文件内容异常时覆盖重抓;后端 retry-rpa 本无状态门禁);fetching 在途去重防并发双跑。 */
function isRetryable(source: TransferSourceOption): boolean {
return source.file_status !== 'fetching';
}
/** 全部可重试来源。 */
const retryableSources = computed(() => props.sources.filter(isRetryable));
/** 已选来源中可重试的数量。 */
const selectedRetryableCount = computed(() =>
[...selected.value].filter((code) => props.sources.some((s) => s.source_code === code && isRetryable(s))).length,
);
const batchRetryDisabled = computed(() => props.busy || selectedRetryableCount.value === 0);
/** 已选来源中是否有具备 ready 文件的(门禁:都无 ready 文件则禁止确认匹配)。 */
const selectedHasReadyFile = computed(() =>
[...selected.value].some((code) => props.sources.find((s) => s.source_code === code)?.has_ready_file),
);
const confirmDisabled = computed(() =>
props.busy || selectedCount.value === 0 || !selectedHasReadyFile.value || dateRangeInvalid.value,
);
const downloadDisabled = computed(() => props.busy || !selectedHasReadyFile.value);
// ---- [知情部分确认 2026-10-09] 混合选择(含非就绪项)先披露范围再确认,替代历史静默剔除 ----
/** 披露条可见性:仅在「已选含就绪 + 非就绪」混合状态点确认后出现。 */
const showPartialConfirm = ref(false);
/** 已选来源中具备 ready 文件的数量。 */
const selectedReadyCount = computed(() =>
[...selected.value].filter((code) => props.sources.find((s) => s.source_code === code)?.has_ready_file).length,
);
const selectedUnreadyCount = computed(() => selectedCount.value - selectedReadyCount.value);
/** 非就绪状态分组展示顺序:先在途(fetching)后终态。 */
const unreadyStatusOrder = ['fetching', 'failed', 'parse_failed', 'no_data', 'expired', 'none'] as const;
/** 非就绪状态 → 徽标文案 key(复用既有状态徽标词汇,披露条逐组计数)。 */
const UNREADY_STATUS_LABEL_KEYS: Record<(typeof unreadyStatusOrder)[number], string> = {
fetching: 'chat.transfer.fileFetching',
failed: 'chat.transfer.fileFailed',
parse_failed: 'chat.transfer.fileParseFailed',
no_data: 'chat.transfer.fileNoData',
expired: 'chat.transfer.fileExpired',
none: 'chat.transfer.fileNone',
};
/** 非就绪来源按状态分组计数(固定顺序),让「抓取中」与「真失败」可区分。 */
const unreadyBreakdownText = computed(() => unreadyStatusOrder
.map((status) => ({
status,
count: [...selected.value].filter(
(code) => props.sources.find((s) => s.source_code === code)?.file_status === status,
).length,
}))
.filter((item) => item.count > 0)
.map((item) => `${t(UNREADY_STATUS_LABEL_KEYS[item.status])} ${item.count}`)
.join(' · '));
function toggle(sourceCode: string, checked: boolean) {
const next = new Set(selected.value);
if (checked) next.add(sourceCode);
else next.delete(sourceCode);
selected.value = next;
}
function togglePlatform(platform: string, checked: boolean) {
const next = new Set(selected.value);
for (const source of props.sources) {
if (source.platform === platform) {
if (checked) next.add(source.source_code);
else next.delete(source.source_code);
}
}
selected.value = next;
}
/** 全选当前可见来源(已启用实例)。 */
function selectVisible() {
selected.value = new Set(props.sources.filter((source) => source.enabled).map((source) => source.source_code));
}
/** 只选可重试来源(除抓取中外全部状态,含 ready 强制重抓),来源多时一键收敛。 */
function selectRetryable() {
selected.value = new Set(retryableSources.value.map((source) => source.source_code));
}
/** 清空选择。 */
function clearSelected() {
selected.value = new Set();
}
/** 批量重试收料 RPA:仅触发所选来源中可重试的那部分。 */
function batchRetry() {
const codes = [...selected.value].filter(
(code) => props.sources.some((s) => s.source_code === code && isRetryable(s)),
);
if (codes.length === 0) {
notifyWarning(t('chat.transfer.noRetryable'), t('chat.transfer.sourceSelectTitle'));
return;
}
emit('retry', codes);
}
function downloadSelected(): void {
const codes = [...selected.value].filter(
(code) => props.sources.find((s) => s.source_code === code)?.has_ready_file,
);
if (codes.length) emit('download', codes);
}
/** 确认范围并匹配:只提交具备 ready 文件的来源。混合选择(含非就绪项)先展示披露条
* (知情部分确认 2026-10-09,替代历史「至少一 ready 则静默剔除整包」),用户确认后
* 才提交 ready-only;全就绪直达。「至少一 ready」门禁保留为兜底告警。 */
function confirm() {
if (selectedCount.value === 0) {
notifyWarning(t('chat.transfer.needSelectSource'), t('chat.transfer.sourceSelectTitle'));
return;
}
const readyCodes = selectedReadyCodes();
if (readyCodes.length === 0) {
notifyWarning(t('chat.transfer.needReadyFile'), t('chat.transfer.sourceSelectTitle'));
return;
}
if (selectedUnreadyCount.value > 0) {
showPartialConfirm.value = true;
return;
}
emit('confirm', readyCodes, { from: dateFrom.value || undefined, to: dateTo.value || undefined }, transferType.value);
}
/** 已选来源中的 ready 来源码(每次 emit 时现算,避免披露期间勾选变化导致口径过期)。 */
function selectedReadyCodes(): string[] {
return [...selected.value].filter(
(code) => props.sources.find((s) => s.source_code === code)?.has_ready_file,
);
}
/** 披露后确认:仅提交就绪来源(其余来源就绪后可重新匹配补入,后端增量圈行不破坏已有行)。 */
function proceedPartialConfirm() {
const readyCodes = selectedReadyCodes();
showPartialConfirm.value = false;
emit('confirm', readyCodes, { from: dateFrom.value || undefined, to: dateTo.value || undefined }, transferType.value);
}
/** 披露后取消:收回披露条,可调整勾选或等待其余来源就绪。 */
function cancelPartialConfirm() {
showPartialConfirm.value = false;
}
// 勾选变化即收回披露:用户在调整范围,旧披露口径已失效。
watch(selected, () => {
showPartialConfirm.value = false;
});
</script>
<template>
<div class="my-2 rounded-2xl border border-brand-100 bg-surface p-4 shadow-sm" data-testid="transfer-source-select-card">
<h3 class="mb-3 text-sm font-bold text-primary">{{ $t('chat.transfer.sourceSelectTitle') }}</h3>
<!-- [ZONE 1] 匹配参数区:调拨类型 + 收料日期同组(确认匹配时一并提交,参数先行定范围)。 -->
<div class="mb-3 rounded-lg border border-subtle p-3" data-testid="transfer-source-params">
<p class="mb-2 text-[11px] font-bold text-muted">{{ $t('chat.transfer.matchParams') }}</p>
<div class="flex flex-wrap items-center gap-2">
<span class="text-xs font-bold text-secondary">{{ $t('chat.transfer.transferTypeLabel') }}</span>
<button
v-for="option in transferTypeOptions"
:key="option.value"
type="button"
class="rounded-full border px-3 py-1 text-xs font-bold disabled:cursor-not-allowed disabled:opacity-40"
:class="transferType === option.value
? 'border-brand-600 bg-brand-600 text-white hover:bg-brand-700'
: 'border-brand-200 text-brand-700 hover:bg-brand-50'"
:disabled="busy || !option.enabled"
:title="option.enabled ? undefined : t('chat.transfer.transferTypeComingSoon')"
:data-testid="`transfer-type-option-${option.value}`"
@click="transferType = option.value"
>
{{ transferTypeLabel(option.value) }}
<span v-if="!option.enabled" class="ml-1 font-normal opacity-70">{{ t('chat.transfer.transferTypeComingSoon') }}</span>
</button>
</div>
<div class="mt-2 flex flex-wrap items-center gap-2">
<span class="text-xs font-bold text-secondary">{{ $t('chat.transfer.receiptDateLabel') }}</span>
<input
v-model="dateFrom"
type="date"
:max="maxReceiptDate"
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
data-testid="transfer-source-date-from"
/>
<span class="text-xs text-muted">~</span>
<input
v-model="dateTo"
type="date"
:max="maxReceiptDate"
:min="dateFrom || undefined"
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
data-testid="transfer-source-date-to"
/>
<!-- D+1 规则属低频说明:收进原生 title 悬浮(渐进披露),避免长文案挤压布局。 -->
<span
class="cursor-help text-xs text-muted"
:title="$t('chat.transfer.receiptDateHint')"
data-testid="transfer-source-date-hint"
>ⓘ</span>
<!-- 输入期校验:起始晚于截止时行内提示并禁用确认(不等提交报错)。 -->
<span v-if="dateRangeInvalid" class="text-xs font-bold text-red-600" data-testid="transfer-source-date-invalid">
{{ $t('chat.transfer.receiptDateInvalid') }}
</span>
</div>
</div>
<!-- [ZONE 2] 选择辅助/上下文操作条:有选中时原位替换辅助区(批量操作惯例),未选中零死按钮。 -->
<div v-if="selectedCount === 0" class="mb-3 flex flex-wrap items-center gap-2" data-testid="transfer-source-aids">
<button
type="button"
class="rounded-lg border border-brand-200 px-3 py-1.5 text-xs font-bold text-brand-700 hover:bg-brand-50 disabled:opacity-50"
:disabled="busy"
data-testid="transfer-source-select-visible"
@click="selectVisible"
>
{{ $t('chat.transfer.selectVisible') }}
</button>
<button
type="button"
class="rounded-lg border border-brand-200 px-3 py-1.5 text-xs font-bold text-brand-700 hover:bg-brand-50 disabled:opacity-50"
:disabled="busy"
data-testid="transfer-source-select-retryable"
@click="selectRetryable"
>
{{ $t('chat.transfer.selectRetryable') }}
</button>
</div>
<div
v-else
class="mb-3 flex flex-wrap items-center gap-2 rounded-lg border border-brand-200 bg-brand-50 px-3 py-2"
data-testid="transfer-source-action-bar"
>
<span class="text-xs font-bold text-secondary">
{{ $t('chat.transfer.selectedSourceCount', { count: selectedCount }) }}
<span v-if="selectedRetryableCount > 0" class="text-amber-600"> · {{ $t('chat.transfer.selectedRetryableCount', { count: selectedRetryableCount }) }}</span>
</span>
<span class="ml-auto flex flex-wrap items-center gap-2">
<button
type="button"
class="rounded-lg border border-brand-200 px-3 py-1.5 text-xs font-bold text-brand-700 hover:bg-brand-50 disabled:opacity-50"
:disabled="batchRetryDisabled"
data-testid="transfer-source-batch-retry"
@click="batchRetry"
>
{{ $t('chat.transfer.batchRetry') }}
</button>
<button
type="button"
class="rounded-lg border border-default px-3 py-1.5 text-xs font-bold text-secondary hover-surface-soft disabled:opacity-50"
:disabled="busy || downloadDisabled"
data-testid="transfer-source-download"
@click="downloadSelected"
>
{{ $t('chat.transfer.downloadFiles') }}
</button>
<button
type="button"
class="rounded-lg border border-default px-3 py-1.5 text-xs font-bold text-secondary hover-surface-soft disabled:opacity-50"
:disabled="busy"
data-testid="transfer-source-clear"
@click="clearSelected"
>
{{ $t('chat.transfer.clearSources') }}
</button>
</span>
</div>
<!-- [ZONE 3] 来源列表:上限随视口伸缩(60vh)而非固定值——来源多时列表尽量占满可用高度再内部滚动,
避免固定小限高把列表压成几行+卡片下方大量留白;来源少时卡片自然收缩不受影响 -->
<div class="max-h-[60vh] space-y-3 overflow-y-auto" data-testid="transfer-source-list">
<div v-for="platform in platforms" :key="platform" class="rounded-lg border border-subtle">
<div class="flex items-center justify-between rounded-t-lg bg-surface-soft px-3 py-1.5">
<b class="text-xs text-secondary">{{ platform.toUpperCase() }}</b>
<label class="text-[11px] text-muted">
<input
type="checkbox"
:checked="props.sources.filter((source) => source.platform === platform).every((source) => selected.has(source.source_code))"
@change="togglePlatform(platform, ($event.target as HTMLInputElement).checked)"
/>
{{ $t('chat.transfer.selectAll') }}
</label>
</div>
<div class="grid grid-cols-1 gap-1 p-2 sm:grid-cols-2">
<div
v-for="source in props.sources.filter((item) => item.platform === platform)"
:key="source.source_code"
class="flex items-center gap-2 rounded-lg px-2 py-1.5 hover-surface-soft"
:data-testid="`transfer-source-option-${source.source_code}`"
>
<input
type="checkbox"
:checked="selected.has(source.source_code)"
:disabled="busy"
@change="toggle(source.source_code, ($event.target as HTMLInputElement).checked)"
/>
<span class="min-w-0 flex-1">
<span class="block truncate text-xs font-semibold text-secondary">{{ source.source_code }}</span>
<span class="block truncate text-[11px] text-muted">{{ source.display_name }}</span>
</span>
<span class="shrink-0">
<span
v-if="source.has_ready_file"
class="inline-flex items-center gap-1 rounded-full bg-emerald-50 px-2 py-0.5 text-[10px] font-bold text-emerald-700"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileReady') }}
</span>
<span
v-else-if="source.file_status === 'fetching'"
class="inline-flex items-center gap-1 rounded-full bg-amber-50 px-2 py-0.5 text-[10px] font-bold text-amber-700"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileFetching') }}
</span>
<span
v-else-if="source.file_status === 'failed'"
class="inline-flex items-center gap-1 rounded-full bg-red-50 px-2 py-0.5 text-[10px] font-bold text-red-700"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileFailed') }}
</span>
<!-- 无收料数据(no_data):抓取成功但当日无收料记录,属业务结果而非故障;当日稍后到货可重抓补数 -->
<span
v-else-if="source.file_status === 'no_data'"
class="inline-flex items-center gap-1 rounded-full bg-sky-50 px-2 py-0.5 text-[10px] font-bold text-sky-700"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileNoData') }}
</span>
<span
v-else-if="source.file_status === 'expired'"
class="inline-flex items-center gap-1 rounded-full bg-orange-50 px-2 py-0.5 text-[10px] font-bold text-orange-700"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileExpired') }}
</span>
<!-- 解析失败(parse_failed):当日收料文件解析失败;重试按状态分层——parse_failed=本地重解析,其余状态=重新触发收料 RPA 重抓 -->
<span
v-else-if="source.file_status === 'parse_failed'"
class="inline-flex items-center gap-1 rounded-full bg-red-50 px-2 py-0.5 text-[10px] font-bold text-red-700"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileParseFailed') }}
</span>
<span
v-else
class="inline-flex items-center gap-1 rounded-full bg-surface-strong px-2 py-0.5 text-[10px] font-bold text-muted"
:data-testid="`transfer-source-status-${source.source_code}`"
>
{{ t('chat.transfer.fileNone') }}
</span>
<button
type="button"
class="ml-1 inline-flex h-6 w-6 items-center justify-center rounded-md border border-default text-sm text-muted hover:border-brand-200 hover:text-brand-700 disabled:cursor-not-allowed disabled:opacity-40"
:disabled="busy || !isRetryable(source) || retrying?.has(source.source_code)"
:title="t('chat.transfer.retryReceipt')"
:data-testid="`transfer-source-retry-${source.source_code}`"
@click.stop="emit('retry', [source.source_code])"
>
<span aria-hidden="true">{{ retrying?.has(source.source_code) ? '…' : '↻' }}</span>
</button>
</span>
</div>
</div>
</div>
</div>
<div class="flex items-center justify-end border-t border-subtle pt-3">
<!-- [知情部分确认] 混合状态点确认后按钮区原位替换为披露条(同槽位切换惯例):
明确本次仅纳入就绪来源、逐状态分组展示未就绪项,用户显式确认后才提交。 -->
<div
v-if="showPartialConfirm"
class="flex w-full flex-col gap-1.5 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2"
data-testid="transfer-source-partial-confirm"
>
<p class="text-xs font-bold text-amber-700" data-testid="transfer-source-partial-summary">
{{ $t('chat.transfer.partialConfirmSummary', { total: selectedCount, ready: selectedReadyCount, unready: selectedUnreadyCount }) }}
<span v-if="unreadyBreakdownText" class="font-normal">{{ $t('chat.transfer.partialConfirmBreakdown', { items: unreadyBreakdownText }) }}</span>
</p>
<p class="text-xs text-amber-700">{{ $t('chat.transfer.partialConfirmHint') }}</p>
<div class="flex items-center justify-end gap-2">
<button
type="button"
class="rounded-lg border border-default px-3 py-1.5 text-xs font-bold text-secondary hover-surface-soft"
data-testid="transfer-source-partial-cancel"
@click="cancelPartialConfirm"
>
{{ $t('chat.transfer.partialConfirmCancel') }}
</button>
<button
type="button"
class="rounded-lg bg-brand-600 px-4 py-1.5 text-xs font-bold text-white hover:bg-brand-700"
data-testid="transfer-source-partial-proceed"
@click="proceedPartialConfirm"
>
{{ $t('chat.transfer.partialConfirmProceed') }}
</button>
</div>
</div>
<button
v-else
type="button"
class="rounded-lg bg-brand-600 px-4 py-1.5 text-sm font-bold text-white hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-40"
:disabled="confirmDisabled"
data-testid="transfer-source-confirm"
@click="confirm"
>
{{ $t('chat.transfer.confirmScopeAndMatch') }}
</button>
</div>
</div>
</template>