| | |
| | | import PropTypes from 'prop-types' |
| | | import { Switch } from 'antd' |
| | | |
| | | import './index.scss' |
| | | import MKEmitter from '@/utils/events.js' |
| | | |
| | | class MKSwitch extends Component { |
| | | static propTpyes = { |
| | |
| | | onChange = (val) => { |
| | | const { config } = this.props |
| | | |
| | | if (val) { |
| | | this.props.onChange(config.openVal) |
| | | } else { |
| | | this.props.onChange(config.closeVal) |
| | | let other = {} |
| | | if (config.subFields) { |
| | | let _val = val ? config.openText : config.closeText |
| | | config.subFields.forEach((n, i) => { |
| | | other[n.field] = _val || '' |
| | | setTimeout(() => { |
| | | MKEmitter.emit('mkFC', 'input', n.uuid, _val || '') |
| | | }, i * 5) |
| | | }) |
| | | } |
| | | |
| | | if (val) { |
| | | this.props.onChange(config.openVal, other) |
| | | } else { |
| | | this.props.onChange(config.closeVal, other) |
| | | } |
| | | |
| | | 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 () { |
| | |
| | | const { defaultChecked } = this.state |
| | | |
| | | return ( |
| | | <Switch checkedChildren={config.openText || ''} unCheckedChildren={config.closeText || ''} defaultChecked={defaultChecked} onChange={this.onChange}/> |
| | | <Switch checkedChildren={config.openText || ''} disabled={config.readonly} unCheckedChildren={config.closeText || ''} defaultChecked={defaultChecked} onChange={this.onChange}/> |
| | | ) |
| | | } |
| | | } |