king
7 天以前 a1e9b18a4dbfd21e1bf4d5cb60974ac2f0115efd
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
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