- 异动解析跳过无异动日期的在途/执行中行,兼容 datetime 日期单元格 - ERP 网关故障降级为逐票阻断并带原因,不再炸整来源 - 预检明细唯一约束升粒度:(预检,来源,单号,料号,收料日期) - Invoice 恢复单号锚定并移至料号前;批号 lot_no 全链贯通, 拨出/拨入批号按 WTP→HOW 转换展示;新增收料日期列 - 预检表格筛选/全选;单行与批量重查 ERP 库存 - 收料日期范围作为预检查询范围,截止卡控不超出 D+1 规则 - 来源多选打包下载收料文件;调拨消息与子流程容器放宽宽度 - 预检恢复明细补齐收料日期与批号字段(修复卡片三列空值)
289 lines
12 KiB
Vue
289 lines
12 KiB
Vue
<!--
|
||
features/chat/components/messages/TransferSourceSelectCard.vue
|
||
用途:来源实例选择卡(决策 2/3/4:手工两步第一步)——按平台 DBS/Crane 分组勾选实例,
|
||
“确认范围并预检”发起预检。
|
||
依赖:props.sources、i18n chat.transfer.*。
|
||
逻辑:平台仅分组不可直接执行;未选任何实例时确认按钮禁用。
|
||
-->
|
||
<script setup lang="ts">
|
||
import { computed, ref } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { useMessage } from '@/shared/composables/useMessage';
|
||
import type { TransferSourceOption } 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 }];
|
||
/** 批量重试收料 RPA:传来源编码列表 */
|
||
retry: [sourceCodes: string[]];
|
||
download: [sourceCodes: string[]];
|
||
}>();
|
||
|
||
const { warning: notifyWarning } = useMessage();
|
||
const { t } = useI18n();
|
||
|
||
const selected = ref<Set<string>>(new Set());
|
||
/** 收料日期范围(预检查询范围);截止不得超出 D+1 规则(后端卡控)。 */
|
||
const dateFrom = ref('');
|
||
const dateTo = ref('');
|
||
|
||
const platforms = computed(() => [...new Set(props.sources.map((source) => source.platform))]);
|
||
const selectedCount = computed(() => selected.value.size);
|
||
|
||
/** 可重试判定:仅 待抓取(none) / 抓取失败(failed) 的来源可重试(ready/fetching 不重复触发)。 */
|
||
function isRetryable(source: TransferSourceOption): boolean {
|
||
return source.file_status === 'none' || source.file_status === 'failed';
|
||
}
|
||
|
||
/** 全部可重试来源。 */
|
||
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);
|
||
const downloadDisabled = computed(() => props.busy || !selectedHasReadyFile.value);
|
||
|
||
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));
|
||
}
|
||
|
||
/** 只选可重试来源(待抓取/抓取失败),来源多时一键收敛。 */
|
||
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);
|
||
}
|
||
|
||
function confirm() {
|
||
if (selectedCount.value === 0) {
|
||
notifyWarning(t('chat.transfer.needSelectSource'), t('chat.transfer.sourceSelectTitle'));
|
||
return;
|
||
}
|
||
if (!selectedHasReadyFile.value) {
|
||
notifyWarning(t('chat.transfer.needReadyFile'), t('chat.transfer.sourceSelectTitle'));
|
||
return;
|
||
}
|
||
emit('confirm', [...selected.value], { from: dateFrom.value || undefined, to: dateTo.value || undefined });
|
||
}
|
||
</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-1 text-sm font-bold text-primary">{{ $t('chat.transfer.sourceSelectTitle') }}</h3>
|
||
<p class="mb-3 text-xs text-muted">{{ $t('chat.transfer.sourceSelectHint') }}</p>
|
||
|
||
<div class="mb-3 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="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>
|
||
<button
|
||
type="button"
|
||
class="rounded-lg bg-brand-600 px-3 py-1.5 text-xs font-bold text-white hover:bg-brand-700 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>
|
||
<div class="ml-auto flex flex-wrap items-center gap-2">
|
||
<label class="flex items-center gap-1 text-xs text-secondary">
|
||
<span>{{ $t('chat.transfer.receiptDateFrom') }}</span>
|
||
<input
|
||
v-model="dateFrom"
|
||
type="date"
|
||
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
|
||
data-testid="transfer-source-date-from"
|
||
/>
|
||
</label>
|
||
<label class="flex items-center gap-1 text-xs text-secondary">
|
||
<span>~</span>
|
||
<input
|
||
v-model="dateTo"
|
||
type="date"
|
||
class="rounded-lg border border-default bg-surface px-2 py-1 text-xs text-primary"
|
||
data-testid="transfer-source-date-to"
|
||
/>
|
||
</label>
|
||
<span class="text-xs text-muted">{{ $t('chat.transfer.receiptDateHint') }}</span>
|
||
</div>
|
||
<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 class="ml-auto text-xs text-muted">
|
||
{{ $t('chat.transfer.selectedSourceCount', { count: selectedCount }) }}
|
||
<span v-if="selectedRetryableCount > 0" class="text-amber-600"> · {{ $t('chat.transfer.selectedRetryableCount', { count: selectedRetryableCount }) }}</span>
|
||
</span>
|
||
</div>
|
||
|
||
<div v-for="platform in platforms" :key="platform" class="mb-3 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>
|
||
<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 class="flex items-center justify-end gap-3 border-t border-subtle pt-3">
|
||
<span class="text-xs text-muted">{{ $t('chat.transfer.selectedCount', { count: selectedCount }) }}</span>
|
||
<button
|
||
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.confirmScopeAndPrecheck') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</template>
|