微信小程序日历的预订系统

废话不多说,从晚上摘了一个日历,修改为可预订系统 ,现在记录一下备忘,我已经把这个日历系统定制为组件,以便以后方便调用.

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 =
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值