//[{monthName: '2021/12',{monthDays: [{ifDisabled: true,day: 1,optionName: '预约'}]}},{monthName: '2022/1'}]
let curDay = new Date().getDate()
let month = new Date().getMonth() + 1
let year = new Date().getFullYear()
let month1
let year1
if(month + 1 == 13){
year1 = year +1
month1 = 1
}else{
year1 = year
month1 = month + 1
}
let lastList = [{month: month,year: year},{month:month1,year: year1}]
lastList = lastList.map((item,index)=>{
let days = new Date(item.year,item.month,0).getDate()
let itemDayArr = [...Array(days)].map((k,i)=>i+1)
let curFirstDay = `${item.year}/${item.month}/${itemDayArr[0]}`
let curFiestDayWeek = new Date(curFirstDay).getDay()
let preloadArr = Array(curFiestDayWeek).fill('')
let curLastDay = `${item.year}/${item.month}/${itemDayArr[itemDayArr.length - 1]}`
let curLastDayWeek = 6 - new Date(curLastDay).getDay()
let lastArr =Array(curLastDayWeek).fill('')
itemDayArr = [...preloadArr,...itemDayArr,...lastArr]
item.myDayList = itemDayArr.map((ele,eleIndex)=>{
if(ele == ''){
ele = {
ifDisabled: true,
day: ele,
optionName: '不可预约'
}
}else{
let eleDay = `${item.year}/${item.month}/${ele}`
let eleWeek = new Date(eleDay).getDay()
if(index == 0){
if(ele <= curDay){
ele = {
ifDisabled: true,
day: ele,
optionName: '不可预约'
}
} else if(eleWeek == 0 || eleWeek == 6){
ele = {
ifDisabled: true,
day: ele,
optionName: '不可预约'
}
} else {
ele = {
ifDisabled: false,
day: ele,
optionName: '预约'
}
}
}else {
if(eleWeek == 0 || eleWeek == 6){
ele = {
ifDisabled: true,
day: ele,
optionName: '不可预约'
}
} else {
ele = {
ifDisabled: false,
day: ele,
optionName: '预约'
}
}
}
}
return ele
})
return item
})
console.log(lastList)
//获取当天
// let curDay = new Date().getDate()
//获取当月
// let month = new Date().getMonth() + 1
//获取当年
// let year = new Date().getFullYear()
// //获取该月份下共有多少天
// let days = new Date(year, month, 0).getDate()
// //天数组成数组
// let arr = [...Array(days)].map((k, i) => i + 1)
// //获取第一天日期
// let curFirstDay = `${year}/${month}/${arr[0]}`
// //获取第一天周几
// let curFirstDayWeek = new Date(curFirstDay).getDay()
// //获取天数首部需要拼接的数据
// let preloadArr = new Array(curFirstDayWeek).fill('')
// //获取最后一天日期
// let curLastDay = `${year}/${month}/${arr[arr.length-1]}`
// //获取最后一天周几
// let curLastDayWeek = 6 - new Date(curLastDay).getDay()
// //获取最后需要拼接的数据
// let lastArr = new Array(curLastDayWeek).fill('')
// arr = [...preloadArr,...arr,...lastArr]
// arr = arr.map(item=>{
// if(item == ''){
// item = {
// ifDisabled: true,
// day: item,
// optionName: '不可预约'
// }
// }else{
// let itemDay = `${year}/${month}/${item}`
// let itemWeek = new Date(itemDay).getDay()
// if(item <= curDay){
// item = {
// ifDisabled: true,
// day: item,
// optionName: '不可预约'
// }
// } else if(itemWeek == 0 || itemWeek == 6){
// item = {
// ifDisabled: true,
// day: item,
// optionName: '不可预约'
// }
// } else {
// item = {
// ifDisabled: false,
// day: item,
// optionName: '预约'
// }
// }
// }
// return item
// })
// console.log(lastArr,curLastDay,preloadArr,curFirstDayWeek, curFirstDay, arr)
console