fix: 管理费用明细切换即时复位 #803

Merged
yueyang merged 1 commits from fix/yueyang-management-expenses-detail-transition into main 2026-10-30 22:11:36 +08:00
2 changed files with 38 additions and 1 deletions

View File

@ -812,6 +812,7 @@
const dialog = document.getElementById('management-expenses-dialog');
if (!dialog) return;
const dialogBody = dialog.querySelector('.me-dialog__body');
const thirdLevelData = @json($thirdLevelSummary, JSON_UNESCAPED_UNICODE);
const detailColumns = @json(array_values($detailColumns), JSON_UNESCAPED_UNICODE);
const detailsUrl = @json($detailsUrl, JSON_UNESCAPED_SLASHES);
@ -828,6 +829,9 @@
let activeThird = '';
let activePage = 1;
let lastPage = 1;
let detailsLoadedKey = '';
let detailsController = null;
let detailsRequestVersion = 0;
const money = (value) => Number(value || 0).toLocaleString('zh-CN', {
minimumFractionDigits: 2,
@ -841,8 +845,13 @@
dialog.querySelectorAll('[data-me-panel]').forEach((panel) => {
panel.hidden = panel.dataset.mePanel !== name;
});
if (dialogBody) dialogBody.scrollTop = 0;
};
const detailScopeKey = () => activeGroup
? `${activeGroup.category}\u0000${activeGroup.secondLevel}\u0000${activeThird}`
: '';
const renderThirdLevels = () => {
thirdRows.replaceChildren();
if (!activeGroup) return;
@ -882,6 +891,7 @@
button.addEventListener('click', () => {
activeThird = row.third_level;
activePage = 1;
detailsLoadedKey = '';
setTab('details');
loadDetails();
});
@ -928,6 +938,12 @@
const loadDetails = async () => {
if (!activeGroup) return;
const scopeKey = detailScopeKey();
const requestVersion = ++detailsRequestVersion;
detailsController?.abort();
const controller = new AbortController();
detailsController = controller;
detailsLoadedKey = '';
detailStatus.textContent = '正在读取符合口径的 OA 审批明细…';
detailRows.replaceChildren();
const params = new URLSearchParams(window.location.search);
@ -947,10 +963,13 @@
headers: { Accept: 'application/json' },
credentials: 'same-origin',
cache: 'no-store',
signal: controller.signal,
});
if (!response.ok) throw new Error('details unavailable');
const payload = await response.json();
if (requestVersion !== detailsRequestVersion) return;
renderDetails(payload);
detailsLoadedKey = scopeKey;
lastPage = Math.max(1, Number(payload.pagination?.last_page || 1));
detailPage.textContent = `第 ${activePage} / ${lastPage} 页 · 共 ${Number(payload.pagination?.total || 0).toLocaleString('zh-CN')} 行`;
prevButton.disabled = activePage <= 1;
@ -958,10 +977,14 @@
detailStatus.textContent = activeThird === ''
? '当前二级全部已打款审批明细'
: `三级:${activeThird}`;
if (dialogBody) dialogBody.scrollTop = 0;
} catch (error) {
if (error.name === 'AbortError' || requestVersion !== detailsRequestVersion) return;
detailStatus.textContent = '明细读取失败,请稍后重试。';
prevButton.disabled = true;
nextButton.disabled = true;
} finally {
if (detailsController === controller) detailsController = null;
}
};
@ -973,6 +996,14 @@
};
activeThird = '';
activePage = 1;
detailsLoadedKey = '';
detailsRequestVersion++;
detailsController?.abort();
detailRows.replaceChildren();
detailPage.textContent = '';
detailStatus.textContent = '';
prevButton.disabled = true;
nextButton.disabled = true;
title.textContent = `${activeGroup.category} / ${activeGroup.secondLevel}`;
subtitle.textContent = '点击三级行继续查看对应已打款审批明细';
const groupRows = secondLevelRows.find((row) =>
@ -984,6 +1015,7 @@
: '';
renderThirdLevels();
setTab('third');
if (dialogBody) dialogBody.scrollTop = 0;
if (typeof dialog.showModal === 'function') dialog.showModal();
else dialog.setAttribute('open', 'open');
});
@ -994,7 +1026,8 @@
dialog.querySelectorAll('[data-me-tab]').forEach((tab) => {
tab.addEventListener('click', () => {
setTab(tab.dataset.meTab);
if (tab.dataset.meTab === 'details' && detailRows.childElementCount === 0) {
if (tab.dataset.meTab === 'details'
&& (detailsLoadedKey !== detailScopeKey() || detailRows.childElementCount === 0)) {
loadDetails();
}
});
@ -1003,12 +1036,14 @@
prevButton?.addEventListener('click', () => {
if (activePage > 1) {
activePage--;
detailsLoadedKey = '';
loadDetails();
}
});
nextButton?.addEventListener('click', () => {
if (activePage < lastPage) {
activePage++;
detailsLoadedKey = '';
loadDetails();
}
});

View File

@ -83,6 +83,8 @@ class ManagementExpensesPageTest extends FeatureTestCase
->assertSee('办公费用品')
->assertSee('202610301323000477793')
->assertSee('data-me-open-group', false)
->assertSee('detailsLoadedKey', false)
->assertSee('dialogBody.scrollTop = 0', false)
->assertDontSee('OA 已付款明细模板')
->assertDontSee('审批单 / 明细行')
->assertDontSee('<th class="num">审批单</th>', false)