page.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React from 'react';
  2. import { Form, Button, Row, Col, List, Icon, Switch, Typography, Input } from 'antd';
  3. import './index.less';
  4. // import Editor from '@src/components/Editor';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import DragList from '@src/components/DragList';
  8. // import FileUpload from '@src/components/FileUpload';
  9. import { formatFormError, formatDate, getMap } from '@src/services/Tools';
  10. import { asyncSMessage } from '@src/services/AsyncTools';
  11. import { PcUrl } from '../../../../Constant';
  12. import { Exercise } from '../../../stores/exercise';
  13. import { Course } from '../../../stores/course';
  14. export default class extends Page {
  15. init() {
  16. this.exerciseMap = {};
  17. Exercise.courseStruct().then((result) => {
  18. this.exerciseMap = getMap(result.map(row => {
  19. row.title = `${row.titleZh}`;
  20. row.value = row.id;
  21. return row;
  22. }), 'id', 'title');
  23. this.setState({ exercise: result });
  24. });
  25. }
  26. initData() {
  27. const { id } = this.params;
  28. let handler;
  29. if (id) {
  30. handler = Course.getAsk({ id });
  31. } else {
  32. handler = Promise.resolve({ others: [] });
  33. }
  34. handler
  35. .then(result => {
  36. result.ignoreStatus = result.answerStatus === 2;
  37. const { getFieldDecorator, setFieldsValue } = this.props.form;
  38. getFieldDecorator('id');
  39. getFieldDecorator('answer');
  40. getFieldDecorator('showStatus');
  41. getFieldDecorator('content');
  42. setFieldsValue({ id: result.id, content: result.content, answer: result.answer });
  43. this.setState({ data: result });
  44. });
  45. }
  46. orderQuestion(oldIndex, newIndex) {
  47. const { data } = this.state;
  48. const { others = [] } = data;
  49. const tmp = others.splice(oldIndex, 1);
  50. if (newIndex === others.length) {
  51. others.push(tmp[0]);
  52. } else {
  53. others.splice(newIndex, 0, tmp[0]);
  54. }
  55. this.setState({ others });
  56. }
  57. addOrder() {
  58. const { data } = this.state;
  59. const { others } = data;
  60. others.push(data);
  61. this.setState({ data });
  62. }
  63. removeOrder() {
  64. const { data } = this.state;
  65. const { others } = data;
  66. data.others = others.filter(row => row.id !== data.id);
  67. this.setState({ data });
  68. }
  69. submit() {
  70. const { form } = this.props;
  71. form.validateFields((err) => {
  72. if (!err) {
  73. const data = form.getFieldsValue();
  74. data.showStatus = data.showStatus ? 1 : 0;
  75. data.other = this.state.data.others.map(row => row.id);
  76. Course.editAsk(data).then(() => {
  77. asyncSMessage('保存成功');
  78. }).catch((e) => {
  79. if (e.result) form.setFields(formatFormError(data, e.result));
  80. });
  81. }
  82. });
  83. }
  84. ignore() {
  85. const { data } = this.state;
  86. Course.editAsk({ id: data.id, ignoreStatus: 1 }).then(() => {
  87. asyncSMessage('操作成功');
  88. goBack();
  89. });
  90. }
  91. renderBase() {
  92. const { data } = this.state;
  93. const { course = {} } = data;
  94. return <Block>
  95. <h1>提问信息</h1>
  96. <Form>
  97. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='学科'>
  98. {this.exerciseMap[course.structId]}
  99. </Form.Item>
  100. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='课程'>
  101. <a href={`${PcUrl}/course/detail/${course.id}`} target='_blank'>{course.title}</a>
  102. </Form.Item>
  103. </Form>
  104. </Block>;
  105. }
  106. renderAsk() {
  107. const { getFieldDecorator, getFieldValue } = this.props.form;
  108. const { data, editContent } = this.state;
  109. const { user = {}, createTime, courseNo = {}, position, originContent, content } = data;
  110. return <Block>
  111. <h1>提问信息</h1>
  112. <Form>
  113. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='用户姓名'>
  114. {user.nickname}
  115. </Form.Item>
  116. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='提问时间'>
  117. {formatDate(createTime, 'YYYY-MM-DD HH:mm:ss')}
  118. </Form.Item>
  119. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='提问位置'>
  120. {`P${courseNo.no}:${position}-${position + 5}min`}
  121. </Form.Item>
  122. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='提问内容'>
  123. {originContent}
  124. </Form.Item>
  125. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='提问详情'>
  126. {!editContent && content}
  127. {getFieldDecorator('content', {
  128. })(
  129. editContent ? <Input.TextArea placeholder='输入内容' /> : <input hidden />,
  130. )}
  131. <Switch checked={editContent} checkedChildren='编辑模式' unCheckedChildren='关闭' onChange={(value) => {
  132. data.content = getFieldValue('content');
  133. this.setState({ editContent: value, data });
  134. }} />
  135. </Form.Item>
  136. </Form>
  137. </Block>;
  138. }
  139. renderQuestionList() {
  140. return <Block>
  141. <h1>该时段的展示中问题</h1>
  142. <DragList
  143. loading={this.props.core.loading}
  144. dataSource={this.state.data.others || []}
  145. handle={'.icon'}
  146. onMove={(oldIndex, newIndex) => {
  147. this.orderQuestion(oldIndex, newIndex);
  148. }}
  149. renderItem={(item) => (
  150. <List.Item actions={[<Icon type='bars' className='icon' />, <Typography.Text copyable={{ text: `${PcUrl}/course/answer/${item.courseId}?courseNoId=${item.courseNoId}&askId=${item.id}` }} />]}>
  151. <Row style={{ width: '100%' }}>
  152. <Col span={11}>问题:<span dangerouslySetInnerHTML={{ __html: item.content }} /></Col>
  153. <Col span={11} offset={1}>答复:<span dangerouslySetInnerHTML={{ __html: item.answer }} /></Col>
  154. </Row>
  155. </List.Item>
  156. )}
  157. /></Block>;
  158. }
  159. renderAnswer() {
  160. const { getFieldDecorator } = this.props.form;
  161. return <Block>
  162. <Form>
  163. {getFieldDecorator('id')(<input hidden />)}
  164. <Form.Item label='教师回复'>
  165. {getFieldDecorator('answer', {
  166. })(
  167. <Input.TextArea placeholder='输入内容' />,
  168. )}
  169. </Form.Item>
  170. <Row type="flex" justify="center">
  171. <Col span={12}>
  172. <Form.Item labelCol={{ span: 12 }} wrapperCol={{ span: 10 }} label='显示状态'>
  173. {getFieldDecorator('showStatus', {
  174. valuePropName: 'checked',
  175. })(
  176. <Switch onChange={(value) => {
  177. if (value) {
  178. this.addOrder();
  179. } else {
  180. this.removeOrder();
  181. }
  182. }} checkedChildren='on' unCheckedChildren='off' />,
  183. )}
  184. </Form.Item>
  185. </Col>
  186. </Row>
  187. </Form>
  188. </Block>;
  189. }
  190. renderView() {
  191. return <div flex>
  192. {this.renderBase()}
  193. {this.renderAsk()}
  194. {this.renderQuestionList()}
  195. {this.renderAnswer()}
  196. <Row type="flex" justify="center">
  197. <Col>
  198. <Button type="drange" onClick={() => {
  199. this.ignore();
  200. }}>忽略问题</Button>
  201. </Col>
  202. <Col>
  203. <Button type="primary" onClick={() => {
  204. this.submit();
  205. }}>保存</Button>
  206. </Col>
  207. </Row>
  208. </div>;
  209. }
  210. }