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
|