功能:选择日期后,默认选中该日期一周内的时间
/**
* 周选择
*传入DateTime对象和options
*/
function weekDateSelectInit(dateTime,options) {
$('body').on('mouseover', '.ui-date-container a.ui-date-item', function () {
$(this).click(function () {
var selectedTime = $(this).attr('data-date');
var nowTime = getNowDateStr();
var endTime = getDateByDays(new Date(selectedTime), 7);
endTime = endTime >= nowTime ? nowTime : endTime;
$('.ui-date-container').remove();
$('label.ui-date-arrow').remove();
var selector = dateTime.el.trigger.prevObject.selector;
var o = {
value: selectedTime + ' 至 ' + endTime,
max: getNowDateStr()
};
//合并原有opt
var opt = $.extend({}, o, options);
//创建一个新的daeTime
$(selector).val('');
dateTime = null;
dateTime = new DateTime($(selector),opt);
dateTime.show();
})
})
}
function getNowDateStr() {
var d = new Date();
var nY = d.getFullYear();
var nM = (d.getMonth()+1)<10?"0"+(d.getMonth()+1):(d.getMonth()+1);
var nD = d.getDate()<10?"0"+d.getDate():d.getDate();
var nowTime =nY+'-'+nM+'-'+nD;
return nowTime;
}
/**
* @return {string}
*/
function getDateByDays(dd,days) {
dd.setDate(dd.getDate()+days);
var y = dd.getFullYear();
var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);
var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();
return y+"-"+m+"-"+d;
}