page.js 7.4 KB

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