import React from 'react'; import { Button, Tabs, Row, Col, Form, Input } from 'antd'; import './index.less'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; import ActionLayout from '@src/layouts/ActionLayout'; import TableLayout from '@src/layouts/TableLayout'; import { formatFormError, formatDate } from '@src/services/Tools'; import { asyncSMessage, asyncForm } from '@src/services/AsyncTools'; import { System } from '../../../stores/system'; export default class extends Page { init() { this.itemList = [{ key: 'id', type: 'hidden', }, { key: 'title', type: 'input', name: '标题', }, { key: 'content', type: 'textarea', name: '内容', }, { key: 'link', type: 'input', name: '链接地址', }, { key: 'sendTime', type: 'date', name: '发送时间', }]; this.columns = [{ title: '消息标题', dataIndex: 'title', }, { title: '消息内容', dataIndex: 'content', }, { title: '发送时间', dataIndex: 'sendTime', render: (text) => { return formatDate(text); }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{( { this.editAction(record); }}>编辑 )}
; }, }]; this.actionList = [{ key: 'add', name: '增加', }]; this.state.tab = 'template'; } initData() { this.refresh(this.state.tab); } refresh(tab) { if (tab === 'template') { return this.refreshTemplate(); } if (tab === 'custom') { return this.refreshCustom(); } return Promise.reject(); } refreshTemplate() { const { form } = this.props; return System.getMessageTemplate().then(result => { form.setFieldsValue(result); this.setState({ template: result || {} }); }); } refreshCustom() { return System.listMessage().then((result) => { this.setState({ list: result.list, total: result.total }); }); } submit(tab) { if (tab === 'template') { this.submitTemplate(); } } submitTemplate() { const { form } = this.props; form.validateFields((err) => { if (!err) { const data = form.getFieldsValue(); System.setMessageTemplate(data) .then(() => { this.setState(data); asyncSMessage('保存成功'); }).catch((e) => { form.setFields(formatFormError(data, e.result)); }); } }); } submitCustom() { const { exercise } = this.state; return System.setExerciseTime(exercise); } addAction() { asyncForm('创建消息', this.itemList, {}, data => { return System.addMessage(data).then(() => { asyncSMessage('添加成功!'); this.refresh('custom'); }); }); } editAction(row) { asyncForm('编辑消息', this.itemList, row, data => { return System.editMessage(data).then(() => { asyncSMessage('编辑成功!'); this.refresh('custom'); }); }); } renderTemplate() { const { getFieldDecorator } = this.props.form; return

购买消息

{getFieldDecorator('pay.content', { rules: [ { required: false, message: '请输入购买消息内容' }, ], })( , )} {getFieldDecorator('pay.link')( , )}

换库消息

{getFieldDecorator('library.content', { rules: [ { required: false, message: '请输入换库消息内容' }, ], })( , )} {getFieldDecorator('library.link')( , )}

课程消息

{getFieldDecorator('course.content', { rules: [ { required: false, message: '请输入课程消息内容' }, ], })( , )} {getFieldDecorator('course.link')( , )}
; } renderCustom() { return this.onAction(key)} /> ; } renderView() { const { tab } = this.state; return
{ this.setState({ tab: value, selectedKeys: [], checkedKeys: [] }); this.refresh(value); }}> {this.renderTemplate()} {this.renderCustom()} {tab !== 'custom' && }
; } }