page.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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, bindSearch, formatTreeData } from '@src/services/Tools';
  9. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  10. import { CommentChannel, SystemSelect } from '../../../../Constant';
  11. import { System } from '../../../stores/system';
  12. import { Course } from '../../../stores/course';
  13. const CommentChannelMap = getMap(CommentChannel, 'value', 'label');
  14. const SystemSelectMap = getMap(SystemSelect, 'value', 'label');
  15. export default class extends Page {
  16. init() {
  17. this.actionList = [{
  18. key: 'add',
  19. type: 'primary',
  20. name: '创建',
  21. }];
  22. this.formF = null;
  23. this.itemList = [{
  24. key: 'id',
  25. type: 'hidden',
  26. }, {
  27. key: 'channel',
  28. type: 'cascader',
  29. allowClear: true,
  30. name: '频道',
  31. select: formatTreeData(CommentChannel, 'value', 'label', 'parent'),
  32. placeholder: '请选择',
  33. onChange: (value) => {
  34. this.changeSearch(this.itemList, this.formF, value.join('-'), null, 2);
  35. },
  36. }, {
  37. key: 'position',
  38. type: 'select',
  39. allowClear: true,
  40. name: '位置',
  41. select: [],
  42. placeholder: '请选择',
  43. }, {
  44. key: 'nickname',
  45. type: 'input',
  46. name: '学员昵称',
  47. }, {
  48. key: 'avatar',
  49. type: 'image',
  50. name: '学员头像',
  51. onUpload: ({ file }) => {
  52. return System.uploadImage(file).then(result => { return result; });
  53. },
  54. }, {
  55. key: 'content',
  56. type: 'textarea',
  57. name: '评价内容',
  58. }];
  59. this.userItemList = [{
  60. key: 'id',
  61. type: 'hidden',
  62. }, {
  63. key: 'content',
  64. type: 'textarea',
  65. name: '评价内容',
  66. }];
  67. this.filterF = null;
  68. this.filterForm = [{
  69. key: 'channel',
  70. type: 'cascader',
  71. allowClear: true,
  72. name: '频道',
  73. select: formatTreeData(CommentChannel, 'value', 'label', 'parent'),
  74. placeholder: '请选择',
  75. onChange: (value) => {
  76. this.changeSearch(this.filterForm, this, value.join('-'), null);
  77. },
  78. }, {
  79. key: 'position',
  80. type: 'select',
  81. allowClear: true,
  82. name: '位置',
  83. select: [],
  84. placeholder: '请选择',
  85. }, {
  86. key: 'isSystem',
  87. type: 'select',
  88. allowClear: true,
  89. number: true,
  90. name: '来源',
  91. select: SystemSelect,
  92. }];
  93. this.columns = [{
  94. title: '频道',
  95. dataIndex: 'channel',
  96. render: (text, record) => {
  97. return CommentChannelMap[record.channel];
  98. },
  99. }, {
  100. title: '商品名称',
  101. dataIndex: 'positionDetail.title',
  102. }, {
  103. title: '创建时间',
  104. sorter: true,
  105. dataIndex: 'createTime',
  106. render: (text) => {
  107. return formatDate(text);
  108. },
  109. }, {
  110. title: '来源',
  111. dataIndex: 'isSystem',
  112. render: (text) => {
  113. return SystemSelectMap[text];
  114. },
  115. }, {
  116. title: '操作',
  117. dataIndex: 'handler',
  118. render: (text, record) => {
  119. return <div className="table-button">
  120. {(
  121. <a onClick={() => {
  122. this.editAction(record);
  123. }}>编辑</a>
  124. )}
  125. </div>;
  126. },
  127. }];
  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, index = 1) {
  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[index].disabled = false;
  147. } else {
  148. list[index].disabled = true;
  149. }
  150. }
  151. initData() {
  152. System.listComment(Object.assign({ isSpecial: true }, this.state.search)).then(result => {
  153. this.setTableData(result.list, result.total);
  154. });
  155. }
  156. addAction() {
  157. asyncForm('创建评价', this.itemList, {}, data => {
  158. data.isShow = 1;
  159. data.isSystem = 1;
  160. data.isSpecial = 1;
  161. return System.addComment(data).then(() => {
  162. asyncSMessage('添加成功!');
  163. this.refresh();
  164. });
  165. }).then(component => {
  166. this.formF = component;
  167. });
  168. }
  169. editAction(row) {
  170. let item = this.itemList;
  171. if (row.userId) {
  172. item = this.userItemList;
  173. }
  174. asyncForm('编辑', item, row, data => {
  175. return System.editComment(data).then(() => {
  176. asyncSMessage('编辑成功!');
  177. this.refresh();
  178. });
  179. }).then(component => {
  180. this.formF = component;
  181. this.changeSearch(this.filterForm, this, row.channel, row.position, 2);
  182. });
  183. }
  184. special(row, isShow) {
  185. System.editComment({ id: row.id, isShow }).then(() => {
  186. asyncSMessage('操作成功!');
  187. this.refresh();
  188. });
  189. }
  190. renderView() {
  191. return <Block flex>
  192. <FilterLayout
  193. show
  194. ref={(ref) => { this.filterF = ref; }}
  195. itemList={this.filterForm}
  196. data={this.state.search}
  197. onChange={data => {
  198. data.channel = data.channel.join('-');
  199. this.search(data);
  200. }} />
  201. <ActionLayout
  202. itemList={this.actionList}
  203. selectedKeys={this.state.selectedKeys}
  204. onAction={key => this.onAction(key)}
  205. />
  206. <TableLayout
  207. columns={this.tableSort(this.columns)}
  208. list={this.state.list}
  209. pagination={this.state.page}
  210. loading={this.props.core.loading}
  211. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  212. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  213. selectedKeys={this.state.selectedKeys}
  214. />
  215. </Block>;
  216. }
  217. }