1
0

page.js 6.1 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, formatTreeData, getMap } 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 { Exercise } from '../../../stores/exercise';
  16. export default class extends Page {
  17. init() {
  18. this.filterForm = [
  19. {
  20. key: 'structId',
  21. type: 'input',
  22. allowClear: true,
  23. name: '搜索',
  24. placeholder: '标题或正文',
  25. }, {
  26. key: 'type',
  27. type: 'select',
  28. name: '类型',
  29. allowClear: true,
  30. select: [],
  31. placeholder: '请输入',
  32. },
  33. ];
  34. this.actionList = [{
  35. key: 'info',
  36. name: '首页视频',
  37. }, {
  38. key: 'addVideo',
  39. type: 'primary',
  40. name: '创建视频课程',
  41. render: (item) => {
  42. return <Link to='/course/detail?module=video'><Button type='primary'>{item.name}</Button></Link>;
  43. },
  44. }, {
  45. key: 'addOnline',
  46. type: 'primary',
  47. name: '创建直播课程',
  48. render: (item) => {
  49. return <Link to='/course/detail?module=online'><Button type='primary'>{item.name}</Button></Link>;
  50. },
  51. }, {
  52. key: 'addVs',
  53. type: 'primary',
  54. name: '创建1vs1课程',
  55. render: (item) => {
  56. return <Link to='/course/detail?module=vs'><Button type='primary'>{item.name}</Button></Link>;
  57. },
  58. }];
  59. this.columns = [{
  60. title: '文章标题',
  61. dataIndex: 'title',
  62. }, {
  63. title: '作者',
  64. dataIndex: 'user',
  65. render: (text) => {
  66. return (text || {}).nickname;
  67. },
  68. }, {
  69. title: '录入时间',
  70. dataIndex: 'createTime',
  71. render: (text) => {
  72. return formatDate(text);
  73. },
  74. }, {
  75. title: '收藏数',
  76. dataIndex: 'collectNumber',
  77. }, {
  78. title: '操作',
  79. dataIndex: 'handler',
  80. render: (text, record) => {
  81. return <div className="table-button">
  82. {<Link to={`/course/experience/detail/${record.id}`}>编辑</Link>}
  83. </div>;
  84. },
  85. }];
  86. System.getCourseIndex().then(result => {
  87. return this.refreshInfo(result);
  88. }).then(() => {
  89. this.initData();
  90. });
  91. Exercise.courseStruct().then((result) => {
  92. const list = result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
  93. this.filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  94. this.exerciseMap = getMap(result.map(row => {
  95. row.title = `${row.titleZh}/${row.titleEn}`;
  96. row.value = row.id;
  97. return row;
  98. }), 'id', 'title');
  99. this.setState({ exercise: result });
  100. });
  101. }
  102. initData() {
  103. Course.list(this.state.search).then(result => {
  104. this.setTableData(result.list, result.total);
  105. });
  106. }
  107. refreshInfo(result) {
  108. this.setState({ info: result });
  109. }
  110. infoAction() {
  111. const { info = {} } = this.state;
  112. this.open(info);
  113. }
  114. changeInfo(field, value) {
  115. const { detail } = this.state;
  116. detail[field] = value;
  117. this.setState({ detail });
  118. }
  119. submitInfo() {
  120. const { detail } = this.state;
  121. System.setCourseIndex(detail).then(() => {
  122. asyncSMessage('保存成功');
  123. this.close(false, 'detail');
  124. return this.refreshInfo(detail);
  125. });
  126. }
  127. renderView() {
  128. const { exercise } = this.state;
  129. return <Block flex>
  130. {exercise && <FilterLayout
  131. show
  132. itemList={this.filterForm}
  133. data={this.state.search}
  134. onChange={data => {
  135. this.search(data);
  136. }} />}
  137. <ActionLayout
  138. itemList={this.actionList}
  139. selectedKeys={this.state.selectedKeys}
  140. onAction={key => this.onAction(key)}
  141. />
  142. <TableLayout
  143. select
  144. columns={this.columns}
  145. list={this.state.list}
  146. pagination={this.state.page}
  147. loading={this.props.core.loading}
  148. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  149. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  150. selectedKeys={this.state.selectedKeys}
  151. />
  152. {this.state.detail && <Modal visible closable title='数据管理' onCancel={() => {
  153. this.close(false, 'detail');
  154. }} onOk={() => {
  155. this.submitInfo();
  156. }}>
  157. <Form>
  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. }