import React from 'react'; import { Tabs } from 'antd'; import { Link } from 'react-router-dom'; 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 { formatDate, getMap } from '@src/services/Tools'; import { asyncSMessage, asyncForm } from '@src/services/AsyncTools'; import { System } from '../../../stores/system'; import { MessageCategory, MessageEmailStatus, MessageCustomStatus } from '../../../../Constant'; const MessageCategoryMap = getMap(MessageCategory, 'value', 'label'); const MessageEmailStatusMap = getMap(MessageEmailStatus, 'value', 'label'); const MessageCustomStatusMap = getMap(MessageCustomStatus, 'value', 'label'); 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: 'sendStatus', render: (text) => { return MessageCustomStatusMap[text] || ''; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{record.sendStatus === 0 && ( { this.editAction(record); }}>编辑 )}
; }, }]; this.insideColumns = [{ title: '站内信标题', dataIndex: 'title', }, { title: '触发场景', dataIndex: 'messageCategory', render: (text) => { return MessageCategoryMap[text] || ''; }, }, { title: '发送数量', dataIndex: 'sendNumber', }, { title: '状态', dataIndex: 'sendStatus', render: (text) => { return MessageEmailStatusMap[text] || ''; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{( 编辑 )} {record.sendStatus === 0 && ( { this.openAction(record); }}>开启 )} {record.sendStatus === 1 && ( { this.closeAction(record); }}>关闭 )}
; }, }]; this.emailColumns = [{ title: '邮件标题', dataIndex: 'title', }, { title: '触发场景', dataIndex: 'messageCategory', render: (text) => { return MessageCategoryMap[text] || ''; }, }, { title: '发送数量', dataIndex: 'sendNumber', }, { title: '状态', dataIndex: 'sendStatus', render: (text) => { return MessageEmailStatusMap[text] || ''; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{( 编辑 )} {record.sendStatus === 0 && ( { this.openAction(record); }}>开启 )} {record.sendStatus === 1 && ( { this.closeAction(record); }}>关闭 )}
; }, }]; this.actionList = [{ key: 'add', name: '增加', }]; } initData() { this.refreshTab(this.state.search.tab || 'inside'); } refreshTab(tab) { const { search } = this.state; search.tab = tab; this.setState({ search }); if (tab === 'inside') { return this.refreshInside(); } if (tab === 'custom') { return this.refreshCustom(); } if (tab === 'email') { return this.refreshEmail(); } return Promise.reject(); } refreshInside() { return System.listMessage({ messageMethod: 'inside', needCustom: false }).then((result) => { this.setState({ list: result.list, total: result.total }); }); } refreshCustom() { return System.listMessage({ messageMethod: 'inside', messageCategory: 'custom' }).then((result) => { this.setState({ list: result.list, total: result.total }); }); } refreshEmail() { return System.listMessage({ messageMethod: 'email', needCustom: false }).then((result) => { this.setState({ list: result.list, total: result.total }); }); } addAction() { asyncForm('创建消息', this.itemList, {}, data => { return System.addMessage(data).then(() => { asyncSMessage('添加成功!'); this.refreshTab('custom'); }); }); } editAction(row) { asyncForm('编辑消息', this.itemList, row, data => { return System.editMessage(data).then(() => { asyncSMessage('编辑成功!'); this.refreshTab('custom'); }); }); } openAction(row) { System.editMessage({ id: row.id, sendStatus: 1 }).then(() => { asyncSMessage('操作成功!'); this.refresh(); }); } closeAction(row) { System.editMessage({ id: row.id, sendStatus: 0 }).then(() => { asyncSMessage('操作成功!'); this.refresh(); }); } renderInside() { return ; } renderCustom() { return this.onAction(key)} /> ; } renderEmail() { return ; } renderView() { const { search } = this.state; const { tab } = search; return
{ this.search({ tab: value }); }}> {this.renderInside()} {this.renderCustom()} {this.renderEmail()}
; } }