更新代码
This commit is contained in:
parent
90de7773a2
commit
47bda569f7
@ -114,29 +114,30 @@
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
dateList: [{
|
// dateList: [{
|
||||||
date: '06-05',
|
// date: '06-05',
|
||||||
title: '周四',
|
// title: '周四',
|
||||||
disabled: true
|
// disabled: true
|
||||||
}, {
|
// }, {
|
||||||
date: '06-06',
|
// date: '06-06',
|
||||||
title: '周四',
|
// title: '周四',
|
||||||
disabled: false
|
// disabled: false
|
||||||
}, {
|
// }, {
|
||||||
date: '06-07',
|
// date: '06-07',
|
||||||
title: '周四',
|
// title: '周四',
|
||||||
disabled: false
|
// disabled: false
|
||||||
}, {
|
// }, {
|
||||||
date: '06-08',
|
// date: '06-08',
|
||||||
title: '周四',
|
// title: '周四',
|
||||||
disabled: false
|
// disabled: false
|
||||||
}, {
|
// }, {
|
||||||
date: '06-09',
|
// date: '06-09',
|
||||||
title: '周四',
|
// title: '周四',
|
||||||
disabled: false
|
// disabled: false
|
||||||
}, ],
|
// }, ],
|
||||||
|
dateList:[],
|
||||||
chooseDate: '06-06',
|
chooseDate: '06-06',
|
||||||
chooseTime: '14:00',
|
chooseTime: '11:00',
|
||||||
timeList: [{
|
timeList: [{
|
||||||
time: '09:00',
|
time: '09:00',
|
||||||
disabled: false
|
disabled: false
|
||||||
@ -186,8 +187,43 @@
|
|||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.initCarList()
|
this.initCarList()
|
||||||
|
this.initDateList()
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
chooseTimeFun(time) {
|
||||||
if (time.disabled) {
|
if (time.disabled) {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user