page.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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: 'createTime',
  58. render: (text) => {
  59. return formatDate(text);
  60. },
  61. }, {
  62. title: '收藏数',
  63. dataIndex: 'collectNumber',
  64. }, {
  65. title: '操作',
  66. dataIndex: 'handler',
  67. render: (text, record) => {
  68. return <div className="table-button">
  69. {<Link to={`/course/experience/detail/${record.id}`}>编辑</Link>}
  70. </div>;
  71. },
  72. }];
  73. System.getExperienceInfo().then(result => {
  74. return this.refreshInfo(result);
  75. }).then(() => {
  76. this.initData();
  77. });
  78. bindSearch(this.filterForm, 'userId', this, (search) => {
  79. return User.list(search);
  80. }, (row) => {
  81. return {
  82. title: `${row.nickname}(${row.mobile})`,
  83. value: row.id,
  84. };
  85. }, this.state.search.userId ? Number(this.state.search.userId) : [], null);
  86. }
  87. initData() {
  88. Course.listExperience(this.state.search).then(result => {
  89. this.setTableData(result.list, result.total);
  90. });
  91. }
  92. refreshInfo(result) {
  93. this.setState({ info: result });
  94. }
  95. infoAction() {
  96. const { info = {} } = this.state;
  97. this.open(info);
  98. }
  99. changeInfoList(field, index, value) {
  100. const { detail } = this.state;
  101. if (!detail[field]) detail[field] = [];
  102. detail[field][index] = value;
  103. this.setState({ detail });
  104. }
  105. changeInfo(field, value) {
  106. const { detail } = this.state;
  107. detail[field] = value;
  108. this.setState({ detail });
  109. }
  110. submitInfo() {
  111. const { detail } = this.state;
  112. System.setExperienceInfo(detail).then(() => {
  113. asyncSMessage('保存成功');
  114. this.close(false, 'detail');
  115. return this.refreshInfo(detail);
  116. });
  117. }
  118. renderView() {
  119. return <Block flex>
  120. <FilterLayout
  121. show
  122. itemList={this.filterForm}
  123. data={this.state.search}
  124. onChange={data => {
  125. this.search(data);
  126. }} />
  127. <ActionLayout
  128. itemList={this.actionList}
  129. selectedKeys={this.state.selectedKeys}
  130. onAction={key => this.onAction(key)}
  131. />
  132. <TableLayout
  133. select
  134. columns={this.columns}
  135. list={this.state.list}
  136. pagination={this.state.page}
  137. loading={this.props.core.loading}
  138. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  139. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  140. selectedKeys={this.state.selectedKeys}
  141. />
  142. {this.state.detail && <Modal visible closable title='数据管理' onCancel={() => {
  143. this.close(false, 'detail');
  144. }} onOk={() => {
  145. this.submitInfo();
  146. }}>
  147. <Form>
  148. <Row>
  149. <Col span={12}><Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 10 }} label={'学员人数'}>
  150. <InputNumber value={this.state.detail.number || 0} placeholder={'人数'} onChange={(value) => {
  151. this.changeInfo('number', value);
  152. }} />
  153. </Form.Item></Col>
  154. </Row>
  155. <Form.Item label='考分分布' />
  156. <Row>
  157. {ExperienceScore.map((row, index) => {
  158. return <Col span={8}><Form.Item labelCol={{ span: 10 }} wrapperCol={{ span: 14 }} label={row.label}>
  159. <InputNumber value={this.state.detail.score ? this.state.detail.score[index] || 0 : 0} onChange={(value) => {
  160. this.changeInfoList('score', index, value);
  161. }} />
  162. </Form.Item></Col>;
  163. })}
  164. </Row>
  165. <Row>
  166. <Col span={12}><Form.Item labelCol={{ span: 8 }} wrapperCol={{ span: 10 }} label={'出分周期'}>
  167. <InputNumber value={this.state.detail.period || 0} placeholder={'单位天'} onChange={(value) => {
  168. this.changeInfo('period', value);
  169. }} />
  170. </Form.Item></Col>
  171. </Row>
  172. <Form.Item label='提分比例' />
  173. <Row>
  174. {ExperiencePercent.map((row, index) => {
  175. return <Col span={8}><Form.Item labelCol={{ span: 10 }} wrapperCol={{ span: 14 }} label={row.label}>
  176. <InputNumber value={this.state.detail.percent ? this.state.detail.percent[index] || 0 : 0} onChange={(value) => {
  177. this.changeInfoList('percent', index, value);
  178. }} />
  179. </Form.Item></Col>;
  180. })}
  181. </Row>
  182. </Form>
  183. </Modal>}
  184. </Block>;
  185. }
  186. }