import React from 'react' import { connect } from 'dva' import { Modal, Form, message } from 'antd' import FormPage from './FormPage' import { permissionUtils, getCustomParams } from "../utils/common" class FormModal extends React.Component { constructor (props) { super(props) this.state = { visible: false, loading: false, formData: {} } }; doShowModel = () => { let isReturn = false const click = this.props.click if (typeof click === 'function') { isReturn = click(true) } //未启用 if (this.state.formData.ENABLE_STATUS === 1) { message.error('当前表单' + this.state.formData.CODE + '已失效,请联系管理员') isReturn = true } if (isReturn) return //权限控制 if (!this.state.formData.IS_IGNORE_PERMISSION && !permissionUtils(this.props.login).checkForm(this.state.formData.ID)) { message.error('您无浏览表单' + this.state.formData.CODE + '的权限,请联系管理员') isReturn = true } if (isReturn) return this.setState({ visible: true }, () => { const data = this.props.data this.props.dispatch({ type: 'editPage/save', payload: { [data ? data.reloadKey : '']: true }, }) }) } showModal = (e) => { // 显示弹窗 e.stopPropagation() if (!this.state.formData.ID) { this.fetch(() => { this.doShowModel() }) return } this.doShowModel() } handleCancel = () => { // 退出弹窗 this.props.form.resetFields() this.setState({ visible: false }) const click = this.props.click if (typeof click === 'function') { click(false) } } fetch = (onComplete) => { const { formCode, dispatch } = this.props const orgId = this.props.login.OrgId const OJson = { 'Key': formCode, 'orgid': orgId } dispatch({ type: 'app/getFormByRedis', payload: OJson, onComplete: (ret) => { if (ret) { this.setState({ formData: ret }, () => { if (onComplete) { onComplete() } }) } } }) } render () { let custParams = getCustomParams(this.props.customParams) const tmpData = { formCode: this.props.formCode, data: { ...this.props.data, close: this.handleCancel, ...custParams, customParams: this.props.customParams, formParam: this.props.formParam, onCancel: this.handleCancel }, id: this.props.id, onSave: this.props.onSave, parentId: this.props.parentId, copySrcId: this.props.copySrcId, onCancel: this.handleCancel, isAddH: this.props.isAddH, onRegDestroyCacheDataFunc: this.onRegDestroyCacheDataFunc, } return (