This commit is contained in:
sophie committed 2026-09-07 11:13:33 +08:00
1 parent 78576f5745
commit 63b997a7e4
68 files changed
+3680 -1413

No files matched your search

@@ -1,19 +1,21 @@
<script setup lang="ts">
/**
* features/workspace/views/AccountingVoucherCheckView.vue
* 用途:立账凭证检核记录页——按月筛选最新状态与缺资料票。
* 用途:立账凭证检核任务列表——按资料所属期间查看批次统计,并可展开 invoice 明细。
* 依赖:voucherCheck.api、vue-i18n、useMessage。
* 逻辑:路由 /workspace/accounting-voucher-check;企微 textcard 也可跳转至此。
* 逻辑:路由 /workspace/accounting-voucher-check;企微汇总卡片可带 run_id 跳转批次明细;强制重检入队周批 force_all。
*/
import { computed, onMounted, ref, watch } from 'vue';
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Loader2, RefreshCw, Search } from 'lucide-vue-next';
import { Loader2, RefreshCw, RotateCcw, Search } from 'lucide-vue-next';
import { useMessage } from '@/shared/composables/useMessage';
import {
listVoucherCheckRunItems,
listVoucherCheckStates,
type VoucherCheckStateItem,
listVoucherCheckRuns,
triggerVoucherCheckForceAll,
type VoucherCheckRunInvoiceItem,
type VoucherCheckRunItem,
} from '../api/voucherCheck.api';
const { t } = useI18n();
@@ -21,47 +23,49 @@ const msg = useMessage();
const route = useRoute();
const loading = ref(false);
const items = ref<VoucherCheckStateItem[]>([]);
const forcing = ref(false);
const items = ref<VoucherCheckRunItem[]>([]);
const total = ref(0);
const page = ref(1);
const pageSize = 50;
const period = ref('');
const status = ref('');
const invoiceNo = ref('');
const runIdFilter = ref<number | null>(null);
const runItems = ref<Awaited<ReturnType<typeof listVoucherCheckRunItems>>['items']>([]);
const runItems = ref<VoucherCheckRunInvoiceItem[]>([]);
let forcePollTimer: ReturnType<typeof setInterval> | null = null;
/**
* 默认检核月份(当前自然月 YYYY-MM)。
* 默认资料所属期间为上一个自然月 YYYY-MM。
*/
function currentPeriod(): string {
function previousPeriod(): string {
const d = new Date();
d.setDate(1);
d.setMonth(d.getMonth() - 1);
const m = String(d.getMonth() + 1).padStart(2, '0');
return `${d.getFullYear()}-${m}`;
}
const statusOptions = computed(() => [
{ value: '', label: t('workspace.voucherCheck.statusAll') },
{ value: 'complete', label: t('workspace.voucherCheck.statusComplete') },
{ value: 'missing', label: t('workspace.voucherCheck.statusMissing') },
{ value: 'completed', label: t('workspace.voucherCheck.statusComplete') },
{ value: 'technical_failed', label: t('workspace.voucherCheck.statusTechError') },
]);
/**
* 加载最新状态列表。
* 加载检核任务列表。
*/
async function loadStates() {
async function loadRuns() {
loading.value = true;
try {
const data = await listVoucherCheckStates({
const data = await listVoucherCheckRuns({
period: period.value || undefined,
status: status.value || undefined,
invoice_no: invoiceNo.value || undefined,
page: page.value,
page_size: pageSize,
});
items.value = data.items || [];
total.value = data.total || 0;
if (data.period && !period.value) period.value = data.period;
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.loadFailed'));
} finally {
@@ -70,7 +74,7 @@ async function loadStates() {
}
/**
* 若 URL 带 run_id,额外加载该批次明细。
* 若 URL 带 run_id(排程批次),加载该批 invoice 明细。
*/
async function loadRunItemsIfNeeded() {
const raw = route.query.run_id;
@@ -90,10 +94,11 @@ async function loadRunItemsIfNeeded() {
}
function statusLabel(value: string) {
if (value === 'complete') return t('workspace.voucherCheck.statusComplete');
if (value === 'complete' || value === 'completed') return t('workspace.voucherCheck.statusComplete');
if (value === 'missing') return t('workspace.voucherCheck.statusMissing');
if (value === 'skipped') return t('workspace.voucherCheck.statusSkipped');
if (value === 'technical_error') return t('workspace.voucherCheck.statusTechError');
if (value === 'technical_error' || value === 'technical_failed') return t('workspace.voucherCheck.statusTechError');
if (value === 'pending') return t('workspace.voucherCheck.statusPending');
return value || '-';
}
@@ -102,11 +107,60 @@ function formatMissing(list?: Array<{ code?: string; name?: string }>) {
return list.map((x) => x.name || x.code || '').filter(Boolean).join('、');
}
async function openRunDetail(row: VoucherCheckRunItem) {
if (!row.schedule_run_id) {
msg.error(t('workspace.voucherCheck.loadFailed'));
return;
}
const scheduleRunId = row.schedule_run_id;
runIdFilter.value = scheduleRunId;
try {
const data = await listVoucherCheckRunItems(scheduleRunId, { page: 1, page_size: 100 });
runItems.value = data.items || [];
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.loadFailed'));
}
}
/**
* 停止强制重检后的列表轮询。
*/
function stopForcePoll() {
if (forcePollTimer) {
clearInterval(forcePollTimer);
forcePollTimer = null;
}
}
/**
* 入队强制重检上一个月:不跳过已归档记录,期间取执行日的上一个自然月。
*/
async function forceRecheck() {
if (forcing.value) return;
if (!window.confirm(t('workspace.voucherCheck.forceConfirm'))) return;
forcing.value = true;
try {
const data = await triggerVoucherCheckForceAll();
msg.success(t('workspace.voucherCheck.forceQueued', { runNo: data.run_no }));
await loadRuns();
stopForcePoll();
const started = Date.now();
forcePollTimer = setInterval(() => {
void loadRuns();
if (Date.now() - started > 120_000) stopForcePoll();
}, 5000);
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.forceFailed'));
} finally {
forcing.value = false;
}
}
onMounted(async () => {
period.value = currentPeriod();
period.value = previousPeriod();
const qStatus = route.query.status;
if (typeof qStatus === 'string' && qStatus) status.value = qStatus;
await Promise.all([loadStates(), loadRunItemsIfNeeded()]);
await Promise.all([loadRuns(), loadRunItemsIfNeeded()]);
});
watch(
@@ -115,6 +169,10 @@ watch(
void loadRunItemsIfNeeded();
},
);
onUnmounted(() => {
stopForcePoll();
});
</script>
<template>
@@ -135,20 +193,10 @@ watch(
<option v-for="opt in statusOptions" :key="opt.value || 'all'" :value="opt.value">{{ opt.label }}</option>
</select>
</label>
<label class="flex min-w-[12rem] flex-1 flex-col gap-1 text-xs text-slate-500">
{{ $t('workspace.voucherCheck.invoiceNo') }}
<input
v-model="invoiceNo"
type="text"
class="rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800"
:placeholder="$t('workspace.voucherCheck.invoicePlaceholder')"
@keyup.enter="page = 1; loadStates()"
/>
</label>
<button
type="button"
class="inline-flex items-center gap-1 rounded-lg bg-sky-600 px-3 py-2 text-sm font-medium text-white hover:bg-sky-700"
@click="page = 1; loadStates()"
@click="page = 1; loadRuns()"
>
<Search class="h-4 w-4" />
{{ $t('workspace.voucherCheck.search') }}
@@ -156,11 +204,21 @@ watch(
<button
type="button"
class="inline-flex items-center gap-1 rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-700 hover:bg-slate-50"
@click="loadStates()"
@click="loadRuns()"
>
<RefreshCw class="h-4 w-4" />
{{ $t('workspace.voucherCheck.refresh') }}
</button>
<button
type="button"
class="ml-auto inline-flex items-center gap-1 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-sm font-medium text-amber-900 hover:bg-amber-100 disabled:opacity-50"
:disabled="forcing"
@click="forceRecheck()"
>
<Loader2 v-if="forcing" class="h-4 w-4 animate-spin" />
<RotateCcw v-else class="h-4 w-4" />
{{ $t('workspace.voucherCheck.forceRecheck') }}
</button>
</section>
<section v-if="runIdFilter" class="rounded-xl border border-amber-200 bg-amber-50/60 p-3">
@@ -177,7 +235,7 @@ watch(
</tr>
</thead>
<tbody>
<tr v-for="row in runItems" :key="row.id" class="border-t border-amber-100">
<tr v-for="(row, idx) in runItems" :key="`${row.invoice_no}-${idx}`" class="border-t border-amber-100">
<td class="px-2 py-1.5 font-medium text-slate-800">{{ row.invoice_no }}</td>
<td class="px-2 py-1.5">{{ statusLabel(row.result) }}</td>
<td class="px-2 py-1.5 text-slate-600">{{ formatMissing(row.missing_materials) }}</td>
@@ -199,31 +257,43 @@ watch(
<table class="min-w-full text-left text-sm">
<thead class="sticky top-0 bg-slate-50 text-xs text-slate-500">
<tr>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.invoiceNo') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.invoiceDate') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.runNo') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.profile') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.period') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.subjectCount') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.missingFiles') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.missingInvoices') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.status') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.folder') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.missing') }}</th>
<th class="px-3 py-2">{{ $t('workspace.voucherCheck.checkedAt') }}</th>
<th class="px-3 py-2"></th>
</tr>
</thead>
<tbody>
<tr v-for="row in items" :key="row.id" class="border-t border-slate-100 hover:bg-slate-50/80">
<td class="px-3 py-2 font-medium text-slate-800">{{ row.invoice_no }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.invoice_date || '-' }}</td>
<td class="px-3 py-2 font-medium text-slate-800">{{ row.run_no }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.profile_code }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.period_month || '-' }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.subject_count }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.missing_file_count }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.missing_invoice_count }}</td>
<td class="px-3 py-2">
<span
class="inline-flex rounded-full px-2 py-0.5 text-xs font-medium"
:class="row.status === 'complete' ? 'bg-emerald-50 text-emerald-700' : 'bg-rose-50 text-rose-700'"
:class="row.status === 'missing' ? 'bg-rose-50 text-rose-700' : row.status === 'completed' ? 'bg-emerald-50 text-emerald-700' : 'bg-slate-100 text-slate-700'"
>
{{ statusLabel(row.status) }}
</span>
</td>
<td class="max-w-[16rem] truncate px-3 py-2 text-slate-600" :title="row.folder_path || ''">
{{ row.folder_path || '-' }}
<td class="px-3 py-2 text-slate-600">{{ row.finished_at || '-' }}</td>
<td class="px-3 py-2">
<button
type="button"
class="text-sky-700 hover:underline"
@click="openRunDetail(row)"
>
{{ $t('workspace.voucherCheck.viewDetail') }}
</button>
</td>
<td class="px-3 py-2 text-slate-600">{{ formatMissing(row.missing_materials) }}</td>
<td class="px-3 py-2 text-slate-600">{{ row.last_checked_at || '-' }}</td>
</tr>
</tbody>
</table>
@@ -235,7 +305,7 @@ watch(
type="button"
class="rounded border border-slate-200 px-2 py-1 disabled:opacity-40"
:disabled="page <= 1 || loading"
@click="page -= 1; loadStates()"
@click="page -= 1; loadRuns()"
>
{{ $t('workspace.voucherCheck.prevPage') }}
</button>
@@ -244,7 +314,7 @@ watch(
type="button"
class="rounded border border-slate-200 px-2 py-1 disabled:opacity-40"
:disabled="page * pageSize >= total || loading"
@click="page += 1; loadStates()"
@click="page += 1; loadRuns()"
>
{{ $t('workspace.voucherCheck.nextPage') }}
</button>