page.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.userItemList = [{
  56. key: 'id',
  57. type: 'hidden',
  58. }, {
  59. key: 'channel',
  60. type: 'select',
  61. allowClear: true,
  62. name: '频道',
  63. select: ChannelModule,
  64. placeholder: '请选择',
  65. }, {
  66. key: 'position',
  67. type: 'select',
  68. allowClear: true,
  69. name: '位置',
  70. select: ChannelModule,
  71. placeholder: '请选择',
  72. }, {
  73. key: 'content',
  74. type: 'textarea',
  75. name: '评价内容',
  76. }];
  77. this.filterForm = [{
  78. key: 'channel',
  79. type: 'select',
  80. allowClear: true,
  81. name: '频道',
  82. select: ChannelModule,
  83. placeholder: '请选择',
  84. }, {
  85. key: 'position',
  86. type: 'select',
  87. allowClear: true,
  88. name: '位置',
  89. select: ChannelModule,
  90. placeholder: '请选择',
  91. }, {
  92. key: 'userId',
  93. type: 'select',
  94. allowClear: true,
  95. name: '用户',
  96. select: [],
  97. number: true,
  98. placeholder: '请输入',
  99. }, {
  100. key: 'isSpecial',
  101. type: 'select',
  102. allowClear: true,
  103. name: '精选',
  104. number: true,
  105. select: SwitchSelect,
  106. }];
  107. this.columns = [
  108. {
  109. title: '频道',
  110. dataIndex: 'channel',
  111. render: (text, record) => {
  112. return ChannelModuleMap[record.channel];
  113. },
  114. },
  115. {
  116. title: '位置',
  117. dataIndex: 'position',
  118. },
  119. {
  120. title: '内容',
  121. dataIndex: 'content',
  122. },
  123. {
  124. title: '用户',
  125. dataIndex: 'user',
  126. render: (text, record) => {
  127. let extend = '';
  128. if (record.isSystem) extend = '系统创建';
  129. else if (!record.userId) extend = '未注册';
  130. return `${text.nickname || record.nickname}${extend ? `(${extend})` : ''}`;
  131. },
  132. }, {
  133. title: '时间',
  134. dataIndex: 'createTime',
  135. render: (text) => {
  136. return formatDate(text);
  137. },
  138. }, {
  139. title: '精选',
  140. dataIndex: 'isSpecial',
  141. render: (text) => {
  142. return SwitchSelectMap[text] || text;
  143. },
  144. }, {
  145. title: '操作',
  146. dataIndex: 'handler',
  147. render: (text, record) => {
  148. return <div className="table-button">
  149. {(
  150. <a onClick={() => {
  151. this.editAction(record);
  152. }}>编辑</a>
  153. )}
  154. {!!record.isSpecial && (
  155. <a onClick={() => {
  156. this.special(record, 0);
  157. }}>取消精选</a>
  158. )}
  159. {!record.isSpecial && (
  160. <a onClick={() => {
  161. this.special(record, 1);
  162. }}>精选</a>
  163. )}
  164. </div>;
  165. },
  166. },
  167. ];
  168. bindSearch(this.filterForm, 'userId', this, (search) => {
  169. return User.list(search);
  170. }, (row) => {
  171. return {
  172. title: `${row.nickname}(${row.mobile})`,
  173. value: row.id,
  174. };
  175. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  176. }
  177. initData() {
  178. System.listComment(this.state.search).then(result => {
  179. this.setTableData(result.list, result.total);
  180. });
  181. }
  182. addAction() {
  183. asyncForm('创建评价', this.itemList, {}, data => {
  184. return System.addComment(data).then(() => {
  185. asyncSMessage('添加成功!');
  186. this.refresh();
  187. });
  188. });
  189. }
  190. editAction(row) {
  191. let item = this.itemList;
  192. if (row.userId) {
  193. item = this.userItemList;
  194. }
  195. asyncForm('编辑', item, row, data => {
  196. return System.editComment(data).then(() => {
  197. asyncSMessage('编辑成功!');
  198. this.refresh();
  199. });
  200. });
  201. }
  202. special(row, isSpecial) {
  203. System.editComment({ id: row.id, isSpecial }).then(() => {
  204. asyncSMessage('操作成功!');
  205. this.refresh();
  206. });
  207. }
  208. renderView() {
  209. return <Block flex>
  210. <FilterLayout
  211. show
  212. itemList={this.filterForm}
  213. data={this.state.search}
  214. onChange={data => {
  215. this.search(data);
  216. }} />
  217. <ActionLayout
  218. itemList={this.actionList}
  219. selectedKeys={this.state.selectedKeys}
  220. onAction={key => this.onAction(key)}
  221. />
  222. <TableLayout
  223. select
  224. columns={this.tableSort(this.columns)}
  225. list={this.state.list}
  226. pagination={this.state.page}
  227. loading={this.props.core.loading}
  228. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  229. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  230. selectedKeys={this.state.selectedKeys}
  231. />
  232. </Block>;
  233. }
  234. }