page.js 5.3 KB

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