antd 禁用时间选择 年月日 时分

1、html

          <a-popover v-model="visible" title="请选择时间" trigger="click">
            <template slot="content">
              <a-date-picker
                v-model="add_time.day"
                :disabledDate="disabledDay"
                style="width: 120px;margin-right: 5px"/>
              <a-time-picker
                v-model="add_time.hour"
                style="width: 80px"
                :allowClear="false"
                :disabledHours="disabledHour"
                :disabledMinutes="disabledMinute"
                format="HH:mm"
                v-show="visible"/>
              <a-button type="primary" style="margin-left: 15px" @click="handleAdd" v-show="visible">确定</a-button>
            </template>
            <a-button class="editable-add-btn" type="primary">添加一行</a-button>
          </a-popover>

效果是这个样子:

 

 

 

 2、js部分

data部分

      add_time: {
        day: moment(),
        hour: moment()
      },
 visible: false,

 methods部分

    // 禁用年月日
    disabledDay (current) {
      return current && current > moment().endOf('day')
    },
    // 禁用小时
    disabledHour () {
      const hours = []
      // 昨天或者更久之前
      if (this.add_time.day.diff(moment(), 'days') === 0) {
        const timeHours = moment().format('HH')
        for (var i = 0; i < 24; i++) {
          if (i > timeHours) {
            hours.push(i)
          }
        }
      }
      return hours
    },
    // 禁用分钟
    disabledMinute (selectedHour) {
      const minute = []
      if (this.add_time.day.diff(moment(), 'days') === 0 && moment().hour(selectedHour).diff(moment(), 'hours') === 0) {
        const timeMinute = moment().format('mm')
        for (var j = 0; j < 59; j++) {
          if (j > timeMinute) {
            minute.push(j)
          }
        }
      }
      return minute
    },
  // 添加
    handleAdd () {
      const data = []
      this.span_key.forEach(item => {
        const child = {}
        child.key = item
        if (item === 'A') {
          child.value = moment(this.add_time.day).format('YYYY-MM-DD')
        } else if (item === 'B') {
          child.value = moment(this.add_time.hour).format('HH:mm')
        } else {
          child.value = ''
        }
        data.push(child)
      })
      const newData = [data]
      接口({
        file: this.fileId || this.$route.query.fileId,
        data: newData,
      }).then(res => {
        this.$message.success('添加成功')
        this.$refs.table.refresh()
      }).catch(err => {
        if (err.code === 10177) {
          this.$message.error('添加失败,该条记录已存在')
        }
      })
      this.visible = false
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值