You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
3 years ago
|
import {makeAutoObservable} from "mobx"
|
||
|
import moment from "moment";
|
||
|
|
||
|
class DatePickerStore {
|
||
|
|
||
|
constructor(rootStore) {
|
||
|
this.rootStore = rootStore;
|
||
|
makeAutoObservable(this);
|
||
|
}
|
||
|
|
||
|
start_date = moment().startOf('week').subtract(7, 'days');
|
||
|
end_date = moment().endOf('week').subtract(7, 'days');
|
||
|
start_date_cp = false;
|
||
|
end_date_cp = false;
|
||
|
|
||
|
onChange_dataPicker = (dates) => {
|
||
|
this.start_date = dates[0];
|
||
|
this.end_date = dates[1];
|
||
|
}
|
||
|
|
||
|
onChange_dataPicker_cp = (dates) => {
|
||
|
if (dates) {
|
||
|
this.start_date_cp = dates[0];
|
||
|
this.end_date_cp = dates[1];
|
||
|
} else {
|
||
|
this.start_date_cp = false;
|
||
|
this.end_date_cp = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//计算上一个时间段
|
||
|
previous_date() {
|
||
|
return [moment(this.start_date).subtract(this.end_date.diff(this.start_date, 'days') + 1, 'days'), moment(this.start_date).subtract(1, 'days')];
|
||
|
}
|
||
|
|
||
|
//去年同期
|
||
|
previous_year() {
|
||
|
return [moment(this.start_date).subtract(1, 'year'), moment(this.end_date).subtract(1, 'year')];
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
export default DatePickerStore;
|
||
|
|