You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

413 lines
14 KiB

2 years ago
<template>
<div>
<xy-dialog ref="dialog" :width="70" :is-show.sync="isShow" :type="'form'" :title="type === 'add' ? '新增课程' : '编辑课程'"
:form="form" :rules='rules' @submit="submit">
<template v-slot:name>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;">*</span>课程名称:
</div>
<div class="xy-table-item-content">
2 years ago
<el-input v-model="form.name" placeholder="请输入课程名称" clearable style="width: 100%;"></el-input>
2 years ago
</div>
</div>
</template>
<template v-slot:type>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;">*</span>课程类别:
</div>
<div class="xy-table-item-content">
2 years ago
<el-select v-model="form.type" placeholder="请选择类别" clearable style="width: 100%;">
2 years ago
<el-option v-for="item in course_type" :key="item.id" :label="item.value" :value="item.id">
2 years ago
</el-option>
</el-select>
</div>
</div>
</template>
2 years ago
<template v-slot:image_id>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold;">
<span style="color: red;font-weight: bold;padding-right: 4px;">*</span>课程封面(750*400):
</div>
<div class="xy-table-item-content">
<el-upload :action="action" class='upload-demo' :limit="1" list-type="picture-card" :file-list="imgList"
ref="pictureUpload" :before-upload="beforeUpload" :auto-upload="true" :on-success="uploadSuccess"
:on-remove="uploadRemove">
<i class="el-icon-plus"></i>
</el-upload>
</div>
</div>
</template>
<template v-slot:content>
2 years ago
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;">*</span>课程简介:
</div>
<div class="xy-table-item-content">
2 years ago
<my-tinymce v-if="showTinymce" @input="saveContent" :value="form.content"></my-tinymce>
2 years ago
</div>
</div>
</template>
2 years ago
<template v-slot:dateRange>
2 years ago
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;">*</span>开课日期:
</div>
<div class="xy-table-item-content">
2 years ago
<el-date-picker @change="changeDateRange" style="width: 100%;" v-model="form.dateRange"
type="daterange" range-separator="至"
value-format="yyyy-MM-dd"
format="yyyy-MM-dd"
2 years ago
start-placeholder="开课日期" end-placeholder="结束日期">
</el-date-picker>
</div>
</div>
</template>
2 years ago
<template v-slot:total>
2 years ago
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
2 years ago
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>开课人数:
2 years ago
</div>
<div class="xy-table-item-content">
2 years ago
<el-input style="width: 100%;" v-model="form.total" placeholder="请输入开课人数" clearable></el-input>
2 years ago
</div>
</div>
</template>
2 years ago
<template v-slot:class>
2 years ago
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
2 years ago
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>所在班级(地点):
2 years ago
</div>
<div class="xy-table-item-content">
2 years ago
<el-input style="width: 100%;" v-model="form.class" placeholder="请输入所在班级(地点)" clearable></el-input>
2 years ago
</div>
</div>
</template>
2 years ago
<template v-slot:company_type>
2 years ago
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>面向学员的企业性质:
</div>
<div class="xy-table-item-content">
2 years ago
<el-select style="width: 100%;" v-model="form.company_type" placeholder="请选择" clearable>
<el-option v-for="item in course_type" :key="item.id" :label="item.value" :value="item.id">
2 years ago
</el-option>
</el-select>
</div>
</div>
</template>
2 years ago
<template v-slot:industry>
2 years ago
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>所属行业:
</div>
<div class="xy-table-item-content">
2 years ago
<el-select style="width: 100%;" v-model="form.industry" placeholder="请选择" clearable>
<el-option v-for="item in course_type" :key="item.id" :label="item.value" :value="item.id">
2 years ago
</el-option>
</el-select>
</div>
</div>
</template>
<template v-slot:status>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>状态:
</div>
<div class="xy-table-item-content">
2 years ago
<el-select style="width: 100%;" v-model="form.status" placeholder="请选择" clearable>
2 years ago
<el-option v-for="item in course_status" :key="item.id" :label="item.value" :value="item.id">
2 years ago
</el-option>
</el-select>
</div>
</div>
</template>
<template v-slot:settings>
<div class="xy-table-item">
2 years ago
<div class="xy-table-item-label" style="font-weight: bold;display:none">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>
2 years ago
</div>
<div class="xy-table-item-content" style="flex-grow: 1;">
2 years ago
课时设置:<el-button type="primary" icon="md-add" style="margin-bottom: 10px"
2 years ago
@click="courseSettings.push({ course_id:id,title: '',content:''})">新增</el-button>
<xy-table style="width: 100%" :height="260" :is-page="false" :list="courseSettings"
:table-item="settings_Table">
<template v-slot:title>
<el-table-column label="课时名称" width="180" header-align="center" align="center">
<template v-slot:default="scope">
<el-input v-model="scope.row.title"></el-input>
</template>
</el-table-column>
</template>
<template v-slot:content>
<el-table-column label="课时简介" width="600" header-align="center" align="center">
<template v-slot:default="scope">
<el-input v-model="scope.row.content"></el-input>
</template>
</el-table-column>
</template>
2 years ago
<template v-slot:btns>
2 years ago
<el-table-column label="操作" width="180" header-align="center" align="center">
<template v-slot:default="scope">
<div v-if="type==='editor'" style="display:inline-block">
<el-button type="primary" size="small" v-if="scope.row.id" @click="saveSetting(scope.$index)">修改</el-button>
<el-button type="primary" size="small" v-else @click="saveSetting(scope.$index)">保存</el-button>
</div>
<el-popconfirm style="margin:0 10px" @confirm="deleteList(scope.row.id,scope.$index)" title="确定删除吗?">
<el-button type="danger" size="small" slot="reference">删除</el-button>
</el-popconfirm>
2 years ago
</template>
</el-table-column>
</template>
2 years ago
</xy-table>
</div>
</div>
</template>
</xy-dialog>
</div>
</template>
<script>
2 years ago
import myMixins from "@/mixin/selectMixin.js";
import {
show,
save
2 years ago
} from "@/api/course/index.js"
import {
index as settingIndex,
destroy as settingDestroy,
save as settingSave,
settingImport
} from "@/api/course/courseSetting.js"
2 years ago
export default {
2 years ago
mixins: [myMixins],
2 years ago
data() {
return {
isShow: false,
2 years ago
type: 'add',
action: `${process.env.VUE_APP_UPLOAD_API}`,
id: '',
showTinymce: false,
imgList: [],
2 years ago
form: {
name: '',
2 years ago
type: '',
image_id: '',
2 years ago
content: '',
2 years ago
dateRange: '',
total: '',
class: '',
company_type: '',
industry: '',
status: 0,
2 years ago
settings: [],
2 years ago
},
courseSettings:[],
2 years ago
settings_Table: [{
2 years ago
label: "课时名称",
prop:'title',
2 years ago
width: 180,
}, {
label: "课时简介",
2 years ago
prop:'content'
2 years ago
}],
2 years ago
rules: {
2 years ago
name: [{
required: true,
message: '请输入标题'
}],
type: [{
required: true,
message: '请选择课程类别'
}],
content: [{
required: true,
message: '请输入课程简介'
}],
// image_id: [{
// required: true,
// message: '请上传课程封面'
// }],
dateRange:[{
required: true,
message: '请选择开课日期'
}],
2 years ago
}
}
},
created() {},
2 years ago
methods: {
saveContent(e) {
this.form.content = e
},
2 years ago
changeDateRange(e){
if(e){
this.form.start_date = e[0]
this.form.end_date = e[1]
console.log(e,this.form)
}else{
this.form.start_date = ''
this.form.end_date = ''
}
},
uploadFail(err) {
console.log(err)
},
beforeUpload(file) {
console.log(file)
const isImage = file.type.includes('image');
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isImage) {
this.$message.error('请上传正确的图片格式文件');
}
if (!isLt2M) {
this.$message.error('上传文件大小不能超过2MB');
}
return isImage && isLt2M;
},
uploadSuccess(response, file, fileList) {
console.log(response, file, fileList)
this.form.image_id = response.id
this.imgList = fileList
},
uploadRemove(file, fileList) {
this.imgList = fileList
this.form.image_id = ''
2 years ago
},
submit() {
if (this.id) {
this.form.id = this.id
}
if (this.type == 'add') {
this.form.id = ''
}
save({
...this.form
2 years ago
}).then(res => {
console.log('res',res)
if(this.type=='add'){
this.importSetting(res.id)
}else{
this.$message({
type: 'success',
message: '编辑课程成功'
})
this.isShow = false
this.$emit('refresh')
}
2 years ago
})
},
getDetail() {
show({
id: this.id,
2 years ago
// show_relation: ['image']
2 years ago
}).then(res => {
2 years ago
this.form = this.base.requestToForm(res, this.form)
if(res.image){
this.imgList.push(res.image)
}
this.form.dateRange = [res.start_date,res.end_date]
2 years ago
this.showTinymce = true
this.getSettingList()
2 years ago
})
2 years ago
},
// 课时相关
async getSettingList() {
const res = await settingIndex({
page: 1,
page_size: 999,
sort_name:'created_at',
sort_type:'ASC',
filter: [{
key: 'course_id',
op: 'eq',
value: this.id
}]
})
this.courseSettings = res.data
},
deleteList(id,index){
if(id){
settingDestroy({
id: id,
}).then(response => {
this.courseSettings.splice(index,1)
}).catch(error => {
console.log(error)
reject(error)
})
}else{
this.courseSettings.splice(index,1)
}
},
// 编辑的时候有course_id了,可以单条课时新增或修改
saveSetting(index){
console.log(this.courseSettings[index])
settingSave({
...this.courseSettings[index]
}).then(res => {
this.$message({
type: 'success',
message: this.courseSettings[index].id ? '修改成功' : '保存成功'
})
this.getSettingList()
})
},
// 新增课程时,先保存课程获取到id,再批量导入课时
importSetting(course_id){
if(this.courseSettings.length>0){
this.courseSettings.map(item=>{
item.course_id = course_id
})
settingImport({
data:this.courseSettings
}).then(res => {
this.$message({
type: 'success',
message: '新增课程成功'
})
this.isShow = false
this.$emit('refresh')
})
}
}
2 years ago
},
watch: {
isShow(newVal) {
if (newVal) {
if (this.type === 'editor') {
2 years ago
this.getDetail()
}else{
this.showTinymce = true
2 years ago
}
} else {
2 years ago
this.id = ''
this.showTinymce = false
2 years ago
this.imgList = []
this.courseSettings = []
2 years ago
this.$refs['dialog'].reset()
}
},
}
}
</script>
<style scoped lang="scss">
2 years ago
::v-deep .content,
::v-deep .settings {
2 years ago
flex-basis: 100%;
}
</style>