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'
|
import './index.scss'
|
|
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))
|
}
|
|
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)
|
}
|
})
|
}
|
|
render () {
|
const { title, width, children } = this.props
|
const { visible, dict, formlist } = this.state
|
|
return (
|
<div className="normal-form-wrap">
|
<span onClick={this.trigger}>{children}</span>
|
<Modal
|
wrapClassName="popview-modal"
|
title={title}
|
visible={visible}
|
width={width}
|
maskClosable={false}
|
okText={dict['model.submit']}
|
onOk={this.submit}
|
onCancel={() => { this.setState({ visible: false }) }}
|
destroyOnClose
|
>
|
<ModalForm
|
dict={dict}
|
formlist={formlist}
|
inputSubmit={this.submit}
|
wrappedComponentRef={(inst) => this.Ref = inst}
|
/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default NormalFormComponent
|