1
0

page.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. import React from 'react';
  2. import moment from 'moment';
  3. import { DatePicker, Checkbox, Modal, Form, Input, Row, Col, Button, 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 { formatDate } from '@src/services/Tools';
  11. import { asyncSMessage, asyncForm } from '@src/services/AsyncTools';
  12. import { UserUrl } from '../../../../Constant';
  13. import { Course } from '../../../stores/course';
  14. import { User } from '../../../stores/user';
  15. import { System } from '../../../stores/system';
  16. export default class extends Page {
  17. init() {
  18. this.videoColumns = [{
  19. title: '时间段',
  20. dataIndex: 'time',
  21. render: (text) => {
  22. return `${formatDate(text.startTime, 'YYYY-MM-DD')}~${formatDate(text.endTime, 'YYYY-MM-DD')}`;
  23. },
  24. }, {
  25. title: '学员id',
  26. dataIndex: 'userId',
  27. }, {
  28. title: '学员名称',
  29. dataIndex: 'user.nickname',
  30. }, {
  31. title: '手机号',
  32. dataIndex: 'user.mobile',
  33. }, {
  34. title: '操作',
  35. dataIndex: 'handler',
  36. render: (text, record) => {
  37. return <div className="table-button">
  38. {<a onClick={() => {
  39. this.deleteOnlineStudent(record);
  40. }}>删除</a>}
  41. </div>;
  42. },
  43. }];
  44. this.vsAction = [{
  45. key: 'addAppointment',
  46. name: '添加预约',
  47. }];
  48. this.vsList = [{
  49. key: 'id',
  50. type: 'hidden',
  51. }, {
  52. key: 'title',
  53. type: 'input',
  54. name: '课程名称',
  55. }, {
  56. key: 'timerange',
  57. type: 'daterange',
  58. name: '上课时间',
  59. }, {
  60. key: 'channel',
  61. type: 'input',
  62. name: '频道号',
  63. }];
  64. this.vsColumns = [{
  65. title: '课时序号',
  66. dataIndex: 'no',
  67. render: (text) => {
  68. const { data } = this.state;
  69. return `${text}/${data.vsNumber}`;
  70. },
  71. }, {
  72. title: '上课时间',
  73. dataIndex: 'time',
  74. render: (text, record) => {
  75. return <DatePicker.RangePicker value={[record.startTime, record.endTime]} onChange={(value) => {
  76. this.changeAppointment(record.id, { startTime: value[0], endTime: value[1] });
  77. }} />;
  78. },
  79. }, {
  80. title: '课程名称',
  81. dataIndex: 'title',
  82. }, {
  83. title: '频道号',
  84. dataIndex: 'channel',
  85. }, {
  86. title: '学习进度',
  87. dataIndex: 'isFinish',
  88. render: (text, record) => {
  89. return <Checkbox checked={text > 0} onChange={(e) => {
  90. this.changeAppointment(record.id, { isFinish: e.target.value ? 1 : 0 });
  91. }} />;
  92. },
  93. }, {
  94. title: '预习作业',
  95. dataIndex: 'userPaper',
  96. render: (text, record) => {
  97. return text ? <a onClick={() => {
  98. User.locationUser(record.userId, `${UserUrl}/paper/report/${record.reportId}`);
  99. }}>查看{text.times > 0 ? '(已完成)' : ''}</a> : '';
  100. },
  101. }, {
  102. title: '笔记批阅',
  103. dataIndex: 'noteList',
  104. render: (text, record) => {
  105. return <a onClick={() => {
  106. this.noteAction(record);
  107. }}>查看</a>;
  108. },
  109. }, {
  110. title: '课后补充',
  111. dataIndex: 'supplyList',
  112. render: (text, record) => {
  113. return <a onClick={() => {
  114. this.supplyAction(record);
  115. }}>查看</a>;
  116. },
  117. }];
  118. }
  119. initData() {
  120. const { id } = this.params;
  121. let handler;
  122. if (id) {
  123. handler = Course.listStudy({ ids: [id] });
  124. }
  125. handler
  126. .then(result => {
  127. const [row] = result.list;
  128. if (!row) {
  129. asyncSMessage('记录不存在');
  130. return;
  131. }
  132. const { course } = row;
  133. this.setState({ module: course.courseModule });
  134. this.setState({ data: row });
  135. this.refresh();
  136. });
  137. }
  138. refresh() {
  139. // const { id } = this.params;
  140. const { module } = this.state;
  141. switch (module) {
  142. case 'video':
  143. this.refreshVideo();
  144. break;
  145. case 'online':
  146. break;
  147. case 'vs':
  148. this.refreshVs();
  149. break;
  150. default:
  151. }
  152. }
  153. refreshVideo() {
  154. // const { id } = this.params;
  155. // Course.listStudentOnline(Object.assign({ courseId: id }, this.state.search)).then(result => {
  156. // this.setTableData(result.list, result.total);
  157. // });
  158. }
  159. refreshVs() {
  160. const { id } = this.params;
  161. User.listCourseAppointment(Object.assign({ courseId: id }, this.state.search)).then(result => {
  162. result.list = result.list.map(row => {
  163. row.startTime = moment(row.startTime);
  164. row.endTime = moment(row.endTime);
  165. return row;
  166. });
  167. this.setTableData(result.list, result.total);
  168. });
  169. }
  170. changeAppointment(id, data) {
  171. data.id = id;
  172. return User.editCourseAppointment(data).then(() => {
  173. this.refreshVs();
  174. this.cleanInfo();
  175. });
  176. }
  177. addAppointmentAction() {
  178. const { id } = this.params;
  179. asyncForm('添加', this.vsList, {}, info => {
  180. const { data } = this.state;
  181. ([info.startTime, info.endTime] = info.timerange);
  182. return User.addCourseAppointment(Object.assign({ recordId: id, userId: data.userId, courseId: data.courseId, noteList: [], supplyList: [] }, info)).then(() => {
  183. asyncSMessage('添加成功!');
  184. this.refreshVs();
  185. });
  186. }).catch(err => {
  187. console.log(err);
  188. });
  189. }
  190. noteAction(record) {
  191. this.open(record, 'note');
  192. }
  193. supplyAction(record) {
  194. this.open(record, 'supply');
  195. }
  196. deleteAppointment(row) {
  197. User.delCourseAppointment({ id: row.id }).then(() => {
  198. asyncSMessage('删除成功!');
  199. this.refresh();
  200. });
  201. }
  202. changeInfo(key, data) {
  203. const info = this.state[key] || {};
  204. this.setState({ [key]: Object.assign(info, data) });
  205. }
  206. cleanInfo() {
  207. this.setState({ supplyInfo: null, noteInfo: null });
  208. }
  209. renderVs() {
  210. const { data, page } = this.state;
  211. return <Block flex>
  212. {data.vsNumber > page.total && <ActionLayout
  213. itemList={this.vsAction}
  214. selectedKeys={this.state.selectedKeys}
  215. onAction={key => this.onAction(key)}
  216. />}
  217. <TableLayout
  218. columns={this.vsColumns}
  219. list={this.state.list}
  220. pagination={this.state.page}
  221. loading={this.props.core.loading}
  222. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  223. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  224. selectedKeys={this.state.selectedKeys}
  225. />
  226. {this.state.note && <Modal visible closable title='课后笔记' footer={null} onCancel={() => {
  227. this.cleanInfo();
  228. this.close(false, 'note');
  229. }}>
  230. {(this.state.note.noteList || []).map(row => {
  231. return <p>{formatDate(row.time)}: {<a href={row.url} target='_blank'>{row.name}</a>}</p>;
  232. })}
  233. <Form>
  234. <Row>
  235. <Col span={1}><Upload
  236. showUploadList={false}
  237. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  238. this.changeInfo('noteInfo', { url: result.url, name: file.name, time: new Date() });
  239. return Promise.reject();
  240. })}
  241. >
  242. <Button>上传文档{(this.state.noteInfo || {}).url ? '(已上传)' : ''}</Button>
  243. </Upload></Col>
  244. <Col span={1} offset={20}><Button type='primary' onClick={() => {
  245. if (!this.state.noteInfo || !this.state.noteInfo.url) return;
  246. let { noteList = [] } = this.state.note;
  247. noteList = noteList || [];
  248. noteList.push(this.state.noteInfo);
  249. this.changeAppointment(this.state.note.id, { noteList });
  250. }}>发布</Button></Col>
  251. </Row>
  252. </Form>
  253. </Modal>}
  254. {this.state.supply && <Modal visible closable title='课后补充' footer={null} onCancel={() => {
  255. this.cleanInfo();
  256. this.close(false, 'supply');
  257. }}>
  258. {(this.state.supply.supplyList || []).map(row => {
  259. return [<p>{formatDate(row.time)}:{<a href={row.url} target='_blank'>{row.name}</a>}</p>, <p>留言 - {row.content}</p>];
  260. })}
  261. <Form>
  262. <Row>
  263. <Col span={12}>
  264. <Input value={(this.state.supplyInfo || {}).content || ''} onChange={value => {
  265. this.changeInfo('supplyInfo', { content: value });
  266. }} />
  267. </Col>
  268. <Col span={1}><Upload
  269. showUploadList={false}
  270. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  271. this.changeInfo('supplyInfo', { url: result.url, name: file.name, time: new Date() });
  272. return Promise.reject();
  273. })}
  274. >
  275. <Button>上传文档{(this.state.supplyInfo || {}).url ? '(已上传)' : ''}</Button>
  276. </Upload></Col>
  277. <Col span={1} offset={10}><Button type='primary' onClick={() => {
  278. if (!this.state.supplyInfo || !this.state.supplyInfo.url) return;
  279. let { supplyList = [] } = this.state.supply;
  280. supplyList = supplyList || [];
  281. supplyList.push(this.state.supplyInfo);
  282. this.changeAppointment(this.state.supply.id, { supplyList });
  283. }}>发布</Button></Col>
  284. </Row>
  285. </Form>
  286. </Modal>}
  287. </Block>;
  288. }
  289. renderVideo() {
  290. return <Block flex>
  291. <TableLayout
  292. columns={this.videoColumns}
  293. list={this.state.list}
  294. pagination={this.state.page}
  295. loading={this.props.core.loading}
  296. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  297. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  298. selectedKeys={this.state.selectedKeys}
  299. />
  300. </Block>;
  301. }
  302. renderView() {
  303. switch (this.state.module) {
  304. case 'online':
  305. return [];
  306. case 'vs':
  307. return [this.renderVs()];
  308. case 'video':
  309. return [this.renderVideo()];
  310. default:
  311. return <div />;
  312. }
  313. }
  314. }