diff --git a/pages/statistics/modules/HotlineRates/HotlineRates.js b/pages/statistics/modules/HotlineRates/HotlineRates.js index 7bc0a0e..908e1ae 100644 --- a/pages/statistics/modules/HotlineRates/HotlineRates.js +++ b/pages/statistics/modules/HotlineRates/HotlineRates.js @@ -1,21 +1,22 @@ import {event12345Rates} from "../../../../utils/statisticsApi"; -import {formatTime} from "../../../../utils/util"; -const formatDay2 = date => { - const year = date.getFullYear() - const month = date.getMonth() + 1 - const day = date.getDay() - return [year, month, day].map(formatNumber).join('-') - } - const formatDay = date => { - const year = date.getFullYear() - const month = date.getMonth() - const day = date.getDay() - return [year, month, day].map(formatNumber).join('-') - } - const formatNumber = n => { - n = n.toString() - return n[1] ? n : '0' + n - } +const formatNumber = n => (n < 10 ? '0' : '') + n; + +const formatCurrentAndLastMonthDay = () => { + const today = new Date(); + const year = today.getFullYear(); + const month = today.getMonth() + 1; + const day = today.getDate(); + + // 上个月的日期 + const lastMonthDate = new Date(year, month - 1, day); + const lastYear = lastMonthDate.getFullYear(); + const lastMonth = lastMonthDate.getMonth() + 1; + const lastDay = lastMonthDate.getDate(); + return { + currentDay: [year, month, day].map(formatNumber).join('-'), + lastMonthDay: [lastYear, lastMonth-1, lastDay].map(formatNumber).join('-'), + }; +}; Component({ properties: { curVal: { @@ -33,13 +34,11 @@ Component({ showitem: 3, }, ready() { + const { currentDay, lastMonthDay } = formatCurrentAndLastMonthDay(); this.setData({ - day: formatDay(new Date()), - }) - this.setData({ - day2: formatDay2(new Date()) + day:lastMonthDay, + day2: currentDay }) - this.getList() }, methods: {