173 lines
4.2 KiB
JavaScript
173 lines
4.2 KiB
JavaScript
import React from 'react';
|
|
import { Modal, message } from 'antd';
|
|
import { createCrudService } from '../../../../components/crud/_';
|
|
|
|
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' });
|
|
}
|
|
|
|
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).edit(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||'修改失败');
|
|
}
|
|
})
|
|
}
|
|
|
|
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();
|
|
}
|
|
} 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();
|
|
}
|
|
} 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,record) => {
|
|
if(value === 'save'){
|
|
return ''
|
|
}else if (value === 'add'){
|
|
return '新增'
|
|
}else if (value === 'edit'){
|
|
return '修改'
|
|
}else if (value === 'view'){
|
|
return record.idx === 1 ? 'Ⅰ级' :
|
|
record.idx === 2 ? 'Ⅱ级' :
|
|
record.idx === 3 ? "Ⅲ级" :
|
|
record.idx === 4 ? "Ⅳ级" :''
|
|
}else if (value === 'show' || value === 'review'){
|
|
return ''
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const { record, open, mode } = this.state;
|
|
const { width, title, style, wrapClassName, formProps, component: Component,data } = this.props;
|
|
if (!record || !open) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Modal
|
|
width={width || 600}
|
|
style={style || { top: 10 }}
|
|
wrapClassName={wrapClassName}
|
|
visible
|
|
title={`${this.whichMod(mode,record)}${title}`}
|
|
footer={null}
|
|
destroyOnClose
|
|
onCancel={() => { this.setState({ open: false }) }}
|
|
>
|
|
<Component
|
|
mode={mode}
|
|
close={()=>{this.setState({ open: false })}}
|
|
onCrudSuccess={this.props.onCrudSuccess}
|
|
record={record}
|
|
onEdit={this.onEdit}
|
|
onSave={this.onSave}
|
|
formProps={formProps}
|
|
data={data}
|
|
/>
|
|
</Modal>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default BasicCrudModal;
|