vue 選擇年度時間框,選擇季度下拉框,並且不能超過當前季度

有一個需求是這樣,選擇年份和季度,要求年份不能超過當前年份,如果年份等於當前年份的時候,再去考慮季度,季度不能超過當前季度。

選擇年事件:

//選擇年事件
getTimeYear(date) {

//選擇的年份
var y = date.getFullYear();//2019、

//當前年份
var tY = new Date().getFullYear();//2019

if (y > tY) {//選擇的年份大於當前年份的時候

this.$message({message: '選擇的年份不能大於等於當前年份,請重新選擇!', type: 'warning'});
//清空輸入的年份
}
this.yearValue = y;
},

選擇季度事件:

getQuter(date) {

var y1 = this.yearMonthForm.yearMonth.getFullYear();//選擇年 2019
var tY1 = new Date().getFullYear();//當前年 2019
//選擇的季度
let q = this.yearMonthForm.yearQuarter;
// //當前的季度
let tQ = '';
if (new Date().getMonth() + 1 <= 3) {
tQ = 3;
} else if (new Date().getMonth() + 1 > 3 && new Date().getMonth() + 1 <= 6) {
tQ = 6;
} else if (new Date().getMonth() + 1 > 6 && new Date().getMonth() + 1 <= 9) {
tQ = 9;
} else if (new Date().getMonth() + 1 > 9 && new Date().getMonth() + 1 <= 12) {
tQ = 12;
}

if ((y1 == tY1) && (q > tQ)) {//選擇的年份與當前的年份相等時
this.$message({message: '選擇的季度不能大於等於當前季度,請重新選擇!', type: 'warning'});
//清空數據
}
this.monthValue = q;
}


分享到:


相關文章: