var thisValue = this.getValue() ;
// 把paraStDate改成自己的开始日期控件名称
var paraStDate = _g().parameterEl.getWidgetByName("paraStDate") ;
// 把paraEdDate改成自己的结束日期控件名称
var paraEdDate = _g().parameterEl.getWidgetByName("paraEdDate") ;
var StartDate = paraStDate.getValue() ;
var EndDate = paraEdDate.getValue() ;
var currentDate = new Date();
switch (thisValue) {
case '近7天':
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1; // getMonth()返回的月份是从0开始的,所以需要+1
var date = currentDate.getDate();
var EndformattedDate = year + '-' + (month < 10 ? '0' + month : month) + '-' + (date < 10 ? '0' + date : date);
// 将日期减去7天
currentDate.setDate(currentDate.getDate() - 6);
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1; // getMonth()返回的月份是从0开始的,所以需要+1
var date = currentDate.getDate();
var StartformattedDate = year + '-' + (month < 10 ? '0' + month : month) + '-' + (date < 10 ? '0' + date : date);
paraStDate.setValue(StartformattedDate) ;
paraStDate.setText(StartformattedDate) ;
paraEdDate.setValue(EndformattedDate) ;
paraEdDate.setText(EndformattedDate) ;
break ;
case '当月':
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1; // getMonth()返回的月份是从0开始的,所以需要+1
var date = currentDate.getDate();
var EndformattedDate = year + '-' + (month < 10 ? '0' + month : month) + '-' + (date < 10 ? '0' + date : date);
var StartformattedDate = year + '-' + (month < 10 ? '0' + month : month) + '-01';
paraStDate.setValue(StartformattedDate) ;
paraStDate.setText(StartformattedDate) ;
paraEdDate.setValue(EndformattedDate) ;
paraEdDate.setText(EndformattedDate) ;
break ;
case '当季':
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1; // getMonth()返回的月份是从0开始的,所以需要+1
var date = currentDate.getDate();
// 季度判断
if(month >= 1 && month <= 3) {
var q = 1 ;
var q_month = 1 ;
} else if (month >= 4 && month <= 6) {
var q = 2 ;
var q_month = 4 ;
}
else if (month >= 7 && month <= 9) {
var q = 3 ;
var q_month = 7 ;
}
else {
var q = 4 ;
var q_month = 10 ;
}
var EndformattedDate = year + '-' + (month < 10 ? '0' + month : month) + '-' + (date < 10 ? '0' + date : date);
var StartformattedDate = year + '-' + (q_month < 10 ? '0' + q_month : q_month) + '-01';
paraStDate.setValue(StartformattedDate) ;
paraStDate.setText(StartformattedDate) ;
paraEdDate.setValue(EndformattedDate) ;
paraEdDate.setText(EndformattedDate) ;
break ;
case '当年':
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1; // getMonth()返回的月份是从0开始的,所以需要+1
var date = currentDate.getDate();
var EndformattedDate = year + '-' + (month < 10 ? '0' + month : month) + '-' + (date < 10 ? '0' + date : date);
var StartformattedDate = year + '-01-01';
paraStDate.setValue(StartformattedDate) ;
paraStDate.setText(StartformattedDate) ;
paraEdDate.setValue(EndformattedDate) ;
paraEdDate.setText(EndformattedDate) ;
break ;
default:
return false
}