230 lines
9.1 KiB
Vue
230 lines
9.1 KiB
Vue
<!--
|
||
features/workspace/shipping-task-center/ShippingTaskTable.vue
|
||
用途:任务中心紧凑表格(一行一待办):编号/阶段/状态摘要/项次缺口/货代状态。
|
||
依赖:shippingTaskCenterShared(编号、阶段、批量可选口径)、element-plus。
|
||
逻辑:行点击向上冒泡选中;复选框仅「货代上传」阶段的正式 Notice 行存在;
|
||
勾选 ≥1 后浮出批量操作条(低频操作不常驻);分页由父级渲染。样式由任务中心页引入。
|
||
-->
|
||
<script setup lang="ts">
|
||
import { computed } from 'vue';
|
||
import { useI18n } from 'vue-i18n';
|
||
import { Close, Download, Select, Upload } from '@element-plus/icons-vue';
|
||
import { ElButton, ElCheckbox, ElTable, ElTableColumn, ElTag, ElText } from 'element-plus';
|
||
import type { ShippingTaskSummary } from '@/features/chat/api/shipping.api';
|
||
import {
|
||
isBatchDownloadableRow,
|
||
lifecycleStageCodeOf,
|
||
todoBlockerText,
|
||
todoDisplayNo,
|
||
todoItemKey,
|
||
todoLineBrief,
|
||
todoSubTitleText,
|
||
todoTitleText,
|
||
} from './shippingTaskCenterShared';
|
||
|
||
const { t, te } = useI18n();
|
||
|
||
const props = defineProps<{
|
||
items: ShippingTaskSummary[];
|
||
/** 当前选中行主键(抽屉联动)。 */
|
||
selectedKey?: string | null;
|
||
/** 是否渲染复选框列(仅待处理桶)。 */
|
||
selectable?: boolean;
|
||
/** 已勾选 business_no 集合。 */
|
||
selectedBusinessNos?: string[];
|
||
/** 批量动作进行中标记,禁用按钮。 */
|
||
batchBusy?: 'download' | 'confirm' | 'rpa' | null;
|
||
/** done 桶行统一终态角标(驳回/作废子视图由服务端过滤保证)。 */
|
||
terminalBadge?: 'upload_complete' | 'reject_void' | null;
|
||
}>();
|
||
|
||
const emit = defineEmits<{
|
||
(event: 'select', item: ShippingTaskSummary): void;
|
||
(event: 'toggle', item: ShippingTaskSummary): void;
|
||
(event: 'toggle-all'): void;
|
||
(event: 'clear-selection'): void;
|
||
(event: 'batch', action: 'download' | 'confirm' | 'rpa'): void;
|
||
}>();
|
||
|
||
const selectedSet = computed(() => new Set(props.selectedBusinessNos || []));
|
||
/** 复选框与全选状态消费同一可下载谓词,保证"能勾的都能下单成功"。 */
|
||
const selectableRows = computed(() => props.items.filter((item) => isBatchDownloadableRow(item)));
|
||
const hasSelection = computed(() => (props.selectedBusinessNos?.length || 0) > 0);
|
||
const allSelectableChecked = computed(() => (
|
||
selectableRows.value.length > 0
|
||
&& selectableRows.value.every((item) => selectedSet.value.has(String(item.business_no)))
|
||
));
|
||
|
||
/**
|
||
* 阶段徽章文案:优先本地化阶段名,后端 label 兜底。
|
||
* @param item - 待办行
|
||
*/
|
||
function stageLabel(item: ShippingTaskSummary): string {
|
||
const code = lifecycleStageCodeOf(item);
|
||
const key = code ? `workspace.shippingNotice.myTodos.lifecycleStages.${code}` : '';
|
||
if (key && te(key)) return t(key);
|
||
return String(item.ui_state?.stage?.label || '—');
|
||
}
|
||
|
||
/**
|
||
* 状态摘要主文案。
|
||
* @param item - 待办行
|
||
*/
|
||
function rowTitle(item: ShippingTaskSummary): string {
|
||
return todoTitleText(item);
|
||
}
|
||
|
||
/**
|
||
* 阻断原因。空字符串表示当前行没有阻断。
|
||
* @param item - 待办行
|
||
*/
|
||
function rowBlocker(item: ShippingTaskSummary): string {
|
||
return todoBlockerText(item, t, te);
|
||
}
|
||
|
||
/**
|
||
* 项次数量短句。没有行时显示占位。
|
||
* @param item - 待办行
|
||
*/
|
||
function lineBriefText(item: ShippingTaskSummary): string {
|
||
const brief = todoLineBrief(item);
|
||
if (!brief.total) return '—';
|
||
return `${brief.total} ${t('workspace.shippingNotice.myTodos.table.lineUnit')}`;
|
||
}
|
||
|
||
/** 全选或取消当前页可批量行。 */
|
||
function onToggleAll(): void {
|
||
emit('toggle-all');
|
||
}
|
||
|
||
/**
|
||
* 点击表格行打开抽屉。复选框点击已 stop,不会进到这里。
|
||
* @param row - 当前待办
|
||
*/
|
||
function onRowClick(row: ShippingTaskSummary): void {
|
||
emit('select', row);
|
||
}
|
||
|
||
/**
|
||
* 行角标:复核、解析、只读或终态。没有角标时返回空。
|
||
* @param item - 待办行
|
||
*/
|
||
function badgeOf(item: ShippingTaskSummary): { type: 'warning' | 'info' | 'success' | 'danger'; label: string } | null {
|
||
if (item.todo_category === 'review' || item.item_kind === 'review_case') {
|
||
return { type: 'warning', label: t('workspace.shippingNotice.myTodos.openReview') };
|
||
}
|
||
if (item.todo_category === 'intake_parse' || item.item_kind === 'order_intake') {
|
||
return { type: 'info', label: t('workspace.shippingNotice.myTodos.intakeParseBadge') };
|
||
}
|
||
if (item.can_handle === false) {
|
||
return { type: 'info', label: t('workspace.shippingNotice.todo.adminViewOnlyShort') };
|
||
}
|
||
if (props.terminalBadge === 'upload_complete') {
|
||
return { type: 'success', label: t('workspace.shippingNotice.myTodos.terminal.uploadComplete') };
|
||
}
|
||
if (props.terminalBadge === 'reject_void') {
|
||
return { type: 'danger', label: t('workspace.shippingNotice.myTodos.terminal.rejectVoid') };
|
||
}
|
||
return null;
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div class="overflow-hidden rounded-2xl border border-default bg-surface">
|
||
<div
|
||
v-if="hasSelection"
|
||
class="flex flex-wrap items-center gap-2 bg-[#1b2740] px-4 py-2.5"
|
||
data-testid="shipping-notice-batch-toolbar"
|
||
>
|
||
<ElTag type="primary" effect="dark">
|
||
{{ $t('workspace.shippingNotice.batch.selected', { count: selectedBusinessNos?.length || 0 }) }}
|
||
</ElTag>
|
||
<ElButton :icon="Download" :disabled="Boolean(batchBusy)" @click="emit('batch', 'download')">
|
||
{{ $t('workspace.shippingNotice.batch.download') }}
|
||
</ElButton>
|
||
<ElButton :icon="Select" :disabled="Boolean(batchBusy)" @click="emit('batch', 'confirm')">
|
||
{{ $t('workspace.shippingNotice.batch.confirm') }}
|
||
</ElButton>
|
||
<ElButton :icon="Upload" :disabled="Boolean(batchBusy)" @click="emit('batch', 'rpa')">
|
||
{{ $t('workspace.shippingNotice.batch.rpa') }}
|
||
</ElButton>
|
||
<span class="flex-1" />
|
||
<ElButton :icon="Close" @click="emit('clear-selection')">
|
||
{{ $t('workspace.shippingNotice.batch.clearSelection') }}
|
||
</ElButton>
|
||
</div>
|
||
|
||
<ElTable
|
||
:data="items"
|
||
:row-key="todoItemKey"
|
||
:current-row-key="selectedKey || undefined"
|
||
highlight-current-row
|
||
@row-click="onRowClick"
|
||
>
|
||
<ElTableColumn v-if="selectable" width="64">
|
||
<template #header>
|
||
<ElCheckbox
|
||
:model-value="allSelectableChecked"
|
||
:aria-label="t('workspace.shippingNotice.batch.selectAll')"
|
||
@change="onToggleAll"
|
||
/>
|
||
</template>
|
||
<template #default="{ row }">
|
||
<span v-if="isBatchDownloadableRow(row as ShippingTaskSummary)" @click.stop>
|
||
<ElCheckbox
|
||
:model-value="selectedSet.has(String((row as ShippingTaskSummary).business_no))"
|
||
:aria-label="String((row as ShippingTaskSummary).business_no)"
|
||
@change="emit('toggle', row as ShippingTaskSummary)"
|
||
/>
|
||
</span>
|
||
</template>
|
||
</ElTableColumn>
|
||
<ElTableColumn :label="t('workspace.shippingNotice.myTodos.table.no')" min-width="220">
|
||
<template #default="{ row }">
|
||
<div :data-testid="`my-todos-row-${todoDisplayNo(row as ShippingTaskSummary)}`">
|
||
<span>{{ todoDisplayNo(row as ShippingTaskSummary) }}</span>
|
||
<ElTag v-if="badgeOf(row as ShippingTaskSummary)" :type="badgeOf(row as ShippingTaskSummary)?.type" effect="light">
|
||
{{ badgeOf(row as ShippingTaskSummary)?.label }}
|
||
</ElTag>
|
||
</div>
|
||
<ElText type="info" size="small">{{ todoSubTitleText(row as ShippingTaskSummary) || '—' }}</ElText>
|
||
</template>
|
||
</ElTableColumn>
|
||
<ElTableColumn :label="t('workspace.shippingNotice.myTodos.table.stage')" min-width="120">
|
||
<template #default="{ row }">
|
||
<ElTag effect="light">{{ stageLabel(row as ShippingTaskSummary) }}</ElTag>
|
||
</template>
|
||
</ElTableColumn>
|
||
<ElTableColumn :label="t('workspace.shippingNotice.myTodos.table.summary')" min-width="180">
|
||
<template #default="{ row }">
|
||
<div>{{ rowTitle(row as ShippingTaskSummary) }}</div>
|
||
<ElText
|
||
v-if="rowBlocker(row as ShippingTaskSummary)"
|
||
type="danger"
|
||
size="small"
|
||
data-testid="my-todos-row-blocker"
|
||
>
|
||
{{ rowBlocker(row as ShippingTaskSummary) }}
|
||
</ElText>
|
||
</template>
|
||
</ElTableColumn>
|
||
<ElTableColumn :label="t('workspace.shippingNotice.myTodos.table.lines')" min-width="120">
|
||
<template #default="{ row }">
|
||
<template v-if="(row as ShippingTaskSummary).business_no">
|
||
<span>{{ lineBriefText(row as ShippingTaskSummary) }}</span>
|
||
<ElText v-if="todoLineBrief(row as ShippingTaskSummary).shortage" type="danger">
|
||
{{ t('workspace.shippingNotice.myTodos.table.shortage', { count: todoLineBrief(row as ShippingTaskSummary).shortage }) }}
|
||
</ElText>
|
||
</template>
|
||
<span v-else>—</span>
|
||
</template>
|
||
</ElTableColumn>
|
||
<ElTableColumn :label="t('workspace.shippingNotice.myTodos.table.freightStatus')" min-width="120">
|
||
<template #default="{ row }">
|
||
{{ (row as ShippingTaskSummary).business_no ? ((row as ShippingTaskSummary).upload_status || '—') : '—' }}
|
||
</template>
|
||
</ElTableColumn>
|
||
</ElTable>
|
||
</div>
|
||
</template>
|