Files
syops/frontend/src/features/workspace/shipping-task-center/ShippingTaskCenterPage.vue
T
hugo 935bf26fa6 feat(shipping-notice): 升级货代发货流程为五阶段,完善业务校验
将货代发货流程从四阶段扩展为五阶段,拆分上传相关逻辑至独立的货代上传阶段;
统一多语言文案修正客户状态语义,将"客户尚未识别"调整为符合业务的"客户尚未确认";
新增严格的上传成功验证谓词,需同时满足任务状态、全部预约单上传成功、存在有效成功上传尝试三个条件方可标记为完成;
新增坐标取值模型配置,支持Legacy冻结绝对坐标和锚点框架受限平移两种模式;
更新全链路相关文档、前端组件、后端服务与测试用例,确保业务逻辑对齐新业务规则。
2026-08-21 09:20:47 +08:00

1030 lines
41 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/workspace/shipping-task-center/ShippingTaskCenterPage.vue
* 用途:发货「任务中心」壳——Pending|Processing|Done + 识别 Run 续办表;列表入口 + STP 重试。
* 依赖:shipping-tasks.api(my-todos)、shipping.api(详情/STP retry)、ShippingRunProgressTable、
* useShippingTodoBadge、useMessage、shippingProcessingLabels。
* 逻辑:选中项展示入口卡 + 五阶段筛选 + 统一进度紧凑摘要;主按钮深链「订单生命周期工作台」;
* review_case 在 failed/manual_fallback 时提供「重试自动推进」(与底栏同一 API/幂等键);
* 不内嵌 ShippingTaskWorkbench;生命周期筛选、禁用与深链只消费后端
* ui_state.lifecycle_entries,Intake parse_status 仅用于解析任务轮询。
*/
<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 { useI18n } from 'vue-i18n';
import {
getWorkspaceShippingTask,
listShippingChatAgents,
retryWorkspaceShippingOrderStpAutoCreate,
SHIPPING_NOTICE_AGENT_CODE,
type ShippingTaskDetail,
type ShippingTaskSummary,
} from '@/features/chat/api/shipping.api';
import {
countWorkspaceShippingMyTodos,
listWorkspaceShippingMyTodos,
type ShippingMyTodosCount,
} from '@/features/workspace/api/shipping-tasks.api';
import { useShippingTodoBadge } from '../composables/useShippingTodoBadge';
import { useMessage } from '@/shared/composables/useMessage';
import { BusinessError } from '@/shared/api/client';
import {
IN_PROGRESS_PROCESSING_STATUSES,
TERMINAL_PROCESSING_STATUSES,
} from '@/features/chat/shipping/shippingProcessingFulfillment';
import { resolveGateReasonLabel } from '@/features/shipping-progress/gateReasonLabel';
import {
isShippingTodoListItemInProgress,
} from './shippingTaskCenterPolling';
import ShippingRunProgressTable from './ShippingRunProgressTable.vue';
const { t, te } = useI18n();
const msg = useMessage();
/** 进行中 Workflow/Task 前台轮询间隔。 */
const FOREGROUND_POLL_MS = 2000;
/** 页面隐藏时后台轮询间隔。 */
const BACKGROUND_POLL_MS = 8000;
/**
* 判断详情是否仍处于进行中。
* 核心逻辑:优先统一 ui_state.stage;技术 processing status 仅用于轮询,不用于业务阶段展示。
*/
function isDetailInProgress(task: ShippingTaskDetail | null): boolean {
if (!task) return false;
const stage = String(task.ui_state?.stage?.code || '').trim();
if (stage) return stage !== 'upload_complete';
const unified = String(task.shipping_processing_status || '').trim().toLowerCase();
if (unified) {
if (TERMINAL_PROCESSING_STATUSES.has(unified)) return false;
return IN_PROGRESS_PROCESSING_STATUSES.has(unified);
}
return false;
}
/**
* 判断列表项是否应触发轮询刷新。
* 核心逻辑:委托 isShippingTodoListItemInProgress(Intake created/queued/parsing 必须轮询)。
*/
function isListItemInProgress(item: ShippingTaskSummary): boolean {
return isShippingTodoListItemInProgress(item);
}
const route = useRoute();
const router = useRouter();
const { refreshShippingTodoBadge } = useShippingTodoBadge();
/** todos=建单后待办;runs=建单前识别续办 */
const surface = ref<'todos' | 'runs'>('todos');
const bucket = ref<'pending' | 'processing' | 'done'>('pending');
const filterTodoCategory = ref<'all' | 'review' | 'exception' | 'manual_upload' | 'intake_parse'>('all');
type LifecycleStageCode = 'intake_parse' | 'order_review' | 'fulfillment_prep' | 'freight_upload' | 'upload_complete';
const LIFECYCLE_STAGES: LifecycleStageCode[] = [
'intake_parse',
'order_review',
'fulfillment_prep',
'freight_upload',
'upload_complete',
];
const lifecycleStageFilter = ref<'all' | LifecycleStageCode>('all');
const lifecycleStageTarget = ref<Exclude<LifecycleStageCode, 'intake_parse'>>('order_review');
const filterCustomer = ref('');
const filterTaskNo = ref('');
const appliedFilters = ref({
todo_category: '',
customer: '',
task_no: '',
});
const loading = ref(false);
const detailLoading = ref(false);
const tasks = ref<ShippingTaskSummary[]>([]);
const selectedRef = ref<string | null>(null);
/** 仅直链摘要,供入口卡展示;禁止内嵌履约工作台。 */
const detail = ref<ShippingTaskDetail | null>(null);
const currentPage = ref(1);
const pageSize = 20;
const totalTasks = ref(0);
const bucketCounts = ref<ShippingMyTodosCount>({
pending: 0,
processing: 0,
done: 0,
total_pending_badge: 0,
});
const chatAgentId = ref<number | null>(null);
let pollTimer: ReturnType<typeof setTimeout> | null = null;
let pollInFlight = false;
const totalPages = computed(() => Math.max(1, Math.ceil(totalTasks.value / pageSize)));
const preferredTaskNo = computed(() =>
String(route.params.taskNo || route.query.task_no || '').trim().toUpperCase(),
);
const isDirectTaskRoute = computed(() => Boolean(String(route.params.taskNo || '').trim()));
const selectedItem = computed(() =>
tasks.value.find((item) => todoItemKey(item) === selectedRef.value) || null,
);
const isReviewSelection = computed(() => selectedItem.value?.item_kind === 'review_case'
|| Boolean(selectedItem.value?.review_run_no && !selectedItem.value?.task_no));
const isIntakeSelection = computed(() => selectedItem.value?.item_kind === 'order_intake'
|| Boolean(selectedItem.value?.intake_no && !selectedItem.value?.task_no && !selectedItem.value?.review_run_no));
/** 建单后 Notice/OT 任务选中(列表项或直链详情)。 */
const isTaskSelection = computed(() => {
if (isDirectTaskRoute.value && detail.value) return true;
if (!selectedItem.value) return false;
return !isReviewSelection.value && !isIntakeSelection.value && Boolean(selectedItem.value.task_no);
});
/**
* 入口卡展示对象:优先列表选中项,直链时回退详情摘要。
*/
const entryItem = computed((): ShippingTaskSummary | ShippingTaskDetail | null => {
if (selectedItem.value) return selectedItem.value;
if (detail.value) return detail.value;
return null;
});
/**
* 任务中心选中项的统一进度紧凑摘要:只展示后端阶段与阻断原因。
* 15 节点只属于订单详情进度条,任务中心不得重复显示。
*/
const entryProgressSummary = computed(() => {
const item = entryItem.value;
if (!item) return null;
const stageCode = String(item.ui_state?.stage?.code || '').trim();
const stageLabel = String(item.ui_state?.stage?.label || '').trim();
if (!stageCode && !stageLabel) return null;
const reason = item.ui_state?.reason;
const blocker = String(reason?.message || '').trim()
|| resolveGateReasonLabel(String(reason?.code || '').trim(), { t, te });
return {
stageLabel: stageLabel || stageCode,
blocker,
poNumber: String(item.po_number || '').trim() || null,
customerName: String(item.customer_name || '').trim() || null,
};
});
/**
* 读取后端已裁决的生命周期入口;缺失即无授权,绝不按 task/case/intake 身份补造入口。
*/
function lifecycleEntriesOf(item: ShippingTaskSummary | ShippingTaskDetail) {
const entries = item.ui_state?.lifecycle_entries;
if (!Array.isArray(entries)) return [];
return entries.filter((entry) => LIFECYCLE_STAGES.includes(entry.code as LifecycleStageCode));
}
/** 当前阶段只取后端标为 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;
}
/** 可进入工作台的业务阶段仅由后端 entry.state 授权。 */
function lifecycleEntryFor(
item: ShippingTaskSummary | ShippingTaskDetail,
stage: Exclude<LifecycleStageCode, 'intake_parse'>,
) {
return lifecycleEntriesOf(item).find((entry) => entry.code === stage) || null;
}
/** 后端仅以 current / available 表示可进入工作台;未知状态一律拒绝深链。 */
function lifecycleEntryIsEnterable(entry: ReturnType<typeof lifecycleEntryFor>): boolean {
return entry?.state === 'current' || entry?.state === 'available';
}
function defaultLifecycleTarget(item: ShippingTaskSummary | ShippingTaskDetail): Exclude<LifecycleStageCode, 'intake_parse'> | null {
const current = lifecycleEntriesOf(item).find(
(entry) => entry.code !== 'intake_parse' && entry.state === 'current',
);
const available = lifecycleEntriesOf(item).find(
(entry) => entry.code !== 'intake_parse' && entry.state === 'available',
);
return (current || available)?.code as Exclude<LifecycleStageCode, 'intake_parse'> | undefined || null;
}
const lifecycleStageCounts = computed(() => {
const counts = Object.fromEntries(LIFECYCLE_STAGES.map((stage) => [stage, 0])) as Record<LifecycleStageCode, number>;
for (const item of tasks.value) {
const stage = lifecycleStageCodeOf(item);
if (stage) counts[stage] += 1;
}
return counts;
});
const filteredTasks = computed(() => (
lifecycleStageFilter.value === 'all'
? tasks.value
: tasks.value.filter((item) => lifecycleStageCodeOf(item) === lifecycleStageFilter.value)
));
const lifecycleStageTargetOptions = computed(() => {
if (!entryItem.value) return [];
return lifecycleEntriesOf(entryItem.value)
.filter((entry) => entry.code !== 'intake_parse')
.map((entry) => ({
code: entry.code as Exclude<LifecycleStageCode, 'intake_parse'>,
disabled: entry.state !== 'current' && entry.state !== 'available',
}));
});
/**
* 待办列表项稳定主键:复核用 case_no,Intake 用 intake_no,任务用 task_no。
*/
function todoItemKey(item: ShippingTaskSummary): string {
if (item.item_kind === 'review_case' || item.review_case_no) {
return String(item.todo_ref || item.review_case_no || item.review_run_no || '');
}
if (item.item_kind === 'order_intake' || item.intake_no) {
return String(item.todo_ref || item.intake_no || '');
}
return String(item.todo_ref || item.task_no || '');
}
/**
* 列表展示编号:复核显示 case_no,Intake 显示 intake_no,任务显示 SN。
*/
function todoDisplayNo(item: ShippingTaskSummary): string {
if (item.item_kind === 'review_case' || item.review_case_no) {
return String(item.review_case_no || item.review_run_no || item.todo_ref || '—');
}
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 || '—');
}
/**
* 是否应继续自动轮询:processing 桶、进行中直链详情,或 runs 面;列表项按统一投影。
*/
const shouldAutoRefresh = computed(() => {
if (surface.value === 'runs') return true;
if (bucket.value === 'processing') return true;
if (isDirectTaskRoute.value && isDetailInProgress(detail.value)) return true;
return tasks.value.some((item) => isListItemInProgress(item));
});
/**
* 按页面可见性选择轮询间隔。
*/
function resolvePollMs(): number {
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {
return BACKGROUND_POLL_MS;
}
return FOREGROUND_POLL_MS;
}
/**
* 停止自动轮询。
*/
function stopAutoRefresh() {
if (pollTimer != null) {
clearTimeout(pollTimer);
pollTimer = null;
}
}
/**
* 调度下一次自动刷新(仅进行中项)。
*/
function scheduleAutoRefresh() {
stopAutoRefresh();
if (!shouldAutoRefresh.value) return;
pollTimer = setTimeout(() => {
void (async () => {
if (pollInFlight || !shouldAutoRefresh.value) {
scheduleAutoRefresh();
return;
}
pollInFlight = true;
try {
await refreshAll({ silent: true });
} finally {
pollInFlight = false;
scheduleAutoRefresh();
}
})();
}, resolvePollMs());
}
/**
* 解析货代 Chat Agent,供订单处理/会话深链。
*/
async function resolveChatAgent() {
try {
const agents = await listShippingChatAgents();
const found = agents.find((a) => String(a.agent_code || '').trim() === SHIPPING_NOTICE_AGENT_CODE);
if (found) chatAgentId.value = found.id;
} catch {
/* ignore */
}
}
/**
* 刷新各 bucket 计数与导航徽标。
*/
async function loadCounts() {
try {
bucketCounts.value = await countWorkspaceShippingMyTodos();
await refreshShippingTodoBadge(true);
} catch {
/* 计数失败不阻断列表 */
}
}
/**
* 将筛选表单同步为已应用条件并重置到第 1 页。
*/
function applyFilters() {
appliedFilters.value = {
todo_category: bucket.value === 'pending' && filterTodoCategory.value !== 'all'
? filterTodoCategory.value
: '',
customer: filterCustomer.value.trim(),
task_no: filterTaskNo.value.trim().toUpperCase(),
};
void loadTodos(true);
}
/**
* 清空筛选并重载。
*/
function resetFilters() {
filterTodoCategory.value = 'all';
filterCustomer.value = '';
filterTaskNo.value = '';
appliedFilters.value = { todo_category: '', customer: '', task_no: '' };
void loadTodos(true);
}
/**
* 拉取当前桶待办列表。
* @param resetPage - 切换桶时重置到第一页
*/
async function loadTodos(resetPage = false) {
if (resetPage) currentPage.value = 1;
loading.value = true;
try {
const category = appliedFilters.value.todo_category || undefined;
const result = await listWorkspaceShippingMyTodos({
bucket: bucket.value,
page: currentPage.value,
page_size: pageSize,
todo_category: category as 'review' | 'exception' | 'manual_upload' | 'intake_parse' | undefined,
customer: appliedFilters.value.customer || undefined,
task_no: appliedFilters.value.task_no || undefined,
});
tasks.value = result.items || [];
totalTasks.value = Number(result.total || 0);
if (preferredTaskNo.value && !selectedRef.value) {
const hit = tasks.value.find(
(item) => String(item.task_no || '').toUpperCase() === preferredTaskNo.value,
);
if (hit) selectedRef.value = todoItemKey(hit);
}
} catch {
tasks.value = [];
totalTasks.value = 0;
} finally {
loading.value = false;
}
}
/**
* 直链场景拉取任务摘要(仅入口卡,不挂工作台)。
*/
async function loadDetail(taskNo: string) {
detailLoading.value = true;
try {
detail.value = await getWorkspaceShippingTask(taskNo);
} catch {
detail.value = null;
} finally {
detailLoading.value = false;
}
}
/**
* 列表与(可选)直链摘要联动刷新。
*/
async function refreshAll(_options?: { silent?: boolean }) {
await Promise.all([loadTodos(), loadCounts()]);
if (isDirectTaskRoute.value && preferredTaskNo.value) {
await loadDetail(preferredTaskNo.value);
}
}
/**
* 打开订单处理工作台(Chat 主区 order-review;单 OT 全生命周期)。
* 任务中心仅作列表入口,禁止在本页履约写操作(STP 重试除外)。
*/
function openOrderProcessing(
item: ShippingTaskSummary | ShippingTaskDetail,
requestedStage?: Exclude<LifecycleStageCode, 'intake_parse'>,
) {
const runNo = String(item.review_run_no || '').trim();
if (!runNo) return;
const agentId = Number(item.owner_agent_id || chatAgentId.value || 0);
if (!agentId) return;
const query: Record<string, string> = {
mode: 'order-review',
run_no: runNo,
};
const stage = requestedStage || defaultLifecycleTarget(item);
if (!stage || !lifecycleEntryIsEnterable(lifecycleEntryFor(item, stage))) return;
query.lifecycle_stage = stage;
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 canOpenOrderProcessing(
item: ShippingTaskSummary | ShippingTaskDetail | null,
stage?: Exclude<LifecycleStageCode, 'intake_parse'>,
): boolean {
if (!item) return false;
const runNo = String(item.review_run_no || '').trim();
const agentId = Number(item.owner_agent_id || chatAgentId.value || 0);
const target = stage || defaultLifecycleTarget(item);
return Boolean(runNo && agentId && target && lifecycleEntryIsEnterable(lifecycleEntryFor(item, target)));
}
const stpRetrying = ref(false);
/**
* 任务中心是否展示「重试自动推进」(与工作台底栏同一 available_actions / 幂等键)。
*/
function canRetryStpAutoCreate(item: ShippingTaskSummary | ShippingTaskDetail | null): boolean {
if (!item || item.can_handle === false) return false;
const caseNo = String(item.review_case_no || '').trim();
if (!caseNo) return false;
const summaryActions = item.ui_state?.summary?.allowed_actions || [];
const actions = [item.ui_state?.actions?.primary, ...(item.ui_state?.actions?.secondary || [])]
.filter(Boolean)
.map((action) => String(action?.code || ''));
return summaryActions.includes('retry_stp_auto_create') || actions.includes('retry_stp_auto_create');
}
/**
* 显式重试 STP 自动建单入队;与 ReviewWorkbenchFooter 共用 POST retry API。
*/
async function retryStpAutoCreate(item: ShippingTaskSummary | ShippingTaskDetail) {
const caseNo = String(item.review_case_no || '').trim();
if (!caseNo || stpRetrying.value) return;
stpRetrying.value = true;
try {
await retryWorkspaceShippingOrderStpAutoCreate(caseNo);
msg.success(t('chat.shippingOrderReview.autoProgress.retryStpSuccess'));
await loadTodos();
} catch (error) {
const message = error instanceof BusinessError
? (error.message || t('chat.shippingOrderReview.autoProgress.retryStp'))
: t('chat.shippingOrderReview.autoProgress.retryStp');
msg.error(message);
} finally {
stpRetrying.value = false;
}
}
/**
* 打开对话「本次处理中」卡,聚焦未建 OT 的 Intake 材料。
*/
function openIntakeConversation(item: ShippingTaskSummary) {
const agentId = Number(item.owner_agent_id || chatAgentId.value || 0);
if (!agentId) return;
const query: Record<string, string> = {};
const cid = String(item.conversation_id || '').trim();
if (cid) query.conversation_id = cid;
const intakeNo = String(item.intake_no || item.todo_ref || '').trim();
if (intakeNo) query.intake_no = intakeNo;
void router.push({ path: `/chat/${agentId}`, query });
}
/**
* 可选深链:打开 Chat 会话查看上下文(非履约写入口)。
*/
function openInChat(item?: ShippingTaskSummary | ShippingTaskDetail | null) {
const row = item || entryItem.value;
if (!chatAgentId.value || !row) return;
const query: Record<string, string> = {};
const taskNo = String(row.task_no || '').trim();
const orderTaskNo = String(row.order_task_no || '').trim();
if (taskNo) query.task_id = taskNo;
if (orderTaskNo) query.focus_task_no = orderTaskNo;
const batchNo = String(('batch_no' in row ? row.batch_no : '') || '').trim();
if (batchNo) query.batch_no = batchNo;
const cid = String(row.conversation_id || '').trim();
if (/^[0-9a-f]{32}$/i.test(cid)) query.conversation_id = cid;
void router.push({ path: `/chat/${chatAgentId.value}`, query });
}
/**
* 选中列表项:仅更新选中态与 query;不拉详情工作台。
*/
async function selectTodo(item: ShippingTaskSummary) {
selectedRef.value = todoItemKey(item);
detail.value = null;
const nextQuery: Record<string, string> = { ...route.query as Record<string, string> };
if (item.item_kind === 'review_case' || (item.review_run_no && !item.task_no)) {
delete nextQuery.task_no;
delete nextQuery.intake_no;
if (item.review_run_no) nextQuery.run_no = String(item.review_run_no);
} else if (item.item_kind === 'order_intake' || item.intake_no) {
delete nextQuery.task_no;
delete nextQuery.run_no;
if (item.intake_no) nextQuery.intake_no = String(item.intake_no);
} else if (item.task_no) {
delete nextQuery.run_no;
delete nextQuery.intake_no;
nextQuery.task_no = item.task_no;
}
void router.replace({
name: route.name || 'workspace-shipping-my-tasks',
params: route.params,
query: nextQuery,
});
}
watch(bucket, () => {
selectedRef.value = null;
detail.value = null;
filterTodoCategory.value = 'all';
appliedFilters.value = {
...appliedFilters.value,
todo_category: '',
};
void loadTodos(true);
});
watch(entryItem, (item) => {
if (!item) return;
const stage = defaultLifecycleTarget(item);
if (stage) lifecycleStageTarget.value = stage;
}, { immediate: true });
watch(lifecycleStageFilter, () => {
selectedRef.value = null;
detail.value = null;
});
watch(selectedItem, (item) => {
if (!item) {
if (!isDirectTaskRoute.value) detail.value = null;
return;
}
// 列表选中不拉详情;履约写一律走订单处理工作台。
detail.value = null;
});
watch(shouldAutoRefresh, () => {
scheduleAutoRefresh();
});
/**
* 页面可见性变化时重排轮询间隔。
*/
function onVisibilityChange() {
scheduleAutoRefresh();
}
onMounted(async () => {
await Promise.all([resolveChatAgent(), loadCounts(), loadTodos()]);
if (preferredTaskNo.value) {
if (isDirectTaskRoute.value) {
selectedRef.value = preferredTaskNo.value;
await loadDetail(preferredTaskNo.value);
} else {
const hit = tasks.value.find((item) => String(item.task_no || '').toUpperCase() === preferredTaskNo.value);
if (hit) {
selectedRef.value = todoItemKey(hit);
} else {
selectedRef.value = preferredTaskNo.value;
await loadDetail(preferredTaskNo.value);
}
}
}
document.addEventListener('visibilitychange', onVisibilityChange);
scheduleAutoRefresh();
});
onBeforeUnmount(() => {
stopAutoRefresh();
document.removeEventListener('visibilitychange', onVisibilityChange);
});
</script>
<template>
<div class="space-y-5 animate-fade-in-up">
<div class="flex items-center justify-between gap-3">
<div>
<h2 class="text-2xl font-bold text-primary">{{ $t('workspace.shippingNotice.myTodos.title') }}</h2>
<p class="text-sm text-muted">{{ $t('workspace.shippingNotice.myTodos.subtitle') }}</p>
</div>
<button
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft"
@click="refreshAll()"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.refresh') }}
</button>
</div>
<div class="flex flex-wrap gap-2">
<button
type="button"
class="rounded-xl px-3 py-1.5 text-sm font-medium"
:class="surface === 'todos' ? 'bg-brand-600 text-white' : 'border border-default text-secondary hover:bg-surface-soft'"
@click="surface = 'todos'"
>
{{ $t('workspace.shippingNotice.myTodos.title') }}
</button>
<button
type="button"
class="rounded-xl px-3 py-1.5 text-sm font-medium"
:class="surface === 'runs' ? 'bg-brand-600 text-white' : 'border border-default text-secondary hover:bg-surface-soft'"
@click="surface = 'runs'"
>
{{ $t('workspace.shippingNotice.myRuns.title') }}
</button>
</div>
<div
v-if="isDirectTaskRoute"
class="rounded-2xl border border-default bg-surface p-4"
data-testid="my-todos-direct-task-entry"
>
<div v-if="detailLoading" class="py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.loading') }}
</div>
<div v-else-if="!detail" class="py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.selectCase') }}
</div>
<div v-else class="space-y-4">
<div class="font-mono text-lg font-bold text-primary">{{ detail.task_no }}</div>
<p class="text-sm text-secondary">
{{ detail.ui_state?.summary?.message || detail.ui_state?.summary?.current_todo || $t('workspace.shippingNotice.myTodos.openProcessingHint') }}
</p>
<p class="text-xs text-muted">
{{ $t('workspace.shippingNotice.myTodos.openProcessingHint') }}
</p>
<div class="flex flex-wrap gap-2">
<button
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)"
data-testid="my-todos-open-order-processing"
@click="openOrderProcessing(detail)"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.myTodos.openReview') }}
</button>
<button
v-if="chatAgentId"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-secondary hover:bg-surface-soft"
@click="openInChat(detail)"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.openChat') }}
</button>
</div>
<p
v-if="!canOpenOrderProcessing(detail)"
class="text-xs text-amber-700 dark:text-amber-300"
data-testid="my-todos-open-processing-unavailable"
>
{{ $t('workspace.shippingNotice.myTodos.openProcessingUnavailable') }}
</p>
</div>
</div>
<ShippingRunProgressTable v-else-if="surface === 'runs'" />
<template v-else>
<div class="flex flex-wrap gap-2">
<button
v-for="key in (['pending', 'processing', 'done'] as const)"
:key="key"
type="button"
class="rounded-xl px-3 py-1.5 text-sm font-medium"
:class="bucket === key ? 'bg-brand-600 text-white' : 'border border-default text-secondary hover:bg-surface-soft'"
@click="bucket = key"
>
{{ $t(`workspace.shippingNotice.myTodos.buckets.${key}`) }}
<span class="ml-1 opacity-80">({{ bucketCounts[key] }})</span>
</button>
</div>
<div
class="grid gap-2 sm:grid-cols-2 xl:grid-cols-4"
data-testid="my-todos-lifecycle-stage-filter"
>
<button
v-for="stage in LIFECYCLE_STAGES"
:key="stage"
type="button"
class="rounded-xl border px-3 py-2 text-left transition-colors"
:class="lifecycleStageFilter === stage
? 'border-brand-500 bg-brand-50 text-brand-950 dark:bg-brand-950/30 dark:text-brand-50'
: 'border-default bg-surface hover:bg-surface-soft'"
:data-testid="`my-todos-stage-filter-${stage}`"
@click="lifecycleStageFilter = lifecycleStageFilter === stage ? 'all' : stage"
>
<span class="block text-xs text-muted">{{ $t('workspace.shippingNotice.myTodos.lifecycleStages.filterLabel') }}</span>
<span class="mt-1 flex items-center justify-between gap-2 text-sm font-semibold">
<span>{{ $t(`workspace.shippingNotice.myTodos.lifecycleStages.${stage}`) }}</span>
<span class="font-mono text-xs">{{ lifecycleStageCounts[stage] }}</span>
</span>
</button>
</div>
<div class="flex flex-wrap items-end gap-3 rounded-2xl border border-default bg-surface px-4 py-3">
<label v-if="bucket === 'pending'" class="space-y-1">
<span class="text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.myTodos.filters.todoCategory') }}</span>
<select v-model="filterTodoCategory" class="input-field text-sm min-w-[9rem]">
<option value="all">{{ $t('workspace.shippingNotice.myTodos.filters.all') }}</option>
<option value="review">{{ $t('workspace.shippingNotice.myTodos.filters.review') }}</option>
<option value="exception">{{ $t('workspace.shippingNotice.myTodos.filters.exception') }}</option>
<option value="manual_upload">{{ $t('workspace.shippingNotice.myTodos.filters.manualUpload') }}</option>
<option value="intake_parse">{{ $t('workspace.shippingNotice.myTodos.filters.intakeParse') }}</option>
</select>
</label>
<label class="space-y-1 flex-1 min-w-[10rem]">
<span class="text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.myTodos.filters.customer') }}</span>
<input
v-model="filterCustomer"
type="text"
class="input-field text-sm w-full"
:placeholder="$t('workspace.shippingNotice.myTodos.filters.customerPlaceholder')"
@keyup.enter="applyFilters"
/>
</label>
<label class="space-y-1 flex-1 min-w-[10rem]">
<span class="text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.myTodos.filters.taskNo') }}</span>
<input
v-model="filterTaskNo"
type="text"
class="input-field text-sm w-full font-mono uppercase"
:placeholder="$t('workspace.shippingNotice.myTodos.filters.taskNoPlaceholder')"
@keyup.enter="applyFilters"
/>
</label>
<div class="flex gap-2">
<button
type="button"
class="rounded-xl bg-brand-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
:disabled="loading"
@click="applyFilters"
>
{{ $t('workspace.shippingNotice.myTodos.filters.apply') }}
</button>
<button
type="button"
class="rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft disabled:opacity-50"
:disabled="loading"
@click="resetFilters"
>
{{ $t('workspace.shippingNotice.myTodos.filters.reset') }}
</button>
</div>
</div>
<div class="grid gap-5 lg:grid-cols-[minmax(18rem,0.85fr)_minmax(0,2.15fr)]">
<div class="space-y-2">
<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>
<div v-else-if="!filteredTasks.length" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.myTodos.empty') }}
</div>
<button
v-for="item in filteredTasks"
:key="todoItemKey(item)"
type="button"
class="w-full rounded-2xl border px-4 py-3 text-left transition-colors"
:class="selectedRef === todoItemKey(item) ? 'border-brand-400 bg-brand-50/60' : 'border-default hover:bg-surface-soft/70'"
@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
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"
>
{{ $t('workspace.shippingNotice.myTodos.openReview') }}
</span>
<span
v-else-if="item.todo_category === 'intake_parse' || item.item_kind === 'order_intake'"
class="rounded-full bg-violet-50 px-2 py-0.5 text-[10px] text-violet-700"
>
{{ $t('workspace.shippingNotice.myTodos.intakeParseBadge') }}
</span>
<span
v-else-if="item.can_handle === false"
class="rounded-full bg-slate-100 px-2 py-0.5 text-[10px] text-slate-600"
>
{{ $t('workspace.shippingNotice.todo.adminViewOnlyShort') }}
</span>
</div>
<div class="mt-1 truncate text-sm text-secondary">
{{ item.ui_state?.todo?.title || item.ui_state?.summary?.current_todo || item.ui_state?.summary?.title || item.ui_state?.stage?.label || '—' }}
</div>
<div class="mt-1 truncate text-xs text-muted">
{{ item.customer_name || item.source_file_name || item.review_run_no || '—' }}
</div>
</button>
<div v-if="totalPages > 1" class="flex items-center justify-between gap-2 pt-2 text-xs text-muted">
<button
type="button"
class="rounded-lg border border-default px-2 py-1 disabled:opacity-50"
:disabled="currentPage <= 1 || loading"
@click="currentPage -= 1; loadTodos()"
>
{{ $t('workspace.shippingNotice.pagination.previous') }}
</button>
<span>{{ currentPage }}/{{ totalPages }}</span>
<button
type="button"
class="rounded-lg border border-default px-2 py-1 disabled:opacity-50"
:disabled="currentPage >= totalPages || loading"
@click="currentPage += 1; loadTodos()"
>
{{ $t('workspace.shippingNotice.pagination.next') }}
</button>
</div>
</div>
<div>
<div
v-if="isReviewSelection && selectedItem"
class="space-y-4 rounded-2xl border border-default bg-surface p-6"
data-testid="my-todos-review-selection"
>
<div class="font-mono text-lg font-bold text-primary">{{ todoDisplayNo(selectedItem) }}</div>
<p class="text-sm text-secondary">
{{ selectedItem.ui_state?.summary?.message || selectedItem.ui_state?.summary?.current_todo }}
</p>
<p v-if="selectedItem.source_file_name" class="text-xs text-muted">
{{ selectedItem.source_file_name }}
<span v-if="selectedItem.review_run_no"> · {{ selectedItem.review_run_no }}</span>
</p>
<div class="flex flex-wrap gap-2">
<label class="sr-only" for="review-stage-target">{{ $t('workspace.shippingNotice.myTodos.lifecycleStages.viewStage') }}</label>
<select
v-if="lifecycleStageTargetOptions.length"
id="review-stage-target"
v-model="lifecycleStageTarget"
class="input-field max-w-40 text-sm"
data-testid="my-todos-lifecycle-stage-target"
>
<option
v-for="option in lifecycleStageTargetOptions"
:key="option.code"
:value="option.code"
:disabled="option.disabled"
>
{{ $t(`workspace.shippingNotice.myTodos.lifecycleStages.${option.code}`) }}
</option>
</select>
<button
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)"
data-testid="my-todos-open-order-processing"
@click="openOrderProcessing(selectedItem, lifecycleStageTarget)"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.myTodos.openLifecycleWorkbench') }}
</button>
<button
v-if="canRetryStpAutoCreate(selectedItem)"
type="button"
class="inline-flex items-center gap-1.5 rounded-xl border border-amber-400 bg-amber-50 px-4 py-2 text-sm font-medium text-amber-950 hover:bg-amber-100 disabled:opacity-50 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-100"
:disabled="stpRetrying"
data-testid="my-todos-retry-stp-auto-create"
@click="() => { if (selectedItem) void retryStpAutoCreate(selectedItem); }"
>
<RefreshCw class="h-3.5 w-3.5" />
{{ $t('chat.shippingOrderReview.autoProgress.retryStp') }}
</button>
</div>
</div>
<div
v-else-if="isIntakeSelection && selectedItem"
class="space-y-4 rounded-2xl border border-default bg-surface p-6"
data-testid="my-todos-intake-selection"
>
<div class="font-mono text-lg font-bold text-primary">{{ todoDisplayNo(selectedItem) }}</div>
<p class="text-sm text-secondary">
{{ selectedItem.ui_state?.summary?.message || selectedItem.ui_state?.summary?.current_todo }}
</p>
<p v-if="selectedItem.source_file_name" class="text-xs text-muted">
{{ selectedItem.source_file_name }}
<span v-if="selectedItem.intake_parse_status"> · {{ selectedItem.intake_parse_status }}</span>
</p>
<button
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="!(selectedItem.owner_agent_id || chatAgentId)"
data-testid="my-todos-open-intake-conversation"
@click="openIntakeConversation(selectedItem)"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.myTodos.openConversation') }}
</button>
</div>
<div
v-else-if="isTaskSelection && entryItem"
class="space-y-4 rounded-2xl border border-default bg-surface p-6"
data-testid="my-todos-task-selection"
>
<div class="font-mono text-lg font-bold text-primary">
{{ 'task_no' in entryItem ? entryItem.task_no : todoDisplayNo(entryItem as ShippingTaskSummary) }}
<span
v-if="entryProgressSummary?.poNumber"
class="ml-2 font-sans text-sm font-medium text-secondary"
>· PO {{ entryProgressSummary.poNumber }}</span>
</div>
<p
v-if="entryProgressSummary"
class="text-sm font-medium text-primary"
data-testid="my-todos-progress-summary"
>
{{ $t('workspace.shippingNotice.myTodos.progressSummary', {
stage: entryProgressSummary.stageLabel,
}) }}
</p>
<p
v-if="entryProgressSummary?.blocker"
class="text-xs text-amber-700 dark:text-amber-300"
data-testid="my-todos-progress-blocker"
>
{{ $t('workspace.shippingNotice.myTodos.progressBlocker', { reason: entryProgressSummary.blocker }) }}
</p>
<p class="text-sm text-secondary">
{{ entryItem.ui_state?.summary?.message || entryItem.ui_state?.summary?.current_todo || $t('workspace.shippingNotice.myTodos.openProcessingHint') }}
</p>
<p class="text-xs text-muted">
{{ $t('workspace.shippingNotice.myTodos.openProcessingHint') }}
</p>
<div class="flex flex-wrap gap-2">
<label class="sr-only" for="task-stage-target">{{ $t('workspace.shippingNotice.myTodos.lifecycleStages.viewStage') }}</label>
<select
v-if="lifecycleStageTargetOptions.length"
id="task-stage-target"
v-model="lifecycleStageTarget"
class="input-field max-w-40 text-sm"
data-testid="my-todos-lifecycle-stage-target"
>
<option
v-for="option in lifecycleStageTargetOptions"
:key="option.code"
:value="option.code"
:disabled="option.disabled"
>
{{ $t(`workspace.shippingNotice.myTodos.lifecycleStages.${option.code}`) }}
</option>
</select>
<button
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)"
data-testid="my-todos-open-order-processing"
@click="openOrderProcessing(entryItem, lifecycleStageTarget)"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.myTodos.openLifecycleWorkbench') }}
</button>
<button
v-if="chatAgentId"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-secondary hover:bg-surface-soft"
@click="openInChat(entryItem)"
>
<ExternalLink class="h-3.5 w-3.5" />
{{ $t('workspace.shippingNotice.openChat') }}
</button>
</div>
<p
v-if="!canOpenOrderProcessing(entryItem)"
class="text-xs text-amber-700 dark:text-amber-300"
data-testid="my-todos-open-processing-unavailable"
>
{{ $t('workspace.shippingNotice.myTodos.openProcessingUnavailable') }}
</p>
</div>
<div v-else-if="detailLoading" class="rounded-2xl border border-dashed border-default py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.loading') }}
</div>
<div v-else class="rounded-2xl border border-dashed border-default py-16 text-center text-sm text-muted">
{{ $t('workspace.shippingNotice.selectCase') }}
</div>
</div>
</div>
</template>
</div>
</template>