|
|
|
@ -1,5 +1,6 @@ |
|
|
|
// components/xx-calendar/xx-calendar.js
|
|
|
|
import calendarFormatter from "./xx_calendar"; |
|
|
|
import commonApi from "../../../utils/https/common" |
|
|
|
Component({ |
|
|
|
/** |
|
|
|
* 组件的属性列表 |
|
|
|
@ -26,7 +27,10 @@ Component({ |
|
|
|
nextMonthDays: [], //下一个月
|
|
|
|
weekDay:[], //周 日期list
|
|
|
|
activeDateStr:'', // 当前日期,
|
|
|
|
currentViewType: 'week' //当前选中的是周还是月
|
|
|
|
currentViewType: 'week', //当前选中的是周还是月
|
|
|
|
holidayList:[], //节假日
|
|
|
|
holidayList2:['2024/01/01','2024/02/10','2024/04/04', '2024/05/01', '2024/06/10','2024/09/17','2024/10/01'], // 节假日()
|
|
|
|
// lisClickNext: true, // 是否可以点下一周
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
@ -40,7 +44,6 @@ Component({ |
|
|
|
/** 总方法 */ |
|
|
|
//创建日期
|
|
|
|
createDays(year, month) { |
|
|
|
|
|
|
|
if( this.data.currentViewType === "month" ) { |
|
|
|
this.getLastMonthDays(year, month) |
|
|
|
this.getNowMonthDays(year, month) |
|
|
|
@ -53,6 +56,9 @@ Component({ |
|
|
|
|
|
|
|
/** 视图收起/展开 */ |
|
|
|
toggleMode() { |
|
|
|
if ((this.data.currentViewType === 'week' && this.data.weekDay.some(s => s.year === 2025)) || (this.data.currentViewType === 'week' && this.data.weekDay.some(s => s.year === 2023))) { |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
currentViewType: this.data.currentViewType === "month" ? "week" : "month", |
|
|
|
}) |
|
|
|
@ -124,18 +130,22 @@ Component({ |
|
|
|
} |
|
|
|
// 当前月数据
|
|
|
|
let festival = calendarFormatter.getFestival(timer) // 返回当前节假日名称, 不是节日返回 '工作日'
|
|
|
|
let realDate = new Date() |
|
|
|
let realMonth = realDate.getMonth() + 1 |
|
|
|
let _time = `${years}/${+months < 10 ? '0'+months : months}/${+day2 < 10 ? '0'+day2 :day2}` |
|
|
|
console.log(this.data.holidayList2.includes(_time)) |
|
|
|
nowMonthDays.push({ |
|
|
|
date: i, //几号
|
|
|
|
week: this.data.weeksArr[new Date(year, month - 1, i).getDay()], //星期几
|
|
|
|
time, |
|
|
|
_time, |
|
|
|
color: false, |
|
|
|
day: ['工作日', '周末'].includes(festival) || festival.indexOf('补') > -1 ? newdate : festival, |
|
|
|
day: newdate, |
|
|
|
// day: ['工作日', '周末'].includes(festival) || festival.indexOf('补') > -1 || [如果有不想展示的日期,放这里].includes(timer) ? newdate : festival,
|
|
|
|
|
|
|
|
isNowMonthDay: (month == nowMonth && i == nowDay) ? "isNowMonthDay" : "", |
|
|
|
isHoliday: calendarFormatter.isHoliday(timer), // 判断是否是休息日 是的话返回true, 不是的话返回false
|
|
|
|
|
|
|
|
}); |
|
|
|
isNowMonthDay: (month == realMonth && i == nowDay) ? "isNowMonthDay" : "", |
|
|
|
isHoliday: this.data.holidayList.find(s => s.date == _time ), // 判断是否是休息日 是的话返回true, 不是的话返回false
|
|
|
|
holidayList2: this.data.holidayList2.includes(_time) |
|
|
|
}); |
|
|
|
} |
|
|
|
this.data.use_date_arr.forEach(ele => { |
|
|
|
ele = ele.replace(/\-/g, "/") |
|
|
|
@ -192,6 +202,9 @@ Component({ |
|
|
|
year = (parseInt(month) + 1) > 12 ? year + 1 : year |
|
|
|
month = (parseInt(month) + 1) > 12 ? 1 : parseInt(month) + 1 |
|
|
|
} |
|
|
|
if (year != this.data.year) { |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
year, |
|
|
|
month, |
|
|
|
@ -200,23 +213,106 @@ Component({ |
|
|
|
}) |
|
|
|
this.createDays(year, month) |
|
|
|
} else { |
|
|
|
let type = e.currentTarget.dataset.type //类型
|
|
|
|
let newActiveDateStr = this.getActiveDateStrByWeek(this.data.activeDateStr, type) |
|
|
|
let { |
|
|
|
year, |
|
|
|
month, |
|
|
|
nowDay |
|
|
|
} = this.data |
|
|
|
let type = e.currentTarget.dataset.type //类型
|
|
|
|
if ((type == 'next' && this.data.weekDay[0].year === 2025) || (type == 'prev' && this.data.weekDay[0].year === 2023)) { |
|
|
|
return |
|
|
|
} |
|
|
|
// if (type == 'next' && this.data.weekDay[0].year === 2025) {
|
|
|
|
// // debugger
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// let newActiveDateStr = this.getActiveDateStrByWeek(this.data.activeDateStr, type)
|
|
|
|
let newActiveDateStr = this.getActiveDateStrByWeek(this.data.weekDay[6].dateStr, type) |
|
|
|
// debugger
|
|
|
|
this.getWeekData(newActiveDateStr) |
|
|
|
this.setData({ |
|
|
|
activeDateStr: newActiveDateStr, |
|
|
|
}) |
|
|
|
console.log(this.data.weekDay); |
|
|
|
// this.data.lisClickNext = this.data.weekDay.every(s => s.year == 2024)
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 获取节假日
|
|
|
|
getHoliday(){ |
|
|
|
commonApi._post("pbservice/Actcalendar/getHoliday",{year:this.data.year}).then(res => { |
|
|
|
// console.log(res);
|
|
|
|
this.setData({ |
|
|
|
holidayList: res.data |
|
|
|
}) |
|
|
|
this.data.holidayList = this.data.holidayList.map(item=> { |
|
|
|
if (item.name == '清明节') { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
color:'#009EA3', |
|
|
|
background:'#DAF0EE' |
|
|
|
} |
|
|
|
}else if (item.name == '劳动节') { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
color:'#DE4126', |
|
|
|
background:'#FFECDB' |
|
|
|
} |
|
|
|
}else if (item.name == '春节') { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
color:'#D10000', |
|
|
|
background:'#FAE3E3' |
|
|
|
} |
|
|
|
}else if (item.name == '元旦') { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
color:'#EB3300', |
|
|
|
background:'#FFDED9' |
|
|
|
} |
|
|
|
}else if (item.name == '端午节') { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
color:'#0B8E3F', |
|
|
|
background:'#CEEDDB' |
|
|
|
} |
|
|
|
}else if (item.name == '国庆节') { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
color:'#D41E1E', |
|
|
|
background:'#FFE8E8' |
|
|
|
} |
|
|
|
}else if (item.name == '中秋节') { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
color:'#FF8E24', |
|
|
|
background:'#FFF3DB' |
|
|
|
} |
|
|
|
} else { |
|
|
|
return { |
|
|
|
...item, |
|
|
|
color:'#fff', |
|
|
|
background:'#fff' |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
console.log('------------------------------',this.data.holidayList); |
|
|
|
let { |
|
|
|
year, |
|
|
|
month, |
|
|
|
nowDay |
|
|
|
} = this.data |
|
|
|
this.setData({ |
|
|
|
activeDateStr: `${year}/${month}/${nowDay}` |
|
|
|
}) |
|
|
|
this.createDays(year, month, nowDay) |
|
|
|
}) |
|
|
|
}, |
|
|
|
/** 获取周视图数据 */ |
|
|
|
getWeekData(defaultDate) { |
|
|
|
/** 是否是从周一开始 */ |
|
|
|
const isStartFromMonday = this.properties.startDay === "monday" |
|
|
|
if (!defaultDate) { |
|
|
|
defaultDate = this.data.activeDateStr |
|
|
|
} |
|
|
|
} |
|
|
|
const YEAR = new Date(defaultDate).getFullYear() |
|
|
|
const MONTH = new Date(defaultDate).getMonth() + 1 |
|
|
|
const DATE = new Date(defaultDate).getDate() |
|
|
|
@ -231,7 +327,7 @@ Component({ |
|
|
|
let lastDay = new Date(YEAR, MONTH, 0) |
|
|
|
/** 当月最后一天是几号 */ |
|
|
|
let lastDate = lastDay.getDate() |
|
|
|
|
|
|
|
// debugger
|
|
|
|
var ret = [] |
|
|
|
/** 前面有几天 */ |
|
|
|
let preCount = isStartFromMonday ? WEEK - 1 : WEEK |
|
|
|
@ -272,19 +368,26 @@ Component({ |
|
|
|
month, |
|
|
|
nowDay |
|
|
|
} = this.data |
|
|
|
let realMonth =new Date().getMonth() + 1 |
|
|
|
// 当前周数据
|
|
|
|
let festival = calendarFormatter.getFestival(`${showYear}-${showMonth}-${showDate}`) // 返回当前节假日名称, 不是节日返回 '工作日'
|
|
|
|
// debugger
|
|
|
|
ret.push({ |
|
|
|
year: showYear, |
|
|
|
month: showMonth, |
|
|
|
date: showDate, |
|
|
|
calDate: date, |
|
|
|
day: ['工作日', '周末'].includes(festival) || festival.indexOf('补') > -1 ? newdate : festival, |
|
|
|
day: newdate, |
|
|
|
dateStr: `${showYear}/${showMonth}/${showDate}`, |
|
|
|
isNowMonthDay: (month == showMonth && nowDay == showDate) ? "isNowMonthDay" : "", |
|
|
|
isHoliday: calendarFormatter.isHoliday(`${showYear}-${showMonth}-${showDate}`), // 判断是否是休息日 是的话返回true, 不是的话返回false
|
|
|
|
isNowMonthDay: ( realMonth == showMonth && nowDay == showDate) ? "isNowMonthDay" : "", |
|
|
|
isHoliday: this.data.holidayList.find(s => s.date === `${showYear}/${+showMonth < 10 ? '0'+showMonth : showMonth}/${+showDate < 10 ? '0'+showDate :showDate}` ), |
|
|
|
holidayList2: this.data.holidayList2.includes(`${showYear}/${+showMonth < 10 ? '0'+showMonth : showMonth}/${+showDate < 10 ? '0'+showDate :showDate}` ) |
|
|
|
// `${showYear}/${showMonth}/${showDate}`
|
|
|
|
// isHoliday: calendarFormatter.isHoliday(`${showYear}-${showMonth}-${showDate}`), // 判断是否是休息日 是的话返回true, 不是的话返回false
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
console.log(ret); |
|
|
|
// debugger
|
|
|
|
this.setData({ |
|
|
|
weekDay: ret, |
|
|
|
year: YEAR, |
|
|
|
@ -335,8 +438,13 @@ Component({ |
|
|
|
selectDate(e){ |
|
|
|
let type = e.currentTarget.dataset.type //选择的时间类型
|
|
|
|
let index = e.currentTarget.dataset.index //选择的下标
|
|
|
|
// let date = e.currentTarget.dataset.item.time //选择的下标
|
|
|
|
let date = e.currentTarget.dataset.item.dateStr //选择的下标
|
|
|
|
let date |
|
|
|
if (this.data.currentViewType == 'week') { |
|
|
|
date = e.currentTarget.dataset.item.dateStr //选择的下标
|
|
|
|
type = 'weekDay' |
|
|
|
} else { |
|
|
|
date = e.currentTarget.dataset.item.time //选择的下标
|
|
|
|
} |
|
|
|
let selectDate = date.replace(/\//g, "-") |
|
|
|
console.log("选择的时间", selectDate) |
|
|
|
// 自定义事件,父组件调用,回调 选择的时间selectDate
|
|
|
|
@ -345,6 +453,7 @@ Component({ |
|
|
|
this.data[type]?.forEach(item => { |
|
|
|
item.isNowMonthDay = '' |
|
|
|
}) |
|
|
|
console.log(index,this.data,[type]); |
|
|
|
this.data[type]?.forEach((item, idx) => { |
|
|
|
if (index == idx) { |
|
|
|
item.isNowMonthDay = (item.time == new Date().toLocaleDateString() ? "isNowMonthDay" : "isNotNowMonthDay"); //判断当前选中的日期是否是当前时间
|
|
|
|
@ -364,15 +473,8 @@ Component({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
ready() { |
|
|
|
let { |
|
|
|
year, |
|
|
|
month, |
|
|
|
nowDay |
|
|
|
} = this.data |
|
|
|
this.setData({ |
|
|
|
activeDateStr: `${year}/${month}/${nowDay}` |
|
|
|
}) |
|
|
|
this.createDays(year, month, nowDay) |
|
|
|
this.getHoliday() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
}) |