<el-date-picker
style=" width: auto;"
v-model="deliveryValue"
format="yyyy 年 MM 月 dd 日"
value-format="yyyy-MM-dd"
type="monthrange"
range-separator="至"
start-placeholder="开始月份"
end-placeholder="结束月份"
:picker-options="pickerOptions"
@change="deliveryDateStartAndEnd"
></el-date-picker>
data() {
return {
// 判断交付率 按财年选择 当年 10 月 到 明年 9 月
choiceDate: '',
pickerOptions: {
onPick: ({ maxDate, minDate }) => {
this.choiceDate = minDate.getTime();
if (maxDate) {
this.choiceDate = '';
}
},
disabledDate: time => {
const self = this;
if (self.choiceDate) {
const selectDate = new Date(self.choiceDate);
const nowYear = selectDate.getFullYear(); // 当前年
const nowMonth = selectDate.getMonth(); // 当前月
if (nowMonth >= 9) {
// 本年的开始时间
const yearStartDate = new Date(nowYear, 10, 0).getTime();
// 本年的结束时间
const yearEndDate = new Date(nowYear + 1, 9, 0).getTime();
return time.getTime() < yearStartDate || time.getTime() > yearEndDate;
} else {
// 本年的开始时间
const yearStartDate = new Date(nowYear, 9, 0).getTime();
// 本年的结束时间
const yearEndDate = new Date(nowYear - 1, 10, 0).getTime();
return time.getTime() > yearStartDate || time.getTime() < yearEndDate;
}
}
},
},
}
}
网友评论