page.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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, formatTreeData, bindSearch, flattenTree } from '@src/services/Tools';
  9. import { asyncSMessage, asyncForm, asyncDelConfirm } from '@src/services/AsyncTools';
  10. import { FaqChannel, SwitchSelect, AnswerStatus, MoneyRange } from '../../../../Constant';
  11. import { System } from '../../../stores/system';
  12. import { User } from '../../../stores/user';
  13. import { Course } from '../../../stores/course';
  14. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  15. const AnswerStatusMap = getMap(AnswerStatus, 'value', 'label');
  16. const FaqChannelTree = formatTreeData(FaqChannel, 'value', 'label', 'parent');
  17. const FaqChannelFlatten = flattenTree(FaqChannelTree, (row, item) => {
  18. row = Object.assign({}, row);
  19. row.value = `${item.value}-${row.value}`;
  20. row.label = `${item.label}-${row.label}`;
  21. return row;
  22. }, 'children');
  23. const FaqChannelMap = getMap(FaqChannelFlatten, 'value', 'label');
  24. export default class extends Page {
  25. init() {
  26. this.actionList = [{
  27. key: 'ignore',
  28. type: 'danger',
  29. name: '批量忽略',
  30. needSelect: 1,
  31. }];
  32. this.formF = null;
  33. this.itemList = [{
  34. key: 'id',
  35. type: 'hidden',
  36. }, {
  37. key: 'content',
  38. type: 'textarea',
  39. name: '用户留言',
  40. }, {
  41. key: 'answer',
  42. type: 'textarea',
  43. name: '编辑回复',
  44. }];
  45. this.answerList = [{
  46. key: 'id',
  47. type: 'hidden',
  48. }, {
  49. key: 'content',
  50. type: 'textarea',
  51. disabled: true,
  52. name: '用户留言',
  53. }, {
  54. key: 'answer',
  55. type: 'textarea',
  56. name: '编辑回复',
  57. }];
  58. this.filterF = null;
  59. this.filterForm = [{
  60. key: 'channel',
  61. type: 'cascader',
  62. allowClear: true,
  63. name: '频道',
  64. select: FaqChannelTree,
  65. placeholder: '请选择',
  66. onChange: (value) => {
  67. this.changeSearch(this.filterForm, this, value.join('-'), null);
  68. },
  69. }, {
  70. key: 'position',
  71. type: 'select',
  72. allowClear: true,
  73. name: '位置',
  74. select: [],
  75. number: true,
  76. placeholder: '请选择',
  77. }, {
  78. key: 'answerStatus',
  79. type: 'select',
  80. allowClear: true,
  81. number: true,
  82. name: '状态',
  83. select: AnswerStatus,
  84. }, {
  85. key: 'userId',
  86. type: 'select',
  87. allowClear: true,
  88. name: '用户',
  89. select: [],
  90. number: true,
  91. placeholder: '请输入',
  92. }, {
  93. key: 'moneyRang',
  94. type: 'select',
  95. allowClear: true,
  96. name: '消费金额',
  97. select: MoneyRange,
  98. number: true,
  99. }, {
  100. key: 'isSpecial',
  101. type: 'select',
  102. allowClear: true,
  103. name: '展示',
  104. number: true,
  105. select: SwitchSelect,
  106. }];
  107. this.columns = [{
  108. title: '频道',
  109. dataIndex: 'channel',
  110. render: (text, record) => {
  111. return FaqChannelMap[record.channel];
  112. },
  113. }, {
  114. title: '位置',
  115. dataIndex: 'positionDetail.title',
  116. }, {
  117. title: '提问时间',
  118. sorter: true,
  119. dataIndex: 'createTime',
  120. render: (text) => {
  121. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  122. },
  123. }, {
  124. title: '提问者',
  125. dataIndex: 'user.nickname',
  126. }, {
  127. title: '消费金额',
  128. dataIndex: 'user.totalMoney',
  129. }, {
  130. title: '回答状态',
  131. dataIndex: 'answerStatus',
  132. render: (text) => {
  133. return AnswerStatusMap[text] || '';
  134. },
  135. }, {
  136. title: '回答时间',
  137. sorter: true,
  138. dataIndex: 'answerTime',
  139. render: (text) => {
  140. return text ? formatDate(text, 'YYYY-MM-DD HH:mm:ss') : '';
  141. },
  142. }, {
  143. title: '展示',
  144. dataIndex: 'isSpecial',
  145. render: (text) => {
  146. return SwitchSelectMap[text] || text;
  147. },
  148. }, {
  149. title: '操作',
  150. dataIndex: 'handler',
  151. render: (text, record) => {
  152. return <div className="table-button">
  153. {record.answerStatus === 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. bindSearch(this.filterForm, 'userId', this, (search) => {
  172. return User.list(search);
  173. }, (row) => {
  174. return {
  175. title: `${row.nickname}(${row.mobile})`,
  176. value: row.id,
  177. };
  178. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  179. this.changeSearch(this.filterForm, this, this.state.search.channel, this.state.search.position);
  180. }
  181. changeSearch(list, component, key, value) {
  182. if (key === 'course-video' || key === 'course-vs' || key === 'course-package' || key === 'course_data') {
  183. bindSearch(list, 'position', component, (search) => {
  184. if (key === 'course-video') {
  185. return Course.list(Object.assign({ courseModule: 'video' }, search));
  186. } if (key === 'course-vs') {
  187. return Course.list(Object.assign({ courseModule: 'vs' }, search));
  188. } if (key === 'course-package') {
  189. return Course.listPackage(search);
  190. }
  191. return Course.listData(search);
  192. }, (row) => {
  193. return {
  194. title: row.title,
  195. value: row.id,
  196. };
  197. }, value ? Number(value) : null, null);
  198. list[1].disabled = false;
  199. } else {
  200. list[1].disabled = true;
  201. }
  202. component.setState({ load: false });
  203. }
  204. initData() {
  205. System.listFAQ(Object.assign({ user: true }, this.state.search)).then(result => {
  206. this.setTableData(result.list, result.total);
  207. });
  208. }
  209. editAction(row) {
  210. asyncForm('编辑', this.itemList, row, data => {
  211. return System.editFAQ(data).then(() => {
  212. asyncSMessage('编辑成功!');
  213. this.refresh();
  214. });
  215. }).then(component => {
  216. this.formF = component;
  217. });
  218. }
  219. answerAction(row) {
  220. asyncForm('回复', this.answerList, row, data => {
  221. data.status = 1;
  222. return System.editFAQ(data).then(() => {
  223. asyncSMessage('回复成功!');
  224. this.refresh();
  225. });
  226. }).then(component => {
  227. this.formF = component;
  228. });
  229. }
  230. special(row, isSpecial) {
  231. System.editFAQ({ id: row.id, isSpecial, isShow: isSpecial }).then(() => {
  232. asyncSMessage('编辑成功!');
  233. this.refresh();
  234. });
  235. }
  236. ignoreAction() {
  237. const { selectedKeys } = this.state;
  238. asyncDelConfirm('忽略确认', '是否忽略选中记录?', () => {
  239. return Promise.all(selectedKeys.map(row => System.editFAQ({ id: row, status: 2 }))).then(() => {
  240. asyncSMessage('操作成功!');
  241. this.refresh();
  242. });
  243. });
  244. }
  245. renderView() {
  246. const { search } = this.state;
  247. return <Block flex>
  248. <FilterLayout
  249. show
  250. ref={(ref) => { this.filterF = ref; }}
  251. itemList={this.filterForm}
  252. data={Object.assign({}, search, { channel: search.channel ? search.channel.split('-') : '' })}
  253. onChange={data => {
  254. data.channel = data.channel ? data.channel.join('-') : data.channel;
  255. data.page = 1;
  256. this.search(data);
  257. }} />
  258. <ActionLayout
  259. itemList={this.actionList}
  260. selectedKeys={this.state.selectedKeys}
  261. onAction={key => this.onAction(key)}
  262. />
  263. <TableLayout
  264. columns={this.tableSort(this.columns)}
  265. list={this.state.list}
  266. pagination={this.state.page}
  267. loading={this.props.core.loading}
  268. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  269. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  270. selectedKeys={this.state.selectedKeys}
  271. />
  272. </Block>;
  273. }
  274. }