Browse Source

数据四率中默认上月当天到当月当天

taidong
mk 10 months ago
parent
commit
17ade4117a
  1. 43
      pages/statistics/modules/HotlineRates/HotlineRates.js

43
pages/statistics/modules/HotlineRates/HotlineRates.js

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

Loading…
Cancel
Save