getLastMonth(date) {
var now = new Date(date)
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var nowMonthDay = new Date(year, month, 0).getDate(); // 当前月的总天数
if (month - 1 <= 0) {
day = day < 10 ? ('0' + day) : day
return year - 1 + "-" + 12 + "-" + day
}; // 如果是1月,年数往前推一年
var lastMonthDay = new Date(year, parseInt(month) - 1, 0).getDate();
if (lastMonthDay >= day) {
month = month -1;
month = month < 10 ? ('0' + month) : month
day = day < 10 ? ('0' + day) : day
return year + "-" + month + "-" + day
};
if (day < nowMonthDay) {
month = month -1;
month = month < 10 ? ('0' + month) : month
day = lastMonthDay - (nowMonthDay - day);
day = day < 10 ? ('0' + day) : day
return year + "-" + month + "-" + day
}; // 1个月前所在月的总天数小于现在的天日期
month = month -1;
month = month < 10 ? ('0' + month) : month
lastMonthDay = lastMonthDay < 10 ? ('0' + lastMonthDay) : lastMonthDay
return year + "-" + month + "-" + lastMonthDay; // 当前天日期小于当前月总天数
},