page.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import React from 'react';
  2. import { Tabs } from 'antd';
  3. import { Link } from 'react-router-dom';
  4. import './index.less';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import ActionLayout from '@src/layouts/ActionLayout';
  8. import TableLayout from '@src/layouts/TableLayout';
  9. import { formatDate, getMap } from '@src/services/Tools';
  10. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  11. import { System } from '../../../stores/system';
  12. import { MessageCategory, MessageEmailStatus, MessageCustomStatus } from '../../../../Constant';
  13. const MessageCategoryMap = getMap(MessageCategory, 'value', 'label');
  14. const MessageEmailStatusMap = getMap(MessageEmailStatus, 'value', 'label');
  15. const MessageCustomStatusMap = getMap(MessageCustomStatus, 'value', 'label');
  16. export default class extends Page {
  17. init() {
  18. this.itemList = [{
  19. key: 'id',
  20. type: 'hidden',
  21. }, {
  22. key: 'title',
  23. type: 'input',
  24. name: '标题',
  25. }, {
  26. key: 'content',
  27. type: 'textarea',
  28. name: '内容',
  29. }, {
  30. key: 'link',
  31. type: 'input',
  32. name: '链接地址',
  33. }, {
  34. key: 'sendTime',
  35. type: 'date',
  36. name: '发送时间',
  37. }];
  38. this.columns = [{
  39. title: '消息标题',
  40. dataIndex: 'title',
  41. }, {
  42. title: '消息内容',
  43. dataIndex: 'content',
  44. }, {
  45. title: '发送时间',
  46. dataIndex: 'sendTime',
  47. render: (text) => {
  48. return formatDate(text);
  49. },
  50. }, {
  51. title: '状态',
  52. dataIndex: 'sendStatus',
  53. render: (text) => {
  54. return MessageCustomStatusMap[text] || '';
  55. },
  56. }, {
  57. title: '操作',
  58. dataIndex: 'handler',
  59. render: (text, record) => {
  60. return <div className="table-button">
  61. {record.sendStatus === 0 && (
  62. <a onClick={() => {
  63. this.editAction(record);
  64. }}>编辑</a>
  65. )}
  66. </div>;
  67. },
  68. }];
  69. this.insideColumns = [{
  70. title: '站内信标题',
  71. dataIndex: 'title',
  72. }, {
  73. title: '触发场景',
  74. dataIndex: 'messageCategory',
  75. render: (text) => {
  76. return MessageCategoryMap[text] || '';
  77. },
  78. }, {
  79. title: '发送数量',
  80. dataIndex: 'sendNumber',
  81. }, {
  82. title: '状态',
  83. dataIndex: 'sendStatus',
  84. render: (text) => {
  85. return MessageEmailStatusMap[text] || '';
  86. },
  87. }, {
  88. title: '操作',
  89. dataIndex: 'handler',
  90. render: (text, record) => {
  91. return <div className="table-button">
  92. {(
  93. <Link to={`/show/message/detail/${record.id}`}>编辑</Link>
  94. )}
  95. {record.sendStatus === 0 && (
  96. <a onClick={() => {
  97. this.openAction(record);
  98. }}>开启</a>
  99. )}
  100. {record.sendStatus === 1 && (
  101. <a onClick={() => {
  102. this.closeAction(record);
  103. }}>关闭</a>
  104. )}
  105. </div>;
  106. },
  107. }];
  108. this.emailColumns = [{
  109. title: '邮件标题',
  110. dataIndex: 'title',
  111. }, {
  112. title: '触发场景',
  113. dataIndex: 'messageCategory',
  114. render: (text) => {
  115. return MessageCategoryMap[text] || '';
  116. },
  117. }, {
  118. title: '发送数量',
  119. dataIndex: 'sendNumber',
  120. }, {
  121. title: '状态',
  122. dataIndex: 'sendStatus',
  123. render: (text) => {
  124. return MessageEmailStatusMap[text] || '';
  125. },
  126. }, {
  127. title: '操作',
  128. dataIndex: 'handler',
  129. render: (text, record) => {
  130. return <div className="table-button">
  131. {(
  132. <Link to={`/show/message/detail/${record.id}`}>编辑</Link>
  133. )}
  134. {record.sendStatus === 0 && (
  135. <a onClick={() => {
  136. this.openAction(record);
  137. }}>开启</a>
  138. )}
  139. {record.sendStatus === 1 && (
  140. <a onClick={() => {
  141. this.closeAction(record);
  142. }}>关闭</a>
  143. )}
  144. </div>;
  145. },
  146. }];
  147. this.actionList = [{
  148. key: 'add',
  149. name: '增加',
  150. }];
  151. }
  152. initData() {
  153. this.refreshTab(this.state.search.tab || 'inside');
  154. }
  155. refreshTab(tab) {
  156. const { search } = this.state;
  157. search.tab = tab;
  158. this.setState({ search });
  159. if (tab === 'inside') {
  160. return this.refreshInside();
  161. }
  162. if (tab === 'custom') {
  163. return this.refreshCustom();
  164. }
  165. if (tab === 'email') {
  166. return this.refreshEmail();
  167. }
  168. return Promise.reject();
  169. }
  170. refreshInside() {
  171. return System.listMessage({ messageMethod: 'inside', needCustom: false }).then((result) => {
  172. this.setState({ list: result.list, total: result.total });
  173. });
  174. }
  175. refreshCustom() {
  176. return System.listMessage({ messageMethod: 'inside', messageCategory: 'custom' }).then((result) => {
  177. this.setState({ list: result.list, total: result.total });
  178. });
  179. }
  180. refreshEmail() {
  181. return System.listMessage({ messageMethod: 'email', needCustom: false }).then((result) => {
  182. this.setState({ list: result.list, total: result.total });
  183. });
  184. }
  185. addAction() {
  186. asyncForm('创建消息', this.itemList, {}, data => {
  187. return System.addMessage(data).then(() => {
  188. asyncSMessage('添加成功!');
  189. this.refreshTab('custom');
  190. });
  191. });
  192. }
  193. editAction(row) {
  194. asyncForm('编辑消息', this.itemList, row, data => {
  195. return System.editMessage(data).then(() => {
  196. asyncSMessage('编辑成功!');
  197. this.refreshTab('custom');
  198. });
  199. });
  200. }
  201. openAction(row) {
  202. System.editMessage({ id: row.id, sendStatus: 1 }).then(() => {
  203. asyncSMessage('操作成功!');
  204. this.refresh();
  205. });
  206. }
  207. closeAction(row) {
  208. System.editMessage({ id: row.id, sendStatus: 0 }).then(() => {
  209. asyncSMessage('操作成功!');
  210. this.refresh();
  211. });
  212. }
  213. renderInside() {
  214. return <Block flex>
  215. <TableLayout
  216. columns={this.tableSort(this.insideColumns)}
  217. list={this.state.list}
  218. pagination={false}
  219. loading={this.props.core.loading}
  220. />
  221. </Block>;
  222. }
  223. renderCustom() {
  224. return <Block flex>
  225. <ActionLayout
  226. itemList={this.actionList}
  227. selectedKeys={this.state.selectedKeys}
  228. onAction={key => this.onAction(key)}
  229. />
  230. <TableLayout
  231. columns={this.tableSort(this.columns)}
  232. list={this.state.list}
  233. pagination={false}
  234. loading={this.props.core.loading}
  235. />
  236. </Block>;
  237. }
  238. renderEmail() {
  239. return <Block flex>
  240. <TableLayout
  241. columns={this.tableSort(this.emailColumns)}
  242. list={this.state.list}
  243. pagination={false}
  244. loading={this.props.core.loading}
  245. />
  246. </Block>;
  247. }
  248. renderView() {
  249. const { search } = this.state;
  250. const { tab } = search;
  251. return <div>
  252. <Tabs activeKey={tab || 'inside'} onChange={(value) => {
  253. this.search({ tab: value });
  254. }}>
  255. <Tabs.TabPane tab="模版消息" key="inside">
  256. {this.renderInside()}
  257. </Tabs.TabPane>
  258. <Tabs.TabPane tab="自定义消息" key="custom">
  259. {this.renderCustom()}
  260. </Tabs.TabPane>
  261. <Tabs.TabPane tab="邮件模版" key="email">
  262. {this.renderEmail()}
  263. </Tabs.TabPane>
  264. </Tabs>
  265. </div>;
  266. }
  267. }