page.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import { Button, Modal, Form, InputNumber, Row, Col } from 'antd';
  4. import './index.less';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import FilterLayout from '@src/layouts/FilterLayout';
  8. import ActionLayout from '@src/layouts/ActionLayout';
  9. import TableLayout from '@src/layouts/TableLayout';
  10. import { formatDate, bindSearch, getMap } from '@src/services/Tools';
  11. import { asyncSMessage } from '@src/services/AsyncTools';
  12. import { ExperienceScore, ExperiencePercent, PrepareStatus, ExperienceDay } from '../../../../Constant';
  13. import { System } from '../../../stores/system';
  14. import { Course } from '../../../stores/course';
  15. import { User } from '../../../stores/user';
  16. const PrepareStatusMap = getMap(PrepareStatus, 'value', 'short');
  17. const ExperiencePercentMap = getMap(ExperiencePercent, 'value', 'label');
  18. export default class extends Page {
  19. init() {
  20. this.filterForm = [{
  21. key: 'keyword',
  22. type: 'input',
  23. allowClear: true,
  24. name: '搜索',
  25. placeholder: '标题或正文',
  26. }, {
  27. key: 'userId',
  28. type: 'select',
  29. name: '用户',
  30. allowClear: true,
  31. select: [],
  32. number: true,
  33. placeholder: '请输入',
  34. }, {
  35. key: 'prepareStatus',
  36. type: 'select',
  37. allowClear: true,
  38. name: '身份',
  39. select: PrepareStatus,
  40. placeholder: '请选择',
  41. }, {
  42. key: 'experienceDay',
  43. type: 'select',
  44. allowClear: true,
  45. name: '备考周期',
  46. select: ExperienceDay,
  47. placeholder: '请选择',
  48. }, {
  49. key: 'experienceScore',
  50. type: 'select',
  51. allowClear: true,
  52. name: '分手成绩',
  53. select: ExperienceScore,
  54. placeholder: '请选择',
  55. }, {
  56. key: 'experiencePercent',
  57. type: 'select',
  58. allowClear: true,
  59. name: '提分比例',
  60. select: ExperiencePercent,
  61. placeholder: '请选择',
  62. }];
  63. this.actionList = [{
  64. key: 'info',
  65. name: '数据管理',
  66. }, {
  67. key: 'add',
  68. type: 'primary',
  69. name: '创建',
  70. render: (item) => {
  71. return <Link to='/course/experience/detail'><Button>{item.name}</Button></Link>;
  72. },
  73. }];
  74. this.columns = [{
  75. title: '文章标题',
  76. dataIndex: 'title',
  77. }, {
  78. title: '作者',
  79. dataIndex: 'user',
  80. render: (text, record) => {
  81. return text ? text.nickname : record.nickname;
  82. },
  83. }, {
  84. title: '更新时间',
  85. dataIndex: 'updateTime',
  86. render: (text) => {
  87. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  88. },
  89. }, {
  90. title: '身份',
  91. dataIndex: 'prepareStatus',
  92. render: (text) => {
  93. return PrepareStatusMap[text] || text;
  94. },
  95. }, {
  96. title: '备考周期',
  97. dataIndex: 'experienceDay',
  98. }, {
  99. title: '分手成绩',
  100. dataIndex: 'experienceScore',
  101. }, {
  102. title: '提分比例',
  103. dataIndex: 'experiencePercent',
  104. render: (text) => {
  105. return ExperiencePercentMap[text] || text;
  106. },
  107. }, {
  108. title: '阅读数',
  109. dataIndex: 'viewNumber',
  110. }, {
  111. title: '收藏数',
  112. dataIndex: 'collectNumber',
  113. }, {
  114. title: '操作',
  115. dataIndex: 'handler',
  116. render: (text, record) => {
  117. return <div className="table-button">
  118. {<Link to={`/course/experience/detail/${record.id}`}>编辑</Link>}
  119. </div>;
  120. },
  121. }];
  122. System.getExperienceInfo().then(result => {
  123. return this.refreshInfo(result);
  124. }).then(() => {
  125. this.initData();
  126. });
  127. bindSearch(this.filterForm, 'userId', this, (search) => {
  128. return User.list(search);
  129. }, (row) => {
  130. return {
  131. title: `${row.nickname}(${row.mobile})`,
  132. value: row.id,
  133. };
  134. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  135. }
  136. initData() {
  137. Course.listExperience(this.state.search).then(result => {
  138. this.setTableData(result.list, result.total);
  139. });
  140. }
  141. refreshInfo(result) {
  142. this.setState({ info: result });
  143. }
  144. infoAction() {
  145. const { info = {} } = this.state;
  146. this.open(info);
  147. }
  148. changeInfoList(field, index, value) {
  149. const { detail } = this.state;
  150. if (!detail[field]) detail[field] = [];
  151. detail[field][index] = value;
  152. this.setState({ detail });
  153. }
  154. changeInfo(field, value) {
  155. const { detail } = this.state;
  156. detail[field] = value;
  157. this.setState({ detail });
  158. }
  159. submitInfo() {
  160. const { detail } = this.state;
  161. System.setExperienceInfo(detail).then(() => {
  162. asyncSMessage('保存成功');
  163. this.close(false, 'detail');
  164. return this.refreshInfo(detail);
  165. });
  166. }
  167. renderView() {
  168. return <Block flex>
  169. <FilterLayout
  170. show
  171. itemList={this.filterForm}
  172. data={this.state.search}
  173. onChange={data => {
  174. data.page = 1;
  175. this.search(data);
  176. }} />
  177. <ActionLayout
  178. itemList={this.actionList}
  179. selectedKeys={this.state.selectedKeys}
  180. onAction={key => this.onAction(key)}
  181. />
  182. <TableLayout
  183. columns={this.tableSort(this.columns)}
  184. list={this.state.list}
  185. pagination={this.state.page}
  186. loading={this.props.core.loading}
  187. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  188. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  189. selectedKeys={this.state.selectedKeys}
  190. />
  191. {this.state.detail && <Modal visible closable title='数据管理' onCancel={() => {
  192. this.close(false, 'detail');
  193. }} onOk={() => {
  194. this.submitInfo();
  195. }}>
  196. <Form>
  197. <Row>
  198. <Col span={12}><Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 10 }} label={'学员人数'}>
  199. <InputNumber value={this.state.detail.number || 0} placeholder={'人数'} onChange={(value) => {
  200. this.changeInfo('number', value);
  201. }} />
  202. </Form.Item></Col>
  203. </Row>
  204. <Form.Item label='考分分布' />
  205. <Row>
  206. {ExperienceScore.map((row, index) => {
  207. return <Col span={8}><Form.Item labelCol={{ span: 10 }} wrapperCol={{ span: 14 }} label={row.label}>
  208. <InputNumber value={this.state.detail.score ? this.state.detail.score[index] || 0 : 0} onChange={(value) => {
  209. this.changeInfoList('score', index, value);
  210. }} />
  211. </Form.Item></Col>;
  212. })}
  213. </Row>
  214. <Row>
  215. <Col span={12}><Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 10 }} label={'出分周期'}>
  216. <InputNumber value={this.state.detail.period || 0} placeholder={'单位天'} onChange={(value) => {
  217. this.changeInfo('period', value);
  218. }} />
  219. </Form.Item></Col>
  220. </Row>
  221. <Form.Item label='提分比例' />
  222. <Row>
  223. {ExperiencePercent.map((row, index) => {
  224. return <Col span={8}><Form.Item labelCol={{ span: 10 }} wrapperCol={{ span: 14 }} label={row.label}>
  225. <InputNumber value={this.state.detail.percent ? this.state.detail.percent[index] || 0 : 0} onChange={(value) => {
  226. this.changeInfoList('percent', index, value);
  227. }} />
  228. </Form.Item></Col>;
  229. })}
  230. </Row>
  231. </Form>
  232. </Modal>}
  233. </Block>;
  234. }
  235. }