page.js 5.8 KB

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