饿了么 plus el-date-picker type=“datetimerange“ 时间区间选择器 禁用日期 小时 分钟 ,禁用当前日期之后日期不能选择

<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];

};

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值