废话不多说,从晚上摘了一个日历,修改为可预订系统 ,现在记录一下备忘,我已经把这个日历系统定制为组件,以便以后方便调用.
calendar文件夹下 的三个文件为
calendar.js
// components/calendar/calendar.js
Component({
/**
* 组件的属性列表
*/
properties: {
workDayNum: { // 激活几个工作日
type: Number,
value: 7
},
offset: { // 向后顺延几天后预定
type: Number,
value: 1
},
// holidays: { // 添加几个休息日
// type: Object,
// value: {}
// },
},
/**
* 组件的初始数据
*/
data: {
year: 0,
month: 0,
date: ['日', '一', '二', '三', '四', '五', '六'],
dateArr: [],
isToday: 0,
isTodayWeek: false,
todayIndex: 0,
},
/**
* 组件的方法列表
*/
methods: {
bookatThisDay(e){
let info=e.currentTarget.dataset;
let value=`${info.year}-${info.month}-${info.datenum}`;
let canBook=info.canbook
this.triggerEvent('bookatThisDay',{value:value,canBook:canBook});
},
calculateActiveDays(workdays){
let now =new Date();
let workdayArray=[];
//let offset=;//向前或向后错几天
let i=0;
now.setDate(now.getDate()+this.properties.offset);
for(;i<workdays;i++){
now.setDate(now.getDate()+1);
let thatday=now.getDay();
if(thatday==0 || thatday==6) {
i--;
continue;
};
let year = now.getFullYear();
let month = now.getMonth();
let day='' + year + (month + 1) + now.getDate();
workdayArray.push(day);
}
return workdayArray;
},
dateInit: function(setYear, setMonth) {
//全部时间的月份都是按0~11基准,显示月份才+1
let dateArr = []; //需要遍历的日历数组数据
let arrLen = 0; //dateArr的数组长度
let now = setYear ? new Date(setYear, setMonth) : new Date();
let year = setYear || now.getFullYear();
let nextYear = 0;
let month = setMonth || now.getMonth(); //没有+1方便后面计算当月总天数
let nextMonth =