page.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. let extend = '';
  124. if (record.isSystem) extend = '系统创建';
  125. else if (!record.userId) extend = '未注册';
  126. return `${text.nickname || record.nickname}${extend ? `(${extend})` : ''}`;
  127. },
  128. },
  129. {
  130. title: '问题摘要',
  131. dataIndex: 'content',
  132. }, {
  133. title: '回答状态',
  134. dataIndex: 'status',
  135. render: (text) => {
  136. return AskStatusMap[text] || '';
  137. },
  138. }, {
  139. title: '精选',
  140. dataIndex: 'isSpecial',
  141. render: (text, record) => {
  142. return record.status > 0 ? SwitchSelectMap[text] || text : '-';
  143. },
  144. }, {
  145. title: '操作',
  146. dataIndex: 'handler',
  147. render: (text, record) => {
  148. return <div className="table-button">
  149. {(
  150. <a onClick={() => {
  151. this.editAction(record);
  152. }}>编辑</a>
  153. )}
  154. {!record.isSystem && record.status === 0 && (
  155. <a onClick={() => {
  156. this.answerAction(record);
  157. }}>回复</a>
  158. )}
  159. {!!record.isSpecial && (
  160. <a onClick={() => {
  161. this.special(record, 0);
  162. }}>取消精选</a>
  163. )}
  164. {!record.isSpecial && (
  165. <a onClick={() => {
  166. this.special(record, 1);
  167. }}>精选</a>
  168. )}
  169. </div>;
  170. },
  171. },
  172. ];
  173. bindSearch(this.filterForm, 'userId', this, (search) => {
  174. return User.list(search);
  175. }, (row) => {
  176. return {
  177. title: `${row.nickname}(${row.mobile})`,
  178. value: row.id,
  179. };
  180. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  181. }
  182. initData() {
  183. System.listFAQ(this.state.search).then(result => {
  184. this.setTableData(result.list, result.total);
  185. });
  186. }
  187. addAction() {
  188. asyncForm('创建', this.itemList, {}, data => {
  189. return System.addFAQ(data).then(() => {
  190. asyncSMessage('添加成功!');
  191. this.refresh();
  192. });
  193. }).then(component => {
  194. this.formF = component;
  195. });
  196. }
  197. editAction(row) {
  198. asyncForm('编辑', this.itemList, row, data => {
  199. return System.editFAQ(data).then(() => {
  200. asyncSMessage('编辑成功!');
  201. this.refresh();
  202. });
  203. }).then(component => {
  204. this.formF = component;
  205. });
  206. }
  207. answerAction(row) {
  208. asyncForm('回复', this.answerList, row, data => {
  209. data.sendUser = true;
  210. return System.editFAQ(data).then(() => {
  211. asyncSMessage('回复成功!');
  212. this.refresh();
  213. });
  214. }).then(component => {
  215. this.formF = component;
  216. });
  217. }
  218. special(row, isSpecial) {
  219. System.editFAQ({ id: row.id, isSpecial }).then(() => {
  220. asyncSMessage('编辑成功!');
  221. this.refresh();
  222. });
  223. }
  224. renderView() {
  225. return <Block flex>
  226. <FilterLayout
  227. show
  228. itemList={this.filterForm}
  229. data={this.state.search}
  230. onChange={data => {
  231. this.search(data);
  232. }} />
  233. <ActionLayout
  234. itemList={this.actionList}
  235. selectedKeys={this.state.selectedKeys}
  236. onAction={key => this.onAction(key)}
  237. />
  238. <TableLayout
  239. select
  240. columns={this.columns}
  241. list={this.state.list}
  242. pagination={this.state.page}
  243. loading={this.props.core.loading}
  244. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  245. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  246. selectedKeys={this.state.selectedKeys}
  247. />
  248. </Block>;
  249. }
  250. }