js完全化日历控件,适用于周报月报或者自定义周期计划查询

页面样式
在这里插入图片描述

首先是选择一个计划,然后根据计划开始时间制定后续区段


	/**
	 * 选周期配置方法
	 */
	this.cycleAllocationSelect = function (){
		
		$m('lingan/basic/sysConstants').cycleAllocationSelect('选择周期配置','QTCL',function(data){
			debugger;
			$('[name = allocationId]').val(data.id);
			$('[name = allocationName]').val(data.cycleName);
			$('#cycleallocationName').html("当前周期配置名称:"+data.cycleName);
			startDate = data.cycleStartdate;
			cycleStartTime = data.cycleStartdate;
			var d = new Date(startDate);
			startYear = d.getFullYear();
			startMonth = d.getMonth() + 1;
			cycleNum = 1;
			cycleStatus = data.cycleStatus;
			$('[name = allocationId]').val(data.id);
			$('[name = cycleStatus]').val(cycleStatus);
			if(cycleStatus=="cycle_week"){
				var day = d.getDay();
				var sd = new Date(cycleStartTime-(day*86400000)+86400000);
				startYear = sd.getFullYear(); 
				startMonth = sd.getMonth() + 1;
				startDate = sd.getDate();
				var ed = new Date(cycleStartTime-(day*86400000)+7*86400000);
				endYear = ed.getFullYear(); 
				endMonth = ed.getMonth() + 1;
				endDate = ed.getDate();
			}else if(cycleStatus=="cycle_month"){
				var day = new Date(startYear,startMonth,0);
				startDate = 1;
				endDate = day.getDate();
				endYear = startYear; 
				endMonth = startMonth;
			}else{
				customizeDay = data.cycleDay;
				startDate = d.getDate();
				var ed = new Date(cycleStartTime+(customizeDay-1)*86400000);
				endYear = ed.getFullYear(); 
				endMonth = ed.getMonth() + 1;
				endDate = ed.getDate();
				cycleStartTime = new Date(startYear+'/'+startMonth+'/'+startDate);
			}
			$('#currentBtn').linkbutton('enable');
			$("#itemizedNameQuery").show();
			$('#downBtn').linkbutton('enable');
			$('#addBtn').linkbutton('enable');
			$('#editBtn').linkbutton('enable');
			$('#removeBtn').linkbutton('enable');
			$('#querybtn').linkbutton('enable');
			$('#resetbtn').linkbutton('enable');
			$('#morebutton').linkbutton('enable');
			$('#itemizedName').attr('disabled',false);
			$('#cycleNum').datebox({disabled:false});
			$('#currentCycle').html("当前查询周期段:"+startYear+"年"+startMonth+"月"+startDate+"日至"+endYear+"年"+endMonth+"月"+endDate+"日"+"     (第"+cycleNum+"期)");
			var model = queryForm.form('getRecord');
			model.sDate = startYear+'-'+startMonth+'-'+startDate;
			model.eDate = endYear+'-'+endMonth+'-'+endDate;
			grid.datagrid('load', model);
		});
	}

上期事件

/****
	 * 上期事件
	 */
	this.upQuery = function (){
		$('#itemizedName').val(null);
		$('#cycleNum').datebox('setValue',null);
		cycleNum = cycleNum-1;
		if(cycleNum==1){
			$('#upBtn').linkbutton('disable');
		}
		var oldsDate = new Date(startYear+'/'+startMonth+'/'+startDate);
		var oldeDate = new Date(endYear+'/'+endMonth+'/'+endDate);
		if(cycleStatus=="cycle_week"){
			var sd = new Date(oldsDate.getTime()-86400000*7); 
			var ed = new Date(oldeDate.getTime()-86400000*7); 
			startYear = sd.getFullYear(); 
			startMonth = sd.getMonth() + 1;
			startDate = sd.getDate();
			endYear = ed.getFullYear(); 
			endMonth = ed.getMonth() + 1;
			endDate = ed.getDate();
		}else if(cycleStatus=="cycle_month"){
			if(startMonth==1){
				startYear = startYear-1;
				startMonth = 12;
				startDate = 1;
				endYear = endYear-1; 
				endMonth = 12;
				endDate = 31;
			}else{ 
				startMonth = oldsDate.getMonth();
				endMonth = oldsDate.getMonth();
				var day = new Date(startYear,startMonth,0);
				endDate = day.getDate();
			}
		}else{
			var sd = new Date(oldsDate.getTime()-86400000*customizeDay); 
			var ed = new Date(oldeDate.getTime()-86400000*customizeDay); 
			startYear = sd.getFullYear(); 
			startMonth = sd.getMonth() + 1;
			startDate = sd.getDate();
			endYear = ed.getFullYear(); 
			endMonth = ed.getMonth() + 1;
			endDate = ed.getDate();
		}
		$('#currentCycle').html("当前查询周期段:"+startYear+"年"+startMonth+"月"+startDate+"日至"+endYear+"年"+endMonth+"月"+endDate+"日"+"     (第"+cycleNum+"期)");
		var model = queryForm.form('getRecord');
		model.sDate = startYear+'-'+startMonth+'-'+startDate;
		model.eDate = endYear+'-'+endMonth+'-'+endDate;
		grid.datagrid('load', model);
	}

