fix: 店铺下钻仅在管理费用弹窗生效

This commit is contained in:
yueyang 2026-11-03 13:22:00 +08:00
parent 817e6cbf17
commit aaa2f0d001
4 changed files with 62 additions and 27 deletions

View File

@ -136,8 +136,19 @@ class ManagementExpensesPageData
public function storeSummary(Request $request): array
{
$filters = $this->filters($request);
$storeName = mb_substr(trim((string) $request->query('store_name', '')), 0, 500);
$storeExpression = "COALESCE(NULLIF(d.store_name, ''), '未填写店铺')";
$rows = $this->baseQuery($filters)
$query = $this->baseQuery($filters);
if ($storeName !== '') {
if ($storeName === '未填写店铺') {
$query->where(function (Builder $blankStore): void {
$blankStore->whereNull('d.store_name')->orWhere('d.store_name', '');
});
} else {
$query->where('d.store_name', $storeName);
}
}
$rows = $query
->selectRaw("{$storeExpression} AS store_name")
->selectRaw($this->amountSplitExpression())
->groupByRaw($storeExpression)

View File

@ -578,16 +578,7 @@
<td class="num">{{ $wan($summaryRow['in_fee_ratio_amount']) }}</td>
<td class="num">{{ $wan($summaryRow['non_fee_ratio_amount']) }}</td>
<td class="num">{{ $wan($summaryRow['unmapped_amount']) }}</td>
<td class="num">
<button
type="button"
class="me-open-group"
data-me-open-stores
data-category="{{ $summaryRow['expense_category'] }}"
data-second-level="{{ $summaryRow['second_level'] }}"
title="查看二级店铺金额"
>{{ $wan($summaryRow['amount_total']) }}</button>
</td>
<td class="num">{{ $wan($summaryRow['amount_total']) }}</td>
<td>
<button
type="button"
@ -901,17 +892,22 @@
? `${activeGroup.category}\u0000${activeGroup.secondLevel}\u0000${activeThird}`
: '';
const openStoreSummary = async (category, secondLevel, thirdLevel = '') => {
const openStoreSummary = async (category, secondLevel, thirdLevel = '', storeName = '') => {
if (!storeDialog) return;
storeController?.abort();
const controller = new AbortController();
storeController = controller;
storeTitle.textContent = thirdLevel
? `${category} / ${secondLevel} / ${thirdLevel}`
: `${category} / ${secondLevel}`;
storeSubtitle.textContent = thirdLevel
? '按店铺查看该三级科目的已打款金额'
: '按店铺查看该二级科目的已打款金额';
storeTitle.textContent = [
category,
secondLevel,
thirdLevel,
storeName,
].filter(Boolean).join(' / ');
storeSubtitle.textContent = storeName
? '当前审批金额对应的店铺汇总'
: thirdLevel
? '按店铺查看该三级科目的已打款金额'
: '按店铺查看该二级科目的已打款金额';
storeStatus.textContent = '正在读取店铺汇总…';
storeRows.replaceChildren();
const params = new URLSearchParams(window.location.search);
@ -924,6 +920,11 @@
} else {
params.delete('third_level');
}
if (storeName) {
params.set('store_name', storeName);
} else {
params.delete('store_name');
}
try {
const response = await fetch(storeSummaryUrl + '?' + params.toString(), {
headers: { Accept: 'application/json' },
@ -1066,7 +1067,24 @@
values.forEach((value, index) => {
const td = document.createElement('td');
if (index === 7) td.className = 'num';
td.textContent = value;
if (index === 7) {
const button = document.createElement('button');
button.type = 'button';
button.className = 'me-open-group';
button.title = '查看该笔明细对应店铺金额';
button.textContent = value;
button.addEventListener('click', () => {
openStoreSummary(
activeGroup.category,
activeGroup.secondLevel,
activeThird,
row.store_name || '未填写店铺',
);
});
td.appendChild(button);
} else {
td.textContent = value;
}
tr.appendChild(td);
});
detailRows.appendChild(tr);
@ -1160,13 +1178,6 @@
const secondLevelRows = @json($secondLevelSummary, JSON_UNESCAPED_UNICODE);
document.querySelectorAll('[data-me-open-stores]').forEach((button) => {
button.addEventListener('click', () => openStoreSummary(
button.dataset.category,
button.dataset.secondLevel,
));
});
dialog.querySelectorAll('[data-me-tab]').forEach((tab) => {
tab.addEventListener('click', () => {
setTab(tab.dataset.meTab);

View File

@ -99,8 +99,8 @@ class ManagementExpensesPageTest extends FeatureTestCase
->assertSee('天猫-测试店')
->assertSee('202610301323000477793')
->assertSee('data-me-open-group', false)
->assertSee('data-me-open-stores', false)
->assertSee('management-expenses-store-dialog', false)
->assertDontSee('data-me-open-stores', false)
->assertSee('detailsLoadedKey', false)
->assertSee('dialogBody.scrollTop = 0', false)
->assertDontSee('OA 已付款明细模板')

View File

@ -131,6 +131,19 @@ class ManagementExpensesPageDataTest extends TestCase
],
$data['rows'],
);
$filtered = $this->pageData->storeSummary(Request::create(
'/1/workspace/financial-operations/management-expenses/store-summary',
'GET',
[
'expense_category' => '管理费用',
'second_level' => '办公费',
'paid_month' => '2026-10',
'store_name' => '京东-办公店',
],
));
$this->assertSame(20.0, $filtered['total']);
$this->assertSame('京东-办公店', $filtered['rows'][0]['store_name']);
}
public function test_unmapped_account_is_visible_instead_of_being_silently_dropped(): void