page.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. dataIndex: 'createTime',
  95. render: (text) => {
  96. return formatDate(text);
  97. },
  98. }, {
  99. title: '展示',
  100. dataIndex: 'isSpecial',
  101. render: (text) => {
  102. return SwitchSelectMap[text] || text;
  103. },
  104. }, {
  105. title: '操作',
  106. dataIndex: 'handler',
  107. render: (text, record) => {
  108. return <div className="table-button">
  109. {(
  110. <a onClick={() => {
  111. this.editAction(record);
  112. }}>编辑</a>
  113. )}
  114. {!!record.isSpecial && (
  115. <a onClick={() => {
  116. this.special(record, 0);
  117. }}>取消展示</a>
  118. )}
  119. {!record.isSpecial && (
  120. <a onClick={() => {
  121. this.special(record, 1);
  122. }}>展示</a>
  123. )}
  124. </div>;
  125. },
  126. }];
  127. bindSearch(this.filterForm, 'userId', this, (search) => {
  128. return User.list(search);
  129. }, (row) => {
  130. return {
  131. title: `${row.nickname}(${row.mobile})`,
  132. value: row.id,
  133. };
  134. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  135. this.changeSearch(this.filterForm, this, this.state.search.channel, this.state.search.position);
  136. }
  137. changeSearch(list, component, key, value) {
  138. if (key === 'course-video' || key === 'course-vs' || key === 'course-package' || key === 'course_data') {
  139. bindSearch(list, 'position', component, (search) => {
  140. if (key === 'course-video') {
  141. return Course.list(Object.assign({ courseModule: 'video' }, search));
  142. } if (key === 'course-vs') {
  143. return Course.list(Object.assign({ courseModule: 'vs' }, search));
  144. } if (key === 'course-package') {
  145. return Course.listPackage(search);
  146. }
  147. return Course.listData(search);
  148. }, (row) => {
  149. return {
  150. title: row.title,
  151. value: row.id,
  152. };
  153. }, value ? Number(value) : null, null);
  154. list[1].disabled = false;
  155. } else {
  156. list[1].disabled = true;
  157. }
  158. component.setState({ load: false });
  159. }
  160. initData() {
  161. System.listComment(Object.assign({ user: true }, this.state.search)).then(result => {
  162. this.setTableData(result.list, result.total);
  163. });
  164. }
  165. editAction(row) {
  166. asyncForm('编辑', this.itemList, row, data => {
  167. return System.editComment(data).then(() => {
  168. asyncSMessage('编辑成功!');
  169. this.refresh();
  170. });
  171. });
  172. }
  173. special(row, isSpecial) {
  174. System.editComment({ id: row.id, isSpecial, isShow: isSpecial }).then(() => {
  175. asyncSMessage('操作成功!');
  176. this.refresh();
  177. });
  178. }
  179. renderView() {
  180. const { search } = this.state;
  181. return <Block flex>
  182. <FilterLayout
  183. show
  184. ref={(ref) => { this.filterF = ref; }}
  185. itemList={this.filterForm}
  186. data={Object.assign({}, search, { channel: search.channel ? search.channel.split('-') : '' })}
  187. onChange={data => {
  188. data.channel = data.channel.join('-');
  189. this.search(data);
  190. }} />
  191. {/* <ActionLayout
  192. itemList={this.actionList}
  193. selectedKeys={this.state.selectedKeys}
  194. onAction={key => this.onAction(key)}
  195. /> */}
  196. <TableLayout
  197. columns={this.tableSort(this.columns)}
  198. list={this.state.list}
  199. pagination={this.state.page}
  200. loading={this.props.core.loading}
  201. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  202. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  203. selectedKeys={this.state.selectedKeys}
  204. />
  205. </Block>;
  206. }
  207. }