import React from 'react'; import { Modal, message } from 'antd'; import { createCrudService } from './_'; import apiurl from '../../service/apiurl'; class BasicCrudModal extends React.Component { constructor(props) { super(props); this.state = { record: null, open: false, mode: null, }; } showEdit(record) { this.setState({ record, open: true, mode: 'edit' }); } showSave(record) { record = record || {}; this.setState({ record, open: true, mode: 'save' }); } showSimilarSave(record) { record = record || {}; this.setState({ record, open: true, mode: 'similarSave' }); } show(record) { record = record || {}; this.setState({ record, open: true, mode: 'show' }); } showView(record) { record = record || {}; this.setState({ record, open: true, mode: 'view' }); } showReView(record) { record = record || {}; this.setState({ record, open: true, mode: 'review' }); } showAdd(record) { record = record || {}; this.setState({ record, open: true, mode: 'add' }); } showImp() { this.setState({ open: true, mode: 'imp' }); } onEdit = (path,values) => { createCrudService(path).edit1(values).then((result) => { if (result?.code === 200) { message.success('修改成功'); this.setState({ open: false }); if (this.props.onCrudSuccess) { this.props.onCrudSuccess(); } if (this.props.extraFun) { this.props.extraFun(); } } else { message.error(result?.msg||'修改失败'); } }) } onSave = (path,values) => { createCrudService(path).save(values).then((result) => { if (result?.code === 200) { message.success('保存成功'); this.setState({ open: false }); if (this.props.onCrudSuccess) { this.props.onCrudSuccess(); } if (this.props.extraFun) { this.props.extraFun(); } } else { message.error(result?.msg||'保存失败'); } }) } onDelete = (path, values) => { createCrudService(path).del(values).then((result) => { if (result?.code === 200) { message.success('删除成功'); this.setState({ open: false }); if (this.props.onCrudSuccess) { this.props.onCrudSuccess(); } } else { message.error(result?.msg||'删除失败'); } }) } onDeleteGet = (path,values) => { createCrudService(path).delGet(values).then((result) => { if (result?.code === 200) { message.success('删除成功'); this.setState({ open: false }); if (this.props.onCrudSuccess) { this.props.onCrudSuccess(); } if (this.props.extraFun) { this.props.extraFun(); } } else { message.error(result?.msg||'删除失败'); } }) } onDeletePost= (path,values) => { createCrudService(path).edit1(values).then((result) => { if (result?.code === 200) { message.success('删除成功'); this.setState({ open: false }); if (this.props.onCrudSuccess) { this.props.onCrudSuccess(); } if (this.props.extraFun) { this.props.extraFun(); } } else { message.error(result?.msg||'删除失败'); } }) } onSimilarSave = (path, values) => { createCrudService(path).delGet(values).then((result) => { if (result?.code === 200) { message.success('类似新增成功'); this.setState({ open: false }); if (this.props.onCrudSuccess) { this.props.onCrudSuccess(); } } else { message.error(result?.msg||'类似新增失败'); } }) } onFileGet = (path,values) => { createCrudService(path).delGet(values).then((result) => { if (result?.code === 200) { message.success('删除成功'); this.setState({ open: false }); if (this.props.onCrudSuccess) { this.props.onCrudSuccess(); } } else { message.error(result?.msg||'删除失败'); } }) } whichMod = (value) => { if(value === 'save'){ return '新增' }else if (value === 'add' || value === ''){ return '新增' }else if (value === 'edit'){ return '修改' }else if (value === 'view'){ return '查看' }else if (value === 'show' || value === 'review'){ return '' } else { return '新增' } } render() { const { record, open, mode } = this.state; const { width, title, style, wrapClassName, formProps, component: Component,extraFun } = this.props; if (!record || !open) { return null; } return ( { this.setState({ open: false }) }} > {this.setState({ open: false })}} onCrudSuccess={this.props.onCrudSuccess} record={record} onEdit={this.onEdit} onSave={this.onSave} onSimilarSave={this.onSimilarSave} formProps={formProps} /> ); } } export default BasicCrudModal;