getWeekDates(year, week) {
if(this.isDateObject(year)){
year = year.getFullYear();
}else{
year = this.mainData.warehouseYear.toString()
year = year.substr(0,4);
}
var januaryFirst = new Date(year, 0, 1);
var firstDay = januaryFirst.getDay();
var weekStartDate = new Date(year, 0, (1 + (week - 1) * 7) - firstDay);
var weekEndDate = new Date(year, 0, (1 + (week - 1) * 7) - firstDay + 6);
var yearStart = weekStartDate.getFullYear();
var yearEnd = weekEndDate.getFullYear();
debugger
if(yearStart != yearEnd){
var mothStart = weekStartDate.getMonth()+1;
var mothEnd = weekEndDate.getMonth()+1;
if(mothStart == 12 && yearStart == year){
//最后一周如果跨年,就取最后一天拼接
var lastDay = new Date(year, 11, 31); // 11代表12月
var datestr = weekStartDate.getFullYear() + "-" + mothStart + "-" + weekStartDate.getDate() + " To " +
lastDay.getFullYear() +"-" + 12 + "-" + lastDay.getDate();
console.log(datestr);
return datestr;
}else if(mothEnd == 1 && yearStart != year){
//第一周跨年的情况,取第一天和往后7天
var mothStart = januaryFirst.getMonth()+1;
//计算januaryFirst 往后7天日期
var januaryFirstLast7 = new Date(year, 0, 7);
var datestr = januaryFirst.getFullYear() + "-" + mothStart + "-" + januaryFirst.getDate() + " To " +
januaryFirstLast7.getFullYear() +"-" + mothStart + "-" + januaryFirstLast7.getDate();
console.log(datestr);
return datestr;
}
}else{
var mothStart = weekStartDate.getMonth()+1;
var mothEnd = weekEndDate.getMonth()+1;
var datestr = weekStartDate.getFullYear() + "-" + mothStart + "-" + weekStartDate.getDate() + " To " +
weekEndDate.getFullYear() +"-" + mothEnd + "-" + weekEndDate.getDate();
console.log(datestr);
return datestr;
}
},
isDateObject(obj) {
return obj instanceof Date;
}