Commit edb86fab authored by 王's avatar

bug fix 课程

parent 7eca7a63
......@@ -6,8 +6,8 @@
:visible.sync="dialogObj.show"
width="800px">
<div v-loading="loading">
<el-form ref="form" :model="form" label-width="120px">
<el-form-item label="课程标题">
<el-form ref="form" :model="form" label-width="120px" :rules="rules">
<el-form-item label="课程标题" prop="title">
<el-input v-model="form.title"></el-input>
</el-form-item>
<el-form-item label="课程封面">
......@@ -31,6 +31,7 @@
</el-form-item>
<el-form-item label="选择课程">
<el-cascader
clearable
:value="selectedLesson"
:options="showLessonList"
:show-all-levels="false"
......@@ -51,6 +52,7 @@
</el-form-item>
<el-form-item label="选择盒子">
<el-cascader
clearable
:value="selectedBox"
:options="showBoxList"
:show-all-levels="false"
......@@ -106,6 +108,11 @@
item_category_ids:[],
cover:0,
},
rules:{
title:[
{ required: true, message: '请输入课程标题', trigger: 'change' }
]
}
}
},
methods:{
......@@ -115,6 +122,7 @@
changLessonItem(){
if(this.form.type === 0){
this.showLessonList.forEach(a=>{
a.children = a.children || [];
a.children.forEach(b=>{
if(b.children){
delete b.children
......@@ -136,8 +144,13 @@
})
},
selectLesson(data){
console.log('selectLesson', data, this.showLessonList)
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]});
let index = this.selectedLessonList.findIndex(val => val === select);
if (index === -1){
......@@ -163,17 +176,42 @@
},
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.selectedLessonList.forEach(i=>{this.form.text_category_ids.push(i.id)});
this.form.text_category_ids = this.form.text_category_ids.toString();
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();
switch(this.dialogObj.type){
case 1:
// this.$refs['form'].validate((valid) => {
// if(valid){
this.$refs['form'].validate((valid) => {
if(valid){
if (!this.form.cover) {
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=>{
this.$message({
type: 'success',
......@@ -182,25 +220,27 @@
this.$emit("reflash");
this.dialogObj.show = false;
});
// }
// });
break;
case 0:
console.log(this.form);
// this.$refs['form'].validate((valid) => {
// if(valid){
addLessonApi(this.form).then(res=>{
this.$message({
type: 'success',
message: '新增成功!'
});
this.$emit("reflash");
this.dialogObj.show = false;
})
// }
// });
break
}
// }
// });
break;
case 0:
console.log(this.form);
// this.$refs['form'].validate((valid) => {
// if(valid){
addLessonApi(this.form).then(res=>{
this.$message({
type: 'success',
message: '新增成功!'
});
this.$emit("reflash");
this.dialogObj.show = false;
})
// }
// });
break
}
}
})
},
initDialog(){
getBoxTypeListApi().then(res=>{
......@@ -211,6 +251,7 @@
});
getCategoryApi().then(res=>{
this.lessonList = res;
console.log('res getCategoryApi', res)
this.showLessonList = JSON.parse(JSON.stringify(res))
});
switch(this.dialogObj.type){
......@@ -236,7 +277,7 @@
item_category_ids:[],
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.selectedLessonList = [];
this.selectedBoxList = [];
......
......@@ -151,8 +151,8 @@
type: 'success',
message: '删除成功!'
});
this.getUser()
});
this.getUser()
});
},
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