page.js 6.0 KB

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