From e2deccc65aecba88e265dc2f5199c6be4fe1a024 Mon Sep 17 00:00:00 2001 From: caojia <1301869380@qq.com> Date: Tue, 17 Nov 2026 16:46:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20=E9=99=90=E5=88=B6=E6=AF=9B?= =?UTF-8?q?=E5=88=A9=E5=88=86=E6=9E=90=E6=9F=A5=E8=AF=A2=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E4=B8=BA=E4=B8=80=E4=B8=AA=E6=9C=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bms-front/src/views/report/profit/index.vue | 37 +++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/bms-front/src/views/report/profit/index.vue b/bms-front/src/views/report/profit/index.vue index c667dcd5..b24dea25 100644 --- a/bms-front/src/views/report/profit/index.vue +++ b/bms-front/src/views/report/profit/index.vue @@ -26,7 +26,7 @@ - + { + if (!hasCompleteDateRange()) return '' + const [start, end] = dateRange.value + return end > maxEndDate(start) ? '计费日期最多查询一个月' : '' +}) const arBillStatus = ref('') const query = reactive({ customerArea: '', @@ -342,15 +347,31 @@ function createRateForm(row = {}) { } */ -function formatLocalDate(offset) { - const date = new Date() - date.setDate(date.getDate() + offset) +function formatLocalDate(date) { const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') return `${year}-${month}-${day}` } +// 次月没有对应日期时取月末,再减一天;起止日期均包含当天。 +function maxEndDate(start) { + const [year, month, day] = start.split('-').map(Number) + const lastDayOfNextMonth = new Date(year, month + 1, 0).getDate() + const limit = new Date(year, month, Math.min(day, lastDayOfNextMonth)) + limit.setDate(limit.getDate() - 1) + return formatLocalDate(limit) +} + +function defaultDateRange() { + const end = new Date() + const start = new Date(end.getFullYear(), end.getMonth(), end.getDate()) + const endText = formatLocalDate(end) + start.setDate(start.getDate() - 31) + while (maxEndDate(formatLocalDate(start)) < endText) start.setDate(start.getDate() + 1) + return [formatLocalDate(start), endText] +} + function buildQuery(paged = true) { const params = { ...query } if (arBillStatus.value) params.arBillStatus = arBillStatus.value @@ -394,6 +415,10 @@ function validateRequiredFilters(showMessage = true) { if (showMessage) ElMessage.warning('请选择完整的计费日期') return false } + if (dateRangeError.value) { + if (showMessage) ElMessage.warning(dateRangeError.value) + return false + } return true } @@ -443,7 +468,7 @@ function handleReset() { Object.keys(query).forEach(key => { query[key] = '' }) query.customerArea = customer_area.value[0]?.value ?? '' arBillStatus.value = '' - dateRange.value = [formatLocalDate(-30), formatLocalDate(0)] + dateRange.value = defaultDateRange() hasSearched.value = false clearReportResults() } From 8d45439931996a7dcba65fb29bbed4df5ba1302e Mon Sep 17 00:00:00 2001 From: caojia <1301869380@qq.com> Date: Tue, 17 Nov 2026 16:51:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:sparkles:=20=E9=99=90=E5=88=B6=E5=BA=94?= =?UTF-8?q?=E6=94=B6=E8=B4=A6=E5=8D=95=E6=AF=9B=E5=88=A9=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=B9=B6=E8=B0=83=E6=95=B4=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bms-front/src/utils/reportDateRange.js | 24 ++++ bms-front/src/views/report/arProfit/index.vue | 114 ++++++++++++------ bms-front/src/views/report/profit/index.vue | 26 +--- 3 files changed, 101 insertions(+), 63 deletions(-) create mode 100644 bms-front/src/utils/reportDateRange.js diff --git a/bms-front/src/utils/reportDateRange.js b/bms-front/src/utils/reportDateRange.js new file mode 100644 index 00000000..02e2e8d7 --- /dev/null +++ b/bms-front/src/utils/reportDateRange.js @@ -0,0 +1,24 @@ +function formatLocalDate(date) { + const year = date.getFullYear() + const month = String(date.getMonth() + 1).padStart(2, '0') + const day = String(date.getDate()).padStart(2, '0') + return `${year}-${month}-${day}` +} + +// 次月没有对应日期时取月末,再减一天;起止日期均包含当天。 +export function maxEndDate(start) { + const [year, month, day] = start.split('-').map(Number) + const lastDayOfNextMonth = new Date(year, month + 1, 0).getDate() + const limit = new Date(year, month, Math.min(day, lastDayOfNextMonth)) + limit.setDate(limit.getDate() - 1) + return formatLocalDate(limit) +} + +export function defaultDateRange() { + const end = new Date() + const start = new Date(end.getFullYear(), end.getMonth(), end.getDate()) + const endText = formatLocalDate(end) + start.setDate(start.getDate() - 31) + while (maxEndDate(formatLocalDate(start)) < endText) start.setDate(start.getDate() + 1) + return [formatLocalDate(start), endText] +} diff --git a/bms-front/src/views/report/arProfit/index.vue b/bms-front/src/views/report/arProfit/index.vue index 2eb8b23e..8480e294 100644 --- a/bms-front/src/views/report/arProfit/index.vue +++ b/bms-front/src/views/report/arProfit/index.vue @@ -1,31 +1,45 @@