feat(invoice-check): 立账凭证优化

This commit is contained in:
sophie committed 2026-09-30 16:12:27 +08:00
1 parent 22b05c91a2
commit 425ed43649
7 files changed
+207 -65

No files matched your search

@@ -1,6 +1,6 @@
/**
* features/workspace/utils/voucherCheck.display.ts
* 用途:立账凭证检核列表、最近一次检核卡片与明细页共用的状态/模式/步骤文案。
* 用途:立账凭证检核列表、最近一次检核卡片与明细页共用的状态、期间、模式与步骤文案。
* 依赖:vue-i18n 的 t()。
* 逻辑:AccountingVoucherCheckView / AccountingVoucherCheckDetailView 调用。
*/
@@ -23,6 +23,25 @@ export function voucherCheckStatusLabel(t: (key: string) => string, value: strin
return value || '-';
}
/**
* 把资料所属期间 YYYY-MM 格式成当前语言的年月。
* 核心逻辑:卡片不展示原始 2026-08;中文为「2026年8月」,英文与泰文用月份名。
* @param period - 期间,例如 2026-08
* @param locale - 当前 vue-i18n locale
* @returns 友好年月;无法解析时回退原文本或 '-'
*/
export function voucherCheckPeriodLabel(period: string | null | undefined, locale: string): string {
const match = /^(\d{4})-(\d{2})$/.exec(String(period || '').trim());
if (!match) return period || '-';
const year = Number(match[1]);
const month = Number(match[2]);
if (month < 1 || month > 12) return period || '-';
const tag = locale === 'zh-TW' ? 'zh-Hant' : locale === 'zh-CN' ? 'zh-Hans' : locale;
return new Intl.DateTimeFormat(tag, { year: 'numeric', month: 'long', calendar: 'gregory' }).format(
new Date(year, month - 1, 1),
);
}
/**
* 将批次执行模式映射为工作台文案。
* @param t - i18n 翻译函数
@@ -5,12 +5,12 @@
* 依赖:voucherCheck.api、vue-i18n、useMessage、DeleteConfirmDialog、PaginationBar、formatLocalDateTime、voucherCheck.display、auth。
* Chat 嵌入时由 VoucherCheckChatPanel 传入 embedded / activeTab。
* 逻辑:独立路由或 Chat 嵌入;进页默认上一个自然月;「最近一次检核」不跟筛选;强制重检仅 is_platform_admin,进度在本卡轮询。
* 终态用矮指标格;排队/执行中才展开进度条与当前步骤。Chat 嵌入时隐藏页头与内层 Tab。
* 终态用矮指标格;排队/执行中才展开进度条与当前步骤。技术失败原因与企微未发送原因都挂在状态旁的提示上,不单独成列。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 { ChevronDown, CircleAlert, Download, Eye, 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';
@@ -28,8 +28,8 @@ import {
type VoucherCheckRunItem,
} from '../api/voucherCheck.api';
import {
voucherCheckModeLabel,
voucherCheckNotifyStatusLabel,
voucherCheckPeriodLabel,
voucherCheckStatusLabel,
voucherCheckStepLabel,
} from '../utils/voucherCheck.display';
@@ -46,7 +46,7 @@ const emit = defineEmits<{
'open-detail': [payload: { runId: number; runNo?: string | null }];
}>();
const { t } = useI18n();
const { t, locale } = useI18n();
const msg = useMessage();
const route = useRoute();
const router = useRouter();
@@ -115,6 +115,42 @@ const latestShowFailureHint = computed(() => {
const MONTH_VALUES = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] as const;
const failureTip = ref<{ text: string; left: number; top: number } | null>(null);
/**
* 技术失败且带有批次失败原因时,才在状态旁挂提示。
* 核心逻辑:缺件、完整没有批次级失败原因;没有 error_message 的技术失败不挂空图标。
* @param row - 检核任务列表行
*/
function showRunFailureReason(row: VoucherCheckRunItem): boolean {
return row.status === 'technical_failed' && Boolean(row.error_message?.trim());
}
/**
* 在失败图标下方打开失败原因提示,避免表格滚动容器把提示裁掉。
* @param event - 悬停或聚焦事件
* @param message - 批次失败原因
*/
function openFailureTip(event: Event, message: string): void {
const target = event.currentTarget;
if (!(target instanceof HTMLElement)) return;
const rect = target.getBoundingClientRect();
const width = 280;
const left = Math.max(8, Math.min(rect.left, window.innerWidth - width - 8));
failureTip.value = {
text: message,
left,
top: rect.bottom + 6,
};
}
/**
* 关闭状态旁的失败原因提示。
*/
function closeFailureTip(): void {
failureTip.value = null;
}
/**
* 进页默认资料所属期间为上一个自然月。
*/
@@ -248,6 +284,15 @@ function notifyBadgeClass(value: string): string {
return 'bg-surface-soft text-secondary';
}
/**
* 有未发送原因时才在发送状态旁挂提示。
* 核心逻辑:已发送且无 skip_reason 不占列、不挂空图标。
* @param row - 企微发送记录
*/
function showNotifySkipReason(row: VoucherCheckNotificationItem): boolean {
return Boolean(row.skip_reason?.trim());
}
/**
* 将接收人姓名拼成展示文本。
* @param names - 系统用户姓名
@@ -532,33 +577,34 @@ onUnmounted(() => {
:class="latestInProgress ? 'bg-blue-50' : ''"
>
<div>
<h2 class="text-sm font-semibold text-primary">{{ $t('workspace.voucherCheck.latestTitle') }}</h2>
<div class="flex items-center gap-2">
<h2 class="text-sm font-semibold text-primary">{{ $t('workspace.voucherCheck.latestTitle') }}</h2>
<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>
</div>
<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>
{{ voucherCheckPeriodLabel(latestRun.period_month, locale) }}
</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"
class="inline-flex items-center gap-1 rounded-xl border border-default bg-surface px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
@click="openLatestDetail"
>
<Eye class="h-3.5 w-3.5" />
{{ $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"
class="inline-flex items-center gap-1 rounded-xl border border-default bg-surface px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft disabled:opacity-50"
:disabled="forcing || latestInProgress"
@click="openForceRecheck()"
>
@@ -683,7 +729,6 @@ onUnmounted(() => {
<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>
@@ -695,15 +740,28 @@ onUnmounted(() => {
<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 class="inline-flex items-center gap-1.5">
<span
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
:class="latestBadgeClass(row.status)"
>
{{ voucherCheckStatusLabel(t, row.status) }}
</span>
<button
v-if="showRunFailureReason(row)"
type="button"
class="inline-flex h-[22px] w-[22px] cursor-help items-center justify-center rounded-full text-rose-600 hover:bg-rose-50"
:aria-label="row.error_message || $t('workspace.voucherCheck.failureReason')"
@mouseenter="openFailureTip($event, row.error_message || '')"
@mouseleave="closeFailureTip"
@focus="openFailureTip($event, row.error_message || '')"
@blur="closeFailureTip"
>
<CircleAlert class="h-4 w-4" />
</button>
</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"
@@ -737,7 +795,6 @@ onUnmounted(() => {
<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>
@@ -752,14 +809,27 @@ onUnmounted(() => {
<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 class="inline-flex items-center gap-1.5">
<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>
<button
v-if="showNotifySkipReason(row)"
type="button"
class="inline-flex h-[22px] w-[22px] cursor-help items-center justify-center rounded-full text-rose-600 hover:bg-rose-50"
:aria-label="row.skip_reason || $t('workspace.voucherCheck.notifySkipReason')"
@mouseenter="openFailureTip($event, row.skip_reason || '')"
@mouseleave="closeFailureTip"
@focus="openFailureTip($event, row.skip_reason || '')"
@blur="closeFailureTip"
>
<CircleAlert class="h-4 w-4" />
</button>
</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">
@@ -819,6 +889,17 @@ onUnmounted(() => {
confirm-tone="primary"
@confirm="forceRecheck"
/>
<Teleport to="body">
<div
v-if="failureTip"
class="pointer-events-none fixed z-[80] max-w-[280px] whitespace-normal break-words rounded-lg bg-slate-900 px-2.5 py-1.5 text-xs leading-relaxed text-white shadow-lg"
role="tooltip"
:style="{ left: `${failureTip.left}px`, top: `${failureTip.top}px` }"
>
{{ failureTip.text }}
</div>
</Teleport>
</div>
</template>