美文网首页
时间控件DatePicker-RangePicker

时间控件DatePicker-RangePicker

作者: 小明的明 | 来源:发表于2020-12-11 18:55 被阅读0次

    <FormItem label={item.name} >
    {getFieldDecorator(${item.id}, {initialValue:item.defaultValue||''})(<RangePicker
    ranges={item.ranges || { 今天: [moment(todayDate.beginTime, 'YYYY/MM/DD HH:mm:ss'), moment(todayDate.endTime, 'YYYY/MM/DD HH:mm:ss')] }}
    disabledDate={item.isAllowAfterTime ? () => false :(e)=>this.disabledDate(e,item)}
    onCalendarChange={this.onCalendarChange}
    onOpenChange={this.onDateOpenChange}
    allowClear={item.allowClear || false}
    showTime={{
    hideDisabledOptions: true,
    defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
    }}
    format="YYYY/MM/DD HH:mm:ss"
    placeholder={['开始时间', '结束时间']} />)}
    </FormItem>

    onCalendarChange = (dates) =>{
    if (!dates || !dates.length) {
    return
    }
    this.setState({
    selectDate:dates[1]
    })
    };

    onDateOpenChange = ()=>{
    this.setState({
    selectDate:null
    })
    }

    disabledDate = (current,item) =>{
    const { selectDate } = this.state;
    if (!current){
    return false
    }
    if(current&&!selectDate&&item.defaultValue){
    return current < moment().subtract(3,'month').subtract(1,'day') || current > moment().endOf('day')
    }

    if(current&&selectDate){
      let selectV = moment(selectDate.valueOf()).format('YYYY/MM/DD HH:mm:ss');
      return current < moment(selectV).subtract(3, 'months')  || current > moment().endOf('day') // ||current >  moment(selectV).add(3,'month') //选择的之后三个月
    };
    
    return current > moment().endOf('day')
    

    }

    相关文章

      网友评论

          本文标题:时间控件DatePicker-RangePicker

          本文链接:https://www.haomeiwen.com/subject/effsgktx.html