NotifyBoardDetail.jsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**
  2. * Created by RaoMeng on 2019/1/15
  3. * Desc: 通知公告详情
  4. */
  5. import React, {Component} from 'react'
  6. import ImagesViewer from "../../components/imagesVIewer";
  7. import {getArrayValue, getIntValue, getSearchParams, getStrValue, isObjEmpty} from "../../utils/common";
  8. import NotifyBoBean from "../../model/NotifyBoBean";
  9. import {fetchGet, fetchPost} from "../../utils/fetchRequest";
  10. import {_baseURL, API} from "../../configs/api.config";
  11. import {List, Icon} from 'antd'
  12. import {Toast} from 'antd-mobile'
  13. import {connect} from 'react-redux'
  14. import {saveListState} from 'action/listState'
  15. class NotifyBoardDetail extends Component {
  16. constructor() {
  17. super()
  18. this.state = {
  19. notifyDetail: '',
  20. previewVisible: false,
  21. }
  22. }
  23. componentWillMount() {
  24. this.searchParams = getSearchParams(this.props.location.search)
  25. this.notifyId = this.props.match.params.notifyId
  26. this.role = this.props.match.params.role
  27. }
  28. componentDidMount() {
  29. document.title = '通知公告详情'
  30. this.obtainDetail()
  31. }
  32. componentWillUnmount() {
  33. }
  34. render() {
  35. const {previewVisible, notifyDetail} = this.state
  36. let enclosureItem = <div></div>
  37. let pictureUrls = []
  38. if (!isObjEmpty(notifyDetail.enclosure) && notifyDetail.enclosure != '[]') {
  39. enclosureItem =
  40. <div className='principal-enclosure-layout'>
  41. <img src={_baseURL + notifyDetail.enclosure[0]} className='principal-enclosure-img'
  42. onClick={this.handlePreview}/>
  43. <span className='principal-enclosure-count'>({notifyDetail.enclosure.length}张)</span>
  44. </div>
  45. notifyDetail.enclosure.forEach((enclosure, index) => {
  46. pictureUrls.push(_baseURL + enclosure)
  47. })
  48. }
  49. const readedList = notifyDetail.readed
  50. const unReadList = notifyDetail.unRead
  51. const receiveItems = []
  52. if (!isObjEmpty(readedList) && readedList != '[]') {
  53. for (let i = 0; i < readedList.length; i++) {
  54. receiveItems.push(<span
  55. className='notify-detail-modal-read'>{getStrValue(readedList[i], 'stuName') ?
  56. getStrValue(readedList[i], 'stuName') : getStrValue(readedList[i], 'teacherName')}</span>)
  57. }
  58. }
  59. if (!isObjEmpty(unReadList) && unReadList != '[]') {
  60. for (let i = 0; i < unReadList.length; i++) {
  61. receiveItems.push(<span
  62. className='notify-detail-modal-unread'>{getStrValue(unReadList[i], 'stuName') ?
  63. getStrValue(unReadList[i], 'stuName') : getStrValue(unReadList[i], 'teacherName')}</span>)
  64. }
  65. }
  66. return (
  67. <div>
  68. {previewVisible ?
  69. <ImagesViewer onClose={this.handleCancel} urls={pictureUrls}
  70. index={0}
  71. needPoint={pictureUrls.length <= 9}/> : ""}
  72. <div className='notify-detail-modal-layout'>
  73. <div className='notify-detail-modal-content-layout'>
  74. <div className='notify-detail-modal-content-header'>
  75. <div className='notify-detail-modal-header-tilte'>{notifyDetail.noTitle}</div>
  76. <span
  77. className={notifyDetail.noStatu === '已读' ?
  78. 'notify-item-statuAl' : 'notify-item-statuNo'}>{notifyDetail.noStatu}</span>
  79. </div>
  80. <div className='notify-detail-modal-content-text'
  81. dangerouslySetInnerHTML={{
  82. __html: notifyDetail.noContent ?
  83. notifyDetail.noContent.replaceAll('\n', '<br/>')
  84. : ''
  85. }}></div>
  86. <div style={{padding: '10px'}}>
  87. {enclosureItem}
  88. </div>
  89. <div className='notify-detail-modal-time'>{notifyDetail.noIssue}</div>
  90. <div className='notify-detail-modal-time'>{notifyDetail.noTime}</div>
  91. {/*<div className='notify-detail-modal-time'>{notifyDetail.noTime}</div>*/}
  92. <div className='gray-line'></div>
  93. <div className='common-flex-row-10 common-font-family'>
  94. <span style={{color: '#363636'}}>接收人名单</span>
  95. <div style={{flex: '1', textAlign: 'right'}}>
  96. {/*<span style={{fontSize: '12px', color: '#CD1D1D'}}>未读:{notifyDetail.unRead}</span>*/}
  97. <span style={{
  98. fontSize: '12px',
  99. color: '#161616',
  100. marginLeft: '10px'
  101. }}>{getIntValue(notifyDetail.readed, 'length')}/{notifyDetail.allCount}</span>
  102. </div>
  103. </div>
  104. <div>
  105. {receiveItems}
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. )
  111. }
  112. obtainDetail = () => {
  113. let url = '', params = {}
  114. if (this.role === 'teacher') {
  115. url = API.NOTIFY_DETAIL_TEACHER
  116. let id = this.props.userInfo.user.userFunId
  117. if (this.searchParams && this.searchParams.teacherId) {
  118. id = this.searchParams.teacherId
  119. }
  120. params = {
  121. notifyId: this.notifyId,
  122. teacherId: id
  123. }
  124. } else if (this.role === 'parent') {
  125. url = API.NOTIFY_DETAIL_PARENT
  126. let id = this.props.userInfo.user.student.stuId
  127. if (this.searchParams && this.searchParams.stuId) {
  128. id = this.searchParams.stuId
  129. }
  130. params = {
  131. notifyId: this.notifyId,
  132. stuId: id
  133. }
  134. } else {
  135. return
  136. }
  137. Toast.loading('', 0)
  138. fetchPost(url, params).then(response => {
  139. Toast.hide()
  140. if (response && response.data) {
  141. let notifyBoBean = new NotifyBoBean()
  142. let item = response.data
  143. if (item) {
  144. notifyBoBean.noId = getIntValue(item, 'notifyId')
  145. notifyBoBean.noTitle = getStrValue(item, 'notifyTitle')
  146. notifyBoBean.enclosure = getArrayValue(item, 'notifyFiles').length > 0
  147. ? JSON.parse(getArrayValue(item, 'notifyFiles')) : []
  148. notifyBoBean.unRead = getArrayValue(item, 'unRead')
  149. notifyBoBean.readed = getArrayValue(item, 'read')
  150. notifyBoBean.allCount = getIntValue(notifyBoBean.unRead, 'length') + getIntValue(notifyBoBean.readed, 'length')
  151. notifyBoBean.noContent = getStrValue(item, 'notifyDetails')
  152. notifyBoBean.noIssue = getStrValue(item, 'teacherName')
  153. notifyBoBean.noTime = getStrValue(item, 'createDate')
  154. notifyBoBean.noStatu = ''
  155. }
  156. this.setState({
  157. notifyDetail: notifyBoBean
  158. })
  159. }
  160. }).catch(error => {
  161. Toast.hide()
  162. if (typeof error === 'string') {
  163. Toast.fail(error)
  164. } else {
  165. Toast.fail('请求异常')
  166. }
  167. })
  168. }
  169. handlePreview = () => {
  170. this.setState({
  171. previewVisible: true,
  172. });
  173. }
  174. handleCancel = () => this.setState({previewVisible: false})
  175. }
  176. let mapStateToProps = (state) => ({
  177. userInfo: {...state.redUserInfo},
  178. listState: {...state.redListState}
  179. })
  180. let mapDispatchToProps = (dispatch) => ({})
  181. export default connect(mapStateToProps, mapDispatchToProps)(NotifyBoardDetail)