setTitle() {
let date = '';
if (this.dialogStatus != 'create') {
date = this.rowData.period;
} else {
date = this.dialogInfo.settlementDate;
}
date = date.split('-');//获取到的当前的月份
let year_ = date[0];
let day_ = date[1];
let day_zero = date[1];
if (_.startsWith(day_, 0)) {
day_ = day_.substring(1);
}
date[1] = year_;
this.monthTitle = day_;
this.yearTitle = year_ ;
// 处理结算日期
这部分代码是处理日期的代码
let runYear = isRunYear(this.yearTitle);
let num1 = ['01','03','05','07','08','10','12'];//31天
let num2 = ['04','06','09','11'];//30天、
判断当前月份是满足31天还是30天,2月份需要单独 处理
if (_.includes(num1, day_zero)){
this.dayNumEnd = '31';
}else if (_.includes(num2, day_zero)){
this.dayNumEnd = '30';
}else {
// 2月处理平年闰年
if (runYear){
this.dayNumEnd = '29';
}else {
this.dayNumEnd = '28';
}
}
this.beginDate = `${this.yearTitle}-${day_zero}-01`;
this.endDate = `${this.yearTitle}-${day_zero}-${this.dayNumEnd}`;
},
// 判断闰年的函数
export function isRunYear(year) {
// 条件:能被4整除并且不能被100整除,或者被400整除的
var flag = false;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
flag = true;
}
return flag;
}