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.

331 lines
11 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"
@click="form.settings.push({ name: '',desc:''})">新增</el-button>
<xy-table style="width: 100%" :height="260" :is-page="false" :list="form.settings"
:table-item="settings_Table">
<template v-slot:btns>
<el-table-column label="操作" width="90" header-align="center" align="center">
<template v-slot:default="scope">
<el-button size="small" type="danger" plain
@click="form.settings.splice(scope.$index, 1)">删除</el-button>
</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
} from "@/api/course/index.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
},
settings_Table: [{
label: "课时名称",
width: 180,
customFn: (row) => {
return ( <el-input placeholder = "请输入课时名称"
type = "text"
v-model = {
row.name
}>
</el-input>
);
},
}, {
label: "课时简介",
customFn: (row) => {
return ( <el-input placeholder = "请输入课时简介"
type = "text"
v-model = {
row.desc
}>
</el-input>
);
},
}],
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
}).then(res => {
2 years ago
this.$message({
2 years ago
type: 'success',
message: this.type === 'add' ? '新增课程成功' : '编辑课程成功'
})
this.isShow = false
this.$emit('refresh')
})
},
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]
this.showTinymce = true
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
this.imgList = []
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>