From 31f44095ecffab4576eff43da1f96037e4e8d0f2 Mon Sep 17 00:00:00 2001
From: qiuxiang <394405259@qq.com>
Date: Tue, 10 Nov 2026 15:31:38 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=9C=88=E5=BA=A6?=
=?UTF-8?q?=E6=9C=9F=E6=9C=AB=E4=BD=99=E9=A2=9D=E5=BA=97=E9=93=BA=E6=B1=87?=
=?UTF-8?q?=E6=80=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
在月度期末余额汇总右侧增加平台账户与店铺汇总切换;店铺视图按需并行读取 7-10 月店铺期末余额,以万元展示并提供环比;缺少期初的店铺保持为空值展示。
---
.../StoreReceivingBalanceOverview.vue | 284 +++++++++++++++++-
.../StoreReceivingBalanceOverviewTest.php | 11 +-
2 files changed, 288 insertions(+), 7 deletions(-)
diff --git a/resources/assets/js/components/business/StoreReceivingBalanceOverview.vue b/resources/assets/js/components/business/StoreReceivingBalanceOverview.vue
index 951e5d55..f2af513c 100644
--- a/resources/assets/js/components/business/StoreReceivingBalanceOverview.vue
+++ b/resources/assets/js/components/business/StoreReceivingBalanceOverview.vue
@@ -132,11 +132,30 @@
+ 2026 年 7-10 月{{ monthlyClosingView === 'store' ? '店铺' : '各平台' }}期末余额
+ · 金额单位:万元
+
+
+
+
+
+ {{ monthlyClosingStoreError }}
+
+
+
+
@@ -342,6 +406,19 @@ const dateConfig = {
onReady: (_, value, picker) => picker.calendarContainer.classList.add('overview-calendar'),
};
+const closingChange = (balances, currentMonth, previousMonth) => {
+ const current = balances[currentMonth];
+ const previous = balances[previousMonth];
+ const amount = Number.isFinite(current) && Number.isFinite(previous)
+ ? Math.round((current - previous) * 100) / 100
+ : null;
+ const rate = amount !== null && Math.abs(previous) >= 0.005
+ ? Math.round((amount / Math.abs(previous)) * 10000) / 100
+ : (amount === 0 ? 0 : null);
+
+ return { amount, rate };
+};
+
export default {
name: 'StoreReceivingBalanceOverview',
components: { flatPicker },
@@ -375,6 +452,12 @@ export default {
monthlyClosingLoading: true,
monthlyClosingError: '',
monthlyClosingRequestSerial: 0,
+ monthlyClosingView: 'platform',
+ monthlyClosingStoreLoading: false,
+ monthlyClosingStoreError: '',
+ monthlyClosingStoreLoaded: false,
+ monthlyClosingStoreRequestSerial: 0,
+ monthlyStoreMonthDetails: [],
monthlyClosing: {
months: [],
summary: {
@@ -605,6 +688,81 @@ export default {
...(Array.isArray(this.monthlyClosing.platforms) ? this.monthlyClosing.platforms : []),
];
},
+ monthlyClosingCountText() {
+ if (this.monthlyClosingView === 'platform') {
+ return `${this.monthlyClosing.summary.available_platform_count} / ${this.monthlyClosing.summary.platform_count} 个平台`;
+ }
+ if (this.monthlyClosingStoreLoading) return '正在读取店铺…';
+ if (this.monthlyClosingStoreError) return '店铺数据暂不可用';
+
+ const total = this.monthlyStoreRows.filter(row => !row.isTotal).length;
+ const incomplete = this.monthlyStoreRows.filter(row => !row.isTotal && !row.available).length;
+
+ return incomplete > 0
+ ? `${total} 个店铺 · ${incomplete} 个期初待补`
+ : `${total} 个店铺`;
+ },
+ monthlyStoreRows() {
+ const months = Array.isArray(this.monthlyClosing.months)
+ ? this.monthlyClosing.months.map(month => month.key)
+ : [];
+ const platformOrder = new Map(
+ this.monthlyClosing.platforms.map((platform, index) => [platform.slug, index]),
+ );
+ const grouped = new Map();
+
+ this.monthlyStoreMonthDetails.forEach((result) => {
+ (Array.isArray(result.details) ? result.details : []).forEach((detail) => {
+ const key = [detail.platform_slug, detail.store_name].join('|');
+ const row = grouped.get(key) || {
+ key,
+ platform_slug: detail.platform_slug,
+ platform: detail.platform,
+ store_name: detail.store_name,
+ balances: Object.fromEntries(months.map(month => [month, null])),
+ };
+ row.balances[result.month] = detail.amount === null || detail.amount === undefined
+ ? null
+ : (Number.isFinite(Number(detail.amount))
+ ? Math.round(Number(detail.amount) * 100) / 100
+ : null);
+ grouped.set(key, row);
+ });
+ });
+
+ const currentMonth = this.monthlyClosing.comparison.current;
+ const previousMonth = this.monthlyClosing.comparison.previous;
+ const rows = Array.from(grouped.values()).map(row => ({
+ ...row,
+ available: months.some(month => row.balances[month] !== null),
+ change: closingChange(row.balances, currentMonth, previousMonth),
+ }));
+ const latestMonth = months[months.length - 1];
+ rows.sort((left, right) => {
+ const leftBalance = left.balances[latestMonth];
+ const rightBalance = right.balances[latestMonth];
+
+ return (
+ (leftBalance === null ? 1 : 0) - (rightBalance === null ? 1 : 0)
+ || (leftBalance === null ? 0 : rightBalance)
+ - (leftBalance === null ? 0 : leftBalance)
+ || (platformOrder.get(left.platform_slug) ?? 99)
+ - (platformOrder.get(right.platform_slug) ?? 99)
+ || left.store_name.localeCompare(right.store_name, 'zh-CN')
+ );
+ });
+
+ if (!this.monthlyClosing.total) return rows;
+
+ return [{
+ ...this.monthlyClosing.total,
+ key: 'monthly-store-total',
+ platform: '合计',
+ store_name: `合计 · ${rows.length} 个店铺`,
+ isTotal: true,
+ available: true,
+ }, ...rows];
+ },
},
mounted() {
this.fetchOverview();
@@ -652,6 +810,9 @@ export default {
const requestId = ++this.monthlyClosingRequestSerial;
this.monthlyClosingLoading = true;
this.monthlyClosingError = '';
+ ++this.monthlyClosingStoreRequestSerial;
+ this.monthlyClosingStoreLoaded = false;
+ this.monthlyStoreMonthDetails = [];
try {
const response = await window.axios.get(`${this.apiBase}/monthly-closing`);
@@ -668,6 +829,9 @@ export default {
total: body.total || null,
platforms: Array.isArray(body.platforms) ? body.platforms : [],
};
+ if (this.monthlyClosingView === 'store') {
+ this.fetchMonthlyClosingStores();
+ }
} catch (error) {
if (requestId !== this.monthlyClosingRequestSerial) return;
this.monthlyClosingError = (error.response && error.response.data && error.response.data.message)
@@ -678,6 +842,54 @@ export default {
}
}
},
+ selectMonthlyClosingView(view) {
+ if (!['platform', 'store'].includes(view) || this.monthlyClosingView === view) return;
+ this.monthlyClosingView = view;
+ if (view === 'store' && !this.monthlyClosingStoreLoaded && !this.monthlyClosingStoreLoading) {
+ this.fetchMonthlyClosingStores();
+ }
+ },
+ async fetchMonthlyClosingStores() {
+ const months = Array.isArray(this.monthlyClosing.months) ? this.monthlyClosing.months : [];
+ if (!months.length) return;
+
+ const requestId = ++this.monthlyClosingStoreRequestSerial;
+ this.monthlyClosingStoreLoading = true;
+ this.monthlyClosingStoreError = '';
+
+ try {
+ const responses = await Promise.all(months.map((month) => {
+ const [year, monthNumber] = month.key.split('-').map(Number);
+ const lastDay = new Date(year, monthNumber, 0).getDate();
+
+ return window.axios.get(`${this.apiBase}/balance-store-detail`, {
+ params: {
+ start: `${month.key}-01`,
+ end: `${month.key}-${pad(lastDay)}`,
+ },
+ });
+ }));
+ if (requestId !== this.monthlyClosingStoreRequestSerial) return;
+
+ this.monthlyStoreMonthDetails = responses.map((response, index) => ({
+ month: months[index].key,
+ details: Array.isArray(response.data && response.data.details)
+ ? response.data.details
+ : [],
+ }));
+ this.monthlyClosingStoreLoaded = true;
+ } catch (error) {
+ if (requestId !== this.monthlyClosingStoreRequestSerial) return;
+ this.monthlyStoreMonthDetails = [];
+ this.monthlyClosingStoreLoaded = false;
+ this.monthlyClosingStoreError = (error.response && error.response.data && error.response.data.message)
+ || '店铺月度期末余额暂时无法读取,请稍后重试。';
+ } finally {
+ if (requestId === this.monthlyClosingStoreRequestSerial) {
+ this.monthlyClosingStoreLoading = false;
+ }
+ }
+ },
changeDate(field, value) {
const date = value || '';
if (this.dateRange[field] === date) return;
@@ -1255,10 +1467,55 @@ export default {
font-size: .6875rem;
font-weight: 600;
}
+.monthly-closing-head-actions {
+ display: flex;
+ flex: 0 0 auto;
+ align-items: center;
+ gap: .75rem;
+}
+.monthly-closing-view-switch {
+ display: inline-flex;
+ padding: 2px;
+ border: 1px solid #d8cdbc;
+ border-radius: .5rem;
+ background: #f7f1e5;
+}
+.monthly-closing-view-switch button {
+ height: 1.9rem;
+ padding: 0 .75rem;
+ border: 0;
+ border-radius: .38rem;
+ background: transparent;
+ color: var(--overview-muted);
+ font: 600 .6875rem/1.2 inherit;
+ white-space: nowrap;
+ cursor: pointer;
+}
+.monthly-closing-view-switch button:hover {
+ color: var(--overview-gold);
+}
+.monthly-closing-view-switch button.is-active {
+ background: #fffdf8;
+ color: var(--overview-gold);
+ box-shadow: 0 1px 2px rgba(63, 50, 29, .10);
+}
+.monthly-closing-view-switch button:focus-visible {
+ box-shadow: 0 0 0 3px rgba(138, 104, 47, .18);
+ outline: none;
+}
.monthly-closing-scroll {
overflow-x: auto;
overscroll-behavior-inline: contain;
}
+.monthly-closing-scroll.is-store {
+ max-height: 30rem;
+ overflow: auto;
+}
+.monthly-closing-scroll.is-store .monthly-closing-table thead th {
+ position: sticky;
+ z-index: 2;
+ top: 0;
+}
.monthly-closing-table {
width: 100%;
min-width: 44rem;
@@ -1267,6 +1524,9 @@ export default {
font-size: .75rem;
font-variant-numeric: tabular-nums;
}
+.monthly-closing-store-table {
+ min-width: 60rem;
+}
.monthly-closing-table th,
.monthly-closing-table td {
padding: .65rem .8rem;
@@ -1316,6 +1576,9 @@ export default {
.monthly-closing-table tbody tr.is-unavailable td {
color: #937b57;
}
+.monthly-closing-store-table .monthly-store-name {
+ min-width: 15rem;
+}
.monthly-closing-compare span,
.monthly-closing-compare small {
display: block;
@@ -1345,6 +1608,10 @@ export default {
font-size: .625rem;
}
.monthly-closing-loading,
+.monthly-closing-error {
+ min-height: 6rem;
+}
+.monthly-closing-loading,
.monthly-closing-error {
padding: 1rem;
}
@@ -1678,6 +1945,11 @@ export default {
align-items: flex-start;
flex-direction: column;
}
+ .monthly-closing-head-actions {
+ width: 100%;
+ flex-wrap: wrap;
+ justify-content: space-between;
+ }
.monthly-closing-foot {
align-items: flex-start;
flex-direction: column;
diff --git a/tests/Unit/View/StoreReceivingBalanceOverviewTest.php b/tests/Unit/View/StoreReceivingBalanceOverviewTest.php
index 79564334..101d82c9 100644
--- a/tests/Unit/View/StoreReceivingBalanceOverviewTest.php
+++ b/tests/Unit/View/StoreReceivingBalanceOverviewTest.php
@@ -74,7 +74,8 @@ class StoreReceivingBalanceOverviewTest extends TestCase
$this->assertStringContainsString('月度期末余额汇总', $source);
$this->assertStringContainsString('平台账户', $source);
$this->assertStringContainsString('monthly-closing-table', $source);
- $this->assertStringContainsString('2026 年 7-10 月各平台期末余额', $source);
+ $this->assertStringContainsString('2026 年 7-10 月', $source);
+ $this->assertStringContainsString("'各平台'", $source);
$this->assertStringContainsString('金额单位:万元', $source);
$this->assertStringContainsString('monthlyBalanceWan', $source);
$this->assertStringContainsString('signedMoneyWan', $source);
@@ -83,5 +84,13 @@ class StoreReceivingBalanceOverviewTest extends TestCase
$this->assertStringContainsString('环比口径:2026年10月期末余额 − 2026年9月期末余额', $source);
$this->assertStringContainsString('monthlyClosingRows', $source);
$this->assertStringContainsString('fetchMonthlyClosing', $source);
+ $this->assertStringContainsString('店铺汇总', $source);
+ $this->assertStringContainsString('monthly-closing-view-switch', $source);
+ $this->assertStringContainsString('selectMonthlyClosingView', $source);
+ $this->assertStringContainsString('fetchMonthlyClosingStores', $source);
+ $this->assertStringContainsString('monthlyStoreRows', $source);
+ $this->assertStringContainsString('monthly-closing-store-table', $source);
+ $this->assertStringContainsString('店铺期末余额 = 期初余额 + 收入 - 支出', $source);
+ $this->assertStringContainsString('缺少期初时显示“—”', $source);
}
}