选择周并且时间从周一开始,时间展示必须小于当前的时间 (今天周五,最后展示时间为周四)
1
<el-form-item label="周" v-show="queryParams.dateType == 1">
<el-date-picker
v-model="weeklyDate"
:picker-options="pickerOptions"
type="week"
placeholder="周"
@change="newDateWeekHandle"
style="width: 280px"
:format="startDate + ' 至 ' + endDate"
>
</el-date-picker>
</el-form-item>
2
data(){
return{
weeklyDate:'', // 选择的日期范围
startDate: '', // 当前选择的周的起始时间
endDate: '', // 当前选择的周的结束时间
pickerOptions: {
firstDayOfWeek: 1,//日期从周一开始算起,默认为周日
disabledDate(time) {
return time.getTime() >= Date.now()- 8.64e7;
}
}
}
3
/* 日期处理 */
newDateWeekHandle() {
console.log(Date.now());
const now = new Date(this.weeklyDate);
const nowTime = now.getTime();
const day = now.getDay();
const oneDayTime = 24*60*60*1000;
const mondayTime = nowTime - (day-1)*oneDayTime;
const sundayTime = nowTime + (7-day)*oneDayTime;
// console.log(sundayTime);
if(sundayTime>Date.now()){
this.sundayTime1=Date.now() - oneDayTime;
}else{
this.sundayTime1=sundayTime;
}
// console.log(this.sundayTime1);
this.startDate = moment(mondayTime).format('YYYY-MM-DD');
this.endDate = moment(this.sundayTime1).format('YYYY-MM-DD');
// console.log( this.startDate);
// console.log( this.endDate);
},