题库-毕设选题编辑页面

dev_aliyun_beta
caicai8 6 years ago
parent 6fa97b3d93
commit 268a36f9aa

@ -66,7 +66,8 @@ class GraduateTopicNew extends Component{
//编辑,信息显示 //编辑,信息显示
getEditInfo=()=>{ getEditInfo=()=>{
const cid = this.props.match.params.coursesId const cid = this.props.match.params.coursesId
let topicId=this.props.match.params.topicId let topicId=this.props.match.params.topicId;
if(topicId){
let url=`/courses/${cid}/graduation_topics/${topicId}/edit.json`; let url=`/courses/${cid}/graduation_topics/${topicId}/edit.json`;
axios.get((url)).then((result)=>{ axios.get((url)).then((result)=>{
if(result){ if(result){
@ -82,11 +83,16 @@ class GraduateTopicNew extends Component{
console.log(error); console.log(error);
}) })
} }
}
// 编辑保存 // 编辑保存
editSave = (params,topicId) =>{ editSave = (param,attachments,topicId) =>{
const cid = this.props.match.params.coursesId const cid = this.props.match.params.coursesId
const editUrl = `/courses/${cid}/graduation_topics/${topicId}.json` const editUrl = `/courses/${cid}/graduation_topics/${topicId}.json`
let params = {
graduation_topic:param,
attachment_ids:attachments
}
axios.put(editUrl, params).then((response) => { axios.put(editUrl, params).then((response) => {
if (response.status == 200) { if (response.status == 200) {
const { id } = response.data; 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 cid = this.props.match.params.coursesId
const url = `/courses/${cid}/graduation_topics.json` const url = `/courses/${cid}/graduation_topics.json`
let params = {
graduation_topic:param,
attachment_ids:attachments
}
axios.post(url, params).then((response) => { axios.post(url, params).then((response) => {
if (response.data) { if (response.data) {
const { id } = response.data; const { id } = response.data;
@ -116,6 +126,16 @@ class GraduateTopicNew extends Component{
console.log(error); 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() { render() {
@ -127,9 +147,9 @@ class GraduateTopicNew extends Component{
const { current_user } = this.props const { current_user } = this.props
let{ topicId,coursesId }=this.props.match.params let{ topicId,coursesId }=this.props.match.params
const common={ const common={
handleSubmit:this.handleSubmit,
editSave:this.editSave, editSave:this.editSave,
newSubmit:this.newSubmit newSubmit:this.newSubmit,
editCancel:this.editCancel
} }
return( return(
<div className="newMain "> <div className="newMain ">
@ -157,6 +177,7 @@ class GraduateTopicNew extends Component{
{...common} {...common}
wrappedComponentRef={(ref) => this.GraduateTopicNewFromRef = ref} wrappedComponentRef={(ref) => this.GraduateTopicNewFromRef = ref}
topicId={topicId} topicId={topicId}
teacherName={true}
></GraduateTopicNewFrom> ></GraduateTopicNewFrom>
</div> </div>

@ -136,7 +136,7 @@ class GraduateTopicNewForm extends Component{
handleSubmit = (e) => { handleSubmit = (e) => {
e.preventDefault(); e.preventDefault();
const topicId = this.props.match.params.topicId const topicId = this.props.topicId
this.props.form.validateFieldsAndScroll((err, values) => { this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) { if (!err) {
if (topicId !=undefined) { if (topicId !=undefined) {
@ -149,14 +149,11 @@ class GraduateTopicNewForm extends Component{
}) })
} }
const param = { const param = {
graduation_topic:{
...values, ...values,
province: values.city==undefined?"":values.city[0], province: values.city==undefined?"":values.city[0],
city: values.city==undefined?"":values.city[1], 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 { } else {
// 新建 // 新建
let attachment_ids = undefined let attachment_ids = undefined
@ -166,14 +163,11 @@ class GraduateTopicNewForm extends Component{
}) })
} }
const param ={ const param ={
graduation_topic:{
...values, ...values,
province: values.city==undefined?"":values.city[0], province: values.city==undefined?"":values.city[0],
city: values.city==undefined?"":values.city[1], 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 { } else {
$("html").animate({ scrollTop: $('html').scrollTop() - 100 }) $("html").animate({ scrollTop: $('html').scrollTop() - 100 })
@ -226,11 +220,13 @@ class GraduateTopicNewForm extends Component{
return isLt150M; return isLt150M;
}, },
}; };
let { topicId }=this.props; let { topicId , teacherName }=this.props;
return( return(
<React.Fragment> <React.Fragment>
<Form {...formItemLayout} onSubmit={this.handleSubmit}> <Form {...formItemLayout} onSubmit={this.handleSubmit}>
<div className="createPage"> <div className="createPage">
{
teacherName &&
<Form.Item <Form.Item
label="指导老师" label="指导老师"
> >
@ -250,6 +246,7 @@ class GraduateTopicNewForm extends Component{
</Select> </Select>
)} )}
</Form.Item> </Form.Item>
}
<style> <style>
{ {
` `
@ -506,7 +503,7 @@ class GraduateTopicNewForm extends Component{
<Form.Item> <Form.Item>
<div className="clearfix mt30 mb30"> <div className="clearfix mt30 mb30">
<Button type="primary" htmlType="submit" className="defalutSubmitbtn fl mr20">{topicId==undefined?"提交":"保存"}</Button> <Button type="primary" htmlType="submit" className="defalutSubmitbtn fl mr20">{topicId==undefined?"提交":"保存"}</Button>
<a className="defalutCancelbtn fl" onClick={()=>this.props.history.goBack()}>取消</ a> <a className="defalutCancelbtn fl" onClick={this.props.editCancel}>取消</ a>
</div> </div>
</Form.Item> </Form.Item>
</Form> </Form>

@ -12,6 +12,7 @@ import "../usersInfo.css"
import "../../../courses/css/members.css" import "../../../courses/css/members.css"
import "../../../courses/css/Courses.css" import "../../../courses/css/Courses.css"
import Loadable from 'react-loadable'; import Loadable from 'react-loadable';
import Loading from '../../../../Loading'; import Loading from '../../../../Loading';
@ -50,6 +51,7 @@ class BanksIndex extends Component{
initPublic:this.initPublic initPublic:this.initPublic
} }
return( return(
<div className="newMain">
<div className="educontent"> <div className="educontent">
{ {
crumbData && crumbData &&
@ -91,6 +93,7 @@ class BanksIndex extends Component{
</Switch> </Switch>
</div> </div>
</div>
) )
} }
} }

@ -6,25 +6,30 @@ import GraduateTopicNewFrom from '../../../courses/graduation/topics/GraduateTop
class GtopicBanksEdit extends Component{ class GtopicBanksEdit extends Component{
constructor(props){ constructor(props){
super(props); super(props);
this.state = {
isPublic:undefined
}
} }
componentDidMount = () =>{ componentDidMount = () =>{
let bankId = this.props.match.params.bankId let bankId = this.props.match.params.bankId;
this.initData(bankId);
}
initData = (bankId) =>{
let url = `/gtopic_banks/${bankId}/edit.json`;
axios.get(url).then((result)=>{
if(result){
const crumbData={ const crumbData={
title:'编辑', title:'编辑',
is_public:true, is_public:result && result.selected_data && result.selected_data.is_public,
crumbArray:[ crumbArray:[
{to:`/banks/gtopic/${bankId}/edit`,content:'详情'}, {to:`/banks/gtopic/${bankId}/edit`,content:'详情'},
{content:'编辑'} {content:'编辑'}
] ]
} }
this.props.initPublic(crumbData); this.props.initPublic(crumbData);
this.initData(bankId);
}
initData = (bankId) =>{
let url = `/gtopic_banks/${bankId}/edit.json`;
axios.get(url).then((result)=>{
if(result){
this.GraduateTopicNewFromRef.initValue(result); this.GraduateTopicNewFromRef.initValue(result);
} }
}).catch((error)=>{ }).catch((error)=>{
@ -32,13 +37,43 @@ class GtopicBanksEdit extends Component{
}) })
} }
// 编辑保存
editSave = (param,attachments,bankId) =>{
const url = `/gtopic_banks/${bankId}.json`;
let params = {
gtopic_bank:param,
attachment_ids:attachments
}
axios.put(url,params).then((result)=>{
if(result){
this.props.showNotification('保存成功!');
this.props.history.push(`/banks/gtopic/${bankId}`);
}
}).catch((error)=>{
console.log(error);
})
}
// 取消
editCancel = () =>{
this.props.history.push(`/banks/gtopic/${this.props.match.params.bankId}`);
}
render(){ render(){
let { bankId } = this.props.match.params let { bankId } = this.props.match.params
const common = { const common = {
editSave:this.editSave,
editCancel:this.editCancel
} }
return( return(
<div className="courseForm"> <div className="courseForm">
<style>
{`
.courseForm .ant-col-sm-24{
text-align:left;
}
`}
</style>
<GraduateTopicNewFrom <GraduateTopicNewFrom
{...this.props} {...this.props}
{...this.state} {...this.state}

Loading…
Cancel
Save