feat(agent): 立账凭证检核

(cherry picked from commit f9e2fb5efc1ec7bf4f6e52e08dd3591b4e77edd9)
This commit is contained in:
sophie committed 2026-08-06 10:05:46 +08:00
1 parent 9bcbf9d211
commit f615e56bb9
70 files changed
+4968 -108

No files matched your search

@@ -0,0 +1,255 @@
<script setup lang="ts">
/**
* features/workspace/views/AccountingVoucherCheckView.vue
* 用途:立账凭证检核记录页——按月筛选最新状态与缺资料票。
* 依赖:voucherCheck.api、vue-i18n、useMessage。
* 逻辑:路由 /workspace/accounting-voucher-check;企微 textcard 也可跳转至此。
*/
import { computed, onMounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Loader2, RefreshCw, Search } from 'lucide-vue-next';
import { useMessage } from '@/shared/composables/useMessage';
import {
listVoucherCheckRunItems,
listVoucherCheckStates,
type VoucherCheckStateItem,
} from '../api/voucherCheck.api';
const { t } = useI18n();
const msg = useMessage();
const route = useRoute();
const loading = ref(false);
const items = ref<VoucherCheckStateItem[]>([]);
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']>([]);
/**
* 默认检核月份(当前自然月 YYYY-MM)。
*/
function currentPeriod(): string {
const d = new Date();
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') },
]);
/**
* 加载最新状态列表。
*/
async function loadStates() {
loading.value = true;
try {
const data = await listVoucherCheckStates({
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 {
loading.value = false;
}
}
/**
* 若 URL 带 run_id,额外加载该批次明细。
*/
async function loadRunItemsIfNeeded() {
const raw = route.query.run_id;
const id = Number(Array.isArray(raw) ? raw[0] : raw);
if (!Number.isFinite(id) || id <= 0) {
runIdFilter.value = null;
runItems.value = [];
return;
}
runIdFilter.value = id;
try {
const data = await listVoucherCheckRunItems(id, { page: 1, page_size: 100 });
runItems.value = data.items || [];
} catch (e: any) {
msg.error(e?.message || t('workspace.voucherCheck.loadFailed'));
}
}
function statusLabel(value: string) {
if (value === 'complete') 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');
return value || '-';
}
function formatMissing(list?: Array<{ code?: string; name?: string }>) {
if (!list?.length) return '-';
return list.map((x) => x.name || x.code || '').filter(Boolean).join('、');
}
onMounted(async () => {
period.value = currentPeriod();
const qStatus = route.query.status;
if (typeof qStatus === 'string' && qStatus) status.value = qStatus;
await Promise.all([loadStates(), loadRunItemsIfNeeded()]);
});
watch(
() => route.query.run_id,
() => {
void loadRunItemsIfNeeded();
},
);
</script>
<template>
<div class="mx-auto flex h-full w-full max-w-6xl flex-col gap-4 p-4 md:p-6">
<header class="space-y-1">
<h1 class="text-xl font-semibold text-slate-800">{{ $t('workspace.voucherCheck.title') }}</h1>
<p class="text-sm text-slate-500">{{ $t('workspace.voucherCheck.subtitle') }}</p>
</header>
<section class="flex flex-wrap items-end gap-3 rounded-xl border border-slate-200 bg-white p-3">
<label class="flex flex-col gap-1 text-xs text-slate-500">
{{ $t('workspace.voucherCheck.period') }}
<input v-model="period" type="month" class="rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800" />
</label>
<label class="flex flex-col gap-1 text-xs text-slate-500">
{{ $t('workspace.voucherCheck.status') }}
<select v-model="status" class="rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800">
<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()"
>
<Search class="h-4 w-4" />
{{ $t('workspace.voucherCheck.search') }}
</button>
<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()"
>
<RefreshCw class="h-4 w-4" />
{{ $t('workspace.voucherCheck.refresh') }}
</button>
</section>
<section v-if="runIdFilter" class="rounded-xl border border-amber-200 bg-amber-50/60 p-3">
<h2 class="mb-2 text-sm font-semibold text-amber-900">
{{ $t('workspace.voucherCheck.runItemsTitle', { runId: runIdFilter }) }}
</h2>
<div class="overflow-x-auto">
<table class="min-w-full text-left text-sm">
<thead class="text-xs text-slate-500">
<tr>
<th class="px-2 py-1">{{ $t('workspace.voucherCheck.invoiceNo') }}</th>
<th class="px-2 py-1">{{ $t('workspace.voucherCheck.result') }}</th>
<th class="px-2 py-1">{{ $t('workspace.voucherCheck.missing') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="row in runItems" :key="row.id" 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>
</tr>
</tbody>
</table>
</div>
</section>
<section class="min-h-0 flex-1 overflow-hidden rounded-xl border border-slate-200 bg-white">
<div v-if="loading" class="flex items-center justify-center gap-2 py-16 text-sm text-slate-500">
<Loader2 class="h-4 w-4 animate-spin" />
{{ $t('workspace.voucherCheck.loading') }}
</div>
<div v-else-if="!items.length" class="py-16 text-center text-sm text-slate-500">
{{ $t('workspace.voucherCheck.empty') }}
</div>
<div v-else class="max-h-full overflow-auto">
<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.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>
</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">
<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'"
>
{{ 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>
<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>
</div>
<div class="flex items-center justify-between border-t border-slate-100 px-3 py-2 text-xs text-slate-500">
<span>{{ $t('workspace.voucherCheck.totalCount', { total }) }}</span>
<div class="flex items-center gap-2">
<button
type="button"
class="rounded border border-slate-200 px-2 py-1 disabled:opacity-40"
:disabled="page <= 1 || loading"
@click="page -= 1; loadStates()"
>
{{ $t('workspace.voucherCheck.prevPage') }}
</button>
<span>{{ page }}</span>
<button
type="button"
class="rounded border border-slate-200 px-2 py-1 disabled:opacity-40"
:disabled="page * pageSize >= total || loading"
@click="page += 1; loadStates()"
>
{{ $t('workspace.voucherCheck.nextPage') }}
</button>
</div>
</div>
</section>
</div>
</template>