1
0

page.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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(url => { return { url }; });
  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. return text ? text.nickname : record.nickname;
  106. },
  107. }, {
  108. title: '时间',
  109. dataIndex: 'createTime',
  110. render: (text) => {
  111. return formatDate(text);
  112. },
  113. }, {
  114. title: '精选',
  115. dataIndex: 'isSpecial',
  116. render: (text) => {
  117. return SwitchSelectMap[text] || text;
  118. },
  119. }, {
  120. title: '操作',
  121. dataIndex: 'handler',
  122. render: (text, record) => {
  123. return <div className="table-button">
  124. {(
  125. <a onClick={() => {
  126. this.editAction(record);
  127. }}>编辑</a>
  128. )}
  129. {!!record.isSpecial && (
  130. <a onClick={() => {
  131. this.special(record, 0);
  132. }}>取消精选</a>
  133. )}
  134. {!record.isSpecial && (
  135. <a onClick={() => {
  136. this.special(record, 1);
  137. }}>精选</a>
  138. )}
  139. </div>;
  140. },
  141. },
  142. ];
  143. bindSearch(this.filterForm, 'userId', this, (search) => {
  144. return User.list(search);
  145. }, (row) => {
  146. return {
  147. title: `${row.nickname}(${row.mobile})`,
  148. value: row.id,
  149. };
  150. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  151. }
  152. initData() {
  153. System.listComment(this.state.search).then(result => {
  154. this.setTableData(result.list, result.total);
  155. });
  156. }
  157. addAction() {
  158. asyncForm('创建评价', this.itemList, {}, data => {
  159. return System.addComment(data).then(() => {
  160. asyncSMessage('添加成功!');
  161. this.refresh();
  162. });
  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 }).then(() => {
  175. asyncSMessage('编辑成功!');
  176. this.refresh();
  177. });
  178. }
  179. renderView() {
  180. return <Block flex>
  181. <FilterLayout
  182. show
  183. itemList={this.filterForm}
  184. data={this.state.search}
  185. onChange={data => {
  186. this.search(data);
  187. }} />
  188. <ActionLayout
  189. itemList={this.actionList}
  190. selectedKeys={this.state.selectedKeys}
  191. onAction={key => this.onAction(key)}
  192. />
  193. <TableLayout
  194. select
  195. columns={this.columns}
  196. list={this.state.list}
  197. pagination={this.state.page}
  198. loading={this.props.core.loading}
  199. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  200. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  201. selectedKeys={this.state.selectedKeys}
  202. />
  203. </Block>;
  204. }
  205. }