//季度计算
varseasonFn= function(month){returnmonth< 4 ? 1:
month< 7 ? 2:
month< 10 ? 3:4;
}//替换修改原月HTML 结构
varreplaceFn= function(that) {
that.find(".laydate-month-list").each(function(i, e) {
$(this).find("li").each(function(inx, ele) {var_li=$(ele)if(inx< 4) {
_li.html(_li.html().replace(/月/g,"季度").replace(/一/g,"第1").replace(/二/g,"第2").replace(/三/g,"第3").replace(/四/g,"第4"))
}else{//_li.hide()
_li.remove();
}
});
});
}var_date= newDate();//最大季度不得超出当前日期
var_max=_date.getFullYear()+'-'+seasonFn(_date.getMonth()+ 1)+ '-' +laydate.getEndDate(seasonFn(_date.getMonth()+ 1));//开始季度
varinsStart=laydate.render({
elem:'#dateStart',
type:'month',
format:'yyyy-第M季度',
range:null,
max: _max,
btns: ['confirm'],//value: '2020-第3季度',
//isInitValue: false,
ready:function() {varhandleDom=$("#layui-laydate" +$('#dateStart').attr("lay-key"));if(handleDom.length> 0) {
handleDom.click(function() {
replaceFn($(this));
});
}
replaceFn(handleDom);
},
done:function(value,date) {varisChange=$('.laydate-month-list li:lt(4)').hasClass('layui-this');varyear=date.year;varmonth=date.month;varseason=seasonFn(month);varval=value;if(isChange){
season=month;
}else{
val=year+'-'+'第'+season+'季度'}
setTimeout(function(){
$('#dateStart').val(val);//更新结束日期的最小日期
insEnd.config.min=lay.extend({}, date, {
month: season- 1});//自动弹出结束日期的选择器
if(!$('#dateEnd').val()){
insEnd.config.elem[0].focus();
}
})
}
});//结束季度
varinsEnd=laydate.render({
elem:'#dateEnd',
type:'month',
format:'yyyy-第M季度',
range:null,
max: _max,
btns: ['confirm'],//value: '2020-第3季度',
//isInitValue: false,
ready:function() {varhandleDom=$("#layui-laydate" +$('#dateEnd').attr("lay-key"));if(handleDom.length> 0) {
handleDom.click(function() {
replaceFn($(this));
});
}
replaceFn(handleDom);
},
done:function(value,date) {varisChange=$('.laydate-month-list li:lt(4)').hasClass('layui-this');varyear=date.year;varmonth=date.month;varseason=seasonFn(month);varval=value;if(isChange){
season=month;
}else{
val=year+'-'+'第'+season+'季度'}
setTimeout(function(){
$('#dateEnd').val(val)//更新开始日期的最大日期
insStart.config.max=lay.extend({}, date, {
month: season- 1});if(!$('#dateStart').val()){
insStart.config.elem[0].focus();
}
})
}
});