| | |
| | | import { Radio } from 'antd' |
| | | |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | |
| | | class MKRadio extends Component { |
| | | static propTpyes = { |
| | |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('mkFP', this.mkFormHandle) |
| | | MKEmitter.addListener('mkFC', this.mkFormControl) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (nextProps.config.timestamp && nextProps.config.timestamp !== this.state.config.timestamp) { |
| | | this.setState({ |
| | | config: fromJS(nextProps.config).toJS(), |
| | | options: fromJS(nextProps.config.options).toJS(), |
| | | }) |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('mkFP', this.mkFormHandle) |
| | | MKEmitter.removeListener('mkFC', this.mkFormControl) |
| | | } |
| | | |
| | | mkFormControl = (type, field, value) => { |
| | | if (field !== this.props.config.field) return |
| | | |
| | | if (type === 'input') { |
| | | this.setState({value}) |
| | | this.props.onChange(value, {}) |
| | | } |
| | | } |
| | | |
| | | mkFormHandle = (field, parentId) => { |
| | |
| | | |
| | | if (field !== config.field) return |
| | | |
| | | let options = config.oriOptions ? config.oriOptions.filter(option => option.ParentID === parentId) : [] |
| | | let options = config.oriOptions ? config.oriOptions.filter(option => option.ParentID === parentId || option.ParentID === '') : [] |
| | | let val = options[0] ? options[0].value : '' |
| | | |
| | | this.setState({ |
| | |
| | | value: val |
| | | }) |
| | | |
| | | this.props.onChange(val) |
| | | this.props.onChange(val, {}) |
| | | |
| | | config.linkFields && config.linkFields.forEach((m, i) => { |
| | | setTimeout(() => { |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { value, options } = this.state |
| | | const { value, options, config } = this.state |
| | | |
| | | return ( |
| | | <Radio.Group value={value} onChange={this.onChange}> |
| | | {options.map(option => <Radio key={option.value} value={option.value}>{option.label}</Radio>)} |
| | | <Radio.Group style={{whiteSpace: 'nowrap'}} disabled={config.disabled} value={value} onChange={this.onChange}> |
| | | {options.map(option => <Radio key={option.value} disabled={option.disabled} value={option.value}>{option.label}</Radio>)} |
| | | </Radio.Group> |
| | | ) |
| | | } |