feat(contract-payment): 采购合同付款预警
This commit is contained in:
1 parent
5aa431cc8e
commit
03e5e88e27
113 files changed
+11381
-2991
No files matched your search
@@ -0,0 +1,197 @@
|
||||
<!--
|
||||
features/contract-payment/views/ContractPaymentWeeklyBatchesPage.vue
|
||||
用途:独立展示合同付款预警的周汇总批次及其企业微信发送审计摘要,并下载 Excel 明细。
|
||||
依赖:contract-payment.api、统一消息提示;由工作台“合同付款预警 > 周汇总批次”路由加载。
|
||||
逻辑:后端扫描产生的批次在此集中查看;Excel 经受控接口下载,手动发送仅提交异步任务。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { CalendarClock, Download, RefreshCw, Send } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { formatLocalDateTime } from '@/shared/utils/dateTime';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
downloadContractPaymentAlertBatchExcel,
|
||||
enqueueContractPaymentWeeklyAlert,
|
||||
listContractPaymentAlertBatches,
|
||||
type AlertBatch,
|
||||
} from '../api/contract-payment.api';
|
||||
|
||||
const { t, te } = useI18n();
|
||||
const msg = useMessage();
|
||||
const batches = ref<AlertBatch[]>([]);
|
||||
const loading = ref(false);
|
||||
const actionLoading = ref(false);
|
||||
const downloadingId = ref<number | null>(null);
|
||||
|
||||
/**
|
||||
* 加载合同付款周汇总批次列表。
|
||||
* 核心逻辑:只读取后端已保存的批次和发送审计摘要;无批次时展示空状态,不由页面自行生成。
|
||||
* @returns 完成后更新批次列表和加载状态。
|
||||
*/
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await listContractPaymentAlertBatches();
|
||||
batches.value = result.items || [];
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('admin.contractPayment.weeklyBatchesLoadFailed'));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动提交本周汇总发送任务。
|
||||
* 核心逻辑:调用异步入队接口,避免浏览器等待企业微信发送和 Excel 文件生成完成。
|
||||
* @returns 提交结果通过统一消息提示反馈,成功后刷新批次列表。
|
||||
*/
|
||||
async function runWeeklyAlert(): Promise<void> {
|
||||
actionLoading.value = true;
|
||||
try {
|
||||
await enqueueContractPaymentWeeklyAlert();
|
||||
msg.success(t('admin.contractPayment.weeklyBatchSubmitted'));
|
||||
await load();
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('admin.contractPayment.actionFailed'));
|
||||
} finally {
|
||||
actionLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断批次是否已归档 Excel,供下载按钮启用。
|
||||
* 核心逻辑:文件名或大小任一存在即视为可下载;真正有无字节由下载接口校验。
|
||||
* @param batch - 周汇总批次。
|
||||
* @returns 是否展示下载入口。
|
||||
*/
|
||||
function hasExcel(batch: AlertBatch): boolean {
|
||||
return Boolean(batch.excel_file_name || batch.excel_file_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载指定周汇总批次的 Excel 明细。
|
||||
* 核心逻辑:经受控接口取 Blob 后由浏览器保存,与合同原文附件下载同一路径。
|
||||
* @param batch - 当前行的周汇总批次。
|
||||
*/
|
||||
async function downloadExcel(batch: AlertBatch): Promise<void> {
|
||||
if (!hasExcel(batch) || downloadingId.value === batch.id) return;
|
||||
downloadingId.value = batch.id;
|
||||
try {
|
||||
const { blob, filename } = await downloadContractPaymentAlertBatchExcel(batch.id);
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = objectUrl;
|
||||
anchor.download = filename || batch.excel_file_name || `contract-payment-alert-${batch.id}.xlsx`;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
document.body.removeChild(anchor);
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('admin.contractPayment.excelDownloadFailed'));
|
||||
} finally {
|
||||
downloadingId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回批次状态的本地化文本。
|
||||
* 核心逻辑:已知状态使用 i18n 翻译,服务端未来新增状态时回退展示原始值,避免列表无法展示。
|
||||
* @param status - 后端保存的批次状态。
|
||||
* @returns 本地化状态或原始状态。
|
||||
*/
|
||||
function displayStatus(status?: string | null): string {
|
||||
const normalized = String(status || '').trim().toLowerCase();
|
||||
const key = `admin.contractPayment.batchStatus.${normalized}`;
|
||||
return normalized && te(key) ? t(key) : (status || '—');
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化批次发送时间为用户本地时间的 YYYY-MM-DD HH:mm:ss。
|
||||
* 核心逻辑:发送时间由后端以 UTC 存储(datetime.utcnow),需换算到浏览器时区展示;
|
||||
* 空值回退 '—',非法日期回退原值以便排障。
|
||||
* @param iso - 后端返回的 ISO 发送时间字符串。
|
||||
* @returns 本地时间文本。
|
||||
*/
|
||||
function displaySentAt(iso?: string | null): string {
|
||||
return iso ? formatLocalDateTime(iso) : '—';
|
||||
}
|
||||
|
||||
onMounted(() => void load());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="section-gap animate-fade-in-up">
|
||||
<div class="flex flex-wrap items-start justify-between gap-4">
|
||||
<div>
|
||||
<h2 class="text-2xl font-bold text-primary">{{ t('admin.contractPayment.weeklyBatchesTitle') }}</h2>
|
||||
<p class="mt-1 text-sm text-muted">{{ t('admin.contractPayment.weeklyBatchesSubtitle') }}</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button class="btn-secondary-ds" :disabled="loading" @click="() => load()">
|
||||
<RefreshCw class="h-4 w-4" />{{ t('admin.contractPayment.refresh') }}
|
||||
</button>
|
||||
<button class="btn-primary" :disabled="actionLoading" @click="runWeeklyAlert">
|
||||
<Send class="h-4 w-4" />{{ t('admin.contractPayment.weeklySend') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="surface-panel mt-5 overflow-x-auto rounded-2xl">
|
||||
<table class="weekly-batch-table text-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ t('admin.contractPayment.batchNo') }}</th>
|
||||
<th>{{ t('admin.contractPayment.weekKey') }}</th>
|
||||
<th>{{ t('admin.contractPayment.batchStatusLabel') }}</th>
|
||||
<th>{{ t('admin.contractPayment.batchTotal') }}</th>
|
||||
<th>{{ t('admin.contractPayment.batchExcel') }}</th>
|
||||
<th>{{ t('admin.contractPayment.batchSentAt') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="batch in batches" :key="batch.id">
|
||||
<td class="font-mono font-semibold text-primary">{{ batch.batch_no || '—' }}</td>
|
||||
<td>{{ batch.week_key || '—' }}</td>
|
||||
<td><span class="batch-status">{{ displayStatus(batch.status) }}</span></td>
|
||||
<td>{{ batch.summary?.total || 0 }}</td>
|
||||
<td>
|
||||
<button
|
||||
v-if="hasExcel(batch)"
|
||||
class="excel-download"
|
||||
type="button"
|
||||
:disabled="downloadingId === batch.id"
|
||||
:title="t('admin.contractPayment.downloadExcel')"
|
||||
@click="downloadExcel(batch)"
|
||||
>
|
||||
<Download class="h-4 w-4" />
|
||||
<span class="truncate">{{ batch.excel_file_name }}</span>
|
||||
</button>
|
||||
<span v-else class="text-muted">—</span>
|
||||
</td>
|
||||
<td>{{ displaySentAt(batch.sent_at) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!loading && !batches.length">
|
||||
<td colspan="6" class="weekly-batch-empty">
|
||||
<CalendarClock class="mx-auto mb-2 h-5 w-5" />
|
||||
{{ t('admin.contractPayment.weeklyBatchesEmpty') }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.weekly-batch-table { width: 100%; min-width: 860px; border-collapse: collapse; color: #183c72; }
|
||||
.weekly-batch-table th { padding: 14px 16px; border-bottom: 1px solid #d7e1ef; background: #f7faff; color: #426493; font-size: 13px; font-weight: 700; text-align: left; white-space: nowrap; }
|
||||
.weekly-batch-table td { padding: 14px 16px; border-bottom: 1px solid #d7e1ef; vertical-align: middle; }
|
||||
.weekly-batch-table tbody tr:last-child td { border-bottom: 0; }
|
||||
.weekly-batch-table tbody tr:hover { background: #fbfdff; }
|
||||
.batch-status { display: inline-flex; min-height: 24px; align-items: center; border-radius: 999px; background: #edf5ff; padding: 2px 9px; color: #2563eb; font-size: 12px; font-weight: 700; }
|
||||
.excel-download { display: inline-flex; max-width: 360px; align-items: center; gap: 6px; color: #2563eb; font-weight: 650; }
|
||||
.excel-download:disabled { opacity: .55; }
|
||||
.weekly-batch-empty { padding: 36px !important; color: var(--text-muted); text-align: center; }
|
||||
</style>
|
||||
Reference in new issue
Block a user