import React from 'react';
import { Form, Input, Button, Row, Col } from 'antd';
import './index.less';
import Editor from '@src/components/Editor';
import Page from '@src/containers/Page';
import Block from '@src/components/Block';
import Select from '@src/components/Select';
// import FileUpload from '@src/components/FileUpload';
import { formatFormError, getMap } from '@src/services/Tools';
import { asyncSMessage } from '@src/services/AsyncTools';
import { Ready } from '../../../stores/ready';
import { System } from '../../../stores/system';
export default class extends Page {
init() {
Ready.getReadyRead().then(result => {
return this.refreshStruct(result);
});
}
initData() {
const { id } = this.params;
const { form } = this.props;
let handler;
if (id) {
handler = Ready.getRead({ id });
} else {
handler = Promise.resolve({});
}
handler
.then(result => {
form.setFieldsValue(result);
});
}
refreshStruct(result) {
result = result || {};
result.plates = (result.plates || []).map((row, index) => { row.value = index + 1; return row; });
this.structMap = getMap(result.plates, 'value', 'plate');
this.setState({
struct: result,
plates: result.plates.map((row) => {
row.value = `${row.value}`;
row.label = row.plate;
row.title = '';
return row;
}),
});
}
submit() {
const { form } = this.props;
form.validateFields((err) => {
if (!err) {
const data = form.getFieldsValue();
let handler;
if (data.id) {
handler = Ready.editRead(data);
} else {
handler = Ready.addRead(data);
}
handler.then(() => {
asyncSMessage('保存成功');
goBack();
}).catch((e) => {
if (e.result) form.setFields(formatFormError(data, e.result));
});
}
});
}
renderBase() {
const { getFieldDecorator } = this.props.form;
return