开始时间大于结束时间

1.dom中代码,监听所选日期值的变化,并把需要比较的时间字段作为参数传到监听方法中,

<el-form-item label="起始日期" prop="startTime">
            <el-date-picker clearable size="small"
                            :disabled="isDisable"
                            v-model="form.startTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            @change="checkTime(form.startTime,form.expirationTime,form.signingTime,'start')"
                            :placeholder="isDisable? '':'选择起始日期'">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="终止日期" prop="expirationTime">
            <el-date-picker clearable size="small"
                            :disabled="isDisable"
                            v-model="form.expirationTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            @change="checkTime(form.startTime,form.expirationTime,form.signingTime,'expiration')"
                            :placeholder="isDisable? '':'选择终止日期'">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="签订时间" prop="signingTime">
            <el-date-picker clearable size="small"
                            :disabled="isDisable"
                            v-model="form.signingTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            @change="checkTime(form.startTime,form.expirationTime,form.signingTime,'signing')"
                            :placeholder="isDisable? '':'选择签订时间'">
            </el-date-picker>
          </el-form-item>

在这里插入图片描述
2.时间比较逻辑处理

 //时间判断
      checkTime(startTime, expirationTime,signingTime, type) {
       /* if (startTime == '' || startTime == null || startTime == undefined) {
          return;
        }
        if (expirationTime == '' || expirationTime == null || expirationTime == undefined) {
          return;
        }
        if (signingTime == '' || signingTime == null || signingTime == undefined) {
          return;
        }*/
        if (startTime > expirationTime) {
          this.$modal.msgWarning("开始时间应小于终止时间!");
          if (type == 'start') {
            this.$set(this.form, 'startTime', '');
          } else if (type == 'expiration') {
            this.$set(this.form, 'expirationTime', '');
          }
        }
        if (startTime < signingTime) {
          this.$modal.msgWarning("开始时间应大于或等于签订时间!");
          if (type == 'start') {
            this.$set(this.form, 'startTime', '');
          }else if (type == 'signing') {
            this.$set(this.form, 'signingTime', '');
          }
        }
      },

二.当比较的是form表单中数组中循环的两个时间时,用以下方法
1.dom中监听日期值的变化 @change=“checkTime()”
在这里插入图片描述

 //本次读数时间必须大于上次读数时间
      checkTime() {
        this.form.readings.forEach(item => {
          if (item.readingTime < item.scdssj) {
            this.$modal.msgError("本次读数时间应大于上次读数时间!");
            item.readingTime = ''; // 清空本次读数所选日期
          }
        });
      },

在这里插入图片描述
3.form中两个时间,即本次时间必须大于上次时间

  //本次读数时间必须大于上次读数时间
    checkTime() {
      if (this.hjhjform.scdssj && this.hjhjform.bcdssj) {
        const scdsTime = new Date(this.hjhjform.scdssj).format("yyyy-MM-dd");
        const bcdsTime = new Date(this.hjhjform.bcdssj).format("yyyy-MM-dd");
        if (bcdsTime <= scdsTime) {
          this.$modal.msgError("本次读数时间应大于上次读数时间!");
          return
        }
      }
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值