123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- 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 <div className="table-button">
- {record.sendStatus === 0 && (
- <a onClick={() => {
- this.editAction(record);
- }}>编辑</a>
- )}
- </div>;
- },
- }];
- 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 <div className="table-button">
- {(
- <Link to={`/show/message/detail/${record.id}`}>编辑</Link>
- )}
- {record.sendStatus === 0 && (
- <a onClick={() => {
- this.openAction(record);
- }}>开启</a>
- )}
- {record.sendStatus === 1 && (
- <a onClick={() => {
- this.closeAction(record);
- }}>关闭</a>
- )}
- </div>;
- },
- }];
- 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 <div className="table-button">
- {(
- <Link to={`/show/message/detail/${record.id}`}>编辑</Link>
- )}
- {record.sendStatus === 0 && (
- <a onClick={() => {
- this.openAction(record);
- }}>开启</a>
- )}
- {record.sendStatus === 1 && (
- <a onClick={() => {
- this.closeAction(record);
- }}>关闭</a>
- )}
- </div>;
- },
- }];
- 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 <Block flex>
- <TableLayout
- columns={this.tableSort(this.insideColumns)}
- list={this.state.list}
- pagination={false}
- loading={this.props.core.loading}
- />
- </Block>;
- }
- renderCustom() {
- return <Block flex>
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- columns={this.tableSort(this.columns)}
- list={this.state.list}
- pagination={false}
- loading={this.props.core.loading}
- />
- </Block>;
- }
- renderEmail() {
- return <Block flex>
- <TableLayout
- columns={this.tableSort(this.emailColumns)}
- list={this.state.list}
- pagination={false}
- loading={this.props.core.loading}
- />
- </Block>;
- }
- renderView() {
- const { search } = this.state;
- const { tab } = search;
- return <div>
- <Tabs activeKey={tab || 'inside'} onChange={(value) => {
- this.search({ tab: value });
- }}>
- <Tabs.TabPane tab="模版消息" key="inside">
- {this.renderInside()}
- </Tabs.TabPane>
- <Tabs.TabPane tab="自定义消息" key="custom">
- {this.renderCustom()}
- </Tabs.TabPane>
- <Tabs.TabPane tab="邮件模版" key="email">
- {this.renderEmail()}
- </Tabs.TabPane>
- </Tabs>
- </div>;
- }
- }
|