import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Switch } from 'antd'
|
|
import './index.scss'
|
|
class CheckCard extends Component {
|
static propTpyes = {
|
Item: PropTypes.bool, // 表单
|
onChange: PropTypes.func // 数据切换
|
}
|
|
state = {
|
defaultChecked: this.props.Item.initval === true
|
}
|
|
UNSAFE_componentWillMount () {
|
const { Item, onChange } = this.props
|
if (Item.initval === true) {
|
onChange && onChange(Item.openVal)
|
} else {
|
onChange && onChange(Item.closeVal)
|
}
|
}
|
|
onChange = (val) => {
|
const { Item, onChange } = this.props
|
if (val) {
|
onChange && onChange(Item.openVal)
|
} else {
|
onChange && onChange(Item.closeVal)
|
}
|
}
|
|
render() {
|
const { Item } = this.props
|
const { defaultChecked } = this.state
|
|
return (
|
<Switch checkedChildren={Item.openText || ''} unCheckedChildren={Item.closeText || ''} defaultChecked={defaultChecked} onChange={this.onChange}/>
|
)
|
}
|
}
|
|
export default CheckCard
|