<el-date-picker clearable v-model="scope.row.instrumentUseTime" format="YYYY-MM-DD HH:mm" value-format="YYYY-MM-DD HH:mm" type="datetimerange" @change="(val) => dateChange(val,scope.$index)" range-separator="~" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%" :disabled-date="disabledDateFn" :disabled-hours="disabledHour" :disabled-minutes="disabledMinute" @calendar-change="calendarChange"></el-date-picker>
const disabledDateFn = (current) => {
// 获取当前日期
var now = new Date();
// 当前日期小于或等于选择的日期才是有效的
return current > now;
};
const startDate = ref()
const endDate = ref()
//获取面板选择的日期
const panelChange =(hour)=>{
if(hour[0]){
startDate.value = hour[0].getDate()
}
if(hour[1]){
endDate.value = hour[1].getDate()
}
}
//禁止小时
const disabledHour = (type) => {
const now = new Date()
const hours = now.getHours()
const disabled = []
//判断 开始的时间 结束的时间
if(type == 'start'){
//判断 开始的日期 结束的日期
if (startDate.value === now.getDate()) {
return Array.from({ length: 24 - hours }, (v, i) => i + 1 + hours);
}else{
return []
}
}else{
if (endDate.value === now.getDate()) {
return Array.from({ length: 24 - hours }, (v, i) => i + 1 + hours);
}else{
return []
}
}
}
//禁止分钟
const disabledMinute = (hour,type) => {
const now = new Date()
const minutes = now.getMinutes()
if( type == 'start'){
if (startDate.value === now.getDate()) {
return Array.from({ length: 60 - minutes }, (v, i) => i + 1 + minutes);
}else{
return []
}
}else{
if (endDate.value === now.getDate()) {
return Array.from({ length: 60 - minutes }, (v, i) => i + 1 + minutes);
}else{
return []
}
}
}
const dateChange = (val, i) => {
instrumentUseList.value[i].startDate = val[0];
instrumentUseList.value[i].endDate = val[1];
};