page.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Block from '@src/components/Block';
  5. import FilterLayout from '@src/layouts/FilterLayout';
  6. import ActionLayout from '@src/layouts/ActionLayout';
  7. import TableLayout from '@src/layouts/TableLayout';
  8. import { getMap, bindSearch, formatDate } from '@src/services/Tools';
  9. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  10. import { ChannelModule, SwitchSelect, AskStatus } from '../../../../Constant';
  11. import { System } from '../../../stores/system';
  12. import { User } from '../../../stores/user';
  13. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  14. const ChannelModuleMap = getMap(ChannelModule, 'value', 'label');
  15. const AskStatusMap = getMap(AskStatus, 'value', 'label');
  16. export default class extends Page {
  17. init() {
  18. this.actionList = [{
  19. key: 'add',
  20. type: 'primary',
  21. name: '创建',
  22. }];
  23. this.formF = null;
  24. this.itemList = [{
  25. key: 'id',
  26. type: 'hidden',
  27. }, {
  28. key: 'channel',
  29. type: 'select',
  30. allowClear: true,
  31. name: '频道',
  32. select: ChannelModule,
  33. placeholder: '请选择',
  34. }, {
  35. key: 'position',
  36. type: 'select',
  37. allowClear: true,
  38. name: '位置',
  39. select: ChannelModule,
  40. placeholder: '请选择',
  41. }, {
  42. key: 'content',
  43. type: 'textarea',
  44. name: '用户留言',
  45. }, {
  46. key: 'answer',
  47. type: 'textarea',
  48. name: '编辑回复',
  49. }];
  50. this.answerList = [{
  51. key: 'id',
  52. type: 'hidden',
  53. }, {
  54. key: 'content',
  55. type: 'textarea',
  56. disabled: true,
  57. name: '用户留言',
  58. }, {
  59. key: 'answer',
  60. type: 'textarea',
  61. name: '编辑回复',
  62. }];
  63. this.filterForm = [{
  64. key: 'channel',
  65. type: 'select',
  66. allowClear: true,
  67. name: '频道',
  68. select: ChannelModule,
  69. placeholder: '请选择',
  70. }, {
  71. key: 'position',
  72. type: 'select',
  73. allowClear: true,
  74. name: '位置',
  75. select: ChannelModule,
  76. placeholder: '请选择',
  77. }, {
  78. key: 'userId',
  79. type: 'select',
  80. allowClear: true,
  81. name: '用户',
  82. select: [],
  83. number: true,
  84. placeholder: '请输入',
  85. }, {
  86. key: 'status',
  87. type: 'select',
  88. allowClear: true,
  89. number: true,
  90. name: '状态',
  91. select: AskStatus,
  92. }, {
  93. key: 'isSpecial',
  94. type: 'select',
  95. allowClear: true,
  96. name: '精选',
  97. number: true,
  98. select: SwitchSelect,
  99. }];
  100. this.columns = [
  101. {
  102. title: '频道',
  103. dataIndex: 'channel',
  104. render: (text, record) => {
  105. return ChannelModuleMap[record.channel];
  106. },
  107. },
  108. {
  109. title: '位置',
  110. dataIndex: 'position',
  111. },
  112. {
  113. title: '提问时间',
  114. dataIndex: 'createTime',
  115. render: (text) => {
  116. return formatDate(text);
  117. },
  118. },
  119. {
  120. title: '提问者',
  121. dataIndex: 'user',
  122. render: (text, record) => {
  123. if (record.isSystem) return '系统创建';
  124. if (!record.userId) return '未注册';
  125. return text ? text.nickname : '';
  126. },
  127. },
  128. {
  129. title: '问题摘要',
  130. dataIndex: 'content',
  131. }, {
  132. title: '回答状态',
  133. dataIndex: 'status',
  134. render: (text) => {
  135. return AskStatusMap[text] || '';
  136. },
  137. }, {
  138. title: '精选',
  139. dataIndex: 'isSpecial',
  140. render: (text, record) => {
  141. return record.status > 0 ? SwitchSelectMap[text] || text : '-';
  142. },
  143. }, {
  144. title: '操作',
  145. dataIndex: 'handler',
  146. render: (text, record) => {
  147. return <div className="table-button">
  148. {(
  149. <a onClick={() => {
  150. this.editAction(record);
  151. }}>编辑</a>
  152. )}
  153. {!record.isSystem && record.status === 0 && (
  154. <a onClick={() => {
  155. this.answerAction(record);
  156. }}>回复</a>
  157. )}
  158. {!!record.isSpecial && (
  159. <a onClick={() => {
  160. this.special(record, 0);
  161. }}>取消精选</a>
  162. )}
  163. {!record.isSpecial && (
  164. <a onClick={() => {
  165. this.special(record, 1);
  166. }}>精选</a>
  167. )}
  168. </div>;
  169. },
  170. },
  171. ];
  172. bindSearch(this.filterForm, 'userId', this, (search) => {
  173. return User.list(search);
  174. }, (row) => {
  175. return {
  176. title: `${row.nickname}(${row.mobile})`,
  177. value: row.id,
  178. };
  179. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  180. }
  181. initData() {
  182. System.listFAQ(this.state.search).then(result => {
  183. this.setTableData(result.list, result.total);
  184. });
  185. }
  186. addAction() {
  187. asyncForm('创建', this.itemList, {}, data => {
  188. return System.addFAQ(data).then(() => {
  189. asyncSMessage('添加成功!');
  190. this.refresh();
  191. });
  192. }).then(component => {
  193. this.formF = component;
  194. });
  195. }
  196. editAction(row) {
  197. asyncForm('编辑', this.itemList, row, data => {
  198. return System.editFAQ(data).then(() => {
  199. asyncSMessage('编辑成功!');
  200. this.refresh();
  201. });
  202. }).then(component => {
  203. this.formF = component;
  204. });
  205. }
  206. answerAction(row) {
  207. asyncForm('回复', this.answerList, row, data => {
  208. data.sendUser = true;
  209. return System.editFAQ(data).then(() => {
  210. asyncSMessage('回复成功!');
  211. this.refresh();
  212. });
  213. }).then(component => {
  214. this.formF = component;
  215. });
  216. }
  217. special(row, isSpecial) {
  218. System.editFAQ({ id: row.id, isSpecial }).then(() => {
  219. asyncSMessage('编辑成功!');
  220. this.refresh();
  221. });
  222. }
  223. renderView() {
  224. return <Block flex>
  225. <FilterLayout
  226. show
  227. itemList={this.filterForm}
  228. data={this.state.search}
  229. onChange={data => {
  230. this.search(data);
  231. }} />
  232. <ActionLayout
  233. itemList={this.actionList}
  234. selectedKeys={this.state.selectedKeys}
  235. onAction={key => this.onAction(key)}
  236. />
  237. <TableLayout
  238. select
  239. columns={this.columns}
  240. list={this.state.list}
  241. pagination={this.state.page}
  242. loading={this.props.core.loading}
  243. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  244. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  245. selectedKeys={this.state.selectedKeys}
  246. />
  247. </Block>;
  248. }
  249. }