import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Modal } from 'antd'
|
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
import ModalForm from './modalform'
|
|
class NormalFormComponent extends Component {
|
static propTpyes = {
|
width: PropTypes.any,
|
check: PropTypes.any,
|
title: PropTypes.string,
|
getForms: PropTypes.func,
|
update: PropTypes.func
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
visible: false,
|
formlist: []
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState)) || !is(fromJS(this.props.children), fromJS(nextProps.children))
|
}
|
|
trigger = () => {
|
this.setState({
|
visible: true,
|
formlist: this.props.getForms()
|
})
|
}
|
|
submit = () => {
|
const { check } = this.props
|
|
this.Ref.handleConfirm().then(res => {
|
if (check) {
|
this.props.update(res, () => {
|
this.setState({
|
visible: false,
|
formlist: []
|
})
|
})
|
} else {
|
this.setState({
|
visible: false,
|
formlist: []
|
})
|
this.props.update(res)
|
}
|
})
|
}
|
|
cancel = () => {
|
this.setState({ visible: false })
|
|
this.props.cancel && this.props.cancel()
|
}
|
|
render () {
|
const { title, width, children, double } = this.props
|
const { visible, dict, formlist } = this.state
|
|
return (
|
<>
|
{!double ? <span onClick={this.trigger}>{children}</span> : <span onDoubleClick={this.trigger}>{children}</span>}
|
<Modal
|
wrapClassName="popview-modal"
|
title={title}
|
visible={visible}
|
width={width}
|
maskClosable={false}
|
okText={dict['model.confirm']}
|
onOk={this.submit}
|
onCancel={this.cancel}
|
destroyOnClose
|
>
|
<ModalForm
|
formlist={formlist}
|
inputSubmit={this.submit}
|
wrappedComponentRef={(inst) => this.Ref = inst}
|
/>
|
</Modal>
|
</>
|
)
|
}
|
}
|
|
export default NormalFormComponent
|