page.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. name: '用户留言',
  57. }, {
  58. key: 'answer',
  59. type: 'textarea',
  60. name: '编辑回复',
  61. }, {
  62. key: 'isSpecial',
  63. type: 'switch',
  64. name: '是否精选',
  65. select: SwitchSelect,
  66. }, {
  67. key: 'sendMail',
  68. type: 'switch',
  69. name: '发送邮件',
  70. select: SwitchSelect,
  71. }];
  72. this.filterForm = [{
  73. key: 'channel',
  74. type: 'select',
  75. allowClear: true,
  76. name: '频道',
  77. select: ChannelModule,
  78. placeholder: '请选择',
  79. }, {
  80. key: 'position',
  81. type: 'select',
  82. allowClear: true,
  83. name: '位置',
  84. select: ChannelModule,
  85. placeholder: '请选择',
  86. }, {
  87. key: 'userId',
  88. type: 'select',
  89. allowClear: true,
  90. name: '用户',
  91. select: [],
  92. number: true,
  93. placeholder: '请输入',
  94. }, {
  95. key: 'status',
  96. type: 'select',
  97. allowClear: true,
  98. number: true,
  99. name: '状态',
  100. select: AskStatus,
  101. }, {
  102. key: 'isSpecial',
  103. type: 'select',
  104. allowClear: true,
  105. name: '精选',
  106. number: true,
  107. select: SwitchSelect,
  108. }];
  109. this.columns = [
  110. {
  111. title: '频道',
  112. dataIndex: 'channel',
  113. render: (text, record) => {
  114. return ChannelModuleMap[record.channel];
  115. },
  116. },
  117. {
  118. title: '位置',
  119. dataIndex: 'position',
  120. },
  121. {
  122. title: '提问时间',
  123. dataIndex: 'createTime',
  124. render: (text) => {
  125. return formatDate(text);
  126. },
  127. },
  128. {
  129. title: '提问者',
  130. dataIndex: 'user',
  131. render: (text, record) => {
  132. if (record.isSystem) return '系统创建';
  133. if (!record.userId) return '未注册';
  134. return text ? text.nickname : '';
  135. },
  136. },
  137. {
  138. title: '问题摘要',
  139. dataIndex: 'content',
  140. }, {
  141. title: '回答状态',
  142. dataIndex: 'status',
  143. render: (text) => {
  144. return AskStatusMap[text] || '';
  145. },
  146. }, {
  147. title: '精选',
  148. dataIndex: 'isSpecial',
  149. render: (text, record) => {
  150. return record.status > 0 ? SwitchSelectMap[text] || text : '-';
  151. },
  152. }, {
  153. title: '操作',
  154. dataIndex: 'handler',
  155. render: (text, record) => {
  156. return <div className="table-button">
  157. {!!record.isSystem && (
  158. <a onClick={() => {
  159. this.editAction(record);
  160. }}>编辑</a>
  161. )}
  162. {!record.isSystem && record.status === 0 && (
  163. <a onClick={() => {
  164. this.answerAction(record);
  165. }}>回复</a>
  166. )}
  167. {!!record.isSpecial && (
  168. <a onClick={() => {
  169. this.special(record, 0);
  170. }}>取消精选</a>
  171. )}
  172. {!record.isSpecial && (
  173. <a onClick={() => {
  174. this.special(record, 1);
  175. }}>精选</a>
  176. )}
  177. </div>;
  178. },
  179. },
  180. ];
  181. bindSearch(this.filterForm, 'userId', this, (search) => {
  182. return User.list(search);
  183. }, (row) => {
  184. return {
  185. title: `${row.nickname}(${row.mobile})`,
  186. value: row.id,
  187. };
  188. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  189. }
  190. initData() {
  191. System.listFAQ(this.state.search).then(result => {
  192. this.setTableData(result.list, result.total);
  193. });
  194. }
  195. addAction() {
  196. asyncForm('创建评价', this.itemList, {}, data => {
  197. return System.addFAQ(data).then(() => {
  198. asyncSMessage('添加成功!');
  199. this.refresh();
  200. });
  201. }).then(component => {
  202. this.formF = component;
  203. });
  204. }
  205. editAction(row) {
  206. asyncForm('编辑', this.itemList, row, data => {
  207. return System.editFAQ(data).then(() => {
  208. asyncSMessage('编辑成功!');
  209. this.refresh();
  210. });
  211. }).then(component => {
  212. this.formF = component;
  213. });
  214. }
  215. answerAction(row) {
  216. asyncForm('回复', this.answerList, row, data => {
  217. data.isSpecial = data.isSpecial ? 1 : 0;
  218. data.sendMail = data.sendMail ? 1 : 0;
  219. return System.editFAQ(data).then(() => {
  220. asyncSMessage('回复成功!');
  221. this.refresh();
  222. });
  223. }).then(component => {
  224. this.formF = component;
  225. });
  226. }
  227. special(row, isSpecial) {
  228. System.editFAQ({ id: row.id, isSpecial }).then(() => {
  229. asyncSMessage('编辑成功!');
  230. this.refresh();
  231. });
  232. }
  233. renderView() {
  234. return <Block flex>
  235. <FilterLayout
  236. show
  237. itemList={this.filterForm}
  238. data={this.state.search}
  239. onChange={data => {
  240. this.search(data);
  241. }} />
  242. <ActionLayout
  243. itemList={this.actionList}
  244. selectedKeys={this.state.selectedKeys}
  245. onAction={key => this.onAction(key)}
  246. />
  247. <TableLayout
  248. select
  249. columns={this.columns}
  250. list={this.state.list}
  251. pagination={this.state.page}
  252. loading={this.props.core.loading}
  253. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  254. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  255. selectedKeys={this.state.selectedKeys}
  256. />
  257. </Block>;
  258. }
  259. }