king
2022-03-10 99966d855531d813197190f68e84f409f4eb1e61
src/tabviews/zshare/mutilform/mkDatePicker/index.jsx
@@ -20,13 +20,19 @@
    if (config.type === 'datemonth') {
      mode = 'month'
      format = 'YYYY-MM'
    } else if (config.type === 'datetime') {
      mode = 'datetime'
    } else if (config.precision === 'day') {
      format = 'YYYY-MM-DD'
    } else if (config.precision === 'hour') {
      format = 'YYYY-MM-DD HH'
    } else if (config.precision === 'minute') {
      format = 'YYYY-MM-DD HH:mm'
    } else if (config.precision === 'second') {
      format = 'YYYY-MM-DD HH:mm:ss'
    }
    let value = config.initval || null
    if (value) {
      value = moment(value, format)
      value = moment(value, 'YYYY-MM-DD HH:mm:ss')
    }
    this.state = {
@@ -49,9 +55,19 @@
  }
  onChange = (val) => {
    const { format } = this.state
    const { config } = this.props
    const { format, mode } = this.state
    let _val = val ? moment(val).format(format) : ''
    this.props.onChange(val ? moment(val).format(format) : '')
    if (mode === 'date' && _val) {
      if (config.precision === 'hour') {
        _val = _val + ':00:00'
      } else if (config.precision === 'minute') {
        _val = _val + ':00'
      }
    }
    this.props.onChange(_val)
  }
  disabledDate = (current) => {
@@ -72,14 +88,12 @@
  render() {
    const { config } = this.props
    const { value, mode } = this.state
    const { value, mode, format } = this.state
    if (mode === 'date') {
      return <DatePicker defaultValue={value} disabledDate={this.disabledDate} disabled={config.readonly} onChange={this.onChange}/>
      return <DatePicker dropdownClassName={'mk-date-picker ' + config.precision} showTime={format !== 'YYYY-MM-DD'} format={format} defaultValue={value} disabledDate={this.disabledDate} disabled={config.readonly} onChange={this.onChange}/>
    } else if (mode === 'month') {
      return <MonthPicker defaultValue={value} disabled={config.readonly} onChange={this.onChange}/>
    } else if (mode === 'datetime') {
      return <DatePicker defaultValue={value} disabledDate={this.disabledDate} showTime disabled={config.readonly} onChange={this.onChange}/>
    }
  }
}