feat(shipping-notice): 新增发货批次和任务管理功能,支持批次创建与任务处理
This commit is contained in:
1 parent
457f0f4e5e
commit
634dee4b81
81 files changed
+9088
-3625
No files matched your search
@@ -1,21 +1,44 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/workspace/views/ShippingNoticeView.vue
|
||||
* 货代发货任务只读工作台:列表筛选、详情、跳转 Chat 继续处理。
|
||||
* 用途:货代发货任务只读工作台,提供任务筛选、详情查看与跳转 Chat 继续处理入口。
|
||||
* 依赖:ShippingWorkflowStepper、ShippingParseReviewMessage、ShippingMatchResultCard、shipping.api。
|
||||
* 逻辑:先拉取任务列表与详情,再复用 Chat 区的发货组件展示步骤、匹配结果和 parse review。
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ArrowLeft, Download, ExternalLink, RefreshCw } from 'lucide-vue-next';
|
||||
import ShippingWorkflowStepper from '@/features/chat/components/ShippingWorkflowStepper.vue';
|
||||
import ShippingParseReviewMessage, {
|
||||
type ShippingParseReviewHandlers,
|
||||
} from '@/features/chat/components/messages/ShippingParseReviewMessage.vue';
|
||||
import ShippingMatchResultCard from '@/features/chat/components/messages/ShippingMatchResultCard.vue';
|
||||
import {
|
||||
addWorkspaceShippingNoticeLine,
|
||||
autoProgressWorkspaceShippingTask,
|
||||
generateWorkspaceShippingExcel,
|
||||
getShippingChatActions,
|
||||
getWorkspaceShippingTask,
|
||||
listWorkspaceShippingTasks,
|
||||
markWorkspaceShippingManualUploaded,
|
||||
matchWorkspaceShippingInventory,
|
||||
removeWorkspaceShippingNoticeLine,
|
||||
SHIPPING_NOTICE_AGENT_NAME,
|
||||
submitWorkspaceShippingDecision,
|
||||
updateWorkspaceShippingNoticeFields,
|
||||
updateWorkspaceShippingNoticeLine,
|
||||
workspaceShippingExportUrl,
|
||||
type ShippingChatAction,
|
||||
type ShippingNoticeHeader,
|
||||
type ShippingNoticeLine,
|
||||
type ShippingTaskDetail,
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import type { ChatMessage } from '@/features/chat/types/chat.types';
|
||||
import type { ShippingParseReviewPayload } from '@/features/chat/types/shipping.types';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { buildShippingWorkflowSteps, shippingActionButtonClass } from '@/features/chat/shipping';
|
||||
|
||||
const props = defineProps<{
|
||||
embedded?: boolean;
|
||||
@@ -29,8 +52,18 @@ const detailLoading = ref(false);
|
||||
const tasks = ref<ShippingTaskSummary[]>([]);
|
||||
const selectedTaskNo = ref<string | null>(null);
|
||||
const detail = ref<ShippingTaskDetail | null>(null);
|
||||
const detailSaving = ref(false);
|
||||
const detailActionBusy = ref(false);
|
||||
const detailActionButtons = ref<ShippingChatAction[]>([]);
|
||||
const statusFilter = ref('all');
|
||||
const chatAgentId = ref<number | null>(null);
|
||||
const batchProgressLabel = computed(() => {
|
||||
if (!detail.value?.batch_index || !detail.value?.batch_total) return '';
|
||||
return t('chat.shippingNoticeUi.batchProgress', {
|
||||
index: detail.value.batch_index,
|
||||
total: detail.value.batch_total,
|
||||
});
|
||||
});
|
||||
|
||||
const statusOptions = computed(() => [
|
||||
{ value: 'all', label: t('workspace.shippingNotice.status.all') },
|
||||
@@ -56,6 +89,8 @@ const statusBadge = (status: string) => {
|
||||
return map[status] || { cls: 'bg-slate-100 text-secondary', label: status };
|
||||
};
|
||||
|
||||
const detailWorkflowSteps = computed(() => buildShippingWorkflowSteps(detail.value));
|
||||
|
||||
const loadCases = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
@@ -73,9 +108,15 @@ const loadCases = async () => {
|
||||
const loadDetail = async (taskNo: string) => {
|
||||
detailLoading.value = true;
|
||||
try {
|
||||
detail.value = await getWorkspaceShippingTask(taskNo);
|
||||
const [taskDetail, chatActions] = await Promise.all([
|
||||
getWorkspaceShippingTask(taskNo),
|
||||
getShippingChatActions(taskNo).catch(() => null),
|
||||
]);
|
||||
detail.value = taskDetail;
|
||||
detailActionButtons.value = chatActions?.action_buttons || [];
|
||||
} catch {
|
||||
detail.value = null;
|
||||
detailActionButtons.value = [];
|
||||
} finally {
|
||||
detailLoading.value = false;
|
||||
}
|
||||
@@ -93,9 +134,11 @@ const resolveChatAgent = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const openInChat = (taskNo: string, conversationId?: string | null) => {
|
||||
const openInChat = (taskNo: string, conversationId?: string | null, batchNo?: string | null) => {
|
||||
if (!chatAgentId.value) return;
|
||||
const query: Record<string, string> = { task_id: taskNo };
|
||||
const normalizedBatchNo = String(batchNo || '').trim();
|
||||
if (normalizedBatchNo) query.batch_no = normalizedBatchNo;
|
||||
const cid = String(conversationId || '').trim();
|
||||
if (/^[0-9a-f]{32}$/i.test(cid)) query.conversation_id = cid;
|
||||
router.push({ path: `/chat/${chatAgentId.value}`, query });
|
||||
@@ -113,6 +156,133 @@ const downloadExport = async (taskNo: string) => {
|
||||
URL.revokeObjectURL(a.href);
|
||||
};
|
||||
|
||||
const parseReviewPayload = computed<ShippingParseReviewPayload | null>(() => {
|
||||
if (!detail.value || detail.value.review_status !== 'pending_confirm') return null;
|
||||
return {
|
||||
taskId: detail.value.task_no,
|
||||
checkpoint: 'parse_review',
|
||||
header: {
|
||||
customer_name: detail.value.customer_name ?? null,
|
||||
customer_code: detail.value.customer_code ?? null,
|
||||
ship_to: detail.value.ship_to ?? null,
|
||||
po_number: detail.value.po_number ?? null,
|
||||
required_date: detail.value.required_date ?? null,
|
||||
},
|
||||
lines: Array.isArray(detail.value.lines) ? detail.value.lines : [],
|
||||
saving: detailSaving.value,
|
||||
};
|
||||
});
|
||||
|
||||
const parseReviewMessage = computed<ChatMessage>(() => ({
|
||||
role: 'assistant',
|
||||
type: 'shipping-parse-review',
|
||||
content: `${t('chat.shippingNoticeUi.parseReviewIntro')}\n${t('chat.shippingNoticeUi.taskId', { taskId: detail.value?.task_no || '' })}`.trim(),
|
||||
payload: parseReviewPayload.value || undefined,
|
||||
}));
|
||||
|
||||
const parseReviewHandlers: ShippingParseReviewHandlers = {
|
||||
getPayload: () => parseReviewPayload.value,
|
||||
updateHeader: async (_msg, fields: Partial<ShippingNoticeHeader>) => {
|
||||
if (!detail.value || detailSaving.value) return false;
|
||||
detailSaving.value = true;
|
||||
try {
|
||||
await updateWorkspaceShippingNoticeFields(detail.value.task_no, fields, '工作台订单表修订');
|
||||
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
detailSaving.value = false;
|
||||
}
|
||||
},
|
||||
updateLine: async (_msg, lineIndex: number, patch: Partial<ShippingNoticeLine>) => {
|
||||
if (!detail.value || detailSaving.value) return false;
|
||||
detailSaving.value = true;
|
||||
try {
|
||||
await updateWorkspaceShippingNoticeLine(detail.value.task_no, lineIndex, patch, '工作台订单表修订');
|
||||
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
detailSaving.value = false;
|
||||
}
|
||||
},
|
||||
addLine: async (_msg, line: Partial<ShippingNoticeLine>) => {
|
||||
if (!detail.value || detailSaving.value) return false;
|
||||
detailSaving.value = true;
|
||||
try {
|
||||
await addWorkspaceShippingNoticeLine(detail.value.task_no, line, '工作台订单表新增行');
|
||||
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
detailSaving.value = false;
|
||||
}
|
||||
},
|
||||
removeLine: async (_msg, lineIndex: number) => {
|
||||
if (!detail.value || detailSaving.value) return false;
|
||||
detailSaving.value = true;
|
||||
try {
|
||||
await removeWorkspaceShippingNoticeLine(detail.value.task_no, lineIndex, '工作台订单表删除行');
|
||||
await Promise.all([loadDetail(detail.value.task_no), loadCases()]);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
detailSaving.value = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const shortageLines = computed(() => detail.value?.shortage?.lines || []);
|
||||
const hasMatchCard = computed(() =>
|
||||
!!detail.value && (
|
||||
(Array.isArray(detail.value.line_results) && detail.value.line_results.length > 0)
|
||||
|| shortageLines.value.length > 0
|
||||
),
|
||||
);
|
||||
|
||||
const handleWorkspaceAction = async (action: ShippingChatAction) => {
|
||||
if (!detail.value || detailActionBusy.value) return;
|
||||
const taskNo = detail.value.task_no;
|
||||
detailActionBusy.value = true;
|
||||
try {
|
||||
if (action.id === 'download_excel') {
|
||||
await downloadExport(taskNo);
|
||||
return;
|
||||
}
|
||||
if (action.id === 'generate_excel') {
|
||||
await generateWorkspaceShippingExcel(taskNo);
|
||||
} else if (action.id === 'match_inventory') {
|
||||
await matchWorkspaceShippingInventory(taskNo);
|
||||
} else if (action.id === 'mark_manual_uploaded') {
|
||||
await markWorkspaceShippingManualUploaded(taskNo);
|
||||
} else if (action.id === 'refresh') {
|
||||
await loadDetail(taskNo);
|
||||
return;
|
||||
} else if (action.id === 'confirm_inventory_mapping') {
|
||||
await autoProgressWorkspaceShippingTask(taskNo);
|
||||
} else if ([
|
||||
'confirm',
|
||||
'reject',
|
||||
'reparse',
|
||||
'correct_inventory_mapping',
|
||||
'reparse_inventory',
|
||||
'rematch',
|
||||
].includes(action.id)) {
|
||||
await submitWorkspaceShippingDecision(taskNo, action.id);
|
||||
} else {
|
||||
openInChat(taskNo, detail.value.conversation_id, detail.value.batch_no);
|
||||
return;
|
||||
}
|
||||
await Promise.all([loadDetail(taskNo), loadCases()]);
|
||||
} finally {
|
||||
detailActionBusy.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
watch(selectedTaskNo, (val) => {
|
||||
if (val) loadDetail(val);
|
||||
else detail.value = null;
|
||||
@@ -189,7 +359,12 @@ onMounted(async () => {
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-1 truncate text-sm text-secondary">{{ item.customer_name || '—' }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ item.created_at || '' }}</div>
|
||||
<div class="mt-1 flex flex-wrap items-center gap-2 text-xs text-muted">
|
||||
<span>{{ item.created_at || '' }}</span>
|
||||
<span v-if="item.batch_index && item.batch_total" class="rounded-full bg-sky-50 px-2 py-0.5 font-medium text-sky-700">
|
||||
{{ t('chat.shippingNoticeUi.batchProgress', { index: item.batch_index, total: item.batch_total }) }}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -207,14 +382,19 @@ onMounted(async () => {
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="font-mono text-lg font-bold text-primary">{{ detail.task_no }}</div>
|
||||
<div class="text-sm text-muted">{{ detail.customer_name }} · {{ detail.customer_code || '—' }}</div>
|
||||
<div class="flex flex-wrap items-center gap-2 text-sm text-muted">
|
||||
<span>{{ detail.customer_name }} · {{ detail.customer_code || '—' }}</span>
|
||||
<span v-if="batchProgressLabel" class="rounded-full bg-sky-50 px-2 py-0.5 text-xs font-medium text-sky-700">
|
||||
{{ batchProgressLabel }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button
|
||||
v-if="chatAgentId"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-brand-300 bg-brand-50 px-3 py-1.5 text-sm font-medium text-brand-700 hover:bg-brand-100"
|
||||
@click="openInChat(detail.task_no, detail.conversation_id)"
|
||||
@click="openInChat(detail.task_no, detail.conversation_id, detail.batch_no)"
|
||||
>
|
||||
<ExternalLink class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.openChat') }}
|
||||
@@ -231,6 +411,8 @@ onMounted(async () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ShippingWorkflowStepper :steps="detailWorkflowSteps" />
|
||||
|
||||
<dl class="grid gap-3 sm:grid-cols-2 text-sm">
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.status') }}</dt><dd>{{ detail.process_status }}</dd></div>
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.match') }}</dt><dd>{{ detail.match_status || '—' }}</dd></div>
|
||||
@@ -242,7 +424,26 @@ onMounted(async () => {
|
||||
{{ detail.error_message }}
|
||||
</div>
|
||||
|
||||
<div v-if="detail.lines?.length">
|
||||
<ShippingMatchResultCard
|
||||
v-if="hasMatchCard"
|
||||
:task-id="detail.task_no"
|
||||
:match-status="detail.match_status"
|
||||
:line-results="detail.line_results"
|
||||
:shortage-lines="shortageLines"
|
||||
:action-buttons="detailActionButtons"
|
||||
:action-busy="detailActionBusy"
|
||||
:action-button-class="shippingActionButtonClass"
|
||||
:on-action-click="handleWorkspaceAction"
|
||||
/>
|
||||
|
||||
<div v-if="parseReviewPayload">
|
||||
<ShippingParseReviewMessage
|
||||
:message="parseReviewMessage"
|
||||
:handlers="parseReviewHandlers"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else-if="detail.lines?.length">
|
||||
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.lines') }}</h3>
|
||||
<div class="overflow-x-auto rounded-xl border border-default">
|
||||
<table class="min-w-full text-sm">
|
||||
@@ -254,8 +455,8 @@ onMounted(async () => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(line, idx) in detail.lines" :key="idx" class="border-t border-default/60">
|
||||
<td class="px-3 py-2 font-mono">{{ line.sku || line.part_no || '—' }}</td>
|
||||
<td class="px-3 py-2">{{ line.qty ?? line.quantity ?? '—' }}</td>
|
||||
<td class="px-3 py-2 font-mono">{{ line.sku || '—' }}</td>
|
||||
<td class="px-3 py-2">{{ line.qty ?? '—' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in new issue
Block a user