本期事件

/****
	 * 本期事件
	 */
	this.currentQuery = function (){
		debugger;
		var d = new Date();
		if(cycleStatus=="cycle_week"){
			var day = d.getDay();
			var sd = new Date(d.getTime()-(day*86400000)+86400000);
			startYear = sd.getFullYear(); 
			startMonth = sd.getMonth() + 1;
			startDate = sd.getDate();
			var ed = new Date(d.getTime()-(day*86400000)+7*86400000);
			endYear = ed.getFullYear(); 
			endMonth = ed.getMonth() + 1;
			endDate = ed.getDate();
			cycleNum = Math.ceil((ed.getTime()-cycleStartTime)/86400000/7);
		}else if(cycleStatus=="cycle_month"){
				startYear = d.getFullYear(); 
				startMonth = d.getMonth() + 1;
				startDate = 1;
				endYear = d.getFullYear(); 
				endMonth =d.getMonth() + 1;
				var day = new Date(startYear,startMonth,0);
				endDate = day.getDate();
				var eDate = new Date(endYear+'/'+endMonth+'/'+endDate);
				cycleNum =Math.ceil((eDate.getTime()-cycleStartTime) / (24 * 3600 * 1000) / 30);
		}else{
			cycleNum =Math.ceil((d.getTime()-cycleStartTime.getTime()) / (24 * 3600 * 1000) / customizeDay);
			var sd = new Date(cycleStartTime.getTime()+(cycleNum-1)*86400000*customizeDay);
			var ed = new Date(cycleStartTime.getTime()+(cycleNum)*86400000*customizeDay-86400000);
			startYear = sd.getFullYear(); 
			startMonth = sd.getMonth() + 1;
			startDate = sd.getDate();
			endYear = ed.getFullYear(); 
			endMonth = ed.getMonth() + 1;
			endDate = ed.getDate();
		}
		if(cycleNum<1){
			$.Msg.alert('提示','当前时间在周期开始时间之前,请从第一期开始安排工作');
			return;
		}
		$('#itemizedName').val(null);
		$('#cycleNum').datebox('setValue',null);
		if(cycleNum!=1){
			$('#upBtn').linkbutton('enable');
		}
		if(cycleNum==1){
			$('#upBtn').linkbutton('disable');
		}
		$('#currentCycle').html("当前查询周期段:"+startYear+"年"+startMonth+"月"+startDate+"日至"+endYear+"年"+endMonth+"月"+endDate+"日"+"     (第"+cycleNum+"期)");
		var model = queryForm.form('getRecord');
		model.sDate = startYear+'-'+startMonth+'-'+startDate;
		model.eDate = endYear+'-'+endMonth+'-'+endDate;
		grid.datagrid('load', model);
	}

下期事件

	/****
	 * 下期事件
	 */
	this.downQuery = function (){
		$('#itemizedName').val(null);
		$('#cycleNum').datebox('setValue',null);
		cycleNum = cycleNum+1;
		$('#upBtn').linkbutton('enable');
		var oldsDate = new Date(startYear+'/'+startMonth+'/'+startDate);
		var oldeDate = new Date(endYear+'/'+endMonth+'/'+endDate);
		if(cycleStatus=="cycle_week"){
			var sd = new Date(oldsDate.getTime()+86400000*7); 
			var ed = new Date(oldeDate.getTime()+86400000*7); 
			startYear = sd.getFullYear(); 
			startMonth = sd.getMonth() + 1;
			startDate = sd.getDate();
			endYear = ed.getFullYear(); 
			endMonth = ed.getMonth() + 1;
			endDate = ed.getDate();
		}else if(cycleStatus=="cycle_month"){
			debugger;
			if(startMonth==12){
				startYear = startYear+1;
				startMonth = 1;
				startDate = 1;
				endYear = endYear+1; 
				endMonth = 1;
				endDate = 31;
			}else{
				startMonth = oldsDate.getMonth() + 2;
				endMonth = oldsDate.getMonth() + 2;
				var day = new Date(startYear,startMonth,0);
				endDate = day.getDate();
			}
		}else{
			var sd = new Date(oldsDate.getTime()+86400000*customizeDay); 
			var ed = new Date(oldeDate.getTime()+86400000*customizeDay); 
			startYear = sd.getFullYear(); 
			startMonth = sd.getMonth() + 1;
			startDate = sd.getDate();
			endYear = ed.getFullYear(); 
			endMonth = ed.getMonth() + 1;
			endDate = ed.getDate();
		}
		$('#currentCycle').html("当前查询周期段:"+startYear+"年"+startMonth+"月"+startDate+"日至"+endYear+"年"+endMonth+"月"+endDate+"日"+"     (第"+cycleNum+"期)");
		var model = queryForm.form('getRecord');
		model.sDate = startYear+'-'+startMonth+'-'+startDate;
		model.eDate = endYear+'-'+endMonth+'-'+endDate;
		grid.datagrid('load', model);
		
	}

