更新代码
This commit is contained in:
parent
90de7773a2
commit
47bda569f7
@ -114,29 +114,30 @@
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
dateList: [{
|
||||
date: '06-05',
|
||||
title: '周四',
|
||||
disabled: true
|
||||
}, {
|
||||
date: '06-06',
|
||||
title: '周四',
|
||||
disabled: false
|
||||
}, {
|
||||
date: '06-07',
|
||||
title: '周四',
|
||||
disabled: false
|
||||
}, {
|
||||
date: '06-08',
|
||||
title: '周四',
|
||||
disabled: false
|
||||
}, {
|
||||
date: '06-09',
|
||||
title: '周四',
|
||||
disabled: false
|
||||
}, ],
|
||||
// dateList: [{
|
||||
// date: '06-05',
|
||||
// title: '周四',
|
||||
// disabled: true
|
||||
// }, {
|
||||
// date: '06-06',
|
||||
// title: '周四',
|
||||
// disabled: false
|
||||
// }, {
|
||||
// date: '06-07',
|
||||
// title: '周四',
|
||||
// disabled: false
|
||||
// }, {
|
||||
// date: '06-08',
|
||||
// title: '周四',
|
||||
// disabled: false
|
||||
// }, {
|
||||
// date: '06-09',
|
||||
// title: '周四',
|
||||
// disabled: false
|
||||
// }, ],
|
||||
dateList:[],
|
||||
chooseDate: '06-06',
|
||||
chooseTime: '14:00',
|
||||
chooseTime: '11:00',
|
||||
timeList: [{
|
||||
time: '09:00',
|
||||
disabled: false
|
||||
@ -186,8 +187,43 @@
|
||||
},
|
||||
onShow() {
|
||||
this.initCarList()
|
||||
this.initDateList()
|
||||
},
|
||||
methods: {
|
||||
initDateList(){
|
||||
const daysOfWeek = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
||||
const currentDate = new Date();
|
||||
const weekDates = [];
|
||||
|
||||
// 获取今天是一周中的第几天,0表示周日,1表示周一,以此类推
|
||||
const todayDayOfWeek = currentDate.getDay();
|
||||
|
||||
// 计算本周的第一天(周日)
|
||||
currentDate.setDate(currentDate.getDate() - todayDayOfWeek);
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
// 格式化日期为 'MM-DD' 格式
|
||||
let dateStr = `${currentDate.getMonth() + 1}-${currentDate.getDate()}`;
|
||||
|
||||
// 获取当天的标题
|
||||
let title = daysOfWeek[currentDate.getDay()];
|
||||
|
||||
// 当天及之前的日期disabled为true,之后的日期disabled为false
|
||||
let disabled = currentDate < new Date(); // 当前日期小于等于计算日期
|
||||
|
||||
// 将日期对象添加到结果数组中
|
||||
weekDates.push({ date: dateStr, title, disabled });
|
||||
|
||||
// 移动到下一天
|
||||
currentDate.setDate(currentDate.getDate() + 1);
|
||||
}
|
||||
|
||||
// 单独拿出当天的日期信息
|
||||
this.chooseDate = weekDates.find(day => day.disabled === false).date;
|
||||
|
||||
|
||||
this.dateList = weekDates;
|
||||
},
|
||||
chooseTimeFun(time) {
|
||||
if (time.disabled) {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user