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

dev_aliyun_beta
杨树明 5 years ago
commit 2f594f1577

@ -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(
<div className="newMain ">
@ -157,6 +177,7 @@ class GraduateTopicNew extends Component{
{...common}
wrappedComponentRef={(ref) => this.GraduateTopicNewFromRef = ref}
topicId={topicId}
teacherName={true}
></GraduateTopicNewFrom>
</div>

@ -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(
<React.Fragment>
<Form {...formItemLayout} onSubmit={this.handleSubmit}>
<div className="createPage">
<Form.Item
label="指导老师"
>
{getFieldDecorator('tea_id', {
rules: [{
required: true, message: '请选择指导老师'
}],
})(
<Select style={{"width":"20%"}} placeholder="请选择指导老师">
{
teacherList && teacherList.map((item,key)=>{
return(
<Option value={item.id} id={key}>{item.name}</Option>
)
})
}
</Select>
)}
</Form.Item>
{
teacherName &&
<Form.Item
label="指导老师"
>
{getFieldDecorator('tea_id', {
rules: [{
required: true, message: '请选择指导老师'
}],
})(
<Select style={{"width":"20%"}} placeholder="请选择指导老师">
{
teacherList && teacherList.map((item,key)=>{
return(
<Option value={item.id} id={key}>{item.name}</Option>
)
})
}
</Select>
)}
</Form.Item>
}
<style>
{
`
@ -506,7 +503,7 @@ class GraduateTopicNewForm extends Component{
<Form.Item>
<div className="clearfix mt30 mb30">
<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>
</Form.Item>
</Form>

@ -12,6 +12,7 @@ import "../usersInfo.css"
import "../../../courses/css/members.css"
import "../../../courses/css/Courses.css"
import Loadable from 'react-loadable';
import Loading from '../../../../Loading';
@ -50,46 +51,48 @@ class BanksIndex extends Component{
initPublic:this.initPublic
}
return(
<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>
<div className="newMain">
<div className="educontent">
{
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}>
<Route path='/banks/gtopic/:bankId/edit'
render={
(props) => {
return (<GtopicBanksEdit {...this.props} {...props} {...this.state} {...common}/>)
}
}></Route>
<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'
render={
(props) => {
return (<BanksTabIndex {...this.props} {...props} {...this.state} {...common}/>)
}
}></Route>
</Switch>
<Switch {...this.props}>
<Route path='/banks/gtopic/:bankId/edit'
render={
(props) => {
return (<GtopicBanksEdit {...this.props} {...props} {...this.state} {...common}/>)
}
}></Route>
<Route path='/banks/gtopic/:bankId'
render={
(props) => {
return (<BanksTabIndex {...this.props} {...props} {...this.state} {...common}/>)
}
}></Route>
</Switch>
</div>
</div>
)
}

@ -6,18 +6,13 @@ import GraduateTopicNewFrom from '../../../courses/graduation/topics/GraduateTop
class GtopicBanksEdit extends Component{
constructor(props){
super(props);
this.state = {
isPublic:undefined
}
}
componentDidMount = () =>{
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);
let bankId = this.props.match.params.bankId;
this.initData(bankId);
}
@ -25,6 +20,16 @@ class GtopicBanksEdit extends Component{
let url = `/gtopic_banks/${bankId}/edit.json`;
axios.get(url).then((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);
}
}).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(){
let { bankId } = this.props.match.params
const common = {
editSave:this.editSave,
editCancel:this.editCancel
}
return(
<div className="courseForm">
<style>
{`
.courseForm .ant-col-sm-24{
text-align:left;
}
`}
</style>
<GraduateTopicNewFrom
{...this.props}
{...this.state}

Loading…
Cancel
Save