king
2024-02-19 1e4a7720c748bc0206b02b30f4a2e0b3dafb54f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, {Component} from 'react'
import { is, fromJS } from 'immutable'
import { InputNumber } from 'antd'
 
import './index.scss'
 
class MKNumber extends Component {
  constructor(props) {
    super(props)
    
    const config = props.config
    let vals = config.initval.split(',')
 
    this.state = {
      minValue: vals[0] !== undefined && vals[0] !== '' ? +vals[0] : '',
      maxValue: vals[1] !== undefined && vals[1] !== '' ? +vals[1] : ''
    }
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  minChange = (val) => {
    this.setState({minValue: val}, () => {
      this.onChange()
    })
  }
 
  maxChange = (val) => {
    this.setState({maxValue: val}, () => {
      this.onChange()
    })
  }
 
  onChange = () => {
    const { minValue, maxValue } = this.state
 
    let vals = []
    if ((!minValue && minValue !== 0) || isNaN(minValue)) {
      vals.push('')
    } else {
      vals.push(minValue)
    }
    if ((!maxValue && maxValue !== 0) || isNaN(maxValue)) {
      vals.push('')
    } else {
      vals.push(maxValue)
    }
 
    vals = vals.join(',')
 
    if (vals === ',') {
      vals = ''
    }
 
    this.props.onChange(vals)
  }
 
  render() {
    const { minValue, maxValue } = this.state
 
    return (
      <div className="range-wrap">
        <InputNumber defaultValue={minValue} onPressEnter={this.props.onInputSubmit} onChange={this.minChange}/>
        至
        <InputNumber defaultValue={maxValue} onPressEnter={this.props.onInputSubmit} onChange={this.maxChange}/>
      </div>
    )
  }
}
 
export default MKNumber