page.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 } from '@src/services/Tools';
  9. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  10. import { ChannelModule, SwitchSelect } from '../../../../Constant';
  11. import { System } from '../../../stores/system';
  12. import { User } from '../../../stores/user';
  13. const SwitchSelectMap = getMap(SwitchSelect, 'value', 'label');
  14. const ChannelModuleMap = getMap(ChannelModule, 'value', 'label');
  15. export default class extends Page {
  16. init() {
  17. this.actionList = [{
  18. key: 'add',
  19. type: 'primary',
  20. name: '创建',
  21. }];
  22. this.itemList = [{
  23. key: 'id',
  24. type: 'hidden',
  25. }, {
  26. key: 'channel',
  27. type: 'select',
  28. allowClear: true,
  29. name: '频道',
  30. select: ChannelModule,
  31. placeholder: '请选择',
  32. }, {
  33. key: 'position',
  34. type: 'select',
  35. allowClear: true,
  36. name: '位置',
  37. select: ChannelModule,
  38. placeholder: '请选择',
  39. }, {
  40. key: 'nickname',
  41. type: 'input',
  42. name: '学员昵称',
  43. }, {
  44. key: 'avatar',
  45. type: 'image',
  46. name: '学员头像',
  47. onUpload: ({ file }) => {
  48. return System.uploadImage(file).then(result => { return result; });
  49. },
  50. }, {
  51. key: 'content',
  52. type: 'textarea',
  53. name: '评价内容',
  54. }];
  55. this.filterForm = [{
  56. key: 'channel',
  57. type: 'select',
  58. allowClear: true,
  59. name: '频道',
  60. select: ChannelModule,
  61. placeholder: '请选择',
  62. }, {
  63. key: 'position',
  64. type: 'select',
  65. allowClear: true,
  66. name: '位置',
  67. select: ChannelModule,
  68. placeholder: '请选择',
  69. }, {
  70. key: 'userId',
  71. type: 'select',
  72. allowClear: true,
  73. name: '用户',
  74. select: [],
  75. number: true,
  76. placeholder: '请输入',
  77. }, {
  78. key: 'isSpecial',
  79. type: 'select',
  80. allowClear: true,
  81. name: '精选',
  82. number: true,
  83. select: SwitchSelect,
  84. }];
  85. this.columns = [
  86. {
  87. title: '频道',
  88. dataIndex: 'channel',
  89. render: (text, record) => {
  90. return ChannelModuleMap[record.channel];
  91. },
  92. },
  93. {
  94. title: '位置',
  95. dataIndex: 'position',
  96. },
  97. {
  98. title: '内容',
  99. dataIndex: 'content',
  100. },
  101. {
  102. title: '用户',
  103. dataIndex: 'user',
  104. render: (text, record) => {
  105. let extend = '';
  106. if (record.isSystem) extend = '系统创建';
  107. else if (!record.userId) extend = '未注册';
  108. return `${text.nickname || record.nickname}${extend ? `(${extend})` : ''}`;
  109. },
  110. }, {
  111. title: '时间',
  112. dataIndex: 'createTime',
  113. render: (text) => {
  114. return formatDate(text);
  115. },
  116. }, {
  117. title: '精选',
  118. dataIndex: 'isSpecial',
  119. render: (text) => {
  120. return SwitchSelectMap[text] || text;
  121. },
  122. }, {
  123. title: '操作',
  124. dataIndex: 'handler',
  125. render: (text, record) => {
  126. return <div className="table-button">
  127. {(
  128. <a onClick={() => {
  129. this.editAction(record);
  130. }}>编辑</a>
  131. )}
  132. {!!record.isSpecial && (
  133. <a onClick={() => {
  134. this.special(record, 0);
  135. }}>取消精选</a>
  136. )}
  137. {!record.isSpecial && (
  138. <a onClick={() => {
  139. this.special(record, 1);
  140. }}>精选</a>
  141. )}
  142. </div>;
  143. },
  144. },
  145. ];
  146. bindSearch(this.filterForm, 'userId', this, (search) => {
  147. return User.list(search);
  148. }, (row) => {
  149. return {
  150. title: `${row.nickname}(${row.mobile})`,
  151. value: row.id,
  152. };
  153. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  154. }
  155. initData() {
  156. System.listComment(this.state.search).then(result => {
  157. this.setTableData(result.list, result.total);
  158. });
  159. }
  160. addAction() {
  161. asyncForm('创建评价', this.itemList, {}, data => {
  162. return System.addComment(data).then(() => {
  163. asyncSMessage('添加成功!');
  164. this.refresh();
  165. });
  166. });
  167. }
  168. editAction(row) {
  169. asyncForm('编辑', this.itemList, row, data => {
  170. return System.editComment(data).then(() => {
  171. asyncSMessage('编辑成功!');
  172. this.refresh();
  173. });
  174. });
  175. }
  176. special(row, isSpecial) {
  177. System.editComment({ id: row.id, isSpecial }).then(() => {
  178. asyncSMessage('编辑成功!');
  179. this.refresh();
  180. });
  181. }
  182. renderView() {
  183. return <Block flex>
  184. <FilterLayout
  185. show
  186. itemList={this.filterForm}
  187. data={this.state.search}
  188. onChange={data => {
  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. select
  198. columns={this.columns}
  199. list={this.state.list}
  200. pagination={this.state.page}
  201. loading={this.props.core.loading}
  202. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  203. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  204. selectedKeys={this.state.selectedKeys}
  205. />
  206. </Block>;
  207. }
  208. }