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 @@