Commit edb86fab authored by 王's avatar

bug fix 课程

parent 7eca7a63
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
:visible.sync="dialogObj.show" :visible.sync="dialogObj.show"
width="800px"> width="800px">
<div v-loading="loading"> <div v-loading="loading">
<el-form ref="form" :model="form" label-width="120px"> <el-form ref="form" :model="form" label-width="120px" :rules="rules">
<el-form-item label="课程标题"> <el-form-item label="课程标题" prop="title">
<el-input v-model="form.title"></el-input> <el-input v-model="form.title"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="课程封面"> <el-form-item label="课程封面">
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
</el-form-item> </el-form-item>
<el-form-item label="选择课程"> <el-form-item label="选择课程">
<el-cascader <el-cascader
clearable
:value="selectedLesson" :value="selectedLesson"
:options="showLessonList" :options="showLessonList"
:show-all-levels="false" :show-all-levels="false"
...@@ -51,6 +52,7 @@ ...@@ -51,6 +52,7 @@
</el-form-item> </el-form-item>
<el-form-item label="选择盒子"> <el-form-item label="选择盒子">
<el-cascader <el-cascader
clearable
:value="selectedBox" :value="selectedBox"
:options="showBoxList" :options="showBoxList"
:show-all-levels="false" :show-all-levels="false"
...@@ -106,6 +108,11 @@ ...@@ -106,6 +108,11 @@
item_category_ids:[], item_category_ids:[],
cover:0, cover:0,
}, },
rules:{
title:[
{ required: true, message: '请输入课程标题', trigger: 'change' }
]
}
} }
}, },
methods:{ methods:{
...@@ -115,6 +122,7 @@ ...@@ -115,6 +122,7 @@
changLessonItem(){ changLessonItem(){
if(this.form.type === 0){ if(this.form.type === 0){
this.showLessonList.forEach(a=>{ this.showLessonList.forEach(a=>{
a.children = a.children || [];
a.children.forEach(b=>{ a.children.forEach(b=>{
if(b.children){ if(b.children){
delete b.children delete b.children
...@@ -136,8 +144,13 @@ ...@@ -136,8 +144,13 @@
}) })
}, },
selectLesson(data){ selectLesson(data){
console.log('selectLesson', data, this.showLessonList)
let select = this.showLessonList.find(i=>{return i.id === data[0]}); let select = this.showLessonList.find(i=>{return i.id === data[0]});
select = select.children.find(i=>{return i.id === data[1]}); if (select.children) {
select = select.children.find(i=>{return i.id === data[1]});
} else {
return
}
if(data.length === 3)select = select.children.find(i=>{return i.id === data[2]}); if(data.length === 3)select = select.children.find(i=>{return i.id === data[2]});
let index = this.selectedLessonList.findIndex(val => val === select); let index = this.selectedLessonList.findIndex(val => val === select);
if (index === -1){ if (index === -1){
...@@ -163,17 +176,42 @@ ...@@ -163,17 +176,42 @@
}, },
sub(){ sub(){
console.log('this.form.item_category_ids', this.form.item_category_ids)
console.log('this.form.text_category_ids', this.form.text_category_ids)
this.selectedBoxList.forEach(i=>{this.form.item_category_ids.push(i.id)}); this.selectedBoxList.forEach(i=>{this.form.item_category_ids.push(i.id)});
this.selectedLessonList.forEach(i=>{this.form.text_category_ids.push(i.id)}); this.selectedLessonList.forEach(i=>{this.form.text_category_ids.push(i.id)});
this.form.text_category_ids = this.form.text_category_ids.toString(); this.form.text_category_ids = this.form.text_category_ids.toString();
if(this.imageList[0]){ if(this.imageList[0]){
this.form.cover = this.imageList[0].name; this.form.cover = this.imageList[0].url;
} }
this.form.item_category_ids = this.form.item_category_ids.toString(); this.form.item_category_ids = this.form.item_category_ids.toString();
switch(this.dialogObj.type){ this.$refs['form'].validate((valid) => {
case 1: if(valid){
// this.$refs['form'].validate((valid) => { if (!this.form.cover) {
// if(valid){ this.$message({
type: 'error',
message: '请上传封面!'
});
return
}
if (!this.form.text_category_ids) {
this.$message({
type: 'error',
message: '请选择课程!'
});
return
}
if (!this.form.item_category_ids) {
this.$message({
type: 'error',
message: '请选择盒子!'
});
return
}
switch(this.dialogObj.type){
case 1:
// this.$refs['form'].validate((valid) => {
// if(valid){
editLessonApi(this.dialogObj.id,this.form).then(res=>{ editLessonApi(this.dialogObj.id,this.form).then(res=>{
this.$message({ this.$message({
type: 'success', type: 'success',
...@@ -182,25 +220,27 @@ ...@@ -182,25 +220,27 @@
this.$emit("reflash"); this.$emit("reflash");
this.dialogObj.show = false; this.dialogObj.show = false;
}); });
// } // }
// }); // });
break; break;
case 0: case 0:
console.log(this.form); console.log(this.form);
// this.$refs['form'].validate((valid) => { // this.$refs['form'].validate((valid) => {
// if(valid){ // if(valid){
addLessonApi(this.form).then(res=>{ addLessonApi(this.form).then(res=>{
this.$message({ this.$message({
type: 'success', type: 'success',
message: '新增成功!' message: '新增成功!'
}); });
this.$emit("reflash"); this.$emit("reflash");
this.dialogObj.show = false; this.dialogObj.show = false;
}) })
// } // }
// }); // });
break break
} }
}
})
}, },
initDialog(){ initDialog(){
getBoxTypeListApi().then(res=>{ getBoxTypeListApi().then(res=>{
...@@ -211,6 +251,7 @@ ...@@ -211,6 +251,7 @@
}); });
getCategoryApi().then(res=>{ getCategoryApi().then(res=>{
this.lessonList = res; this.lessonList = res;
console.log('res getCategoryApi', res)
this.showLessonList = JSON.parse(JSON.stringify(res)) this.showLessonList = JSON.parse(JSON.stringify(res))
}); });
switch(this.dialogObj.type){ switch(this.dialogObj.type){
...@@ -236,7 +277,7 @@ ...@@ -236,7 +277,7 @@
item_category_ids:[], item_category_ids:[],
cover:'', cover:'',
}; };
this.imageList = [{name:res.cover,url:process.env.IMAGE_URL_HEAD + res.cover}]; this.imageList = [{name:res.cover,url:res.cover}];
this.uploadShow = false; this.uploadShow = false;
this.selectedLessonList = []; this.selectedLessonList = [];
this.selectedBoxList = []; this.selectedBoxList = [];
......
...@@ -151,8 +151,8 @@ ...@@ -151,8 +151,8 @@
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!'
}); });
this.getUser()
}); });
this.getUser()
}); });
}, },
changeShow(data){ changeShow(data){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment