import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Checkbox } from 'antd'
|
|
import MKEmitter from '@/utils/events.js'
|
|
class MKCheck extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
onChange: PropTypes.func
|
}
|
|
state = {
|
defaultChecked: this.props.config.initval === this.props.config.openVal
|
}
|
|
onChange = (e) => {
|
const { config } = this.props
|
|
if (e.target.checked) {
|
this.props.onChange(config.openVal)
|
} else {
|
this.props.onChange(config.closeVal)
|
}
|
|
this.setState({}, () => {
|
if (config.enter === 'tab') {
|
MKEmitter.emit('mkFC', 'focus', config.tabUuid)
|
} else if (config.enter === 'sub') {
|
config.tabUuid && MKEmitter.emit('mkFC', 'focus', config.tabUuid)
|
if (config.linkFields || config.subFields || config.controlFields) {
|
setTimeout(() => {
|
this.props.onSubmit(config.tabUuid, config.errTabUuid)
|
}, 1000)
|
} else {
|
this.props.onSubmit(config.tabUuid, config.errTabUuid)
|
}
|
}
|
})
|
}
|
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
render() {
|
const { config } = this.props
|
const { defaultChecked } = this.state
|
|
return (
|
<Checkbox disabled={config.readonly} defaultChecked={defaultChecked} onChange={this.onChange}>{config.checkTip}</Checkbox>
|
)
|
}
|
}
|
|
export default MKCheck
|