Files
syops/frontend/src/features/workspace/views/AccountingVoucherCheckView.vue
T

872 lines
34 KiB
Vue
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
<script setup lang="ts">
/**
* features/workspace/views/AccountingVoucherCheckView.vue
* 用途:立账凭证检核任务列表——按资料所属期间(年 + 月)查看批次统计,并展示最近一次检核。
* 依赖:voucherCheck.api、vue-i18n、useMessage、DeleteConfirmDialog、PaginationBar、formatLocalDateTime、voucherCheck.display、auth。
* Chat 嵌入时由 VoucherCheckChatPanel 传入 embedded / activeTab。
* 逻辑:独立路由或 Chat 嵌入;进页默认上一个自然月;「最近一次检核」不跟筛选;强制重检仅 admin,进度在本卡轮询。
* 终态用矮指标格;排队/执行中才展开进度条与当前步骤。Chat 嵌入时隐藏页头与内层 Tab。
*/
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { ChevronDown, Download, Loader2, RotateCcw, Search } from 'lucide-vue-next';
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
import PaginationBar from '@/shared/components/PaginationBar.vue';
import { useMessage } from '@/shared/composables/useMessage';
import { getStoredAuthUser } from '@/shared/utils/auth';
import { formatLocalDateTime } from '@/shared/utils/dateTime';
import { WORKSPACE_PATHS } from '../constants/routes';
import {
downloadVoucherCheckExcel,
getLatestVoucherCheckRun,
listVoucherCheckNotifications,
listVoucherCheckRuns,
triggerVoucherCheckForceAll,
type VoucherCheckLatestRun,
type VoucherCheckNotificationItem,
type VoucherCheckRunItem,
} from '../api/voucherCheck.api';
import {
voucherCheckModeLabel,
voucherCheckNotifyStatusLabel,
voucherCheckStatusLabel,
voucherCheckStepLabel,
} from '../utils/voucherCheck.display';
const props = withDefaults(defineProps<{
embedded?: boolean;
activeTab?: 'tasks' | 'notifications';
}>(), {
embedded: false,
activeTab: 'tasks',
});
const emit = defineEmits<{
'open-detail': [payload: { runId: number; runNo?: string | null }];
}>();
const { t } = useI18n();
const msg = useMessage();
const route = useRoute();
const router = useRouter();
const loading = ref(false);
const forcing = ref(false);
const showForceConfirm = ref(false);
const items = ref<VoucherCheckRunItem[]>([]);
const total = ref(0);
const page = ref(1);
const pageSize = ref(50);
const periodYear = ref('');
const periodMonth = ref('');
const status = ref('');
const listTab = ref<'tasks' | 'notifications'>(props.activeTab);
const notifyLoading = ref(false);
const notifyItems = ref<VoucherCheckNotificationItem[]>([]);
const notifyTotal = ref(0);
const notifyPage = ref(1);
const notifyPageSize = ref(50);
const notifyStatus = ref('');
const latestRun = ref<VoucherCheckLatestRun | null>(null);
const latestLoading = ref(false);
let forcePollTimer: ReturnType<typeof setInterval> | null = null;
const isAdmin = computed(() => String(getStoredAuthUser()?.role || '').trim().toLowerCase() === 'admin');
const latestInProgress = computed(() => {
const cardStatus = latestRun.value?.status;
return cardStatus === 'queued' || cardStatus === 'running';
});
const latestHasMissing = computed(() => {
const row = latestRun.value;
if (!row) return false;
return (row.missing_file_count || 0) > 0 || (row.missing_invoice_count || 0) > 0;
});
const latestCanOpenDetail = computed(() => {
const row = latestRun.value;
if (!row?.schedule_run_id) return false;
return row.status === 'missing' || row.status === 'completed';
});
/**
* 最近一次检核的四个指标格,终态矮格与执行中共用。
* 核心逻辑:缺件时后两项(缺件文件 / 缺件 invoice)标红。
*/
const latestMetrics = computed(() => {
const row = latestRun.value;
if (!row) return [];
const warn = latestHasMissing.value;
return [
{ key: 'subject', value: row.subject_count, labelKey: 'workspace.voucherCheck.subjectCount', warn: false },
{ key: 'archived', value: row.archived_file_count, labelKey: 'workspace.voucherCheck.archivedFiles', warn: false },
{ key: 'missingFiles', value: row.missing_file_count, labelKey: 'workspace.voucherCheck.missingFiles', warn },
{ key: 'missingInvoices', value: row.missing_invoice_count, labelKey: 'workspace.voucherCheck.missingInvoices', warn },
];
});
/**
* 终态是否展示失败原因:仅技术失败或带 error_message 时占一行,完整/缺件不再重复完成提示。
*/
const latestShowFailureHint = computed(() => {
const row = latestRun.value;
if (!row || latestInProgress.value) return false;
return row.status === 'technical_failed' || Boolean(row.error_message);
});
const MONTH_VALUES = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] as const;
/**
* 进页默认资料所属期间为上一个自然月。
*/
function previousYearMonth(): { year: string; month: string } {
const d = new Date();
d.setDate(1);
d.setMonth(d.getMonth() - 1);
return {
year: String(d.getFullYear()),
month: String(d.getMonth() + 1).padStart(2, '0'),
};
}
/**
* 组装列表查询 period:有月份则为 YYYY-MM,否则为 YYYY。
*/
const periodQuery = computed(() => {
if (!periodYear.value) return undefined;
if (periodMonth.value) return `${periodYear.value}-${periodMonth.value}`;
return periodYear.value;
});
const yearOptions = computed(() => {
const now = new Date().getFullYear();
const years: string[] = [];
for (let year = now - 5; year <= now; year += 1) {
years.push(String(year));
}
if (periodYear.value && !years.includes(periodYear.value)) {
years.unshift(periodYear.value);
years.sort();
}
return years;
});
const statusOptions = computed(() => [
{ value: '', label: t('workspace.voucherCheck.statusAll') },
{ value: 'missing', label: t('workspace.voucherCheck.statusMissing') },
{ value: 'completed', label: t('workspace.voucherCheck.statusComplete') },
{ value: 'technical_failed', label: t('workspace.voucherCheck.statusTechError') },
]);
const notifyStatusOptions = computed(() => [
{ value: '', label: t('workspace.voucherCheck.notifyStatusAll') },
{ value: 'sent', label: t('workspace.voucherCheck.notifyStatusSent') },
{ value: 'failed', label: t('workspace.voucherCheck.notifyStatusFailed') },
{ value: 'skipped_no_missing', label: t('workspace.voucherCheck.notifyStatusNoMissing') },
{ value: 'skipped_no_recipients', label: t('workspace.voucherCheck.notifyStatusNoRecipients') },
{ value: 'skipped_disabled', label: t('workspace.voucherCheck.notifyStatusDisabled') },
]);
const pages = computed(() =>
Math.max(1, Math.ceil((total.value || 0) / Math.max(1, pageSize.value))),
);
const notifyPages = computed(() =>
Math.max(1, Math.ceil((notifyTotal.value || 0) / Math.max(1, notifyPageSize.value))),
);
/**
* 加载企微缺件汇总发送记录。
*/
async function loadNotifications() {
notifyLoading.value = true;
try {
const data = await listVoucherCheckNotifications({
period: periodQuery.value,
send_status: notifyStatus.value || undefined,
page: notifyPage.value,
page_size: notifyPageSize.value,
});
notifyItems.value = data.items || [];
notifyTotal.value = data.total || 0;
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.notifyLoadFailed'));
} finally {
notifyLoading.value = false;
}
}
/**
* 切换检核任务 / 企微发送记录。
* @param tab - 列表页 Tab
*/
function setListTab(tab: 'tasks' | 'notifications') {
if (listTab.value === tab) return;
listTab.value = tab;
if (tab === 'notifications') {
notifyPage.value = 1;
void loadNotifications();
return;
}
page.value = 1;
void loadRuns();
void loadLatestRun();
}
/**
* 当前 Tab 按筛选条件查询。
*/
function searchCurrentTab() {
if (listTab.value === 'tasks') {
page.value = 1;
void loadRuns();
return;
}
notifyPage.value = 1;
void loadNotifications();
}
/**
* 下载该发送记录对应批次的 Excel。
* @param row - 企微发送记录
*/
async function downloadNotifyExcel(row: VoucherCheckNotificationItem) {
if (!row.schedule_run_id || !row.has_excel) return;
try {
await downloadVoucherCheckExcel(row.schedule_run_id, row.excel_filename);
} catch {
msg.error(t('workspace.voucherCheck.downloadExcelFailed'));
}
}
/**
* 企微发送状态徽标样式。
* @param value - send_status
*/
function notifyBadgeClass(value: string): string {
if (value === 'sent') return 'bg-emerald-50 text-emerald-700';
if (value === 'failed') return 'bg-rose-50 text-rose-700';
return 'bg-surface-soft text-secondary';
}
/**
* 将接收人姓名拼成展示文本。
* @param names - 系统用户姓名
*/
function formatRecipientNames(names?: string[]): string {
if (!names?.length) return '-';
return names.join('、');
}
/**
* 打开批次明细:Chat 嵌入时回传父级,独立页则跳转工作台详情路由。
*/
function navigateToDetail(runId: number, runNo?: string | null) {
if (props.embedded) {
emit('open-detail', { runId, runNo: runNo || null });
return;
}
void router.push({
path: WORKSPACE_PATHS.accountingVoucherCheckDetail(runId),
query: runNo ? { runNo } : undefined,
});
}
/**
* 从发送记录跳转对应批次明细。
* @param row - 企微发送记录
*/
function openNotifyDetail(row: VoucherCheckNotificationItem) {
if (!row.schedule_run_id) {
msg.error(t('workspace.voucherCheck.loadFailed'));
return;
}
navigateToDetail(row.schedule_run_id, row.run_no);
}
/**
* 加载检核任务列表。
*/
async function loadRuns() {
loading.value = true;
try {
const data = await listVoucherCheckRuns({
period: periodQuery.value,
status: status.value || undefined,
page: page.value,
page_size: pageSize.value,
});
items.value = data.items || [];
total.value = data.total || 0;
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.loadFailed'));
} finally {
loading.value = false;
}
}
/**
* 企微卡片若仍带 ?run_id=,转到独立明细页,避免在列表上方展开。
*/
function redirectLegacyRunQuery() {
const raw = route.query.run_id;
const id = Number(Array.isArray(raw) ? raw[0] : raw);
if (!Number.isFinite(id) || id <= 0) return false;
void router.replace(WORKSPACE_PATHS.accountingVoucherCheckDetail(id));
return true;
}
/**
* 打开批次 invoice 明细独立页。
* @param row - 列表中的检核批次
*/
function openRunDetail(row: VoucherCheckRunItem) {
if (!row.schedule_run_id) {
msg.error(t('workspace.voucherCheck.loadFailed'));
return;
}
navigateToDetail(row.schedule_run_id, row.run_no);
}
/**
* 停止最近一次检核的进度轮询。
*/
function stopLatestPoll() {
if (forcePollTimer) {
clearInterval(forcePollTimer);
forcePollTimer = null;
}
}
/**
* 拉取最近一次检核卡片;不跟下方列表的年/月/状态筛选。
* @param options.silent - 轮询时不切换卡片 loading,避免进度条闪烁
*/
async function loadLatestRun(options?: { silent?: boolean }) {
if (!options?.silent) latestLoading.value = true;
try {
latestRun.value = await getLatestVoucherCheckRun();
} catch (e: any) {
if (!options?.silent) {
msg.error(e?.message || t('workspace.voucherCheck.latestLoadFailed'));
}
} finally {
if (!options?.silent) latestLoading.value = false;
}
}
/**
* 排队或执行中时轮询卡片;进入终态后刷新下方列表。
*/
function syncLatestPoll() {
stopLatestPoll();
if (listTab.value !== 'tasks' || !latestInProgress.value) return;
forcePollTimer = setInterval(() => {
void (async () => {
const previous = latestRun.value?.status;
await loadLatestRun({ silent: true });
const next = latestRun.value?.status;
if ((previous === 'queued' || previous === 'running') && next !== 'queued' && next !== 'running') {
stopLatestPoll();
void loadRuns();
}
})();
}, 3000);
}
/**
* 最近一次检核状态徽章样式。
* @param value - 卡片状态
*/
function latestBadgeClass(value: string): string {
if (value === 'missing' || value === 'technical_failed') return 'bg-rose-50 text-rose-700';
if (value === 'completed') return 'bg-emerald-50 text-emerald-700';
if (value === 'queued' || value === 'running') return 'bg-blue-50 text-blue-700';
return 'bg-surface-soft text-secondary';
}
/**
* 卡片当前步骤主文案:终态用完成提示,其余按步骤码翻译。
* @param row - 最近一次检核
*/
function latestStepText(row: VoucherCheckLatestRun): string {
if (row.status === 'queued') return t('workspace.voucherCheck.stepQueued');
if (row.status === 'missing' && (row.current_step?.step === 'done' || !row.current_step)) {
return t('workspace.voucherCheck.latestDoneHint');
}
if (row.status === 'completed' && (row.current_step?.step === 'done' || !row.current_step)) {
return t('workspace.voucherCheck.latestCompleteHint');
}
if (row.status === 'technical_failed' && row.current_step?.step === 'fetch_erp') {
return t('workspace.voucherCheck.stepFetchErpIncomplete');
}
return voucherCheckStepLabel(t, row.current_step?.step);
}
/**
* 卡片步骤辅文案:失败原因、排队等待或扫描进度。
* @param row - 最近一次检核
*/
function latestHintText(row: VoucherCheckLatestRun): string {
if (row.error_message) return row.error_message;
if (row.status === 'queued') return t('workspace.voucherCheck.stepQueuedHint');
if (row.status === 'running' && row.current_step?.step === 'scan_dms' && row.subject_count > 0) {
return t('workspace.voucherCheck.processedHint', {
processed: row.processed_count,
total: row.subject_count,
});
}
return '';
}
/**
* 打开强制重检确认框;用公共 DeleteConfirmDialog 替代原生 window.confirm。
*/
function openForceRecheck() {
if (forcing.value) return;
showForceConfirm.value = true;
}
/**
* 确认后入队强制重检上一个月:不跳过已归档记录,期间取执行日的上一个自然月。
*/
async function forceRecheck() {
if (forcing.value) return;
forcing.value = true;
try {
const data = await triggerVoucherCheckForceAll();
msg.success(t('workspace.voucherCheck.forceQueued', { runNo: data.run_no }));
await loadLatestRun({ silent: true });
syncLatestPoll();
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.forceFailed'));
} finally {
forcing.value = false;
}
}
/**
* 从最近一次检核卡片打开本批明细。
*/
function openLatestDetail() {
const row = latestRun.value;
if (!row?.schedule_run_id) {
msg.error(t('workspace.voucherCheck.loadFailed'));
return;
}
navigateToDetail(row.schedule_run_id, row.run_no);
}
/**
* 仅在检核任务 Tab 且最近一批仍在排队/执行时轮询卡片。
*/
watch([listTab, latestInProgress], () => {
syncLatestPoll();
});
watch(
() => props.activeTab,
(tab) => {
if (!props.embedded) return;
if (listTab.value === tab) return;
setListTab(tab);
},
);
onMounted(async () => {
if (!props.embedded && redirectLegacyRunQuery()) return;
const previous = previousYearMonth();
periodYear.value = previous.year;
periodMonth.value = previous.month;
const qStatus = route.query.status;
if (typeof qStatus === 'string' && qStatus) status.value = qStatus;
if (props.embedded) listTab.value = props.activeTab;
if (listTab.value === 'notifications') {
await loadNotifications();
return;
}
await Promise.all([loadRuns(), loadLatestRun()]);
});
onUnmounted(() => {
stopLatestPoll();
});
</script>
<template>
<div class="space-y-4 animate-fade-in-up">
<header v-if="!embedded" class="space-y-1">
<h1 class="text-2xl font-bold text-primary">{{ $t('workspace.voucherCheck.title') }}</h1>
<p class="text-sm text-muted">{{ $t('workspace.voucherCheck.subtitle') }}</p>
</header>
<div v-if="!embedded" class="flex gap-1 border-b border-default" role="tablist">
<button
type="button"
role="tab"
class="px-4 py-2.5 text-sm font-medium border-b-2 -mb-px transition-colors"
:class="listTab === 'tasks' ? 'border-brand-600 text-brand-600' : 'border-transparent text-muted hover:text-secondary'"
:aria-selected="listTab === 'tasks'"
@click="setListTab('tasks')"
>
{{ $t('workspace.voucherCheck.tabTasks') }}
</button>
<button
type="button"
role="tab"
class="px-4 py-2.5 text-sm font-medium border-b-2 -mb-px transition-colors"
:class="listTab === 'notifications' ? 'border-brand-600 text-brand-600' : 'border-transparent text-muted hover:text-secondary'"
:aria-selected="listTab === 'notifications'"
@click="setListTab('notifications')"
>
{{ $t('workspace.voucherCheck.tabNotifications') }}
</button>
</div>
<article
v-if="listTab === 'tasks'"
class="overflow-hidden rounded-2xl border border-default bg-surface"
aria-live="polite"
>
<div
class="flex flex-wrap items-start justify-between gap-3 px-4 py-2.5"
:class="latestInProgress ? 'bg-blue-50' : ''"
>
<div>
<h2 class="text-sm font-semibold text-primary">{{ $t('workspace.voucherCheck.latestTitle') }}</h2>
<p v-if="latestRun" class="mt-0.5 text-xs text-muted">
<span class="mr-3">{{ $t('workspace.voucherCheck.latestBatch', { runNo: latestRun.run_no }) }}</span>
<span class="mr-3">{{ $t('workspace.voucherCheck.latestPeriod', { period: latestRun.period_month || '-' }) }}</span>
<span>{{ voucherCheckModeLabel(t, latestRun.mode) }}</span>
</p>
</div>
<div class="flex shrink-0 items-center gap-2">
<button
v-if="latestCanOpenDetail"
type="button"
class="text-sm font-semibold text-brand-700 hover:underline"
@click="openLatestDetail"
>
{{ $t('workspace.voucherCheck.viewLatestDetail') }}
</button>
<span
v-if="latestRun"
class="inline-flex rounded-full px-2.5 py-0.5 text-xs font-semibold"
:class="latestBadgeClass(latestRun.status)"
>
{{ voucherCheckStatusLabel(t, latestRun.status) }}
</span>
<button
v-if="isAdmin"
type="button"
class="inline-flex items-center gap-1 rounded-xl border border-amber-300 bg-amber-50 px-3 py-1.5 text-sm font-medium text-amber-900 transition-colors hover:bg-amber-100 disabled:opacity-50"
:disabled="forcing || latestInProgress"
@click="openForceRecheck()"
>
<Loader2 v-if="forcing" class="h-3.5 w-3.5 animate-spin" />
<RotateCcw v-else class="h-3.5 w-3.5" />
{{ $t('workspace.voucherCheck.forceRecheck') }}
</button>
</div>
</div>
<div v-if="latestLoading && !latestRun" class="flex items-center justify-center gap-2 px-4 py-6 text-sm text-muted">
<Loader2 class="h-4 w-4 animate-spin" />
{{ $t('workspace.voucherCheck.loading') }}
</div>
<p v-else-if="!latestRun" class="px-4 py-6 text-center text-sm text-muted">
{{ $t('workspace.voucherCheck.latestEmpty') }}
</p>
<div v-else class="px-4 pb-3">
<template v-if="latestInProgress">
<div class="h-2 overflow-hidden rounded-full bg-slate-200">
<div
class="h-full rounded-full bg-teal-700 transition-[width] duration-300"
:style="{ width: `${latestRun.progress_percent || 0}%` }"
/>
</div>
<div class="mt-1.5 mb-2.5 flex flex-wrap justify-between gap-3 text-xs text-muted">
<span>{{ $t('workspace.voucherCheck.progress', { percent: latestRun.progress_percent || 0 }) }}</span>
<span>
{{ $t('workspace.voucherCheck.startedAt') }}:{{ formatLocalDateTime(latestRun.started_at) }}
 {{ $t('workspace.voucherCheck.finishedAt') }}:{{ $t('workspace.voucherCheck.inProgress') }}