跳转到指定日期所在期事件

this.savecycleplan=function(data){
		debugger;
		var itemizedName = $('#itemizedName').val();
		var cycleNum = $('#cycleNum').datebox('getValue');
		if($('#cycleNum').datebox('getValue')!=""&&$('#cycleNum').datebox('getValue')!=null){
		var d =	new Date(Date.parse($('#cycleNum').datebox('getValue').replace(/-/g,   "/")));   
		if(cycleStatus=="cycle_week"){
			var day = d.getDay();
			var sd = new Date(d.getTime()-(day*86400000)+86400000);
			startYear = sd.getFullYear(); 
			startMonth = sd.getMonth() + 1;
			startDate = sd.getDate();
			var ed = new Date(d.getTime()-(day*86400000)+7*86400000);
			endYear = ed.getFullYear(); 
			endMonth = ed.getMonth() + 1;
			endDate = ed.getDate();
			cycleNum = Math.ceil((ed.getTime()-cycleStartTime)/86400000/7);
		}else if(cycleStatus=="cycle_month"){
				startYear = d.getFullYear(); 
				startMonth = d.getMonth() + 1;
				startDate = 1;
				endYear = d.getFullYear(); 
				endMonth =d.getMonth() + 1;
				var day = new Date(startYear,startMonth,0);
				endDate = day.getDate();
				var eDate = new Date(endYear+'/'+endMonth+'/'+endDate);
				cycleNum =Math.ceil((eDate.getTime()-cycleStartTime) / (24 * 3600 * 1000) / 30);
		}else{
			cycleNum =Math.ceil((d.getTime()+1-cycleStartTime.getTime()) / (24 * 3600 * 1000) / customizeDay);
			var sd = new Date(cycleStartTime.getTime()+(cycleNum-1)*86400000*customizeDay);
			var ed = new Date(cycleStartTime.getTime()+(cycleNum)*86400000*customizeDay-86400000);
			startYear = sd.getFullYear(); 
			startMonth = sd.getMonth() + 1;
			startDate = sd.getDate();
			endYear = ed.getFullYear(); 
			endMonth = ed.getMonth() + 1;
			endDate = ed.getDate();
		}
		if(cycleNum<1){
			$('#cycleNum').datebox('setValue',null);
			$.Msg.alert('提示','当前查询时间在周期开始时间之前,请从第一期开始安排工作');
			return;
		}
		if(cycleNum!=1){
			$('#upBtn').linkbutton('enable');
		}
		if(cycleNum==1){
			$('#upBtn').linkbutton('disable');
		}
		$('#currentCycle').html("当前查询周期段:"+startYear+"年"+startMonth+"月"+startDate+"日至"+endYear+"年"+endMonth+"月"+endDate+"日"+"     (第"+cycleNum+"期)");
		var model = queryForm.form('getRecord');
		model.sDate = startYear+'-'+startMonth+'-'+startDate;
		model.eDate = endYear+'-'+endMonth+'-'+endDate;
		model.itemizedName = itemizedName;
		grid.datagrid('load', model);
		}else{
			var model = queryForm.form('getRecord');
			model.sDate = startYear+'-'+startMonth+'-'+startDate;
			model.eDate = endYear+'-'+endMonth+'-'+endDate;
			model.itemizedName = itemizedName;
			grid.datagrid('load', model);
		}
	}

注:上面代码d为传入日期
可以支持月,周,和自定义时间区段,例如5.10.20天等进行规划工作

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值