page.js 7.0 KB

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