</span>
</div>
<p class="mb-2.5 text-[13px] text-slate-700">
{{ latestStepText(latestRun) }}
<small v-if="latestHintText(latestRun)" class="mt-0.5 block text-muted">{{ latestHintText(latestRun) }}</small>
</p>
</template>
<div class="grid grid-cols-2 gap-2 md:grid-cols-4">
<div
v-for="metric in latestMetrics"
:key="metric.key"
class="rounded-[10px] border border-default bg-slate-50 px-2.5 py-2"
>
<b
class="block text-lg font-semibold leading-tight tabular-nums"
:class="metric.warn ? 'text-rose-700' : 'text-primary'"
>{{ metric.value }}</b>
<span class="text-[11px] text-muted">{{ $t(metric.labelKey) }}</span>
</div>
</div>
<p v-if="latestShowFailureHint" class="mt-2 text-[13px] text-slate-700">
{{ latestStepText(latestRun) }}
<small v-if="latestHintText(latestRun)" class="mt-0.5 block text-muted">{{ latestHintText(latestRun) }}</small>
</p>
</div>
</article>
<section class="flex flex-wrap items-end gap-3 rounded-2xl border border-default/80 bg-surface/70 px-4 py-3 shadow-sm">
<label class="flex flex-col gap-1 text-xs font-medium text-muted">
{{ $t('workspace.voucherCheck.period') }}
<span class="flex items-center gap-2">
<span class="period-select">
<select v-model="periodYear" class="period-select__control w-[4.75rem]">
<option v-for="year in yearOptions" :key="year" :value="year">{{ year }}</option>
</select>
<ChevronDown class="period-select__icon" aria-hidden="true" />
</span>
<span class="period-select">
<select v-model="periodMonth" class="period-select__control w-[4.75rem]">
<option value="">{{ $t('workspace.voucherCheck.periodMonthAll') }}</option>
<option v-for="month in MONTH_VALUES" :key="month" :value="month">
{{ $t('workspace.voucherCheck.periodMonthValue', { n: Number(month) }) }}
</option>
</select>
<ChevronDown class="period-select__icon" aria-hidden="true" />
</span>
</span>
</label>
<label v-if="listTab === 'tasks'" class="flex flex-col gap-1 text-xs font-medium text-muted">
{{ $t('workspace.voucherCheck.status') }}
<span class="period-select">
<select v-model="status" class="period-select__control w-[6rem]">
<option v-for="opt in statusOptions" :key="opt.value || 'all'" :value="opt.value">{{ opt.label }}</option>
</select>
<ChevronDown class="period-select__icon" aria-hidden="true" />
</span>
</label>
<label v-else class="flex flex-col gap-1 text-xs font-medium text-muted">
{{ $t('workspace.voucherCheck.notifyStatus') }}
<span class="period-select">
<select v-model="notifyStatus" class="period-select__control w-[7.25rem]">
<option v-for="opt in notifyStatusOptions" :key="opt.value || 'all'" :value="opt.value">{{ opt.label }}</option>
</select>
<ChevronDown class="period-select__icon" aria-hidden="true" />
</span>
</label>
<button
type="button"
class="inline-flex items-center gap-1 rounded-xl bg-brand-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-brand-700"
@click="searchCurrentTab"
>
<Search class="h-3.5 w-3.5" />
{{ $t('workspace.voucherCheck.search') }}
</button>
</section>
<section v-if="listTab === 'tasks'" class="overflow-hidden rounded-2xl border border-default bg-surface">
<div v-if="loading" class="flex items-center justify-center gap-2 py-16 text-sm text-muted">
<Loader2 class="h-4 w-4 animate-spin" />
{{ $t('workspace.voucherCheck.loading') }}
</div>
<div v-else-if="!items.length" class="rounded-2xl border border-dashed border-transparent py-16 text-center text-sm text-muted">
{{ $t('workspace.voucherCheck.empty') }}
</div>
<div v-else class="max-h-[calc(100vh-17rem)] overflow-auto scrollbar-thin">
<table class="w-full min-w-[960px] text-left text-sm">
<thead class="sticky top-0 z-10">
<tr class="border-b border-subtle bg-surface-soft text-xs font-semibold text-secondary">
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.runNo') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.period') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.subjectCount') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.missingInvoices') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.missingFiles') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.status') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.checkedAt') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.failureReason') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3"></th>
</tr>
</thead>
<tbody>
<tr v-for="row in items" :key="row.id" class="border-b border-subtle transition-colors hover:bg-surface-soft/50">
<td class="whitespace-nowrap px-4 py-3 font-medium text-primary">{{ row.run_no }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.period_month || '-' }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.subject_count }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.missing_invoice_count }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.missing_file_count }}</td>
<td class="whitespace-nowrap px-4 py-3">
<span
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
:class="row.status === 'missing' ? 'bg-rose-50 text-rose-700' : row.status === 'completed' ? 'bg-emerald-50 text-emerald-700' : 'bg-surface-soft text-secondary'"
>
{{ voucherCheckStatusLabel(t, row.status) }}
</span>
</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ formatLocalDateTime(row.finished_at) }}</td>
<td class="max-w-64 truncate px-4 py-3 text-rose-700" :title="row.error_message || ''">{{ row.error_message || '-' }}</td>
<td class="whitespace-nowrap px-4 py-3">
<button
type="button"
class="text-sm font-medium text-brand-700 hover:underline"
@click="openRunDetail(row)"
>
{{ $t('workspace.voucherCheck.viewDetail') }}
</button>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section v-else class="overflow-hidden rounded-2xl border border-default bg-surface">
<div v-if="notifyLoading" class="flex items-center justify-center gap-2 py-16 text-sm text-muted">
<Loader2 class="h-4 w-4 animate-spin" />
{{ $t('workspace.voucherCheck.loading') }}
</div>
<div v-else-if="!notifyItems.length" class="rounded-2xl border border-dashed border-transparent py-16 text-center text-sm text-muted">
{{ $t('workspace.voucherCheck.notifyEmpty') }}
</div>
<div v-else class="max-h-[calc(100vh-17rem)] overflow-auto scrollbar-thin">
<table class="w-full min-w-[1180px] text-left text-sm">
<thead class="sticky top-0 z-10">
<tr class="border-b border-subtle bg-surface-soft text-xs font-semibold text-secondary">
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.runNo') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.period') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.subjectCount') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.missingInvoices') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.missingFiles') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifyStatus') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifySkipReason') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifyRecipients') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifySentAt') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifyExcel') }}</th>
<th class="whitespace-nowrap bg-surface-soft px-4 py-3"></th>
</tr>
</thead>
<tbody>
<tr v-for="row in notifyItems" :key="row.id" class="border-b border-subtle transition-colors hover:bg-surface-soft/50">
<td class="whitespace-nowrap px-4 py-3 font-medium text-primary">{{ row.run_no || '-' }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.period_month || '-' }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.subject_count }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.missing_invoice_count }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.missing_file_count }}</td>
<td class="whitespace-nowrap px-4 py-3">
<span
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
:class="notifyBadgeClass(row.send_status)"
>
{{ voucherCheckNotifyStatusLabel(t, row.send_status) }}
</span>
</td>
<td class="max-w-56 truncate px-4 py-3 text-muted" :title="row.skip_reason || ''">{{ row.skip_reason || '-' }}</td>
<td class="max-w-48 truncate px-4 py-3 text-muted" :title="formatRecipientNames(row.recipient_names)">{{ formatRecipientNames(row.recipient_names) }}</td>
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ formatLocalDateTime(row.sent_at || row.created_at) }}</td>
<td class="whitespace-nowrap px-4 py-3">
<button
v-if="row.has_excel && row.schedule_run_id"
type="button"
class="inline-flex items-center gap-1 text-sm font-medium text-brand-700 hover:underline"
@click="downloadNotifyExcel(row)"
>
<Download class="h-3.5 w-3.5" />
{{ $t('workspace.voucherCheck.downloadExcel') }}
</button>
<span v-else class="text-muted">-</span>
</td>
<td class="whitespace-nowrap px-4 py-3">
<button
type="button"
class="text-sm font-medium text-brand-700 hover:underline disabled:text-muted disabled:no-underline"
:disabled="!row.schedule_run_id"
@click="openNotifyDetail(row)"
>
{{ $t('workspace.voucherCheck.viewDetail') }}
</button>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<PaginationBar
v-if="listTab === 'tasks'"
v-model:page="page"
v-model:page-size="pageSize"
:total="total"
:pages="pages"
:visible="total > 0 || !!status"
@update:page="() => loadRuns()"
@update:page-size="() => loadRuns()"
/>
<PaginationBar
v-else
v-model:page="notifyPage"
v-model:page-size="notifyPageSize"
:total="notifyTotal"
:pages="notifyPages"
:visible="notifyTotal > 0 || !!notifyStatus"
@update:page="() => loadNotifications()"
@update:page-size="() => loadNotifications()"
/>
<DeleteConfirmDialog
v-model="showForceConfirm"
:title="t('workspace.voucherCheck.forceRecheck')"
:message="t('workspace.voucherCheck.forceConfirm')"
:confirm-loading="forcing"
confirm-tone="primary"
@confirm="forceRecheck"
/>
</div>
</template>
<style scoped>
/**
* 隐藏系统原生下拉箭头(含 Chromium ::picker-icon / Edge ::-ms-expand)。
* 只保留模板里的 ChevronDown,避免 Windows 下年份与月份箭头叠在一起。
*/
.period-select {
position: relative;
display: inline-flex;
align-items: center;
}
.period-select__control {
box-sizing: border-box;
border-radius: 0.75rem;
border: 1px solid var(--border-default);
background-color: var(--bg-surface);
background-image: none;
padding: 0.375rem 1.75rem 0.375rem 0.625rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--text-primary);
font-size: 0.875rem;
line-height: 1.25rem;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.period-select__control::-ms-expand {
display: none;
}
.period-select__control::picker-icon {
display: none;
content: none;
}
.period-select__icon {
pointer-events: none;
position: absolute;
right: 0.5rem;
height: 0.875rem;
width: 0.875rem;
color: var(--text-muted);
}
</style>