import React from 'react'; import { Tabs, Form, Row, Col, Input, InputNumber, Button } from 'antd'; import './index.less'; import Editor from '@src/components/Editor'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; import { flattenObject, formatFormError } from '@src/services/Tools'; import { asyncSMessage } from '@src/services/AsyncTools'; import { System } from '../../../stores/system'; export default class extends Page { constructor(props) { super(props); this.state.tab = 'sentence'; } initData() { this.refresh(this.state.tab); } refresh(tab) { if (tab === 'sentence') { return this.refreshSentence(); } if (tab === 'prepare') { return this.refreshPrepare(); } return Promise.reject(); } refreshSentence() { return System.getSentenceInfo().then(result => { this.setState({ sentence: result || {} }); const { form } = this.props; form.setFieldsValue(flattenObject(result, 'sentence')); }); } refreshPrepare() { return System.getPrepareInfo().then(result => { this.setState({ prepare: result || {} }); const { form } = this.props; form.setFieldsValue(flattenObject(result, 'prepare')); }); } changeMapValue(field, second, index, key, value) { const data = this.state[field] || {}; data[second] = data[second] || []; data[second][index] = data[second][index] || {}; data[second][index][key] = value; this.setState({ [field]: data }); } changeValue(field, key, value) { const { data } = this.state; data[field] = data[field] || {}; data[field][key] = value; this.setState({ data }); } submit(tab) { let handler = Promise.reject(); if (tab === 'sentence') { handler = this.submitSentence(); } if (tab === 'prepare') { handler = this.submitPrepare(); } handler.then(() => { asyncSMessage('保存成功'); }); } submitSentence() { const { form } = this.props; return new Promise((resolve, reject) => { form.validateFields(['sentence'], (err, values) => { if (err) { reject(err); } const data = values.sentence; return System.setSentenceInfo(data) .then(() => { resolve(); }).catch((e) => { form.setFields(formatFormError(data, e.result)); reject(e); }); }); }); } submitPrepare() { const { form } = this.props; return new Promise((resolve, reject) => { form.validateFields(['prepare'], (err, values) => { if (err) { reject(err); } const data = values.prepare; return System.setPrepareInfo(data) .then(() => { resolve(); }).catch((e) => { form.setFields(formatFormError(data, e.result)); reject(e); }); }); }); } renderSentence() { const { getFieldDecorator } = this.props.form; return
; } renderPrepare() { const { getFieldDecorator } = this.props.form; return ; } renderView() { const { tab } = this.state; return