多的不说,直接上代码
html
<el-form :model="formData" :rules="rules" ref="form">
<el-row style="border-top: 1px solid #f1f2f3" class="flex-wrap">
<el-col :span="12" class="colspan">
<div class="desc-label">
<span>开始时间:</span>
</div>
<div class="desc-value time-value">
<el-form-item prop="beginTime" style="width: 100%">
<el-date-picker
:picker-options="pickerOptions"
placeholder="请选择"
v-model="formData.beginTime"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetime"
/>
</el-form-item>
</div>
</el-col>
<el-col :span="12" class="colspan">
<div class="desc-label">
<span>结束时间:</span>
</div>
<div class="desc-value time-value">
<el-form-item prop="endTime" style="width: 100%">
<el-date-picker
:picker-options="pickerOptions1"
placeholder="请选择"
v-model="formData.endTime"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetime"
:start-placeholder="formData.beginTime"
/>
</el-form-item>
</div>
</el-col>
</el-row>
</el-form>
computed
computed:{
pickerOptions() {
return{
selectableRange:(()=>{
if(this.formData.endTime){
let data=new Date(this.formData.endTime);
let hour=data.getHours();
let minute=data.getMinutes();
let second=data.getSeconds();
return [`00:00:00 - ${hour}:${minute}:${second}`]
}else {
return [`00:00:00 - 23:59:59`]
}
})(),
disabledDate: time => {
if(this.formData.endTime){
if(new Date(this.formData.endTime).getHours()){
return time.getTime() > new Date(this.formData.endTime)+86400000
}else {
return time.getTime() > new Date(this.formData.endTime)
}
}
},}
},
pickerOptions1() {
return{
selectableRange:(()=>{
if(this.formData.beginTime){
let data=new Date(this.formData.beginTime);
let hour=data.getHours();
let minute=data.getMinutes();
let second=data.getSeconds()+1;
return [`${hour}:${minute}:${second} - 23:59:59`]
}else {
return [`00:00:00 - 23:59:59`]
}
})(),
disabledDate: time => {
if(this.formData.beginTime){
if(new Date(this.formData.beginTime).getHours()){
return time.getTime() < new Date(this.formData.beginTime) -86400000
}else {
return time.getTime() < new Date(this.formData.beginTime)
}
}
},}
},
},