page.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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, formatTreeData, flattenTree } from '@src/services/Tools';
  9. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  10. import { CommentChannel, SwitchSelect, 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 CommentChannelTree = formatTreeData(CommentChannel, 'value', 'label', 'parent');
  16. const CommentChannelFlatten = flattenTree(CommentChannelTree, (row, item) => {
  17. row = Object.assign({}, row);
  18. row.value = `${item.value}-${row.value}`;
  19. row.label = `${item.label}-${row.label}`;
  20. return row;
  21. }, 'children');
  22. const CommentChannelMap = getMap(CommentChannelFlatten, 'value', 'label');
  23. export default class extends Page {
  24. init() {
  25. this.itemList = [{
  26. key: 'id',
  27. type: 'hidden',
  28. }, {
  29. key: 'content',
  30. type: 'textarea',
  31. name: '评价内容',
  32. }];
  33. this.filterF = null;
  34. this.filterForm = [{
  35. key: 'channel',
  36. type: 'cascader',
  37. allowClear: true,
  38. name: '频道',
  39. select: CommentChannelTree,
  40. placeholder: '请选择',
  41. onChange: (value) => {
  42. this.changeSearch(this.filterForm, this, value.join('-'), null);
  43. },
  44. }, {
  45. key: 'position',
  46. type: 'select',
  47. allowClear: true,
  48. name: '位置',
  49. select: [],
  50. placeholder: '请选择',
  51. }, {
  52. key: 'userId',
  53. type: 'select',
  54. allowClear: true,
  55. name: '用户',
  56. select: [],
  57. number: true,
  58. placeholder: '请输入',
  59. }, {
  60. key: 'moneyRang',
  61. type: 'select',
  62. allowClear: true,
  63. name: '消费金额',
  64. select: MoneyRange,
  65. number: true,
  66. }, {
  67. key: 'isSpecial',
  68. type: 'select',
  69. allowClear: true,
  70. name: '展示',
  71. number: true,
  72. select: SwitchSelect,
  73. }];
  74. this.columns = [{
  75. title: '频道',
  76. dataIndex: 'channel',
  77. render: (text, record) => {
  78. return CommentChannelMap[record.channel];
  79. },
  80. }, {
  81. title: '位置',
  82. dataIndex: 'position',
  83. }, {
  84. title: '用户',
  85. dataIndex: 'user',
  86. render: (text, record) => {
  87. let extend = '';
  88. if (record.isSystem) extend = '系统创建';
  89. else if (!record.userId) extend = '未注册';
  90. return `${text.nickname || record.nickname}${extend ? `(${extend})` : ''}`;
  91. },
  92. }, {
  93. title: '评价时间',
  94. sorter: true,
  95. dataIndex: 'updateTime',
  96. render: (text) => {
  97. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  98. },
  99. }, {
  100. title: '展示',
  101. dataIndex: 'isSpecial',
  102. render: (text) => {
  103. return SwitchSelectMap[text] || text;
  104. },
  105. }, {
  106. title: '操作',
  107. dataIndex: 'handler',
  108. render: (text, record) => {
  109. return <div className="table-button">
  110. {(
  111. <a onClick={() => {
  112. this.editAction(record);
  113. }}>编辑</a>
  114. )}
  115. {!!record.isSpecial && (
  116. <a onClick={() => {
  117. this.special(record, 0);
  118. }}>取消展示</a>
  119. )}
  120. {!record.isSpecial && (
  121. <a onClick={() => {
  122. this.special(record, 1);
  123. }}>展示</a>
  124. )}
  125. </div>;
  126. },
  127. }];
  128. bindSearch(this.filterForm, 'userId', this, (search) => {
  129. return User.list(search);
  130. }, (row) => {
  131. return {
  132. title: `${row.nickname}(${row.mobile})`,
  133. value: row.id,
  134. };
  135. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  136. this.changeSearch(this.filterForm, this, this.state.search.channel, this.state.search.position);
  137. }
  138. changeSearch(list, component, key, value) {
  139. if (key === 'course-video' || key === 'course-vs' || key === 'course-package' || key === 'course_data') {
  140. bindSearch(list, 'position', component, (search) => {
  141. if (key === 'course-video') {
  142. return Course.list(Object.assign({ courseModule: 'video' }, search));
  143. } if (key === 'course-vs') {
  144. return Course.list(Object.assign({ courseModule: 'vs' }, search));
  145. } if (key === 'course-package') {
  146. return Course.listPackage(search);
  147. }
  148. return Course.listData(search);
  149. }, (row) => {
  150. return {
  151. title: row.title,
  152. value: row.id,
  153. };
  154. }, value ? Number(value) : null, null);
  155. list[1].disabled = false;
  156. } else {
  157. list[1].disabled = true;
  158. }
  159. component.setState({ load: false });
  160. }
  161. initData() {
  162. System.listComment(Object.assign({ user: true }, this.state.search)).then(result => {
  163. this.setTableData(result.list, result.total);
  164. });
  165. }
  166. editAction(row) {
  167. asyncForm('编辑', this.itemList, row, data => {
  168. return System.editComment(data).then(() => {
  169. asyncSMessage('编辑成功!');
  170. this.refresh();
  171. });
  172. });
  173. }
  174. special(row, isSpecial) {
  175. System.editComment({ id: row.id, isSpecial, isShow: isSpecial }).then(() => {
  176. asyncSMessage('操作成功!');
  177. this.refresh();
  178. });
  179. }
  180. renderView() {
  181. const { search } = this.state;
  182. return <Block flex>
  183. <FilterLayout
  184. show
  185. ref={(ref) => { this.filterF = ref; }}
  186. itemList={this.filterForm}
  187. data={Object.assign({}, search, { channel: search.channel ? search.channel.split('-') : '' })}
  188. onChange={data => {
  189. data.channel = data.channel ? data.channel.join('-') : data.channel;
  190. data.page = 1;
  191. this.search(data);
  192. }} />
  193. {/* <ActionLayout
  194. itemList={this.actionList}
  195. selectedKeys={this.state.selectedKeys}
  196. onAction={key => this.onAction(key)}
  197. /> */}
  198. <TableLayout
  199. columns={this.tableSort(this.columns)}
  200. list={this.state.list}
  201. pagination={this.state.page}
  202. loading={this.props.core.loading}
  203. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  204. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  205. selectedKeys={this.state.selectedKeys}
  206. />
  207. </Block>;
  208. }
  209. }