element选择器只能选择七天

是通过v-model绑定的值来判断,用watch监听,获取到用户填写的数据经过处理,点击发布提示

 在data中将makeDate定义成数组

        <div style="margin-top: 30px">
          <span style="display:inline-block;width: 120px;">选择预约日期:</span>
          <el-date-picker
            v-model="makeDate"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
            @change="dateChange()"
          ></el-date-picker>
        </div>

watch监听,取到用户填写开始时间和结束时间相减,处理数据

 watch: {
    makeDate(newVal) {
      // 7天时间
      this.seven = 6 * 86400000
      // 用户填写的开始时间和结束时间
      let dStart = new Date(newVal[0])
      let tStart = dStart.getTime(dStart)
      let dEnd = new Date(newVal[1])
      let tEnd = dEnd.getTime(dEnd)
      // 结束时间减去开始时间
      this.time = tEnd - tStart
      // 判断用户的时间是否大于7天
      if (this.time > this.seven) {
        console.log('超过7天!')
        this.date = [newVal[0], newVal[0]]
      }
    }
  },

点击立即添加

  addMake() {
      if (this.makeLoading) return
      if (this.timeIsNull() || !this.makeDate) {
        this.$notify({
          message: '请填写完整预约信息',
          type: 'warning'
        })
        return
      }
      // 当用户选择的时间大于7天,提示再return出去,后面的不执行
      if (this.time > this.seven) {
        this.$message({
          showClose: true,
          message: '预约日期最多可以选择7天!',
          type: 'error'
        })
        return
      }
      this.makeLoading = true
      this.handleTimeList()
      this.$axios
        .post(BASE.BASE_URL2 + `/venueDestine/addVenueDestine`, {
          beginDate: this.makeStartDate,
          endDate: this.makeEndDate,
          fieldId: this.fieldId,
          openTimeSection: this.timeStr,
          venueId: this.$route.query.venueId
        })
        .then(res => {
          this.makeLoading = false
          if (res.data.status === 'success') {
            this.$notify({
              message: '发布成功',
              type: 'success'
            })
            this.closeRoomPopover()
          } else {
          }
        })
    },

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值