<el-date-picker
type="datetime"
placeholder="选择上线日期"
:picker-options="startDatePicker"
v-model="addStartPageForm.onlineTime"
value-format="yyyy-MM-dd HH:mm:ss"
style=" 100%;"
></el-date-picker>
<el-date-picker
type="datetime"
placeholder="选择下线日期"
v-model="addStartPageForm.downlineTime"
:picker-options="endDatePicker"
value-format="yyyy-MM-dd HH:mm:ss"
@change="checkDateTime"
style=" 100%;"
></el-date-picker>
data
startDatePicker: {},
endDatePicker: {},
method
//设置开始时间 禁用昨天和以前时间
beginDate() {
return {
disabledDate(time) {
return new Date().getTime() - 60 * 60 * 24 * 1000 >= time.getTime();
},
};
},
//设置结束时间 禁用昨天和以前时间
processDate() {
const _this = this;
return {
disabledDate(time) {
if (_this.addStartPageForm.onlineTime) {
return (
new Date(_this.addStartPageForm.onlineTime).getTime() -
60 * 60 * 24 * 1000 >=
time.getTime()
);
}
},
};
},
//结束时间必须大于开始时间
checkDateTime(val) {
if (
this.addStartPageForm.onlineTime &&
this.addStartPageForm.downlineTime
) {
if (new Date(this.addStartPageForm.onlineTime) > new Date(val)) {
this.$message.error("结束时间必须大于开始时间");
this.addStartPageForm.downlineTime = "";
}
}
},
created() {
this.startDatePicker = this.beginDate(); //设置开始时间
this.endDatePicker = this.processDate(); //设置结束时间
},