diff --git a/public/react/src/modules/courses/graduation/topics/GraduateTopicNew.js b/public/react/src/modules/courses/graduation/topics/GraduateTopicNew.js index 8eeae8095..02fc5018e 100644 --- a/public/react/src/modules/courses/graduation/topics/GraduateTopicNew.js +++ b/public/react/src/modules/courses/graduation/topics/GraduateTopicNew.js @@ -66,27 +66,33 @@ class GraduateTopicNew extends Component{ //编辑,信息显示 getEditInfo=()=>{ const cid = this.props.match.params.coursesId - let topicId=this.props.match.params.topicId - let url=`/courses/${cid}/graduation_topics/${topicId}/edit.json`; - axios.get((url)).then((result)=>{ - if(result){ - this.setState({ - left_banner_id:result.data.left_banner_id, - course_name:result.data.course_name, - left_banner_name:result.data.left_banner_name - }) - this.GraduateTopicNewFromRef.initValue(result); - - } - }).catch((error)=>{ - console.log(error); - }) + let topicId=this.props.match.params.topicId; + if(topicId){ + let url=`/courses/${cid}/graduation_topics/${topicId}/edit.json`; + axios.get((url)).then((result)=>{ + if(result){ + this.setState({ + left_banner_id:result.data.left_banner_id, + course_name:result.data.course_name, + left_banner_name:result.data.left_banner_name + }) + this.GraduateTopicNewFromRef.initValue(result); + + } + }).catch((error)=>{ + console.log(error); + }) + } } // 编辑保存 - editSave = (params,topicId) =>{ + editSave = (param,attachments,topicId) =>{ const cid = this.props.match.params.coursesId const editUrl = `/courses/${cid}/graduation_topics/${topicId}.json` + let params = { + graduation_topic:param, + attachment_ids:attachments + } axios.put(editUrl, params).then((response) => { if (response.status == 200) { const { id } = response.data; @@ -101,9 +107,13 @@ class GraduateTopicNew extends Component{ } // 新建提交 - newSubmit = (params,topicId) =>{ + newSubmit = (param,attachments,topicId) =>{ const cid = this.props.match.params.coursesId const url = `/courses/${cid}/graduation_topics.json` + let params = { + graduation_topic:param, + attachment_ids:attachments + } axios.post(url, params).then((response) => { if (response.data) { const { id } = response.data; @@ -116,6 +126,16 @@ class GraduateTopicNew extends Component{ console.log(error); }); } + // 取消编辑或者新建 + editCancel = () =>{ + const cid = this.props.match.params.coursesId; + let topicId=this.props.match.params.topicId; + if(topicId){ + this.props.history.push(`/courses/${cid}/graduation_topics/${topicId}/detail`); + }else{ + this.props.history.push(`/courses/${cid}/graduation_topics/${this.state.left_banner_id}`); + } + } render() { @@ -127,9 +147,9 @@ class GraduateTopicNew extends Component{ const { current_user } = this.props let{ topicId,coursesId }=this.props.match.params const common={ - handleSubmit:this.handleSubmit, editSave:this.editSave, - newSubmit:this.newSubmit + newSubmit:this.newSubmit, + editCancel:this.editCancel } return(
@@ -157,6 +177,7 @@ class GraduateTopicNew extends Component{ {...common} wrappedComponentRef={(ref) => this.GraduateTopicNewFromRef = ref} topicId={topicId} + teacherName={true} >
diff --git a/public/react/src/modules/courses/graduation/topics/GraduateTopicNewFrom.js b/public/react/src/modules/courses/graduation/topics/GraduateTopicNewFrom.js index 9802084fc..a015b96cf 100644 --- a/public/react/src/modules/courses/graduation/topics/GraduateTopicNewFrom.js +++ b/public/react/src/modules/courses/graduation/topics/GraduateTopicNewFrom.js @@ -136,7 +136,7 @@ class GraduateTopicNewForm extends Component{ handleSubmit = (e) => { e.preventDefault(); - const topicId = this.props.match.params.topicId + const topicId = this.props.topicId this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { if (topicId !=undefined) { @@ -149,14 +149,11 @@ class GraduateTopicNewForm extends Component{ }) } const param = { - graduation_topic:{ ...values, province: values.city==undefined?"":values.city[0], city: values.city==undefined?"":values.city[1], - }, - attachment_ids } - this.props.editSave(param,topicId); + this.props.editSave && this.props.editSave(param,attachment_ids,topicId); } else { // 新建 let attachment_ids = undefined @@ -165,15 +162,12 @@ class GraduateTopicNewForm extends Component{ return item.response.id }) } - const param = { - graduation_topic:{ + const param ={ ...values, province: values.city==undefined?"":values.city[0], city: values.city==undefined?"":values.city[1], - }, - attachment_ids, } - this.props.newSubmit(param,topicId); + this.props.newSubmit && this.props.newSubmit(param,attachment_ids,topicId); } } else { $("html").animate({ scrollTop: $('html').scrollTop() - 100 }) @@ -226,30 +220,33 @@ class GraduateTopicNewForm extends Component{ return isLt150M; }, }; - let { topicId }=this.props; + let { topicId , teacherName }=this.props; return(
- - {getFieldDecorator('tea_id', { - rules: [{ - required: true, message: '请选择指导老师' - }], - })( - - )} - + { + teacherName && + + {getFieldDecorator('tea_id', { + rules: [{ + required: true, message: '请选择指导老师' + }], + })( + + )} + + }