AnnounceRelease.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /**
  2. * Created by RaoMeng on 2018/11/14
  3. * Desc: 发布通知公告
  4. */
  5. import React, {Component} from 'react'
  6. import {Input, Button} from 'antd'
  7. import 'css/announce.css'
  8. import {Toast} from 'antd-mobile'
  9. import TargetSelect from 'components/TargetSelect'
  10. import UploadEnclosure from 'components/UploadEnclosure'
  11. import {fetchGet, fetchPost,fetchPostObj} from "../../utils/fetchRequest";
  12. import {_baseURL, API} from "../../configs/api.config";
  13. import {getIntValue, getStrValue, isObjEmpty} from "../../utils/common";
  14. import {connect} from 'react-redux'
  15. import {clearListState} from 'action/listState'
  16. const {TextArea} = Input
  17. class AnnounceRelease extends Component {
  18. constructor() {
  19. super()
  20. this.state = {
  21. announceTitle: '',
  22. announceContent: '',
  23. previewVisible: false,
  24. previewImage: '',
  25. fileList: [],
  26. targetList: [],
  27. targetCount: 0,
  28. targetData: [],
  29. }
  30. }
  31. componentDidMount() {
  32. document.title = '发布通知公告'
  33. // this.getOrganization()
  34. }
  35. componentWillUnmount() {
  36. Toast.hide()
  37. clearTimeout(this.backTask)
  38. }
  39. render() {
  40. const {announceTitle, announceContent, targetCount, targetList, fileList, targetData} = this.state
  41. /*const targetProps = {
  42. targetData: targetData,
  43. targetValues: targetList,
  44. title: '通知对象',
  45. targetCount: targetCount,
  46. onTargetChange: this.onTargetChange.bind(this),
  47. onTargetFocus: this.onTargetFocus.bind(this)
  48. }
  49. const defaultTargetProps = {
  50. targetData: [],
  51. targetValues: targetList,
  52. title: '通知对象',
  53. targetCount: targetCount,
  54. onTargetChange: this.onTargetChange.bind(this),
  55. onTargetFocus: this.onTargetFocus.bind(this)
  56. }*/
  57. return (
  58. <div className='common-column-layout'>
  59. {/*<div className='gray-line'></div>
  60. {targetData.length > 0 ? <TargetSelect {...targetProps}/>
  61. : <TargetSelect {...defaultTargetProps}/>}*/}
  62. <div className='gray-line'></div>
  63. <input className='titleInput' placeholder='请输入通知标题'
  64. value={announceTitle} onChange={this.titleChange}/>
  65. <div className='gray-line' style={{height: '1px'}}></div>
  66. <TextArea className='contentInput' placeholder='请输入通知内容'
  67. autosize={{minRows: 6, maxRows: 12}} value={announceContent}
  68. onChange={this.contentChange}/>
  69. <div className='gray-line'></div>
  70. <UploadEnclosure
  71. action={API.UPLOAD_FILE}
  72. fileList={fileList}
  73. count={9}
  74. multiple={true}
  75. beforeUpload={this.beforeUpload.bind(this)}
  76. handleChange={this.handleChange.bind(this)}
  77. />
  78. <Button className='commonButton' type='primary' style={{margin: '35px',borderRadius:30}}
  79. onClick={this.releaseAnnounce}>发布</Button>
  80. {/*<span className='announce-release-history'>历史发布</span>*/}
  81. </div>
  82. )
  83. }
  84. getOrganization = () => {
  85. Toast.loading('', 0)
  86. fetchGet(API.getClazzByTeacherId, {
  87. teacherId: this.props.userInfo.user.userFunId,
  88. }).then(response => {
  89. Toast.hide()
  90. const {targetData} = this.state
  91. targetData.length = 0
  92. if (response && response.data) {
  93. response.data.forEach((dataObj, data_index) => {
  94. const stusDOSArray = dataObj.studentDOS
  95. const teacherDOSArray = dataObj.teacherDOS
  96. if (!isObjEmpty(stusDOSArray)) {
  97. const classData = []
  98. stusDOSArray.forEach((stuObj, index) => {
  99. if (stuObj) {
  100. classData.push({
  101. title: getStrValue(stuObj, 'stuName'),
  102. userId: getIntValue(stuObj, 'stuId'),
  103. userPhone: getStrValue(stuObj, 'userPhone'),
  104. value: `2-${data_index}-${index}-` + getStrValue(stuObj, 'stuName'),
  105. key: `2-${data_index}-${index}`,
  106. })
  107. }
  108. })
  109. targetData.push({
  110. title: dataObj.gradeName + dataObj.clazzName + '全体学生',
  111. value: `2-${data_index}-` + dataObj.gradeName + dataObj.clazzName + '全体学生',
  112. key: `2-${data_index}`,
  113. children: classData,
  114. })
  115. }
  116. if (!isObjEmpty(teacherDOSArray)) {
  117. const teacherData = []
  118. teacherDOSArray.forEach((teacherObj, index) => {
  119. if (teacherObj) {
  120. teacherData.push({
  121. title: getStrValue(teacherObj, 'teacherName'),
  122. userId: getIntValue(teacherObj, 'teacherId'),
  123. userPhone: getStrValue(teacherObj, 'userPhone'),
  124. value: `0-${data_index}-${index}-` + getStrValue(teacherObj, 'teacherName'),
  125. key: `0-${data_index}-${index}`,
  126. })
  127. }
  128. })
  129. targetData.push({
  130. title: dataObj.gradeName + dataObj.clazzName + '全体老师',
  131. value: `0-${data_index}-` + dataObj.gradeName + dataObj.clazzName + '全体老师',
  132. key: `0-${data_index}`,
  133. children: teacherData,
  134. })
  135. }
  136. })
  137. }
  138. this.setState({
  139. targetData,
  140. })
  141. }).catch(error => {
  142. Toast.hide()
  143. if (typeof error === 'string') {
  144. Toast.fail(error, 2)
  145. } else {
  146. Toast.fail('请求异常', 2)
  147. }
  148. })
  149. }
  150. releaseAnnounce = () => {
  151. if (this.isRequesting == true) {
  152. return
  153. }
  154. const {announceTitle, announceContent, fileList} = this.state
  155. if (isObjEmpty(announceTitle)) {
  156. Toast.fail('请输入通知标题')
  157. return
  158. }
  159. if (isObjEmpty(announceContent)) {
  160. Toast.fail('请输入通知内容')
  161. return
  162. }
  163. // if (isObjEmpty(this.checkNodes)) {
  164. // Toast.fail('请选择通知对象')
  165. // return
  166. // }
  167. if (announceTitle.length > 50) {
  168. Toast.fail('通知标题过长')
  169. return
  170. }
  171. const fileUrls = []
  172. if (fileList) {
  173. fileList.forEach((value, index) => {
  174. if (value.status === 'uploading') {
  175. Toast.fail('有附件正在上传,请稍候')
  176. return
  177. }
  178. if (value.status === 'done') {
  179. fileUrls.push(value.picUrl)
  180. }
  181. })
  182. }
  183. // const stuList = [], teacherList = []
  184. // if (!isObjEmpty(this.checkNodes)) {
  185. // this.checkNodes.forEach((node, index) => {
  186. // if (node.value.startWith('0')) {
  187. // teacherList.push(node.userId)
  188. // } else if (node.value.startWith('2')) {
  189. // stuList.push(node.userId)
  190. // }
  191. // })
  192. // }
  193. const paramObj = {
  194. /* notifyTitle: announceTitle,
  195. notifyType: 3,
  196. notifyDetails: announceContent,
  197. notifyCreator: this.props.userInfo.user.userFunId,
  198. notifyStatus: 1,
  199. notifyFiles: JSON.stringify(fileUrls),
  200. notifyRemarks: '',*/
  201. // notifyTeacher: JSON.stringify(teacherList),
  202. // notifyStu: JSON.stringify(stuList),
  203. notify_title:announceTitle,
  204. notify_details:announceContent,
  205. notify_status:1,
  206. notify_creator:this.props.userInfo.user.userFunId,
  207. creator:this.props.userInfo.user.userName,
  208. notify_files:JSON.stringify(fileUrls)
  209. }
  210. console.log(paramObj)
  211. this.isRequesting = true
  212. Toast.loading('正在发布...', 0)
  213. fetchPostObj(API.NOTIFY_CREATE,
  214. JSON.stringify(paramObj),
  215. {"Content-Type": 'application/json;charset=UTF-8'}).then(response => {
  216. Toast.hide()
  217. Toast.success('发布成功', 1)
  218. clearListState()()
  219. this.setState({
  220. announceTitle: '',
  221. announceContent: '',
  222. fileList: []
  223. })
  224. this.backTask = setTimeout(() => {
  225. this.props.history.goBack()
  226. }, 1000)
  227. }).catch(error => {
  228. this.isRequesting = false
  229. Toast.hide()
  230. if (typeof error === 'string') {
  231. Toast.fail(error, 2)
  232. } else {
  233. Toast.fail('请求异常', 2)
  234. }
  235. })
  236. }
  237. onTargetFocus = (e) => {
  238. if (isObjEmpty(this.state.targetData)) {
  239. this.getOrganization()
  240. }
  241. }
  242. onTargetChange = (value, label, checkNodes, count) => {
  243. this.checkNodes = checkNodes
  244. this.setState({
  245. targetList: value,
  246. targetCount: count
  247. });
  248. }
  249. titleChange = e => {
  250. this.setState({
  251. announceTitle: e.target.value
  252. })
  253. }
  254. contentChange = e => {
  255. this.setState({
  256. announceContent: e.target.value
  257. })
  258. }
  259. beforeUpload = (file, fileList) => {
  260. }
  261. handleChange = fileList => {
  262. if (fileList) {
  263. this.setState({fileList})
  264. }
  265. }
  266. }
  267. let mapStateToProps = (state) => ({
  268. userInfo: {...state.redUserInfo}
  269. })
  270. let mapDispatchToProps = (dispatch) => ({})
  271. export default connect(mapStateToProps, mapDispatchToProps)(AnnounceRelease)