Merge branch 'fix-contract' into dev
This commit is contained in:
commit
d13c881efb
26 files changed
+1599
-117
No files matched your search
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* 合同付款预警 API 类型与请求封装。
|
||||
* 依赖:统一 requestJson;后端 /api/contract-payment。
|
||||
* 逻辑:台账/合同详情查询、汇总卡统计、待发送摘要、每日扫描入队、周五汇总入队及批次附件下载。
|
||||
* 逻辑:台账/合同详情查询、汇总卡统计、待发送摘要、每日扫描入队、周五汇总入队、批次附件下载、失败原因及后台任务状态。
|
||||
*/
|
||||
import { requestBlob, requestJson } from '@/shared/api/client';
|
||||
|
||||
@@ -28,7 +28,8 @@ export interface LedgerSummary {
|
||||
active: number;
|
||||
due_this_month: number;
|
||||
}
|
||||
export interface AlertBatch { id: number; batch_no: string; week_key: string; status: string; summary?: { total?: number; stages?: Record<string, number> }; excel_file_name?: string | null; excel_file_size?: number | null; sent_at?: string | null; }
|
||||
export interface AlertBatchFailureReason { code: string; detail?: string | null; }
|
||||
export interface AlertBatch { id: number; batch_no: string; week_key: string; status: string; summary?: { total?: number; stages?: Record<string, number> }; excel_file_name?: string | null; excel_file_size?: number | null; sent_at?: string | null; created_at?: string | null; failure_reasons?: AlertBatchFailureReason[]; }
|
||||
export interface AlertSummary { pending_count: number; next_send_at?: string | null; timezone?: string | null; }
|
||||
|
||||
/**
|
||||
@@ -37,7 +38,7 @@ export interface AlertSummary { pending_count: number; next_send_at?: string | n
|
||||
* @param params.keyword - 模糊检索词,可为空。
|
||||
* @param params.parse_status - 解析状态精确筛选。
|
||||
* @param params.reviewOnly - 为 true 时只查 needs_review。
|
||||
* @param params.focus - 汇总卡口径:即将到期 / 逾期未付 / 进行中 / 本月应付。
|
||||
* @param params.focus - 汇总卡口径:即将到期 / 逾期未付 / 未到期 / 本月应付。
|
||||
* @returns 分页后的合同列表。
|
||||
*/
|
||||
export const listContractPaymentContracts = (params?: { keyword?: string; parse_status?: string; reviewOnly?: boolean; focus?: LedgerFocus; page?: number; pageSize?: number }) => {
|
||||
@@ -55,7 +56,16 @@ export const enqueueContractPaymentSync = (force = false) => requestJson<{ job_i
|
||||
/** 提交存量合同批量重解析,直接使用已归档附件刷新历史解析结果。 */
|
||||
export const enqueueContractPaymentReparse = () => requestJson<{ job_id: string }>('/api/contract-payment/sync', { method: 'POST', body: JSON.stringify({ reparse_existing: true }) });
|
||||
export const enqueueContractPaymentAlertScan = () => requestJson<{ job_id: string }>('/api/contract-payment/alerts/run', { method: 'POST' });
|
||||
export const enqueueContractPaymentWeeklyAlert = () => requestJson<{ job_id: string }>('/api/contract-payment/alerts/weekly-run', { method: 'POST' });
|
||||
export const enqueueContractPaymentWeeklyAlert = () => requestJson<{ job_id: number }>('/api/contract-payment/alerts/weekly-run', { method: 'POST' });
|
||||
export interface ContractPaymentJobResult { batches?: number; sent?: number; failed?: number; alerts?: number; }
|
||||
export interface ContractPaymentJob { id: number; status: string; message?: string | null; result?: ContractPaymentJobResult | null; }
|
||||
/**
|
||||
* 查询当前管理员刚提交的合同付款后台任务。
|
||||
* 核心逻辑:发送预警只是入队,页面需轮询本接口直到 success / failed,再刷新周汇总列表。
|
||||
* @param jobId - 入队接口返回的任务主键。
|
||||
* @returns 任务状态与发送计数。
|
||||
*/
|
||||
export const getContractPaymentJob = (jobId: number) => requestJson<ContractPaymentJob>(`/api/contract-payment/jobs/${jobId}`);
|
||||
/** 查询本周待发送笔数和下一次周五汇总发送时间。 */
|
||||
export const getContractPaymentAlertSummary = () => requestJson<AlertSummary>('/api/contract-payment/alerts/summary');
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
view / contractId 写入 /chat/:agentId 查询参数,旧工作台地址重定向后仍可深链打开。
|
||||
列表 Tab 内容区 overflow-hidden,把纵向滚动交给子页表格区域;Chat 顶栏仅保留标题。
|
||||
管理员顶栏顺序:同步 OA → 发送预警 → 更多;前两者常显,低频操作收进「更多」以节省小屏高度。
|
||||
发送预警结束后重新拉取周汇总批次,避免列表停在点击前的失败记录。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
@@ -37,6 +38,16 @@ const reviewCount = ref(0);
|
||||
const moreMenuOpen = ref(false);
|
||||
const moreMenuRef = ref<HTMLElement | null>(null);
|
||||
|
||||
const batchesPage = ref<{ reload: () => Promise<void> } | null>(null);
|
||||
|
||||
/**
|
||||
* 周汇总发送结束后刷新当前批次表。
|
||||
* 核心逻辑:只有停在周汇总 Tab 时组件才挂载;其它 Tab 下次进入会自行加载。
|
||||
*/
|
||||
async function reloadWeeklyBatches(): Promise<void> {
|
||||
await batchesPage.value?.reload();
|
||||
}
|
||||
|
||||
const {
|
||||
isAdmin,
|
||||
actionLoading,
|
||||
@@ -45,7 +56,7 @@ const {
|
||||
run,
|
||||
confirmForceSync,
|
||||
confirmReparseExisting,
|
||||
} = useContractPaymentAdminActions();
|
||||
} = useContractPaymentAdminActions(reloadWeeklyBatches);
|
||||
|
||||
const tabs = computed(() => ([
|
||||
{ key: 'ledger' as const, label: t('admin.contractPayment.ledger') },
|
||||
@@ -258,6 +269,7 @@ watch(
|
||||
/>
|
||||
<ContractPaymentWeeklyBatchesPage
|
||||
v-else
|
||||
ref="batchesPage"
|
||||
class="h-full min-h-0 flex-1"
|
||||
embedded
|
||||
/>
|
||||
|
||||
+62
-8
@@ -3,6 +3,7 @@
|
||||
* 用途:合同付款预警管理员异步任务(同步 / 重解析 / 扫描 / 发送)共用入口。
|
||||
* 依赖:contract-payment.api、useAuthStore、useMessage、i18n。
|
||||
* 逻辑:Chat 顶栏与旧台账页共用;非管理员直接忽略,强制覆盖和存量重解析先走确认框。
|
||||
* 发送预警会等到后台任务结束,再按 sent/failed 提示,并回调刷新周汇总列表。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -14,14 +15,37 @@ import {
|
||||
enqueueContractPaymentReparse,
|
||||
enqueueContractPaymentSync,
|
||||
enqueueContractPaymentWeeklyAlert,
|
||||
getContractPaymentJob,
|
||||
type ContractPaymentJob,
|
||||
} from '../api/contract-payment.api';
|
||||
|
||||
export type ContractPaymentAdminAction = 'sync' | 'force-sync' | 'reparse-existing' | 'scan' | 'weekly';
|
||||
|
||||
const WEEKLY_JOB_POLL_MS = 1000;
|
||||
const WEEKLY_JOB_TIMEOUT_MS = 90_000;
|
||||
const WEEKLY_JOB_DONE = new Set(['success', 'failed', 'dead', 'cancelled']);
|
||||
|
||||
/**
|
||||
* 轮询周汇总发送任务,直到进入终态或超时。
|
||||
* 核心逻辑:入队接口立即返回,真正的企微发送在 Worker 里;页面不能把「已提交」当成发送完成。
|
||||
* @param jobId - 刚入队的任务主键。
|
||||
* @returns 终态任务;超时返回 null。
|
||||
*/
|
||||
async function waitForWeeklyJob(jobId: number): Promise<ContractPaymentJob | null> {
|
||||
const deadline = Date.now() + WEEKLY_JOB_TIMEOUT_MS;
|
||||
while (Date.now() < deadline) {
|
||||
const job = await getContractPaymentJob(jobId);
|
||||
if (WEEKLY_JOB_DONE.has(job.status)) return job;
|
||||
await new Promise((resolve) => window.setTimeout(resolve, WEEKLY_JOB_POLL_MS));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供合同付款预警管理员操作状态与提交函数。
|
||||
* 核心逻辑:仅 role=admin 可提交;入队成功只提示任务已提交,不阻塞等待 Worker。
|
||||
* @param onAfterScanOrWeekly - 扫描或发送后刷新本周待发送摘要的回调
|
||||
* 核心逻辑:仅 role=admin 可提交。同步、重解析、扫描入队后即提示已提交。
|
||||
* 发送预警会等到 Worker 结束,先刷新列表,再按 sent/failed 提示。
|
||||
* @param onAfterScanOrWeekly - 扫描提交后或周汇总发送结束后刷新列表的回调
|
||||
*/
|
||||
export function useContractPaymentAdminActions(onAfterScanOrWeekly?: () => Promise<void> | void) {
|
||||
const { t } = useI18n();
|
||||
@@ -32,9 +56,36 @@ export function useContractPaymentAdminActions(onAfterScanOrWeekly?: () => Promi
|
||||
const showForceSyncConfirm = ref(false);
|
||||
const showReparseExistingConfirm = ref(false);
|
||||
|
||||
/**
|
||||
* 按周汇总任务的 sent/failed 给出结果,避免把入队成功说成已经发出。
|
||||
* 核心逻辑:全部失败用错误提示,部分失败用警告,没有待发送记录时说明列表不会变化。
|
||||
* @param job - 已结束的任务;null 表示轮询超时。
|
||||
*/
|
||||
function reportWeeklyJob(job: ContractPaymentJob | null): void {
|
||||
if (!job) {
|
||||
msg.warning(t('admin.contractPayment.weeklyJobTimeout'));
|
||||
return;
|
||||
}
|
||||
if (job.status !== 'success') {
|
||||
msg.error(job.message || t('admin.contractPayment.weeklyJobError'));
|
||||
return;
|
||||
}
|
||||
const sent = Number(job.result?.sent || 0);
|
||||
const failed = Number(job.result?.failed || 0);
|
||||
if (sent > 0 && failed > 0) {
|
||||
msg.warning(t('admin.contractPayment.weeklyJobPartial', { sent, failed }));
|
||||
} else if (failed > 0) {
|
||||
msg.error(t('admin.contractPayment.weeklyJobFailed', { failed }));
|
||||
} else if (sent > 0) {
|
||||
msg.success(t('admin.contractPayment.weeklyJobSent', { sent }));
|
||||
} else {
|
||||
msg.info(t('admin.contractPayment.weeklyJobEmpty'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交合同付款预警后台任务。
|
||||
* 核心逻辑:按操作类型调用相应异步接口;扫描和发送成功后刷新摘要。
|
||||
* 核心逻辑:同步、重解析、扫描入队后立即提示。发送预警先等到 Worker 结束,刷新批次列表,再按发送计数提示。
|
||||
*/
|
||||
async function submitAction(action: ContractPaymentAdminAction): Promise<void> {
|
||||
if (!isAdmin.value) return;
|
||||
@@ -42,16 +93,19 @@ export function useContractPaymentAdminActions(onAfterScanOrWeekly?: () => Promi
|
||||
try {
|
||||
if (action === 'sync' || action === 'force-sync') {
|
||||
await enqueueContractPaymentSync(action === 'force-sync');
|
||||
msg.success(t('admin.contractPayment.jobSubmitted'));
|
||||
} else if (action === 'reparse-existing') {
|
||||
await enqueueContractPaymentReparse();
|
||||
msg.success(t('admin.contractPayment.jobSubmitted'));
|
||||
} else if (action === 'scan') {
|
||||
await enqueueContractPaymentAlertScan();
|
||||
msg.success(t('admin.contractPayment.jobSubmitted'));
|
||||
if (onAfterScanOrWeekly) await onAfterScanOrWeekly();
|
||||
} else {
|
||||
await enqueueContractPaymentWeeklyAlert();
|
||||
}
|
||||
msg.success(t('admin.contractPayment.jobSubmitted'));
|
||||
if ((action === 'scan' || action === 'weekly') && onAfterScanOrWeekly) {
|
||||
await onAfterScanOrWeekly();
|
||||
const queued = await enqueueContractPaymentWeeklyAlert();
|
||||
const job = await waitForWeeklyJob(Number(queued.job_id));
|
||||
if (onAfterScanOrWeekly) await onAfterScanOrWeekly();
|
||||
reportWeeklyJob(job);
|
||||
}
|
||||
} catch (error) {
|
||||
msg.error(error instanceof BusinessError ? error.message : t('admin.contractPayment.actionFailed'));
|
||||
|
||||
@@ -48,13 +48,13 @@ export function nodeDueReference(node: Pick<PaymentNode, 'due_date' | 'anchor_da
|
||||
return node.due_date || node.anchor_date || null;
|
||||
}
|
||||
|
||||
/** 台账级付款状态编码:进行中 / 即将到期 / 已逾期 / 已完成 / 待补充。 */
|
||||
/** 台账级付款状态编码:未到期 / 即将到期 / 已逾期 / 已完成 / 待补充。 */
|
||||
export type ContractNodeStatusCode = 'active' | 'due' | 'overdue' | 'completed' | 'needs_completion';
|
||||
|
||||
/**
|
||||
* 按付款节点聚合出合同台账的进度/逾期状态。
|
||||
* 核心逻辑:先在合同层排除「待补充」(非激活或解析待确认);否则若存在未付且已过 due_date 的
|
||||
* 节点 → 已逾期;存在 7 天内到期 → 即将到期;仍有未付节点 → 进行中;全部节点已付 → 已完成。
|
||||
* 节点 → 已逾期;存在 7 天内到期 → 即将到期;仍有未付且付款日在 7 日外 → 未到期;全部节点已付 → 已完成。
|
||||
* @param nodes - 合同的付款节点列表。
|
||||
* @returns 台账状态编码。
|
||||
*/
|
||||
|
||||
@@ -274,11 +274,11 @@ onMounted(() => void load());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="section-gap animate-fade-in-up">
|
||||
<section class="section-gap contract-detail animate-fade-in-up">
|
||||
<header class="mb-5 flex items-start justify-between gap-3">
|
||||
<div v-if="contract" class="min-w-0">
|
||||
<h2 class="text-2xl font-bold text-primary">{{ contract.contract_no || t('admin.contractPayment.contractNoPending') }}</h2>
|
||||
<p class="mt-1 text-sm text-muted">{{ contract.supplier_name || '—' }}<span v-if="contract.purchase_order_no"> · {{ contract.purchase_order_no }}</span></p>
|
||||
<p class="mt-1 text-sm text-muted">{{ contract.supplier_name || '—' }}</p>
|
||||
</div>
|
||||
<div class="flex shrink-0 gap-2"><button class="btn-secondary-ds" :disabled="reparsing" @click="reparseContract"><RefreshCw class="h-4 w-4" :class="{ 'animate-spin': reparsing }" />{{ t('admin.contractPaymentReparse.action') }}</button><button class="btn-secondary-ds" @click="backToLedger"><ArrowLeft class="h-4 w-4" />{{ t('admin.contractPayment.backToLedger') }}</button></div>
|
||||
</header>
|
||||
@@ -353,7 +353,8 @@ onMounted(() => void load());
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.detail-summary-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; }.detail-summary-card { min-height: 82px; padding: 14px; border: 1px solid #d7e1ef; border-radius: 12px; background: #f8fbff; }.detail-summary-card span { display: block; color: #58749f; font-size: 12px; }.detail-summary-card strong { display: block; margin-top: 6px; color: #102d59; font-size: 14px; word-break: break-word; }.detail-tabs { display: flex; width: fit-content; max-width: 100%; overflow-x: auto; border: 1px solid #d7e1ef; border-radius: 999px; background: #f1f5fb; padding: 4px; }.detail-tabs button { flex: none; border-radius: 999px; padding: 8px 14px; color: #58749f; font-size: 13px; font-weight: 700; }.detail-tabs button.active { background: #fff; color: #2875d5; box-shadow: 0 1px 3px rgba(35, 68, 113, .12); }.detail-panel { border: 1px dashed #b9cbe2; border-radius: 12px; background: #fff; padding: 18px; }.detail-panel h3 { margin-bottom: 14px; color: #102d59; font-size: 16px; font-weight: 750; }.detail-description-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 28px; }.detail-description-list div { display: flex; gap: 8px; }.detail-description-list dt { color: #58749f; }.detail-description-list dd { color: #102d59; font-weight: 650; }.detail-note { margin-top: 16px; border-radius: 8px; background: #f7faff; padding: 10px 12px; color: #58749f; font-size: 13px; }.attachment-row { display: flex; align-items: center; gap: 12px; border-top: 1px solid #e4ecf6; padding: 13px 0; }.attachment-row:first-of-type { border-top: 0; }.attachment-row span { color: #58749f; font-size: 12px; }.payment-node-row { position: relative; display: flex; gap: 14px; padding: 0 0 18px 6px; }.payment-node-row::before { position: absolute; top: 18px; bottom: -2px; left: 12px; width: 2px; background: #d7e1ef; content: ''; }.payment-node-row:last-child::before { display: none; }.timeline-dot { z-index: 1; width: 14px; height: 14px; margin-top: 8px; flex: none; border-radius: 999px; background: #fff; border: 2px solid #3b82e5; }.payment-node-card { flex: 1; border: 1px solid #d7e1ef; border-radius: 12px; padding: 13px 15px; }.payment-node-card strong { color: #102d59; }.payment-node-card p { margin-top: 5px; color: #58749f; font-size: 13px; }.node-status { display: inline-flex; min-height: 22px; align-items: center; border-radius: 999px; background: #edf5ff; padding: 2px 8px; color: #2563eb; font-size: 12px; font-weight: 700; }.node-alert-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }.node-alert-list span { border-radius: 6px; background: #f7faff; padding: 4px 7px; color: #58749f; font-size: 12px; }.alert-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; border-top: 1px solid #e4ecf6; padding: 12px 0; color: #58749f; font-size: 13px; }.alert-row:first-of-type { border-top: 0; }.alert-row strong { color: #102d59; }.detail-empty { padding: 38px; color: var(--text-muted); text-align: center; } @media (max-width: 1280px) { .detail-summary-grid { grid-template-columns: repeat(3, minmax(160px, 1fr)); } } @media (max-width: 640px) { .detail-summary-grid, .detail-description-list { grid-template-columns: 1fr; }.attachment-row { align-items: flex-start; flex-wrap: wrap; }.attachment-row button { margin-left: 32px; } }
|
||||
/* 四张概要卡按详情区域宽度排:够宽时一行,窄于 640px 再折成两行。 */
|
||||
.contract-detail { container-type: inline-size; }.detail-summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }.detail-summary-card { min-width: 0; min-height: 82px; padding: 14px; border: 1px solid #d7e1ef; border-radius: 12px; background: #f8fbff; }.detail-summary-card span { display: block; color: #58749f; font-size: 12px; }.detail-summary-card strong { display: block; margin-top: 6px; color: #102d59; font-size: 14px; word-break: break-word; }.detail-tabs { display: flex; width: fit-content; max-width: 100%; overflow-x: auto; border: 1px solid #d7e1ef; border-radius: 999px; background: #f1f5fb; padding: 4px; }.detail-tabs button { flex: none; border-radius: 999px; padding: 8px 14px; color: #58749f; font-size: 13px; font-weight: 700; }.detail-tabs button.active { background: #fff; color: #2875d5; box-shadow: 0 1px 3px rgba(35, 68, 113, .12); }.detail-panel { border: 1px dashed #b9cbe2; border-radius: 12px; background: #fff; padding: 18px; }.detail-panel h3 { margin-bottom: 14px; color: #102d59; font-size: 16px; font-weight: 750; }.detail-description-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 28px; font-size: 13px; }.detail-description-list div { display: flex; gap: 8px; min-width: 0; }.detail-description-list dt { flex: none; color: #58749f; }.detail-description-list dd { min-width: 0; color: #102d59; font-weight: 650; white-space: nowrap; }.detail-note { margin-top: 16px; border-radius: 8px; background: #f7faff; padding: 10px 12px; color: #58749f; font-size: 13px; }.attachment-row { display: flex; align-items: center; gap: 12px; border-top: 1px solid #e4ecf6; padding: 13px 0; }.attachment-row:first-of-type { border-top: 0; }.attachment-row span { color: #58749f; font-size: 12px; }.payment-node-row { position: relative; display: flex; gap: 14px; padding: 0 0 18px 6px; }.payment-node-row::before { position: absolute; top: 18px; bottom: -2px; left: 12px; width: 2px; background: #d7e1ef; content: ''; }.payment-node-row:last-child::before { display: none; }.timeline-dot { z-index: 1; width: 14px; height: 14px; margin-top: 8px; flex: none; border-radius: 999px; background: #fff; border: 2px solid #3b82e5; }.payment-node-card { flex: 1; border: 1px solid #d7e1ef; border-radius: 12px; padding: 13px 15px; }.payment-node-card strong { color: #102d59; }.payment-node-card p { margin-top: 5px; color: #58749f; font-size: 13px; }.node-status { display: inline-flex; min-height: 22px; align-items: center; border-radius: 999px; background: #edf5ff; padding: 2px 8px; color: #2563eb; font-size: 12px; font-weight: 700; }.node-alert-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }.node-alert-list span { border-radius: 6px; background: #f7faff; padding: 4px 7px; color: #58749f; font-size: 12px; }.alert-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; border-top: 1px solid #e4ecf6; padding: 12px 0; color: #58749f; font-size: 13px; }.alert-row:first-of-type { border-top: 0; }.alert-row strong { color: #102d59; }.detail-empty { padding: 38px; color: var(--text-muted); text-align: center; } @container (max-width: 640px) { .detail-summary-grid, .detail-description-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } } @media (max-width: 640px) { .detail-description-list { grid-template-columns: 1fr; }.attachment-row { align-items: flex-start; flex-wrap: wrap; }.attachment-row button { margin-left: 32px; } }
|
||||
.help-label { position: relative; cursor: help; }.help-label::after { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: max-content; max-width: min(280px, 70vw); padding: 7px 9px; border-radius: 6px; background: #334155; color: #fff; content: attr(data-help); font-size: 11px; font-weight: 400; line-height: 1.45; opacity: 0; pointer-events: none; transition: opacity .15s ease; white-space: normal; }.help-label:hover::after { opacity: 1; }.detail-parse-issues { margin-top: 14px; border-radius: 8px; background: #fff7ed; padding: 10px 12px; color: #9a3412; font-size: 13px; }.detail-parse-issues strong { display: block; margin-bottom: 4px; font-weight: 700; }.detail-parse-issues ul { margin: 0; padding-left: 16px; }.detail-parse-issues li { line-height: 1.6; }
|
||||
.timeline-dot.dot-paid, .timeline-dot.dot-current { background: #16a34a; border-color: #16a34a; }.timeline-dot.dot-due { background: #ea580c; border-color: #ea580c; }.timeline-dot.dot-overdue { background: #dc2626; border-color: #dc2626; }.timeline-dot.dot-pending { background: #fff; border-color: #93a7c8; }.timeline-dot.dot-review { background: #f59e0b; border-color: #f59e0b; }.node-status.status-paid { background: #e8f7ee; color: #16a34a; }.node-status.status-current { background: #e8f7ee; color: #16a34a; }.node-status.status-due { background: #fff4e8; color: #ea580c; }.node-status.status-overdue { background: #fee2e2; color: #dc2626; }.node-status.status-pending { background: #eef3fa; color: #5c76a0; }.node-status.status-review { background: #fff7ed; color: #c2410c; }.payment-node-pay-line { margin-top: 6px; color: #102d59; font-weight: 650; }
|
||||
</style>
|
||||
@@ -42,7 +42,7 @@ const page = ref(1); const pageSize = ref(20); const total = ref(0); const pages
|
||||
const ledgerFocusCards = computed(() => ([
|
||||
{ key: 'due' as const, label: t('admin.contractPayment.ledgerFocus.due'), hint: t('admin.contractPayment.ledgerFocus.dueHint'), value: ledgerSummary.value.due, tone: 'due' },
|
||||
{ key: 'overdue' as const, label: t('admin.contractPayment.ledgerFocus.overdue'), hint: '', value: ledgerSummary.value.overdue, tone: 'overdue' },
|
||||
{ key: 'active' as const, label: t('admin.contractPayment.ledgerFocus.active'), hint: '', value: ledgerSummary.value.active, tone: 'in-progress' },
|
||||
{ key: 'active' as const, label: t('admin.contractPayment.ledgerFocus.active'), hint: t('admin.contractPayment.ledgerFocus.activeHint'), value: ledgerSummary.value.active, tone: 'in-progress' },
|
||||
{ key: 'due_this_month' as const, label: t('admin.contractPayment.ledgerFocus.dueThisMonth'), hint: t('admin.contractPayment.ledgerFocus.dueThisMonthHint'), value: ledgerSummary.value.due_this_month, tone: 'month' },
|
||||
]));
|
||||
const stage = (item: ContractPaymentContract, name: string) => item.nodes.find((node) => node.node_type === name);
|
||||
@@ -72,7 +72,7 @@ const paymentCell = (item: ContractPaymentContract, name: string) => {
|
||||
return { amountRatio, date, missingDate: !date };
|
||||
};
|
||||
/**
|
||||
* 按付款节点聚合台账状态:进行中 / 即将到期 / 已逾期 / 已完成 / 待补充。
|
||||
* 按付款节点聚合台账状态:未到期 / 即将到期 / 已逾期 / 已完成 / 待补充。
|
||||
* 核心逻辑:合同层先排除「待补充」(非激活或解析待确认);否则按节点到期/逾期状态取最高优先级展示,
|
||||
* 让台账行一眼看出是否有逾期款。 @param item - 合同台账行。 @returns 状态标签和对应的视觉色调。
|
||||
*/
|
||||
|
||||
+132
-13
@@ -1,13 +1,13 @@
|
||||
<!--
|
||||
features/contract-payment/views/ContractPaymentWeeklyBatchesPage.vue
|
||||
用途:独立展示合同付款预警的周汇总批次及其企业微信发送审计摘要,并下载 Excel 明细。
|
||||
依赖:contract-payment.api、统一消息提示。
|
||||
逻辑:后端扫描产生的批次在此集中查看;Excel 经受控接口下载;Chat 顶栏共用发送入口,本页 embedded 时隐藏页头与发送按钮。
|
||||
嵌入布局仅表格区域滚动,表头 sticky,滚动条常显。
|
||||
依赖:contract-payment.api、统一消息提示、lucide 图标。
|
||||
逻辑:后端扫描产生的批次在此集中查看;Excel 经受控接口下载;发送失败时点击图标查看原因。
|
||||
Chat 顶栏共用发送入口,本页 embedded 时隐藏页头与发送按钮。嵌入布局仅表格区域滚动,表头 sticky,滚动条常显。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { CalendarClock, Download } from 'lucide-vue-next';
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { CalendarClock, CircleAlert, Download, X } from 'lucide-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { formatLocalDateTime } from '@/shared/utils/dateTime';
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
downloadContractPaymentAlertBatchExcel,
|
||||
listContractPaymentAlertBatches,
|
||||
type AlertBatch,
|
||||
type AlertBatchFailureReason,
|
||||
} from '../api/contract-payment.api';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
@@ -27,6 +28,7 @@ const msg = useMessage();
|
||||
const batches = ref<AlertBatch[]>([]);
|
||||
const loading = ref(false);
|
||||
const downloadingId = ref<number | null>(null);
|
||||
const failureBatch = ref<AlertBatch | null>(null);
|
||||
|
||||
/**
|
||||
* 加载合同付款周汇总批次列表。
|
||||
@@ -94,16 +96,81 @@ function displayStatus(status?: string | null): string {
|
||||
|
||||
/**
|
||||
* 格式化批次发送时间为用户本地时间的 YYYY-MM-DD HH:mm:ss。
|
||||
* 核心逻辑:发送时间由后端以 UTC 存储(datetime.utcnow),需换算到浏览器时区展示;
|
||||
* 空值回退 '—',非法日期回退原值以便排障。
|
||||
* @param iso - 后端返回的 ISO 发送时间字符串。
|
||||
* @returns 本地时间文本。
|
||||
* 核心逻辑:成功与失败都展示最近一次尝试时间。历史失败批次没有 sent_at 时,回退到批次创建时间。
|
||||
* @param batch - 周汇总批次。
|
||||
* @returns 本地时间文本;两边都空时返回 '—'。
|
||||
*/
|
||||
function displaySentAt(iso?: string | null): string {
|
||||
return iso ? formatLocalDateTime(iso) : '—';
|
||||
function displaySentAt(batch: AlertBatch): string {
|
||||
const iso = batch.sent_at || batch.created_at;
|
||||
if (!iso) return '—';
|
||||
const text = formatLocalDateTime(iso);
|
||||
return text === '-' ? '—' : text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断批次是否为发送失败,用于展示失败原因图标。
|
||||
* 核心逻辑:只认后端 status=failed,大小写不敏感。
|
||||
* @param status - 批次发送状态。
|
||||
* @returns 是否展示失败原因入口。
|
||||
*/
|
||||
function isFailed(status?: string | null): boolean {
|
||||
return String(status || '').trim().toLowerCase() === 'failed';
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开指定失败批次的原因弹层。
|
||||
* 核心逻辑:原因来自列表接口的 failure_reasons,点击图标时不再额外请求。
|
||||
* @param batch - 当前失败批次。
|
||||
*/
|
||||
function openFailureReason(batch: AlertBatch): void {
|
||||
failureBatch.value = batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭失败原因弹层。
|
||||
* 核心逻辑:清空当前批次即可卸下弹层与 Esc 监听。
|
||||
*/
|
||||
function closeFailureReason(): void {
|
||||
failureBatch.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把失败原因编码翻译成当前语言的多行文本。
|
||||
* 核心逻辑:已知 code 走 i18n;有 detail 时拼到标签后;没有任何原因时展示空态文案。
|
||||
* @param batch - 当前失败批次。
|
||||
* @returns 弹层正文。
|
||||
*/
|
||||
function failureReasonText(batch: AlertBatch): string {
|
||||
const reasons = (batch.failure_reasons || []).filter((item): item is AlertBatchFailureReason => Boolean(item?.code || item?.detail));
|
||||
if (!reasons.length) return t('admin.contractPayment.batchFailureReasonEmpty');
|
||||
return reasons.map((item) => {
|
||||
const code = String(item.code || 'unknown').trim() || 'unknown';
|
||||
const key = `admin.contractPayment.batchFailureReasonCode.${code}`;
|
||||
const label = te(key) ? t(key) : t('admin.contractPayment.batchFailureReasonCode.unknown');
|
||||
const detail = String(item.detail || '').trim();
|
||||
return detail ? t('admin.contractPayment.batchFailureReasonLine', { reason: label, detail }) : label;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败原因弹层打开时按 Esc 关闭。
|
||||
* 核心逻辑:只处理 Escape,避免拦截弹层外的其它按键。
|
||||
* @param event - 窗口键盘事件。
|
||||
*/
|
||||
function onFailureKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === 'Escape') closeFailureReason();
|
||||
}
|
||||
|
||||
watch(failureBatch, (batch) => {
|
||||
if (batch) window.addEventListener('keydown', onFailureKeydown);
|
||||
else window.removeEventListener('keydown', onFailureKeydown);
|
||||
});
|
||||
|
||||
onMounted(() => void load());
|
||||
onBeforeUnmount(() => window.removeEventListener('keydown', onFailureKeydown));
|
||||
|
||||
/** 供发送预警完成后重新拉取批次,避免列表停在点击前的状态。 */
|
||||
defineExpose({ reload: load });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -129,7 +196,21 @@ onMounted(() => void load());
|
||||
<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>
|
||||
<span class="batch-status-wrap">
|
||||
<span class="batch-status" :class="{ 'is-failed': isFailed(batch.status) }">{{ displayStatus(batch.status) }}</span>
|
||||
<button
|
||||
v-if="isFailed(batch.status)"
|
||||
class="failure-reason-btn"
|
||||
type="button"
|
||||
:aria-label="t('admin.contractPayment.batchFailureReasonAria')"
|
||||
:title="t('admin.contractPayment.batchFailureReason')"
|
||||
@click.stop="openFailureReason(batch)"
|
||||
>
|
||||
<CircleAlert class="h-4 w-4" />
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ batch.summary?.total || 0 }}</td>
|
||||
<td>
|
||||
<button
|
||||
@@ -145,7 +226,7 @@ onMounted(() => void load());
|
||||
</button>
|
||||
<span v-else class="text-muted">—</span>
|
||||
</td>
|
||||
<td>{{ displaySentAt(batch.sent_at) }}</td>
|
||||
<td>{{ displaySentAt(batch) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!loading && !batches.length">
|
||||
<td colspan="6" class="weekly-batch-empty">
|
||||
@@ -156,6 +237,40 @@ onMounted(() => void load());
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="failureBatch"
|
||||
class="fixed inset-0 z-[80] flex items-center justify-center bg-slate-900/30 p-6"
|
||||
@click.self="closeFailureReason"
|
||||
>
|
||||
<div
|
||||
class="w-full max-w-[420px] rounded-2xl bg-white p-4 text-[#183c72] shadow-[0_18px_50px_rgba(15,23,42,0.18)]"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
:aria-label="t('admin.contractPayment.batchFailureReason')"
|
||||
>
|
||||
<div class="flex items-start gap-2.5">
|
||||
<CircleAlert class="mt-0.5 h-5 w-5 shrink-0 text-rose-600" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<h3 class="text-[15px] font-bold leading-snug">{{ t('admin.contractPayment.batchFailureReason') }}</h3>
|
||||
<p class="mt-0.5 break-all font-mono text-xs text-slate-500">{{ failureBatch.batch_no || '—' }}</p>
|
||||
</div>
|
||||
<button
|
||||
class="inline-flex h-7 w-7 items-center justify-center rounded-lg text-slate-500 hover:bg-slate-100 hover:text-slate-900"
|
||||
type="button"
|
||||
:aria-label="t('common.close')"
|
||||
@click="closeFailureReason"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
<p class="mt-3.5 max-h-60 overflow-auto whitespace-pre-wrap break-words rounded-xl bg-rose-50 px-3.5 py-3 text-[13px] leading-relaxed text-rose-800">
|
||||
{{ failureReasonText(failureBatch) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -179,6 +294,10 @@ onMounted(() => void load());
|
||||
.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; }
|
||||
.batch-status.is-failed { background: #fff1f2; color: #e11d48; }
|
||||
.batch-status-wrap { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.failure-reason-btn { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; margin: 0; border: 0; border-radius: 999px; background: transparent; padding: 0; color: #e11d48; cursor: pointer; }
|
||||
.failure-reason-btn:hover { background: #fff1f2; }
|
||||
.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; }
|
||||
|
||||
Reference in new issue
Block a user