ReleaseAssignmentPage.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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 './ReleaseAssignmentPage.css'
  8. import '../../style/css/app-gloal.css'
  9. import moment from 'moment'
  10. import {Input, Button, Icon, message} from 'antd';
  11. import TargetSelect from "../../components/TargetSelect";
  12. import {fetchPost, fetchGet} from '../../utils/fetchRequest';
  13. import {_baseURL, API} from '../../configs/api.config';
  14. import {isObjEmpty, getIntValue, getStrValue} from '../../utils/common';
  15. import UploadEnclosure from 'components/UploadEnclosure'
  16. import {Toast, DatePicker, List} from 'antd-mobile'
  17. import {connect} from 'react-redux'
  18. const {TextArea} = Input;
  19. /**
  20. * 发布作业
  21. * Created by Arison on 17:47.
  22. */
  23. class ReleaseAssignmentPage extends React.Component {
  24. constructor(props) {
  25. super(props);
  26. this.state = {
  27. name: 'ReleaseAssignmentPage',
  28. targetList: [],
  29. targetCount: 0,
  30. targetData: [],
  31. checkNodes: [],
  32. startDate: null,//当前时间
  33. endDate: null,//截止时间
  34. data: {
  35. notifyName: '',//标题
  36. notifyType: '3',//作业发布
  37. notifyDetails: '',//内容
  38. notifyCreator: '',//创建者
  39. notifyStatus: '2',//状态 2发布 1草稿
  40. userIds: [],//通知
  41. notifyFiles: [],
  42. startDate: '',//当前时间
  43. endDate: null//截止时间
  44. }
  45. }
  46. }
  47. componentWillMount() {
  48. document.title = "发布作业";
  49. }
  50. componentWillUnmount() {
  51. Toast.hide()
  52. clearTimeout(this.backTask)
  53. }
  54. handleChange = (file, fileList) => {
  55. if (fileList) {
  56. fileList.forEach((value, index) => {
  57. value.url = value.response ? (_baseURL + value.response.data) : value.url
  58. value.picUrl = value.response ? value.response.data : value.picUrl
  59. })
  60. this.setState({
  61. data: {
  62. notifyFiles: fileList
  63. }
  64. })
  65. }
  66. /* this.state.data.notifyFiles.length = 0;
  67. for (let i = 0; i < fileList.length; i++) {
  68. if (fileList[i].status === "done") {
  69. this.state.data.notifyFiles.push(fileList[i].response.data)
  70. }
  71. }*/
  72. }
  73. handleRemove = (file) => {
  74. }
  75. componentDidMount() {
  76. this.getOrganization();
  77. }
  78. changeName = (value) => {
  79. this.setState({
  80. data: {
  81. notifyName: value.target.value,//标题
  82. notifyType: '3',//作业发布
  83. notifyDetails: this.state.data.notifyDetails,//内容
  84. notifyCreator: '',//创建者
  85. notifyStatus: '2',//状态 2发布 1草稿
  86. userIds: ['10001', '10000', '10002', '10003'],//通知
  87. notifyFiles: [],
  88. startDate: '',//当前时间
  89. endDate: this.state.data.endDate//截止时间
  90. }
  91. })
  92. }
  93. changeContent = (value) => {
  94. this.setState({
  95. data: {
  96. notifyDetails: value.target.value,//标题
  97. notifyName: this.state.data.notifyName,//标题
  98. notifyType: '3',//作业发布
  99. notifyCreator: '10000',//创建者
  100. notifyStatus: '2',//状态 2发布 1草稿
  101. userIds: ['10001', '10000', '10002', '10003'],//通知
  102. notifyFiles: [],
  103. startDate: '',//当前时间
  104. endDate: this.state.data.endDate//截止时间
  105. }
  106. })
  107. }
  108. changeEndDateOk = (value) => {
  109. if (isObjEmpty(value)) {
  110. message.info("请选择日期");
  111. return
  112. }
  113. }
  114. changeEndDate = (value, dateString) => {
  115. this.setState({
  116. data: {
  117. notifyDetails: this.state.data.notifyDetails,//标题
  118. notifyName: this.state.data.notifyName,//标题
  119. notifyType: '3',//作业发布
  120. notifyCreator: '10000',//创建者
  121. notifyStatus: '2',//状态 2发布 1草稿
  122. userIds: JSON.stringify([10001, 10000, 10002, 10003]),//通知
  123. notifyFiles: [],
  124. startDate: '',//当前时间
  125. endDate: dateString,//标题
  126. }
  127. })
  128. }
  129. onTargetChange = (value, label, checkNodes, count) => {
  130. this.setState({
  131. targetList: value,
  132. targetCount: count,
  133. checkNodes: checkNodes
  134. });
  135. }
  136. commitAction = () => {
  137. if (isObjEmpty(this.state.data.notifyName)) {
  138. Toast.fail("请输入作业名称");
  139. return;
  140. }
  141. if (isObjEmpty(this.state.data.notifyDetails)) {
  142. Toast.fail('请输入作业内容...')
  143. return;
  144. }
  145. if (isObjEmpty(this.state.endDate)) {
  146. Toast.fail("请输入截止时间");
  147. return;
  148. }
  149. if (isObjEmpty(this.state.targetList)) {
  150. Toast.fail("请选择抄送对象");
  151. return;
  152. }
  153. let personArrays = [];
  154. if (!isObjEmpty(this.state.checkNodes)) {
  155. this.state.checkNodes.forEach((node) => {
  156. personArrays.push(node.userId)
  157. })
  158. }
  159. Toast.loading('正在发布...', 0)
  160. fetchPost(API.homeWorkAdd, {
  161. notifyName: this.state.data.notifyName,//标题
  162. notifyType: '3',//作业发布
  163. notifyDetails: this.state.data.notifyDetails,//内容
  164. notifyCreator: this.props.userInfo.userId,//创建者
  165. notifyStatus: '2',//状态
  166. endDate: moment(this.state.endDate).format('YYYY-MM-DD HH:mm:ss'),
  167. userIds: JSON.stringify(personArrays),//通知
  168. notifyFiles: JSON.stringify(this.state.data.notifyFiles)
  169. }).then((response) => {
  170. Toast.hide();
  171. if (response.success) {
  172. Toast.success("发布成功!", 1)
  173. this.initPageData()
  174. this.backTask = setTimeout(() => {
  175. this.props.history.goBack()
  176. }, 1000)
  177. }
  178. }).catch((error) => {
  179. Toast.hide()
  180. if (typeof error === 'string') {
  181. Toast.fail(error, 2)
  182. } else {
  183. Toast.fail('请求异常', 2)
  184. }
  185. })
  186. }
  187. goListAction = () => {
  188. // this.props.history.push("/assignmentList/teacher");
  189. this.props.history.goBack();
  190. }
  191. onTargetFocus = (e) => {
  192. if (isObjEmpty(this.state.targetData)) {
  193. this.getOrganization()
  194. }
  195. }
  196. render() {
  197. const {targetCount, targetList, targetData, data} = this.state
  198. console.log("render()", targetData);
  199. const targetProps = {
  200. placeholder: '请选择抄送对象',
  201. targetData: targetData,
  202. targetValues: targetList,
  203. title: '抄送对象',
  204. targetCount: targetCount,
  205. onTargetChange: this.onTargetChange.bind(this),
  206. onTargetFocus: this.onTargetFocus.bind(this)
  207. }
  208. const defaultTargetProps = {
  209. targetData: [],
  210. targetValues: this.state.targetList,
  211. title: '抄送对象',
  212. targetCount: this.state.targetCount,
  213. onTargetChange: this.onTargetChange.bind(this),
  214. onTargetFocus: this.onTargetFocus.bind(this)
  215. }
  216. return <div className='common-column-layout' style={{paddingBottom: '40px'}}>
  217. <div className='gray-line'></div>
  218. {this.state.targetData.length > 0 ? <TargetSelect {...targetProps}/>
  219. : <TargetSelect {...defaultTargetProps}/>}
  220. <div className='gray-line'></div>
  221. <DatePicker
  222. value={this.state.endDate}
  223. locale={{
  224. okText: '确定',
  225. dismissText: '取消'
  226. }}
  227. onChange={date => this.setState({endDate: date})}>
  228. <List.Item arrow="horizontal">截止时间</List.Item>
  229. </DatePicker>
  230. <div className='gray-line'></div>
  231. <input placeholder="请输入作业名称" defaultValue={this.state.data.notifyName}
  232. onChange={this.changeName}
  233. className='titleInput'/>
  234. <div className='gray-line' style={{height: '1px'}}></div>
  235. <TextArea autosize={{minRows: 6, maxRows: 12}}
  236. value={this.state.data.notifyDetails}
  237. onChange={this.changeContent}
  238. className='contentInput'
  239. placeholder="请输入作业内容"/>
  240. <div className='gray-line'></div>
  241. <UploadEnclosure
  242. action={API.UPLOAD_FILE}
  243. fileList={data.notifyFiles}
  244. count={9}
  245. multiple={true}
  246. beforeUpload={this.beforeUpload.bind(this)}
  247. handleChange={this.handleChange.bind(this)}
  248. />
  249. <Button type="primary" onClick={this.commitAction}
  250. style={{margin: '35px 35px 16px'}}
  251. className='commonButton'>发布作业</Button>
  252. <span className='announce-release-history' onClick={this.goListAction}>历史发布</span>
  253. </div>
  254. }
  255. beforeUpload = (file, fileList) => {
  256. }
  257. initPageData = () => {
  258. this.setState({
  259. data: {
  260. notifyName: '',//标题
  261. notifyType: '3',//作业发布
  262. notifyDetails: '',//内容
  263. notifyCreator: '',//创建者
  264. notifyStatus: '2',//状态 2发布 1草稿
  265. userIds: [],//通知
  266. notifyFiles: [],
  267. startDate: '',//当前时间
  268. endDate: null//截止时间
  269. }
  270. })
  271. }
  272. getOrganization = () => {
  273. Toast.loading('', 0)
  274. fetchGet(API.getClazzByTeacherId, {
  275. teacherId: this.props.userInfo.user.userFunId,
  276. }).then(response => {
  277. Toast.hide()
  278. const {targetData} = this.state
  279. targetData.length = 0
  280. if (response && response.data) {
  281. response.data.forEach((dataObj, data_index) => {
  282. const stusDOSArray = dataObj.studentDOS
  283. if (!isObjEmpty(stusDOSArray)) {
  284. const classData = []
  285. stusDOSArray.forEach((stuObj, index) => {
  286. if (stuObj) {
  287. classData.push({
  288. title: getStrValue(stuObj, 'stuName'),
  289. userId: getIntValue(stuObj, 'stuId'),
  290. userPhone: getStrValue(stuObj, 'userPhone'),
  291. value: `2-${data_index}-${index}-` + getStrValue(stuObj, 'stuName'),
  292. key: `2-${data_index}-${index}`,
  293. })
  294. }
  295. })
  296. targetData.push({
  297. title: dataObj.gradeName + dataObj.clazzName + '全体学生',
  298. value: `2-${data_index}` + dataObj.gradeName + dataObj.clazzName + '全体学生',
  299. key: `2-${data_index}`,
  300. children: classData,
  301. })
  302. }
  303. })
  304. }
  305. this.setState({
  306. targetData,
  307. })
  308. }).catch(error => {
  309. Toast.hide()
  310. if (typeof error === 'string') {
  311. Toast.fail(error, 2)
  312. } else {
  313. Toast.fail('请求异常', 2)
  314. }
  315. })
  316. }
  317. }
  318. let mapStateToProps = (state) => ({
  319. userInfo: {...state.redUserInfo},
  320. })
  321. let mapDispatchToProps = (dispatch) => ({})
  322. export default connect(mapStateToProps, mapDispatchToProps)(ReleaseAssignmentPage)