page.js 7.6 KB

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