Merge remote-tracking branch 'origin/topic_bank' into topic_bank

dev_aliyun_beta
杨树明 6 years ago
commit 2f594f1577

@ -66,27 +66,33 @@ 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;
let url=`/courses/${cid}/graduation_topics/${topicId}/edit.json`; if(topicId){
axios.get((url)).then((result)=>{ let url=`/courses/${cid}/graduation_topics/${topicId}/edit.json`;
if(result){ axios.get((url)).then((result)=>{
this.setState({ if(result){
left_banner_id:result.data.left_banner_id, this.setState({
course_name:result.data.course_name, left_banner_id:result.data.left_banner_id,
left_banner_name:result.data.left_banner_name course_name:result.data.course_name,
}) left_banner_name:result.data.left_banner_name
this.GraduateTopicNewFromRef.initValue(result); })
this.GraduateTopicNewFromRef.initValue(result);
} }
}).catch((error)=>{ }).catch((error)=>{
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
@ -165,15 +162,12 @@ class GraduateTopicNewForm extends Component{
return item.response.id return item.response.id
}) })
} }
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,30 +220,33 @@ 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">
<Form.Item {
label="指导老师" teacherName &&
> <Form.Item
{getFieldDecorator('tea_id', { label="指导老师"
rules: [{ >
required: true, message: '请选择指导老师' {getFieldDecorator('tea_id', {
}], rules: [{
})( required: true, message: '请选择指导老师'
<Select style={{"width":"20%"}} placeholder="请选择指导老师"> }],
{ })(
teacherList && teacherList.map((item,key)=>{ <Select style={{"width":"20%"}} placeholder="请选择指导老师">
return( {
<Option value={item.id} id={key}>{item.name}</Option> teacherList && teacherList.map((item,key)=>{
) return(
}) <Option value={item.id} id={key}>{item.name}</Option>
} )
</Select> })
)} }
</Form.Item> </Select>
)}
</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,46 +51,48 @@ class BanksIndex extends Component{
initPublic:this.initPublic initPublic:this.initPublic
} }
return( return(
<div className="educontent"> <div className="newMain">
{ <div className="educontent">
crumbData &&
<Breadcrumb separator=">" className="breadcrumb">
<Breadcrumb.Item href="/users/innov/banks">题库</Breadcrumb.Item>
{
crumbData.crumbArray && crumbData.crumbArray.map((item,key)=>{
return(
<Breadcrumb.Item href={item.to || ""}>{item.content}</Breadcrumb.Item>
)
})
}
</Breadcrumb>
}
<p className="clearfix mt20 mb20">
<span className="fl font-24 color-grey-3 task-hide lineh-30" style={{maxWidth:'800px'}}>{crumbData && crumbData.title}</span>
{ {
crumbData && crumbData.is_public && <span className="bank_is_public">{crumbData.is_public == true ? '公开':'私有'}</span> crumbData &&
<Breadcrumb separator=">" className="breadcrumb">
<Breadcrumb.Item href="/users/innov/banks">题库</Breadcrumb.Item>
{
crumbData.crumbArray && crumbData.crumbArray.map((item,key)=>{
return(
<Breadcrumb.Item href={item.to || ""}>{item.content}</Breadcrumb.Item>
)
})
}
</Breadcrumb>
} }
</p>
<Switch {...this.props}> <p className="clearfix mt20 mb20">
<span className="fl font-24 color-grey-3 task-hide lineh-30" style={{maxWidth:'800px'}}>{crumbData && crumbData.title}</span>
{
crumbData && crumbData.is_public && <span className="bank_is_public">{crumbData.is_public == true ? '公开':'私有'}</span>
}
</p>
<Route path='/banks/gtopic/:bankId/edit' <Switch {...this.props}>
render={
(props) => {
return (<GtopicBanksEdit {...this.props} {...props} {...this.state} {...common}/>)
}
}></Route>
<Route path='/banks/gtopic/:bankId' <Route path='/banks/gtopic/:bankId/edit'
render={ render={
(props) => { (props) => {
return (<BanksTabIndex {...this.props} {...props} {...this.state} {...common}/>) return (<GtopicBanksEdit {...this.props} {...props} {...this.state} {...common}/>)
} }
}></Route> }></Route>
<Route path='/banks/gtopic/:bankId'
render={
(props) => {
return (<BanksTabIndex {...this.props} {...props} {...this.state} {...common}/>)
}
}></Route>
</Switch> </Switch>
</div>
</div> </div>
) )
} }

@ -6,18 +6,13 @@ 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;
const crumbData={
title:'编辑',
is_public:true,
crumbArray:[
{to:`/banks/gtopic/${bankId}/edit`,content:'详情'},
{content:'编辑'}
]
}
this.props.initPublic(crumbData);
this.initData(bankId); this.initData(bankId);
} }
@ -25,6 +20,16 @@ class GtopicBanksEdit extends Component{
let url = `/gtopic_banks/${bankId}/edit.json`; let url = `/gtopic_banks/${bankId}/edit.json`;
axios.get(url).then((result)=>{ axios.get(url).then((result)=>{
if(result){ if(result){
const crumbData={
title:'编辑',
is_public:result && result.selected_data && result.selected_data.is_public,
crumbArray:[
{to:`/banks/gtopic/${bankId}/edit`,content:'详情'},
{content:'编辑'}
]
}
this.props.initPublic(crumbData);
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