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.

521 lines
18 KiB

2 years ago
<template>
<div>
<xy-dialog ref="dialog" :width="70" :is-show.sync="isShow" :type="'form'" :title="type === 'add' ? '新增课程' : '编辑课程'"
2 years ago
:form="form" :rules='rules' :hasIscheck="true" @mysubmit="mysubmit">
<template v-slot:step>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold;display:none">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>
</div>
<div class="xy-table-item-content">
<el-steps :active="active" finish-status="success" simple>
<el-step title="课程信息"></el-step>
<el-step title="报名信息"></el-step>
</el-steps>
</div>
</div>
</template>
<template v-slot:name v-if="active===0">
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-input v-model="form.name" placeholder="请输入课程名称" clearable style="width: 100%;"></el-input>
2 years ago
</div>
</div>
</template>
<template v-slot:type v-if="active===0">
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">
<el-select v-model="form.type" @change="changeType" placeholder="请选择类别" clearable style="width: 100%;">
2 years ago
<el-option v-for="item in courseTypesList" :key="item.id" :label="item.name" :value="item.id">
2 years ago
</el-option>
</el-select>
</div>
</div>
</template>
<template v-slot:dateRange v-if="active===0">
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">
<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" start-placeholder="开课日期"
end-placeholder="结束日期">
</el-date-picker>
2 years ago
</div>
</div>
</template>
2 years ago
<template v-slot:total v-if="active===0">
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>
</div>
</div>
</template>
<template v-slot:sign_start_date v-if="active===0">
<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">
<el-date-picker style="width: 100%;" v-model="form.sign_start_date" type="date" value-format="yyyy-MM-dd"
format="yyyy-MM-dd" placeholder="报名开始日期">
2 years ago
</el-date-picker>
</div>
</div>
</template>
2 years ago
<template v-slot:sign_end_date v-if="active===0">
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-date-picker style="width: 100%;" v-model="form.sign_end_date" type="date" value-format="yyyy-MM-dd"
format="yyyy-MM-dd" placeholder="报名截止日期">
</el-date-picker>
2 years ago
</div>
</div>
</template>
2 years ago
<template v-slot:status v-if="active===0">
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>状态:
2 years ago
</div>
<div class="xy-table-item-content">
<el-select style="width: 100%;" v-model="form.status" placeholder="请选择" clearable>
<el-option v-for="item in course_status" :key="item.id" :label="item.value" :value="item.id">
</el-option>
</el-select>
2 years ago
</div>
</div>
</template>
<template v-slot:is_arrange v-if="active===0">
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>是否排课:
2 years ago
</div>
<div class="xy-table-item-content">
<el-radio-group style="width:100%" v-model="form.is_arrange">
<el-radio :label="1">是</el-radio>
<el-radio :label="0">否</el-radio>
</el-radio-group>
2 years ago
</div>
</div>
</template>
<template v-slot:is_fee v-if="active===0">
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>是否缴费:
2 years ago
</div>
<div class="xy-table-item-content">
<el-radio-group style="width:100%" v-model="form.is_fee">
<el-radio :label="1">是</el-radio>
<el-radio :label="0">否</el-radio>
</el-radio-group>
2 years ago
</div>
</div>
</template>
<template v-slot:image_id v-if="active===0">
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>课程封面(680*380):
2 years ago
</div>
<div class="xy-table-item-content">
<el-upload :action="action" class='upload-demo' :on-exceed="onExceed" :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>
2 years ago
</div>
</div>
</template>
<template v-slot:publicize_ids v-if="active===0">
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>课程宣传页(宽750):
2 years ago
</div>
<div class="xy-table-item-content">
<el-upload :action="action" multiple class='upload-demo' list-type="picture-card" :file-list="publicizeList"
ref="pictureUpload" :auto-upload="true" :on-success="uploadSuccesspublic" :on-remove="uploadRemovepublic">
<i class="el-icon-plus"></i>
</el-upload>
2 years ago
</div>
</div>
</template>
<template v-slot:content v-if="active===0">
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">
<my-tinymce v-if="showTinymce" @input="saveContent" :value="form.content"></my-tinymce>
2 years ago
</div>
</div>
</template>
<!-- 自定义报名 表单 -->
<template v-slot:applylabel v-if="active===1">
2 years ago
<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="min-height: 300px;">
<div>
<el-dialog id="template-dialog" :title="'模板表单'"
style="position: relative; inset: 0 0 0 0; height: 100%;padding:20px 0" width="90%" top="0px"
:visible="true" :modal="false" :append-to-body="false" :show-close="false"
:modal-append-to-body="false">
<template v-slot:title>
<Button v-if="formList.length>0" ghost type="primary" @click="editForm('editor')">编辑表单</Button>
<Button v-else ghost type="primary" @click="editForm('add')">新增表单</Button>
</template>
2 years ago
<el-form style="min-height: 300px;display: flex;flex-wrap: wrap;" label-width="80px"
label-position="right" size="small">
<el-divider>基础字段</el-divider>
<el-form-item :label="i.name" :required="
i.rule ? !!i.rule.includes('required') : false
" v-for="(i, index) in defaultFormList">
<el-input placeholder="基础字段" :disabled="true"></el-input>
2 years ago
</el-form-item>
<el-divider>选填字段</el-divider>
<el-form-item :label="i.name" v-for="(i, index) in selectFormList">
<el-input placeholder="选填字段" :disabled="true"></el-input>
2 years ago
</el-form-item>
<el-divider>自定义字段</el-divider>
<el-form-item style="flex-basis: 100%;" :label="i.name || '字段名称'" :required="
i.rule ? !!i.rule.includes('required') : false
2 years ago
" v-for="(i, index) in formList">
<formSlotRender :config="i" :index="index"></formSlotRender>
</el-form-item>
</el-form>
</el-dialog>
</div>
2 years ago
</div>
</div>
</template>
<template v-slot:footerContent>
<Button ghost type="primary" v-if="active===1" @click="active=0">上一步</Button>
2 years ago
<!-- <Button ghost type="primary" v-if="active===0" @click="next">下一步</Button> -->
<Button type="primary" ghost @click="checkSubmit" v-if="active===0">保存并下一步</Button>
<Button type="primary" @click="closeSubmit">关闭</Button>
</template>
2 years ago
</xy-dialog>
<applyForm ref="applyForm" @refresh="getFormList"></applyForm>
2 years ago
</div>
</template>
<script>
2 years ago
import myMixins from "@/mixin/selectMixin.js";
2 years ago
import formMixins from "@/mixin/formMixin.js";
2 years ago
import {
show,
save
} from "@/api/course/index.js"
2 years ago
import {
index as formIndex
} from "@/api/course/form";
import {
deepCopy
} from "@/utils";
import applyForm from "../components/applyForm.vue";
import formSlotRender from "@/views/system/components/formSlotRender.vue";
2 years ago
export default {
2 years ago
mixins: [myMixins, formMixins],
components: {
applyForm,
formSlotRender
},
2 years ago
data() {
return {
isShow: false,
2 years ago
type: 'add',
active: 0,
id: '',
2 years ago
action: `${process.env.VUE_APP_UPLOAD_API}`,
showTinymce: false,
2 years ago
courseTypesList: [],
2 years ago
imgList: [],
publicizeList: [],
2 years ago
form: {
step: '', // 控制课程 课表
2 years ago
name: '',
type: '',
2 years ago
dateRange: '',
total: '',
2 years ago
sign_start_date: '',
sign_end_date: '',
2 years ago
status: 0,
2 years ago
is_arrange: 1,
is_fee: 1,
image_id: '',
publicize_ids: [],
content: '',
applylabel: ''
},
2 years ago
rules: {
2 years ago
name: [{
required: true,
message: '请输入标题'
}],
type: [{
required: true,
message: '请选择课程类别'
}],
2 years ago
sign_start_date: [{
required: true,
message: '请选择报名开始日期'
}],
2 years ago
// image_id: [{
// required: true,
// message: '请上传课程封面'
// }],
2 years ago
// content: [{
// required: true,
// message: '请输入课程简介'
// }],
},
// 自定义表单
selectForm: {
page: 1,
page_size: 999,
sort_name: 'sort',
sort_type: 'ASC'
},
formList: []
2 years ago
}
},
created() {},
methods: {
2 years ago
changeType(e) {
if (e == 1) {
this.form.is_arrange = 1
this.form.is_fee = 1
} else {
this.form.is_arrange = 0
this.form.is_fee = 0
}
2 years ago
},
saveContent(e) {
this.form.content = e
},
changeDateRange(e) {
if (e) {
this.form.start_date = e[0]
this.form.end_date = e[1]
} else {
this.form.start_date = ''
this.form.end_date = ''
}
2 years ago
},
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;
},
onExceed(file, fileList) {
this.$Message.warning("课程封面只需上传一张")
},
2 years ago
uploadSuccess(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
},
uploadSuccesspublic(response, file, fileList) {
this.publicizeList = fileList
},
uploadRemovepublic(file, fileList) {
this.publicizeList = fileList
},
// 验证form提交规则
mysubmit(e) {
if (e) {
this.submit()
}
},
checkSubmit() {
this.$refs.dialog.submit(true)
2 years ago
},
compareTime(date, sign) {
let date1 = this.$moment(date)
let sign1 = this.$moment(sign)
return sign1.isBefore(date1)
},
2 years ago
submit() {
if (this.id) {
this.form.id = this.id
2 years ago
}
// 报名截止时间 不能晚于 日程开始时间
if (this.form.start_date && this.form.sign_end_date) {
if (!this.compareTime(this.form.start_date, this.form.sign_end_date)) {
this.$Message.warning("报名截止时间不能晚于课程开始时间")
return
}
}
2 years ago
// return
let pubFiles = []
if (this.publicizeList.length > 0) {
this.publicizeList.map(item => {
2 years ago
if (item.response) {
pubFiles.push(item.response.id)
} else {
pubFiles.push(item.id)
}
})
2 years ago
}
2 years ago
this.form.publicize_ids = pubFiles
2 years ago
this.form.publicize = []
2 years ago
save({
...this.form
}).then(res => {
this.$message({
type: 'success',
message: '保存课程成功'
})
this.id = res.id
2 years ago
this.$emit('refresh')
2 years ago
this.active = 1
// this.active = 1
2 years ago
2 years ago
})
},
closeSubmit() {
this.isShow = false
this.$emit('refresh')
},
2 years ago
getDetail() {
show({
2 years ago
id: this.id,
show_relation: ['image']
2 years ago
}).then(res => {
this.form = this.base.requestToForm(res, this.form)
if (res.image) {
this.imgList.push(res.image)
2 years ago
}
2 years ago
this.publicizeList = res.publicize
this.form.dateRange = [res.start_date, res.end_date]
2 years ago
this.form.status = res.status ? res.status : 0
this.form.is_arrange = res.is_arrange ? res.is_arrange : 0
2 years ago
this.form.is_fee = res.is_fee ? res.is_fee : 0
this.showTinymce = true
2 years ago
})
2 years ago
},
// 下一步
next() {
if (this.id) {
this.active = 1
} else {
this.$Message.warning("请先保存课程信息")
}
},
// 获取自定义表单列表
async getFormList() {
const res = await formIndex({
filter: [{
key: 'course_id',
op: 'eq',
value: this.id
}],
...this.selectForm
})
this.formList = res.data
2 years ago
},
// 打开自定义表单
editForm(type, id) {
2 years ago
// this.$refs.applyForm.formList = deepCopy(this.formList)
this.$refs.applyForm.course_id = this.id
this.$refs.applyForm.dialogVisible = true
}
2 years ago
2 years ago
},
watch: {
isShow(newVal) {
if (newVal) {
if (this.type === 'editor') {
2 years ago
this.getDetail()
this.getFormList()
} else {
this.showTinymce = true
2 years ago
}
} else {
this.id = ''
this.showTinymce = false
this.imgList = []
this.publicizeList = []
this.active = 0
2 years ago
this.formList = []
this.form = {
step: '', // 控制课程 课表
name: '',
type: '',
dateRange: '',
total: '',
sign_start_date: '',
sign_end_date: '',
status: 0,
is_arrange: 1,
is_fee: 1,
image_id: '',
publicize_ids: [],
content: '',
applylabel: ''
2 years ago
}
2 years ago
this.$refs['dialog'].reset()
2 years ago
}
},
}
}
</script>
<style scoped lang="scss">
2 years ago
::v-deep .content,
::v-deep .step,
::v-deep .applylabel,
::v-deep .image_id,
::v-deep .publicize_ids {
2 years ago
flex-basis: 100%;
}
::v-deep .status,
::v-deep .is_arrange,
::v-deep .is_fee,
{
flex-basis: 33%;
}
::v-deep .el-step.is-simple .el-step__head {
display: flex
}
2 years ago
</style>