page.js 6.0 KB

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