page.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React from 'react';
  2. import { Link } from 'react-router-dom';
  3. import { Button, Modal, Form, Icon, Upload } 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 { formatTreeData, getMap } from '@src/services/Tools';
  11. import { asyncSMessage } from '@src/services/AsyncTools';
  12. import { CourseModule } from '../../../../Constant';
  13. import { System } from '../../../stores/system';
  14. import { Course } from '../../../stores/course';
  15. import { Exercise } from '../../../stores/exercise';
  16. const CourseModuleMap = getMap(CourseModule, 'value', 'label');
  17. export default class extends Page {
  18. init() {
  19. this.exerciseMap = {};
  20. this.filterForm = [
  21. {
  22. key: 'structId',
  23. type: 'tree',
  24. allowClear: true,
  25. tree: [],
  26. name: '学科',
  27. placeholder: '标题或正文',
  28. }, {
  29. key: 'type',
  30. type: 'select',
  31. name: '类型',
  32. allowClear: true,
  33. select: [],
  34. placeholder: '请输入',
  35. },
  36. ];
  37. this.actionList = [{
  38. key: 'info',
  39. name: '首页视频',
  40. }, {
  41. key: 'addVideo',
  42. type: 'primary',
  43. name: '创建视频课程',
  44. render: (item) => {
  45. return <Link to='/course/detail?module=video'><Button type='primary'>{item.name}</Button></Link>;
  46. },
  47. }, {
  48. key: 'addOnline',
  49. type: 'primary',
  50. name: '创建小班课程',
  51. render: (item) => {
  52. return <Link to='/course/detail?module=online'><Button type='primary'>{item.name}</Button></Link>;
  53. },
  54. }, {
  55. key: 'addVs',
  56. type: 'primary',
  57. name: '编辑1vs1课程',
  58. render: (item) => {
  59. return <Link to='/course/vs'><Button type='primary'>{item.name}</Button></Link>;
  60. },
  61. }];
  62. this.columns = [{
  63. title: '课程种类',
  64. dataIndex: 'courseModule',
  65. render: (text) => {
  66. return CourseModuleMap[text] || text;
  67. },
  68. }, {
  69. title: '学科',
  70. dataIndex: 'structId',
  71. render: (text, record) => {
  72. return `${record.parentStructId ? `${this.exerciseMap[record.parentStructId]}-` : ''}${this.exerciseMap[record.structId]}`;
  73. },
  74. }, {
  75. title: '类型',
  76. dataIndex: 'type',
  77. }, {
  78. title: '课程名称',
  79. dataIndex: 'title',
  80. }, {
  81. title: '售价',
  82. dataIndex: 'price',
  83. }, {
  84. title: '试听人数',
  85. dataIndex: 'trailNumber',
  86. }, {
  87. title: '购买数量(含套餐)',
  88. dataIndex: 'saleNumber',
  89. }, {
  90. title: '操作',
  91. dataIndex: 'handler',
  92. render: (text, record) => {
  93. return <div className="table-button">
  94. {<Link to={`/course/detail/${record.id}`}>编辑</Link>}
  95. {(record.courseModule === 'online') && <Link to={`/course/student/${record.id}`}>查看学员</Link>}
  96. </div>;
  97. },
  98. }];
  99. System.getCourseIndex().then(result => {
  100. return this.refreshInfo(result);
  101. }).then(() => {
  102. this.initData();
  103. });
  104. Exercise.courseStruct().then((result) => {
  105. const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; });
  106. this.filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  107. this.exerciseMap = getMap(result.map(row => {
  108. row.title = `${row.titleZh}`;
  109. row.value = row.id;
  110. return row;
  111. }), 'id', 'title');
  112. this.setState({ exercise: result });
  113. });
  114. }
  115. initData() {
  116. Course.list(Object.assign({ excludeVs: true }, this.state.search)).then(result => {
  117. this.setTableData(result.list, result.total);
  118. });
  119. }
  120. refreshInfo(result) {
  121. this.setState({ info: result });
  122. }
  123. infoAction() {
  124. const { info = {} } = this.state;
  125. this.open(info);
  126. }
  127. changeInfo(field, value) {
  128. const { detail } = this.state;
  129. detail[field] = value;
  130. this.setState({ detail });
  131. }
  132. submitInfo() {
  133. const { detail } = this.state;
  134. System.setCourseIndex(detail).then(() => {
  135. asyncSMessage('保存成功');
  136. this.close(false, 'detail');
  137. return this.refreshInfo(detail);
  138. });
  139. }
  140. renderView() {
  141. const { exercise } = this.state;
  142. return <Block flex>
  143. {exercise && <FilterLayout
  144. show
  145. itemList={this.filterForm}
  146. data={this.state.search}
  147. onChange={data => {
  148. this.search(data);
  149. }} />}
  150. <ActionLayout
  151. itemList={this.actionList}
  152. selectedKeys={this.state.selectedKeys}
  153. onAction={key => this.onAction(key)}
  154. />
  155. <TableLayout
  156. select
  157. columns={this.columns}
  158. list={this.state.list}
  159. pagination={this.state.page}
  160. loading={this.props.core.loading}
  161. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  162. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  163. selectedKeys={this.state.selectedKeys}
  164. />
  165. {this.state.detail && <Modal visible closable title='数据管理' onCancel={() => {
  166. this.close(false, 'detail');
  167. }} onOk={() => {
  168. this.submitInfo();
  169. }}>
  170. <Form>
  171. {this.state.uploadErr}
  172. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 10 }} label={'在线课程'} help={this.state.onlineErr}>
  173. <Upload
  174. listType="picture-card"
  175. showUploadList={false}
  176. beforeUpload={(file) => System.uploadVideo(file).then((result) => {
  177. this.changeInfo('onlineVideo', result.url);
  178. }).catch(err => {
  179. this.setState({ onlineErr: err.message });
  180. })}
  181. >
  182. {this.state.detail.onlineVideo ? <div>
  183. <Icon type={this.props.core.loading ? 'loading' : 'plus'} />
  184. <div className="ant-upload-text">已上传</div>
  185. </div> : <div>
  186. <Icon type={this.props.core.loading ? 'loading' : 'plus'} />
  187. <div className="ant-upload-text">Upload</div>
  188. </div>}
  189. </Upload>
  190. </Form.Item>
  191. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 10 }} label={'1v1课程'} help={this.state.vsErr}>
  192. <Upload
  193. listType="picture-card"
  194. showUploadList={false}
  195. beforeUpload={(file) => System.uploadVideo(file).then((result) => {
  196. this.changeInfo('vsVideo', result.url);
  197. }).catch(err => {
  198. this.setState({ vsErr: err.message });
  199. })}
  200. >
  201. {this.state.detail.vsVideo ? <div>
  202. <Icon type={this.props.core.loading ? 'loading' : 'plus'} />
  203. <div className="ant-upload-text">已上传</div>
  204. </div> : <div>
  205. <Icon type={this.props.core.loading ? 'loading' : 'plus'} />
  206. <div className="ant-upload-text">Upload</div>
  207. </div>}
  208. </Upload>
  209. </Form.Item>
  210. </Form>
  211. </Modal>}
  212. </Block>;
  213. }
  214. }