feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理
清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
This commit is contained in:
1 parent
7cfd5d167e
commit
1e5aedb9ed
235 files changed
+11394
-9613
No files matched your search
@@ -11,12 +11,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { ExternalLink, RefreshCw } from 'lucide-vue-next';
|
||||
import { CheckSquare, Download, ExternalLink, RefreshCw, Upload } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
getWorkspaceShippingTask,
|
||||
listShippingChatAgents,
|
||||
retryWorkspaceShippingOrderStpAutoCreate,
|
||||
batchConfirmWorkspaceShippingNoticesUploaded,
|
||||
batchStartWorkspaceShippingNoticeRpaUpload,
|
||||
SHIPPING_NOTICE_AGENT_CODE,
|
||||
type ShippingTaskDetail,
|
||||
type ShippingTaskSummary,
|
||||
@@ -38,6 +40,7 @@ import {
|
||||
isShippingTodoListItemInProgress,
|
||||
} from './shippingTaskCenterPolling';
|
||||
import ShippingRunProgressTable from './ShippingRunProgressTable.vue';
|
||||
import { downloadWorkspaceShippingNoticeExportArchive } from '@/features/chat/shipping/shippingDownload';
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const msg = useMessage();
|
||||
@@ -98,6 +101,9 @@ const appliedFilters = ref({
|
||||
const loading = ref(false);
|
||||
const detailLoading = ref(false);
|
||||
const tasks = ref<ShippingTaskSummary[]>([]);
|
||||
/** 货代批量选择只容纳有 business_no 的正式发货通知,Review/Intake 永不进入集合。 */
|
||||
const selectedBusinessNos = ref<string[]>([]);
|
||||
const batchActionBusy = ref<'download' | 'confirm' | 'rpa' | null>(null);
|
||||
const selectedRef = ref<string | null>(null);
|
||||
/** 仅直链摘要,供入口卡展示;禁止内嵌履约工作台。 */
|
||||
const detail = ref<ShippingTaskDetail | null>(null);
|
||||
@@ -176,7 +182,13 @@ function lifecycleEntriesOf(item: ShippingTaskSummary | ShippingTaskDetail) {
|
||||
/** 当前阶段只取后端标为 current 的入口,不能以技术 stage 或阶段顺序回填。 */
|
||||
function lifecycleStageCodeOf(item: ShippingTaskSummary | ShippingTaskDetail): LifecycleStageCode | null {
|
||||
const current = lifecycleEntriesOf(item).find((entry) => entry.state === 'current');
|
||||
return current ? current.code as LifecycleStageCode : null;
|
||||
if (current) return current.code as LifecycleStageCode;
|
||||
// [AUTHORITY] 待人工处理的 Review Case 可能没有可进入工作台的 lifecycle entry,
|
||||
// 但后端仍会下发 ui_state.stage 作为当前业务阶段;统计与筛选必须保留该阶段。
|
||||
const stage = String(item.ui_state?.stage?.code || '').trim();
|
||||
return LIFECYCLE_STAGES.includes(stage as LifecycleStageCode)
|
||||
? stage as LifecycleStageCode
|
||||
: null;
|
||||
}
|
||||
|
||||
/** 可进入工作台的业务阶段仅由后端 entry.state 授权。 */
|
||||
@@ -192,6 +204,35 @@ function lifecycleEntryIsEnterable(entry: ReturnType<typeof lifecycleEntryFor>):
|
||||
return entry?.state === 'current' || entry?.state === 'available';
|
||||
}
|
||||
|
||||
/** 接收解析入口只消费后端独立授权,不从阶段名称推导可写权限。 */
|
||||
function canOpenIntakeParse(item: ShippingTaskSummary | ShippingTaskDetail | null): boolean {
|
||||
if (!item) return false;
|
||||
const runNo = String(item.review_run_no || '').trim();
|
||||
const agentId = Number(item.owner_agent_id || chatAgentId.value || 0);
|
||||
return Boolean(
|
||||
runNo
|
||||
&& agentId
|
||||
&& item.ui_state?.intake_parse_authorized === true,
|
||||
);
|
||||
}
|
||||
|
||||
/** 打开对话中的接收解析工作面,复用批次进度中心的同一深链契约。 */
|
||||
function openIntakeParse(item: ShippingTaskSummary | ShippingTaskDetail) {
|
||||
if (!canOpenIntakeParse(item)) return;
|
||||
const runNo = String(item.review_run_no || '').trim();
|
||||
const agentId = Number(item.owner_agent_id || chatAgentId.value || 0);
|
||||
const query: Record<string, string> = {
|
||||
mode: 'order-review',
|
||||
run_no: runNo,
|
||||
lifecycle_stage: 'intake_parse',
|
||||
};
|
||||
const cid = String(item.conversation_id || '').trim();
|
||||
if (cid) query.conversation_id = cid;
|
||||
const caseNo = String(item.review_case_no || '').trim();
|
||||
if (caseNo) query.case_no = caseNo;
|
||||
void router.push({ path: `/chat/${agentId}`, query });
|
||||
}
|
||||
|
||||
function defaultLifecycleTarget(item: ShippingTaskSummary | ShippingTaskDetail): Exclude<LifecycleStageCode, 'intake_parse'> | null {
|
||||
const current = lifecycleEntriesOf(item).find(
|
||||
(entry) => entry.code !== 'intake_parse' && entry.state === 'current',
|
||||
@@ -215,6 +256,12 @@ const filteredTasks = computed(() => (
|
||||
? tasks.value
|
||||
: tasks.value.filter((item) => lifecycleStageCodeOf(item) === lifecycleStageFilter.value)
|
||||
));
|
||||
const noticeRows = computed(() => filteredTasks.value.filter((item) => Boolean(String(item.business_no || '').trim())));
|
||||
const selectedBusinessNoSet = computed(() => new Set(selectedBusinessNos.value));
|
||||
const selectedNoticeCount = computed(() => selectedBusinessNos.value.length);
|
||||
const allVisibleNoticesSelected = computed(() => (
|
||||
noticeRows.value.length > 0 && noticeRows.value.every((item) => selectedBusinessNoSet.value.has(String(item.business_no)))
|
||||
));
|
||||
const lifecycleStageTargetOptions = computed(() => {
|
||||
if (!entryItem.value) return [];
|
||||
return lifecycleEntriesOf(entryItem.value)
|
||||
@@ -248,7 +295,53 @@ function todoDisplayNo(item: ShippingTaskSummary): string {
|
||||
if (item.item_kind === 'order_intake' || item.intake_no) {
|
||||
return String(item.intake_no || item.todo_ref || '—');
|
||||
}
|
||||
return String(item.task_no || item.todo_ref || '—');
|
||||
return String(item.business_no || item.task_no || item.todo_ref || '—');
|
||||
}
|
||||
|
||||
/** 切换一张正式发货通知的批量选择,始终按 business_no 去重。 */
|
||||
function toggleNoticeSelection(item: ShippingTaskSummary): void {
|
||||
const businessNo = String(item.business_no || '').trim();
|
||||
if (!businessNo) return;
|
||||
selectedBusinessNos.value = selectedBusinessNoSet.value.has(businessNo)
|
||||
? selectedBusinessNos.value.filter((value) => value !== businessNo)
|
||||
: [...selectedBusinessNos.value, businessNo];
|
||||
}
|
||||
|
||||
/** 对当前筛选页的正式通知全选/取消;Review 与 Intake 保持不可选。 */
|
||||
function toggleAllVisibleNotices(): void {
|
||||
const visible = noticeRows.value.map((item) => String(item.business_no || '').trim()).filter(Boolean);
|
||||
selectedBusinessNos.value = allVisibleNoticesSelected.value
|
||||
? selectedBusinessNos.value.filter((value) => !visible.includes(value))
|
||||
: Array.from(new Set([...selectedBusinessNos.value, ...visible]));
|
||||
}
|
||||
|
||||
/** 批量请求后只提示汇总,逐单状态由服务端结果决定,避免前端自行推断。 */
|
||||
function summarizeBatchResults(results: Array<Record<string, unknown>>, action: string): void {
|
||||
const accepted = results.filter((item) => ['accepted', 'confirmed'].includes(String(item.status || ''))).length;
|
||||
const blocked = results.length - accepted;
|
||||
if (blocked) msg.warning(t('workspace.shippingNotice.batch.partialResult', { action, accepted, blocked }));
|
||||
else msg.success(t('workspace.shippingNotice.batch.success', { action, count: accepted }));
|
||||
}
|
||||
|
||||
async function runNoticeBatchAction(action: 'download' | 'confirm' | 'rpa'): Promise<void> {
|
||||
if (!selectedBusinessNos.value.length || batchActionBusy.value) return;
|
||||
batchActionBusy.value = action;
|
||||
try {
|
||||
if (action === 'download') {
|
||||
await downloadWorkspaceShippingNoticeExportArchive(selectedBusinessNos.value);
|
||||
msg.success(t('workspace.shippingNotice.batch.downloadStarted'));
|
||||
return;
|
||||
}
|
||||
const result = action === 'confirm'
|
||||
? await batchConfirmWorkspaceShippingNoticesUploaded(selectedBusinessNos.value)
|
||||
: await batchStartWorkspaceShippingNoticeRpaUpload(selectedBusinessNos.value);
|
||||
summarizeBatchResults(result.results || [], t(`workspace.shippingNotice.batch.${action}`));
|
||||
await refreshAll();
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('workspace.shippingNotice.actions.failed'));
|
||||
} finally {
|
||||
batchActionBusy.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,6 +465,8 @@ async function loadTodos(resetPage = false) {
|
||||
task_no: appliedFilters.value.task_no || undefined,
|
||||
});
|
||||
tasks.value = result.items || [];
|
||||
const visibleBusinessNos = new Set(tasks.value.map((item) => String(item.business_no || '').trim()).filter(Boolean));
|
||||
selectedBusinessNos.value = selectedBusinessNos.value.filter((value) => visibleBusinessNos.has(value));
|
||||
totalTasks.value = Number(result.total || 0);
|
||||
if (preferredTaskNo.value && !selectedRef.value) {
|
||||
const hit = tasks.value.find(
|
||||
@@ -670,6 +765,17 @@ onBeforeUnmount(() => {
|
||||
</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button
|
||||
v-if="canOpenIntakeParse(detail)"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1.5 rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
|
||||
data-testid="my-todos-open-intake-parse"
|
||||
@click="openIntakeParse(detail)"
|
||||
>
|
||||
<ExternalLink class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.myTodos.openIntakeParse') }}
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1.5 rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
|
||||
:disabled="!canOpenOrderProcessing(detail)"
|
||||
@@ -690,7 +796,7 @@ onBeforeUnmount(() => {
|
||||
</button>
|
||||
</div>
|
||||
<p
|
||||
v-if="!canOpenOrderProcessing(detail)"
|
||||
v-if="!canOpenOrderProcessing(detail) && !canOpenIntakeParse(detail)"
|
||||
class="text-xs text-amber-700 dark:text-amber-300"
|
||||
data-testid="my-todos-open-processing-unavailable"
|
||||
>
|
||||
@@ -717,7 +823,7 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="grid gap-2 sm:grid-cols-2 xl:grid-cols-4"
|
||||
class="grid gap-2 sm:grid-cols-2 xl:grid-cols-5"
|
||||
data-testid="my-todos-lifecycle-stage-filter"
|
||||
>
|
||||
<button
|
||||
@@ -792,6 +898,51 @@ onBeforeUnmount(() => {
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-[minmax(18rem,0.85fr)_minmax(0,2.15fr)]">
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-if="noticeRows.length"
|
||||
class="flex flex-wrap items-center gap-2 rounded-2xl border border-default bg-surface px-3 py-2"
|
||||
data-testid="shipping-notice-batch-toolbar"
|
||||
>
|
||||
<label class="inline-flex items-center gap-2 text-xs text-secondary">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="allVisibleNoticesSelected"
|
||||
:aria-label="$t('workspace.shippingNotice.batch.selectAll')"
|
||||
@change="toggleAllVisibleNotices"
|
||||
>
|
||||
{{ $t('workspace.shippingNotice.batch.selectAll') }}
|
||||
</label>
|
||||
<span class="text-xs text-muted">
|
||||
{{ $t('workspace.shippingNotice.batch.selected', { count: selectedNoticeCount }) }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default px-2 py-1 text-xs disabled:opacity-50"
|
||||
:disabled="!selectedNoticeCount || Boolean(batchActionBusy)"
|
||||
@click="runNoticeBatchAction('download')"
|
||||
>
|
||||
<Download class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.batch.download') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default px-2 py-1 text-xs disabled:opacity-50"
|
||||
:disabled="!selectedNoticeCount || Boolean(batchActionBusy)"
|
||||
@click="runNoticeBatchAction('confirm')"
|
||||
>
|
||||
<CheckSquare class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.batch.confirm') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default px-2 py-1 text-xs disabled:opacity-50"
|
||||
:disabled="!selectedNoticeCount || Boolean(batchActionBusy)"
|
||||
@click="runNoticeBatchAction('rpa')"
|
||||
>
|
||||
<Upload class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.batch.rpa') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="loading" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
|
||||
{{ $t('workspace.shippingNotice.loading') }}
|
||||
</div>
|
||||
@@ -807,7 +958,17 @@ onBeforeUnmount(() => {
|
||||
@click="selectTodo(item)"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="font-mono text-sm font-semibold text-primary">{{ todoDisplayNo(item) }}</span>
|
||||
<span class="inline-flex min-w-0 items-center gap-2">
|
||||
<input
|
||||
v-if="item.business_no"
|
||||
type="checkbox"
|
||||
:checked="selectedBusinessNoSet.has(String(item.business_no))"
|
||||
:aria-label="String(item.business_no)"
|
||||
@click.stop
|
||||
@change="toggleNoticeSelection(item)"
|
||||
>
|
||||
<span class="font-mono text-sm font-semibold text-primary">{{ todoDisplayNo(item) }}</span>
|
||||
</span>
|
||||
<span
|
||||
v-if="item.todo_category === 'review' || item.item_kind === 'review_case'"
|
||||
class="rounded-full bg-amber-50 px-2 py-0.5 text-[10px] text-amber-700"
|
||||
@@ -833,6 +994,20 @@ onBeforeUnmount(() => {
|
||||
<div class="mt-1 truncate text-xs text-muted">
|
||||
{{ item.customer_name || item.source_file_name || item.review_run_no || '—' }}
|
||||
</div>
|
||||
<template v-if="item.business_no">
|
||||
<div class="mt-2 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-muted">
|
||||
<span>PO: {{ item.po_number || '—' }}</span>
|
||||
<span>{{ $t('workspace.shippingNotice.batch.lines') }}: {{ item.notice_line_summary?.length || 0 }}</span>
|
||||
<span>{{ $t('workspace.shippingNotice.batch.parts') }}: {{ item.notice_line_summary?.map((line) => line.part_number).filter(Boolean).join(' / ') || '—' }}</span>
|
||||
</div>
|
||||
<div class="mt-1 text-[11px] text-muted">
|
||||
{{ $t('workspace.shippingNotice.batch.quantities') }}:
|
||||
{{ item.notice_line_summary?.map((line) => `${line.shipment_qty || '—'} / ${line.available_qty || '—'}`).join(' · ') || '—' }}
|
||||
</div>
|
||||
<div class="mt-1 text-[11px] text-muted">
|
||||
Excel: {{ item.artifact_summary?.export_file_name || '—' }} · {{ $t('workspace.shippingNotice.batch.uploadStatus') }}: {{ item.upload_status || '—' }}
|
||||
</div>
|
||||
</template>
|
||||
</button>
|
||||
<div v-if="totalPages > 1" class="flex items-center justify-between gap-2 pt-2 text-xs text-muted">
|
||||
<button
|
||||
@@ -888,6 +1063,17 @@ onBeforeUnmount(() => {
|
||||
</option>
|
||||
</select>
|
||||
<button
|
||||
v-if="canOpenIntakeParse(selectedItem)"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1.5 rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
|
||||
data-testid="my-todos-open-intake-parse"
|
||||
@click="openIntakeParse(selectedItem)"
|
||||
>
|
||||
<ExternalLink class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.myTodos.openIntakeParse') }}
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1.5 rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
|
||||
:disabled="!canOpenOrderProcessing(selectedItem, lifecycleStageTarget)"
|
||||
@@ -987,6 +1173,17 @@ onBeforeUnmount(() => {
|
||||
</option>
|
||||
</select>
|
||||
<button
|
||||
v-if="canOpenIntakeParse(entryItem)"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1.5 rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
|
||||
data-testid="my-todos-open-intake-parse"
|
||||
@click="openIntakeParse(entryItem)"
|
||||
>
|
||||
<ExternalLink class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.myTodos.openIntakeParse') }}
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1.5 rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
|
||||
:disabled="!canOpenOrderProcessing(entryItem, lifecycleStageTarget)"
|
||||
@@ -1007,7 +1204,7 @@ onBeforeUnmount(() => {
|
||||
</button>
|
||||
</div>
|
||||
<p
|
||||
v-if="!canOpenOrderProcessing(entryItem)"
|
||||
v-if="!canOpenOrderProcessing(entryItem) && !canOpenIntakeParse(entryItem)"
|
||||
class="text-xs text-amber-700 dark:text-amber-300"
|
||||
data-testid="my-todos-open-processing-unavailable"
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user