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,263 @@
|
||||
<!--
|
||||
合同付款预警工作台:展示合同台账、付款阶段字段、本周待发送摘要,并提供预警任务入口。
|
||||
依赖:contract-payment.api、PaginationBar、统一消息提示;周汇总批次由独立页面展示。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { CalendarClock, RefreshCw, Search, Send } from 'lucide-vue-next';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { WORKSPACE_PATHS } from '@/features/workspace/constants/routes';
|
||||
import {
|
||||
enqueueContractPaymentAlertScan,
|
||||
enqueueContractPaymentReparse,
|
||||
enqueueContractPaymentSync,
|
||||
enqueueContractPaymentWeeklyAlert,
|
||||
getContractPaymentAlertSummary,
|
||||
listContractPaymentContracts,
|
||||
type AlertSummary,
|
||||
type ContractPaymentContract,
|
||||
} from '../api/contract-payment.api';
|
||||
import { displayCurrency } from '../utils/currency';
|
||||
import { aggregateContractNodeStatus, type ContractNodeStatusCode } from '../utils/paymentStatus';
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
const msg = useMessage(); const keyword = ref(''); const loading = ref(false); const actionLoading = ref(false);
|
||||
const showForceSyncConfirm = ref(false);
|
||||
const showReparseExistingConfirm = ref(false);
|
||||
const contracts = ref<ContractPaymentContract[]>([]);
|
||||
const alertSummary = ref<AlertSummary | null>(null);
|
||||
const page = ref(1); const pageSize = ref(20); const total = ref(0); const pages = ref(1);
|
||||
const stage = (item: ContractPaymentContract, name: string) => item.nodes.find((node) => node.node_type === name);
|
||||
/**
|
||||
* 以整数格式展示付款比例,不改变接口返回的精确比例值。
|
||||
* 核心逻辑:兼容字符串或数值;非数值保持原样,避免将异常数据错误改写为零。
|
||||
* @param percentage - 节点的原始付款比例。
|
||||
* @returns 去除无意义小数位后的比例文本。
|
||||
*/
|
||||
const displayPercentage = (percentage?: string | null): string => {
|
||||
if (percentage === undefined || percentage === null || percentage === '') return '—';
|
||||
const value = Number(percentage);
|
||||
return Number.isFinite(value) ? String(Math.round(value)) : String(percentage);
|
||||
};
|
||||
/**
|
||||
* 将付款节点拆为原型表格需要的金额比例行和日期行。
|
||||
* 核心逻辑:节点不存在时显示短横线;存在但日期未明确时仅显示“待补充日期”,避免把锚点日期误当付款日期。
|
||||
* @param item - 合同台账行。
|
||||
* @param name - 付款节点类型。
|
||||
* @returns 表格单元格展示所需的金额比例、日期及是否为待补充状态。
|
||||
*/
|
||||
const paymentCell = (item: ContractPaymentContract, name: string) => {
|
||||
const node = stage(item, name);
|
||||
if (!node) return { amountRatio: '—', date: '', missingDate: false };
|
||||
const amountRatio = node.amount || node.percentage ? `${node.amount || '—'} / ${displayPercentage(node.percentage)}%` : '—';
|
||||
const date = node.due_date || node.anchor_date || '';
|
||||
return { amountRatio, date, missingDate: !date };
|
||||
};
|
||||
/**
|
||||
* 按付款节点聚合台账状态:进行中 / 即将到期 / 已逾期 / 已完成 / 待补充。
|
||||
* 核心逻辑:合同层先排除「待补充」(非激活或解析待确认);否则按节点到期/逾期状态取最高优先级展示,
|
||||
* 让台账行一眼看出是否有逾期款。 @param item - 合同台账行。 @returns 状态标签和对应的视觉色调。
|
||||
*/
|
||||
const displayStatus = (item: ContractPaymentContract) => {
|
||||
if (item.status !== 'active' || item.parse_status === 'needs_review') {
|
||||
return { label: t('admin.contractPayment.statusNeedsCompletion'), tone: 'needs-completion' };
|
||||
}
|
||||
const code = aggregateContractNodeStatus(item.nodes || []);
|
||||
const map: Record<ContractNodeStatusCode, { label: string; tone: string }> = {
|
||||
overdue: { label: t('admin.contractPayment.statusOverdue'), tone: 'overdue' },
|
||||
due: { label: t('admin.contractPayment.statusUpcoming'), tone: 'due' },
|
||||
active: { label: t('admin.contractPayment.statusActive'), tone: 'normal' },
|
||||
completed: { label: t('admin.contractPayment.statusCompleted'), tone: 'completed' },
|
||||
needs_completion: { label: t('admin.contractPayment.statusNeedsCompletion'), tone: 'needs-completion' },
|
||||
};
|
||||
return map[code];
|
||||
};
|
||||
/**
|
||||
* 将下次发送的 UTC 时间格式化为业务时区(默认上海)的年月日时分。
|
||||
* 核心逻辑:使用接口返回的 timezone,避免浏览器本地时区把周五 18:00 显示成错误日期。
|
||||
* @param iso - 后端返回的 UTC ISO 时间。
|
||||
* @param timeZone - 业务时区名称。
|
||||
* @returns `YYYY-MM-DD HH:mm`;无法解析时回退原值。
|
||||
*/
|
||||
function formatNextSendAt(iso?: string | null, timeZone?: string | null): string {
|
||||
if (!iso) return '—';
|
||||
const date = new Date(iso);
|
||||
if (Number.isNaN(date.getTime())) return iso;
|
||||
try {
|
||||
return new Intl.DateTimeFormat('sv-SE', {
|
||||
timeZone: timeZone || 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
}).format(date).replace('T', ' ');
|
||||
} catch {
|
||||
return iso;
|
||||
}
|
||||
}
|
||||
const weeklyPendingText = computed(() => {
|
||||
if (!alertSummary.value) return '';
|
||||
const count = alertSummary.value.pending_count ?? 0;
|
||||
const datetime = formatNextSendAt(alertSummary.value.next_send_at, alertSummary.value.timezone);
|
||||
if (!alertSummary.value.next_send_at) {
|
||||
return t('admin.contractPayment.weeklyPendingCountOnly', { count });
|
||||
}
|
||||
return t('admin.contractPayment.weeklyPendingSummary', { count, datetime });
|
||||
});
|
||||
/**
|
||||
* 刷新本周待发送笔数和下一次周五发送时间。
|
||||
* 核心逻辑:与合同列表分开请求,摘要失败不阻断台账展示。
|
||||
*/
|
||||
async function refreshSummary(): Promise<void> {
|
||||
try {
|
||||
alertSummary.value = await getContractPaymentAlertSummary();
|
||||
} catch {
|
||||
if (!alertSummary.value) alertSummary.value = { pending_count: 0, next_send_at: null, timezone: 'Asia/Shanghai' };
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 加载当前页合同台账。
|
||||
* 核心逻辑:合同列表使用服务端分页;搜索和每页条数变化均从第一页开始,并并行刷新待发送摘要。
|
||||
* @param resetPage - 为 true 时重置为第一页,用于关键词查询。
|
||||
* @returns 完成后更新当前列表、分页元数据和待发送摘要。
|
||||
*/
|
||||
async function load(resetPage = false): Promise<void> {
|
||||
if (resetPage) page.value = 1;
|
||||
loading.value = true;
|
||||
try {
|
||||
const [result] = await Promise.all([
|
||||
listContractPaymentContracts({ keyword: keyword.value.trim(), page: page.value, pageSize: pageSize.value }),
|
||||
refreshSummary(),
|
||||
]);
|
||||
contracts.value = result.items || [];
|
||||
total.value = result.total || 0;
|
||||
pages.value = result.pages || 1;
|
||||
page.value = result.page || 1;
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('admin.contractPayment.loadFailed'));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 提交合同付款预警后台任务。
|
||||
* 核心逻辑:按操作类型调用相应的异步接口,任务入队成功后仅展示任务编号,不等待长耗时同步或发送完成。
|
||||
* @param action - sync 同步 OA、force-sync 强制覆盖、reparse-existing 刷新存量解析、scan 扫描预警、weekly 周汇总。
|
||||
* @returns 任务提交完成后显示成功或失败提示。
|
||||
*/
|
||||
async function submitAction(action: 'sync' | 'force-sync' | 'reparse-existing' | 'scan' | 'weekly'): Promise<void> {
|
||||
actionLoading.value = true;
|
||||
try {
|
||||
if (action === 'sync' || action === 'force-sync') {
|
||||
await enqueueContractPaymentSync(action === 'force-sync');
|
||||
} else if (action === 'reparse-existing') {
|
||||
await enqueueContractPaymentReparse();
|
||||
} else if (action === 'scan') {
|
||||
await enqueueContractPaymentAlertScan();
|
||||
} else {
|
||||
await enqueueContractPaymentWeeklyAlert();
|
||||
}
|
||||
msg.success(t('admin.contractPayment.jobSubmitted'));
|
||||
if (action === 'scan' || action === 'weekly') {
|
||||
await refreshSummary();
|
||||
}
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('admin.contractPayment.actionFailed'));
|
||||
} finally {
|
||||
actionLoading.value = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 触发任务入口;强制覆盖同步先弹出统一确认框,其余直接提交。
|
||||
* 核心逻辑:用公共确认组件替代原生 confirm,避免浏览器差异;确认后仍走统一的提交逻辑。
|
||||
* @param action - 待提交的预警任务类型。
|
||||
*/
|
||||
function run(action: 'sync' | 'force-sync' | 'reparse-existing' | 'scan' | 'weekly'): void {
|
||||
if (action === 'force-sync') {
|
||||
showForceSyncConfirm.value = true;
|
||||
return;
|
||||
}
|
||||
if (action === 'reparse-existing') {
|
||||
showReparseExistingConfirm.value = true;
|
||||
return;
|
||||
}
|
||||
void submitAction(action);
|
||||
}
|
||||
/** 强制覆盖同步确认后的提交回调。 */
|
||||
function confirmForceSync(): void {
|
||||
void submitAction('force-sync');
|
||||
}
|
||||
/** 存量合同批量重解析确认后的提交回调。 */
|
||||
function confirmReparseExisting(): void {
|
||||
void submitAction('reparse-existing');
|
||||
}
|
||||
/**
|
||||
* 进入所选合同的付款计划和预警审计详情。
|
||||
* 核心逻辑:仅使用台账已返回的内部主键构造路由,合同编号为空时仍可安全查看详情。
|
||||
* @param contractId - 合同台账主键。
|
||||
* @returns 详情路由跳转完成。
|
||||
*/
|
||||
async function openContractDetail(contractId: number): Promise<void> {
|
||||
await router.push(WORKSPACE_PATHS.contractPaymentDetail(contractId));
|
||||
}
|
||||
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.title') }}</h2><p class="text-sm text-muted mt-1">{{ t('admin.contractPayment.subtitle') }}</p></div><div class="flex gap-2"><button class="btn-secondary-ds" :disabled="actionLoading" @click="run('sync')"><RefreshCw class="w-4 h-4" />{{ t('admin.contractPayment.sync') }}</button><button class="btn-secondary-ds" :disabled="actionLoading" @click="run('force-sync')"><RefreshCw class="w-4 h-4" />{{ t('admin.contractPayment.forceSync') }}</button><button class="btn-secondary-ds" :disabled="actionLoading" @click="run('reparse-existing')"><RefreshCw class="w-4 h-4" />{{ t('admin.contractPayment.reparseExisting') }}</button><button class="btn-secondary-ds" :disabled="actionLoading" @click="run('scan')"><CalendarClock class="w-4 h-4" />{{ t('admin.contractPayment.scanAlerts') }}</button><button class="btn-primary" :disabled="actionLoading" @click="run('weekly')"><Send class="w-4 h-4" />{{ t('admin.contractPayment.weeklySend') }}</button></div></div>
|
||||
<div class="surface-panel rounded-2xl p-4 mt-5"><div class="flex flex-wrap gap-3 items-center"><div class="relative w-full md:w-[360px]"><Search class="absolute left-3 top-2.5 w-4 h-4 text-muted" /><input v-model="keyword" class="input-field pl-9" :placeholder="t('admin.contractPayment.searchPlaceholder')" @keyup.enter="load(true)" /></div><button class="btn-secondary-ds" @click="load(true)">{{ t('admin.contractPayment.search') }}</button><span v-if="weeklyPendingText" class="text-xs text-muted">{{ weeklyPendingText }}</span></div></div>
|
||||
<div class="surface-panel contract-ledger-panel mt-4 overflow-x-auto">
|
||||
<table class="contract-ledger-table text-sm">
|
||||
<thead><tr>
|
||||
<th>{{ t('admin.contractPayment.contractSupplier') }}</th><th>{{ t('admin.contractPayment.amount') }}</th>
|
||||
<th v-for="nodeType in ['prepayment', 'shipment', 'acceptance', 'warranty']" :key="nodeType"><span>{{ t(`admin.contractPayment.nodeType.${nodeType}`) }}</span><small>{{ t('admin.contractPayment.amountRatioDate') }}</small></th>
|
||||
<th>{{ t('admin.contractPayment.applicant') }}</th><th>{{ t('admin.contractPayment.statusLabel') }}</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="item in contracts" :key="item.id" class="contract-ledger-row" @click="openContractDetail(item.id)">
|
||||
<td class="contract-identify"><strong>{{ t('admin.contractPayment.contractPrefix') }}:{{ item.contract_no || t('admin.contractPayment.contractNoPending') }}</strong><span>{{ t('admin.contractPayment.workflowNo') }}:{{ item.workflow_no || '—' }}</span><span>{{ t('admin.contractPayment.purchaseOrder') }}:{{ item.purchase_order_no || '—' }}</span><span>{{ item.supplier_name || '—' }}</span></td>
|
||||
<td class="contract-money">{{ item.total_amount || '—' }}<span v-if="displayCurrency(item.currency)"> {{ displayCurrency(item.currency) }}</span></td>
|
||||
<td v-for="nodeType in ['prepayment', 'shipment', 'acceptance', 'warranty']" :key="nodeType" class="contract-payment-cell"><template v-if="paymentCell(item, nodeType).amountRatio !== '—'"><strong>{{ paymentCell(item, nodeType).amountRatio }}</strong><span :class="{ 'contract-date-pending': paymentCell(item, nodeType).missingDate }">{{ paymentCell(item, nodeType).date || t('admin.contractPayment.datePending') }}</span></template><span v-else>—</span></td>
|
||||
<td class="contract-applicant">{{ item.applicant_name || '—' }}</td>
|
||||
<td><span class="contract-status" :class="displayStatus(item).tone">{{ displayStatus(item).label }}</span></td>
|
||||
</tr>
|
||||
<tr v-if="!loading && !contracts.length"><td colspan="8" class="contract-empty">{{ t('admin.contractPayment.empty') }}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<PaginationBar v-model:page="page" v-model:page-size="pageSize" :total="total" :pages="pages" :visible="total > 0 || !!keyword.trim()" @update:page="() => load()" @update:page-size="() => load()" />
|
||||
<DeleteConfirmDialog
|
||||
v-model="showForceSyncConfirm"
|
||||
:title="t('admin.contractPayment.forceSync')"
|
||||
:message="t('admin.contractPayment.forceSyncConfirm')"
|
||||
confirm-tone="primary"
|
||||
@confirm="confirmForceSync"
|
||||
/>
|
||||
<DeleteConfirmDialog
|
||||
v-model="showReparseExistingConfirm"
|
||||
:title="t('admin.contractPayment.reparseExisting')"
|
||||
:message="t('admin.contractPayment.reparseExistingConfirm')"
|
||||
confirm-tone="primary"
|
||||
@confirm="confirmReparseExisting"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
<style scoped>
|
||||
.contract-ledger-panel { border: 1px solid #d7e1ef; border-radius: 14px; background: #fff; box-shadow: 0 6px 20px rgba(33, 65, 111, .05); }
|
||||
.contract-ledger-table { width: 100%; min-width: 1260px; border-collapse: collapse; color: #183c72; }
|
||||
.contract-ledger-table th { height: 59px; padding: 11px 12px; background: #f7faff; border-bottom: 1px solid #d7e1ef; color: #426493; font-size: 13px; font-weight: 700; line-height: 1.35; text-align: left; vertical-align: top; white-space: nowrap; }
|
||||
.contract-ledger-table th small { display: block; margin-top: 2px; font-size: 12px; font-weight: 600; }
|
||||
.contract-ledger-table td { padding: 12px; border-bottom: 1px solid #d7e1ef; vertical-align: top; line-height: 1.5; }
|
||||
.contract-ledger-table tbody tr:last-child td { border-bottom: 0; }
|
||||
.contract-ledger-table tbody tr:hover { background: #fbfdff; }.contract-ledger-row { cursor: pointer; }
|
||||
.contract-ledger-table th:nth-child(1) { width: 22%; }.contract-ledger-table th:nth-child(2) { width: 8.5%; }.contract-ledger-table th:nth-child(n+3):nth-child(-n+6) { width: 13.5%; }.contract-ledger-table th:nth-child(7) { width: 7.5%; }.contract-ledger-table th:nth-child(8) { width: 7%; }
|
||||
.contract-identify strong, .contract-payment-cell strong { display: block; color: #102d59; font-weight: 750; }.contract-identify span, .contract-payment-cell span { display: block; margin-top: 3px; color: #58749f; }.contract-identify strong { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }.contract-money { color: #102d59; white-space: nowrap; }.contract-payment-cell { color: #102d59; }.contract-date-pending { color: #5c76a0; }.contract-applicant { white-space: nowrap; color: #102d59; }.contract-status { display: inline-flex; align-items: center; min-height: 23px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }.contract-status.normal { color: #2563eb; background: #edf5ff; }.contract-status.due { color: #ea580c; background: #fff4e8; }.contract-status.overdue { color: #dc2626; background: #fee2e2; }.contract-status.completed { color: #16a34a; background: #e8f7ee; }.contract-status.needs-completion { color: #c2410c; background: #fff4e8; }.contract-empty { padding: 34px !important; color: var(--text-muted); text-align: center; }
|
||||
</style>
|
||||
Reference in new issue
Block a user