AssignmentDetailPage.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. * Created by Arison on 2018/11/6.
  3. */
  4. import React from 'react';
  5. import 'bootstrap/dist/css/bootstrap.css'
  6. import 'bootstrap/dist/css/bootstrap.min.css'
  7. import './AssignmentDetailPage.css'
  8. import '../../style/css/app-gloal.css'
  9. import {List, Input, Button} from 'antd';
  10. import {fetchPost, fetchGet} from '../../utils/fetchRequest';
  11. import {API, _baseURL} from '../../configs/api.config';
  12. import {getIntValue, getSearchParams, getStrValue, isObjEmpty} from '../../utils/common';
  13. import ImagesViewer from "../../components/imagesVIewer/ImagesViewer";
  14. import {Toast} from 'antd-mobile'
  15. import {Avatar} from 'antd'
  16. import leave_img from '../../style/imgs/leave_messages.png';
  17. import {connect} from 'react-redux'
  18. import {saveListState} from "../../redux/actions/listState";
  19. /**
  20. * 作业详情
  21. * Created by Arison on 17:49.
  22. */
  23. class AssignmentDetailPage extends React.Component {
  24. constructor(props) {
  25. super(props);
  26. this.state = {
  27. id: this.props.match.params.id,
  28. role: this.props.match.params.role,
  29. name: 'AssignmentDetailPage',
  30. previewVisible: false,
  31. teachName: "",
  32. endTime: "",
  33. headerUrl: "",
  34. title: "",
  35. content: "",
  36. messageContent: null,
  37. files: [],
  38. data: []
  39. };
  40. }
  41. componentWillMount() {
  42. document.title = "作业详情";
  43. }
  44. componentDidMount() {
  45. this.searchParams = getSearchParams(this.props.location.search)
  46. this.stuId = this.props.userInfo.user.student.stuId
  47. this.parentId = this.props.userInfo.user.userFunId
  48. if (this.searchParams) {
  49. if (this.searchParams.stuId) {
  50. this.stuId = this.searchParams.stuId
  51. }
  52. if (this.searchParams.parentId) {
  53. this.parentId = this.searchParams.parentId
  54. }
  55. }
  56. Toast.show('', 0)
  57. this.getHomeworkDetail()
  58. }
  59. componentWillUnmount() {
  60. Toast.hide()
  61. }
  62. onClickImage() {
  63. this.setState({
  64. previewVisible: true
  65. })
  66. }
  67. getHomeworkDetail = () => {
  68. fetchPost(API.HOMEWORK_DETAIL, {
  69. taskId: this.state.id,
  70. stuId: this.stuId
  71. }).then((response) => {
  72. Toast.hide()
  73. if (response && response.data) {
  74. let images = [];
  75. if (response.data.taskFiles) {
  76. let temps = JSON.parse(response.data.taskFiles);
  77. for (let i = 0; i < temps.length; i++) {
  78. images.push(temps[i]);
  79. }
  80. }
  81. if (response.data.taskContext) {
  82. response.data.taskContext = response.data.taskContext.replace(/\r\n/g, '<br/>');
  83. }
  84. const taskReplyDOs = response.data.taskReplyDOs
  85. if (this.state.data) {
  86. this.state.data.length = 0
  87. }
  88. if (taskReplyDOs) {
  89. for (let i = 0; i < taskReplyDOs.length; i++) {
  90. let model = {
  91. name: taskReplyDOs[i].stuName,
  92. content: taskReplyDOs[i].replyContext
  93. }
  94. this.state.data.push(model);
  95. }
  96. }
  97. this.setState({
  98. teachName: response.data.teacherName,
  99. endTime: response.data.endDate,
  100. headerUrl: response.data.teacherPhoto,
  101. title: response.data.taskTitle,
  102. content: response.data.taskContext,
  103. files: images,
  104. data: this.state.data
  105. })
  106. }
  107. }).catch((error) => {
  108. Toast.hide()
  109. if (typeof error === 'string') {
  110. Toast.fail(error, 2)
  111. } else {
  112. Toast.fail('请求异常', 2)
  113. }
  114. })
  115. }
  116. refreshListData = () => {
  117. if (this.props.listState.itemIndex >= 0) {
  118. const homeWorkCache = this.props.listState.listData[this.props.listState.itemIndex]
  119. if ("teacher" == this.state.role) {
  120. homeWorkCache.readStatus = ''
  121. homeWorkCache.taskStatus = 2
  122. } else {
  123. homeWorkCache.readStatus = '已回复'
  124. homeWorkCache.taskStatus = 2
  125. }
  126. this.props.listState.listData[this.props.listState.itemIndex] = homeWorkCache
  127. }
  128. saveListState({
  129. listData: this.props.listState.listData,
  130. })()
  131. }
  132. onMessageSend = () => {
  133. if (isObjEmpty(this.state.messageContent)) {
  134. Toast.info("请输入留言内容")
  135. return;
  136. }
  137. const params = {
  138. taskId: this.state.id,
  139. replyTitle: '这是作业的回复',
  140. replyContext: this.state.messageContent,
  141. parentId: this.parentId,
  142. stuId: this.stuId
  143. }
  144. fetchPost(API.HOMEWORK_REPLY, {
  145. taskRepayString: JSON.stringify(params)
  146. }).then((response) => {
  147. console.log("response:" + JSON.stringify(response));
  148. if (response.success) {
  149. Toast.info("留言成功!");
  150. this.setState({
  151. messageContent: ""
  152. });
  153. this.refreshListData()
  154. this.getHomeworkDetail()
  155. }
  156. }).catch((error) => {
  157. Toast.hide()
  158. if (typeof error === 'string') {
  159. Toast.fail(error, 2)
  160. } else {
  161. Toast.fail('请求异常', 2)
  162. }
  163. })
  164. }
  165. onChangeMessage = (event) => {
  166. let msg = event.target.value;
  167. this.setState({
  168. messageContent: msg
  169. })
  170. }
  171. handleCancel = () => this.setState({previewVisible: false})
  172. render() {
  173. const {userInfo} = this.props
  174. return <div className="class-page-layout">
  175. <div style={{flex: '1'}}>
  176. <div className="homework-detail-top-layout common-flex-row">
  177. {isObjEmpty(userInfo.userAvatar) ?
  178. <Avatar size={55} icon='user'/> :
  179. <img className="img-circle"
  180. src={userInfo.userAvatar}
  181. width={55} height={55}/>
  182. }
  183. <div className='common-flex-column-y-center' style={{paddingLeft: '14px'}}>
  184. <div className="homework-detail-top-name">{this.state.teachName}老师</div>
  185. <div className='homework-detail-top-time'>
  186. <span>截止时间:</span>
  187. <span>{this.state.endTime}</span>
  188. </div>
  189. </div>
  190. </div>
  191. <div className="homework-detail-title">{this.state.title} </div>
  192. <div className="homework-detail-content"
  193. dangerouslySetInnerHTML={{__html: this.state.content.replaceAll('\n', '<br/>')}}></div>
  194. <div className="margin_top_bottom_10 flex_center">
  195. {this.state.previewVisible ?
  196. <ImagesViewer onClose={this.handleCancel} urls={this.state.files}
  197. index={0}
  198. needPoint={this.state.files.length <= 9}/> : ""}
  199. {this.state.files.length != 0 ? (<img onClick={this.onClickImage.bind(this)}
  200. style={{margin: "0px"}}
  201. src={this.state.files[0]}
  202. height={130}/>) : ("")}
  203. </div>
  204. <div className="margin_top_bottom_10 homework-detail-leave-caption">
  205. <img src={leave_img} style={{height: 18, width: 21, marginRight: 10}}/>
  206. {this.state.data.length != 0 ? (
  207. <span>
  208. ({this.state.data.length}条)
  209. </span>) : (<div></div>)}</div>
  210. <div id="page_horizontal_line"></div>
  211. </div>
  212. <div className='homework-detail-leave-layout'
  213. style={{paddingBottom: this.state.role === "teacher" ? '0' : '50px'}}>
  214. <List
  215. locale={{emptyText: '暂无留言'}}
  216. dataSource={this.state.data}
  217. renderItem={item => (
  218. <div style={{display: 'flex', paddingTop: 5, paddingBottom: 5}}>
  219. <div className="homework-detail-leave-name">{item.name}:</div>
  220. <div className='homework-detail-leave-content'>{item.content}</div>
  221. </div>
  222. )}/>
  223. </div>
  224. {this.state.role === "teacher" ? "" :
  225. <div className="footer flex padding_10" style={{background: '#F2F2F2', alignItems: 'center'}}>
  226. <img src={require('imgs/ic_edit.png')} width={28} height={28}/>
  227. <input ref={ref => this.input_content = ref} value={this.state.messageContent}
  228. onChange={this.onChangeMessage} placeholder="留言"
  229. className='homework-detail-leave-input'></input>
  230. <span onClick={this.onMessageSend} className="homework-detail-leave-send">发送</span>
  231. </div>}
  232. </div>
  233. }
  234. }
  235. let mapStateToProps = (state) => ({
  236. userInfo: {...state.redUserInfo},
  237. listState: {...state.redListState}
  238. })
  239. let mapDispatchToProps = (dispatch) => ({})
  240. export default connect(mapStateToProps, mapDispatchToProps)(AssignmentDetailPage)