king
7 天以前 a1e9b18a4dbfd21e1bf4d5cb60974ac2f0115efd
src/tabviews/zshare/mutilform/mkNumberInput/index.jsx
@@ -4,7 +4,7 @@
import MKEmitter from '@/utils/events.js'
import './index.scss'
// import './index.scss'
class MKNumberInput extends Component {
  constructor(props) {
@@ -19,8 +19,6 @@
      value: config.initval
    }
  }
  inputNumberRef = React.createRef()
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
@@ -39,27 +37,58 @@
  mkFormHandle = (type, uuid, value) => {
    if (uuid !== this.props.config.uuid) return
    if (type === 'focus') {
      this.inputNumberRef.current.focus()
      let node = document.getElementById(uuid)
      node && node.select()
    } else if (type === 'input') {
      this.setState({value})
      this.props.onChange(value, true)
    }
  }
  handleChange = (val) => {
    this.props.onChange(val)
    this.setState({value: val})
    let _val = val
    if (typeof(_val) !== 'number') {
      _val = parseFloat(_val)
      if (isNaN(_val)) {
        _val = ''
      }
    }
    this.props.onChange(_val)
  }
  handleSubmit = () => {
    const { config } = this.props
    if (config.enter === 'false') return
    if (config.enter === 'tab') {
      MKEmitter.emit('mkFC', 'focus', config.tabUuid)
    } else {
      MKEmitter.emit('mkFC', 'focus', config.tabUuid)
      this.props.onSubmit(config.tabUuid, config.errTabUuid)
    }
  }
  render() {
    const { config, onSubmit } = this.props
    const { config } = this.props
    const { value, precision } = this.state
    if (precision === null) {
      return (<InputNumber ref={this.inputNumberRef} value={value} disabled={config.readonly} onChange={this.handleChange} onPressEnter={onSubmit}/>)
    if (config.format === 'thdSeparator') {
      if (precision === null) {
        return (<InputNumber id={config.uuid} formatter={value => `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')} parser={value => value.replace(/,*/g, '')} value={value} disabled={config.readonly} onChange={this.handleChange} onPressEnter={this.handleSubmit}/>)
      } else {
        return (<InputNumber id={config.uuid} formatter={value => `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')} parser={value => value.replace(/,*/g, '')} value={value} precision={precision} disabled={config.readonly} onChange={this.handleChange} onPressEnter={this.handleSubmit} />)
      }
    } else if (precision === null) {
      return (<InputNumber id={config.uuid} value={value} disabled={config.readonly} onChange={this.handleChange} onPressEnter={this.handleSubmit}/>)
    } else {
      return (<InputNumber ref={this.inputNumberRef} value={value} precision={precision} disabled={config.readonly} onChange={this.handleChange} onPressEnter={onSubmit} />)
      return (<InputNumber id={config.uuid} value={value} precision={precision} disabled={config.readonly} onChange={this.handleChange} onPressEnter={this.handleSubmit} />)
    }
  }
}