<style lang="scss" scoped>
@import "../table.scss";
</style>
<template>
    <div>
        <el-card>
            <!--两个div层之间都用margin，则会自动隔开-->

            <el-tabs type="border-card" v-model="queryParams.type" @tab-change="clickTabsitem">
                <el-tab-pane label="班级" :name="0">
                    <div class="seachbox">
                        <el-button type="success" @click="addbox1" class="seachboxadd">
                            <el-icon class="el-icon-left">
                                <Plus :size="30" />
                            </el-icon>
                            <div> 新增班级 </div>
                        </el-button>
                    </div>
                    <div class="seachbox">

                        <el-input class="ml-5 seachbox_input" v-model.trim="queryParams.clname" placeholder="请输入班级名称"
                            clearable size="small" />
                        <el-button type="primary" @click="getclassinfoDatainfo(pageobj.pageNum)" class="seachboxadd">
                            搜索
                        </el-button>

                    </div>
                    <el-table :data="tableData" border stripe :header-cell-style="{ 'text-align': 'center' }"
                        :scrollbar-always-on="true">
                        <!-- <el-table-column type="selection" width="55" align="center" /> -->
                        <el-table-column prop="Name" label="班级名称" align="center">
                        </el-table-column>
                        <el-table-column prop="HeadTeacherNum" label="教师" align="center">
                        </el-table-column>
                        <el-table-column prop="TrainingStartTime" align="center" label="培训开始时间">
                        </el-table-column>
                        <el-table-column prop="TrainingEndTime" align="center" label="培训结束时间">
                        </el-table-column>
                        <!-- <el-table-column prop="Grade" align="center" label="类型">
                        </el-table-column>
                        <el-table-column prop="Grade" align="center" label="单位">
                        </el-table-column> -->
                        <el-table-column prop="ClassRemark" align="center" label="备注">
                        </el-table-column>
                        <el-table-column label="操作" align="center" width="150" fixed="right">
                            <template #default="scope">
                                <el-row class="rowcenter">
                                    <Edit-Button permission="ClassesColumns:Edit" content="编辑"
                                        @clicknative="editclassitem(scope.row)"></Edit-Button>
                                    <Delete-Button permission="ClassesColumns:Delete" @confirm="delclassitem(scope.row)"
                                        content="删除"></Delete-Button>
                                </el-row>
                            </template>
                        </el-table-column>

                    </el-table>
                    <div class="paginationbox">
                        <!--内边距空一些-->
                        <!-- 搞定 -->
                        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                            :current-page="pageobj.pageNum" :page-sizes="pageobj.pageSizeOptions"
                            :page-size="pageobj.pageSize" layout="total, sizes, prev, pager, next"
                            :total="pageobj.Total">
                        </el-pagination>
                    </div>
                </el-tab-pane>
                <!-- <el-tab-pane label="课程" :name="1">
                    <div class="seachbox">
                        <el-button type="success" @click="addbox2" class="seachboxadd">
                            <el-icon class="el-icon-left">
                                <Plus :size="30" />
                            </el-icon>
                            <div> 新增课程 </div>
                        </el-button>
                    </div>
                    <div class="seachbox" style="display: flex;">
                        <el-input class="ml-5 seachbox_input" v-model.trim="queryParams.coursename"
                            placeholder="请输入课程级名称" clearable size="small" />
                        <el-button class="ml-5" type="primary" style="margin-left: 10px;"
                            @click="getCourseinfoDatainfo(pageobj.pageNum)">搜索</el-button>
                    </div>
                    <el-table :data="tableData" border stripe :header-cell-style="{ 'text-align': 'center' }">
                        <el-table-column prop="Name" align="center" label="课程名称">
                        </el-table-column>
                        <el-table-column prop="Code" align="center" label="课程编号">
                        </el-table-column>
                        <el-table-column prop="Type" align="center" label="课程类型">
                        </el-table-column>
                        <el-table-column prop="Grade" align="center" label="学分">
                        </el-table-column>
                        <el-table-column prop="MajorName" align="center" label="专业名称">
                        </el-table-column>
                        <el-table-column prop="Description" align="center" label="课程简介">
                        </el-table-column>
                        <el-table-column label="操作" align="center" width="150" fixed="right">
                            <template #default="scope">
                                <el-row class="rowcenter">
                                    <Edit-Button permission="CourseColumns:Edit" content="编辑"
                                        @clicknative="editCourseitem(scope.row)"></Edit-Button>
                                    <Delete-Button permission="CourseColumns:Delete" @confirm="delCourseitem(scope.row)"
                                        content="删除"></Delete-Button>
                                </el-row>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="paginationbox">
                        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                            :current-page="pageobj.pageNum" :page-sizes="pageobj.pageSizeOptions"
                            :page-size="pageobj.pageSize" layout="total, sizes, prev, pager, next"
                            :total="pageobj.Total">
                        </el-pagination>
                    </div>
                </el-tab-pane> -->
            </el-tabs>
        </el-card>

        <el-drawer v-model="drawerform1" :title="drawerformtitle1" :append-to-body="false">
            <!-- 新增修改班级左侧框 -->
            <div class="demo-drawer__content">
                <el-form label-position="right" ref="ruleForm" :rules="rules" label-width="120px" :model="formItem">
                    <!-- <el-form-item label="学院名称" prop="collegeId">
                        <el-select v-model="formItem.collegeId" filterable placeholder="请选择学院" @change="classmajorList"
                            :disabled="formItem.collegeId ? true : false">
                            <el-option v-for="item in collegeList" :key="item.value" :label="item.name"
                                :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="专业名称" prop="collegeId">
                        <el-select v-model="formItem.selectId" filterable placeholder="请选择专业"
                            :disabled="formItem.selectId ? true : false">
                            <el-option v-for="item in majorList" :key="item.value" :label="item.name"
                                :value="item.value"></el-option>
                        </el-select>
                    </el-form-item> -->
                    <el-form-item label="班级名称" prop="Name">
                        <el-input v-model.trim="formItem.Name" placeholder="请输入班级名称" autocomplete="off"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="年级" prop="ClassinfoGrade">
                        <el-input v-model.trim="formItem.ClassinfoGrade" placeholder="请输入年级"
                            autocomplete="off"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="培训形式" prop="ClassinfoGrade">
                        <el-input v-model.trim="formItem.ClassinfoGrade" placeholder="新增-线下班、融合班"
                            autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="学期类型" prop="ClassinfoGrade">
                        <el-input v-model.trim="formItem.ClassinfoGrade" placeholder="新增-春季、秋季"
                            autocomplete="off"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="单位" prop="Counselor">
                        <el-input v-model.trim="formItem.Counselor" placeholder="新增-单位"
                            autocomplete="off"></el-input>
                    </el-form-item> -->
                    <el-form-item label="培训开始时间" prop="TrainingStartTime">
                        <el-date-picker
                            v-model="formItem.TrainingStartTime"
                            type="date"
                            placeholder="请选择培训开始时间"
                            value-format="YYYY-MM-DD"
                        />
                    </el-form-item>
                    <el-form-item label="培训结束时间" prop="TrainingEndTime">
                        <el-date-picker
                            v-model="formItem.TrainingEndTime"
                            type="date"
                            placeholder="请选择培训结束时间"
                            value-format="YYYY-MM-DD"
                        />
                    </el-form-item>
                    <el-form-item label="教师" prop="TeacherName">
                        <el-input v-model="formItem.TeacherName" readonly placeholder="请选择教师" @click="modelteacher"
                            autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="备注" prop="ClassRemark">
                        <el-input v-model.trim="formItem.ClassRemark" placeholder=""
                            autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div class="demo-drawer__footer" v-if="!isedit1">
                    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                </div>
                <div class="demo-drawer__footer" v-if="isedit1">
                    <el-button type="primary" @click="editsubmitForm('ruleForm')">提交</el-button>
                    <el-button @click="editresetForm('ruleForm')">重置</el-button>
                </div>

            </div>
        </el-drawer>


        <el-drawer v-model="drawerform2" :title="drawerformtitle2" :append-to-body="false">
            <!-- 新增修改课程左侧框 -->
            <div class="demo-drawer__content">
                <el-form label-position="right" ref="ruleForm2" :rules="rules2" label-width="100px" :model="formItem1">
                    <el-form-item label="学院名称" prop="collegeId">
                        <el-select v-model="formItem1.collegeId" filterable placeholder="请选择学院" @change="classmajorList"
                            :disabled="formItem1.collegeId ? true : false">
                            <el-option v-for="item in collegeList" :key="item.value" :label="item.name"
                                :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="专业名称" prop="collegeId">
                        <el-select v-model="formItem1.selectId" filterable placeholder="请选择专业"
                            :disabled="formItem1.selectId ? true : false">
                            <el-option v-for="item in majorList" :key="item.value" :label="item.name"
                                :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="课程名称" prop="Name">
                        <el-input v-model.trim="formItem1.Name" placeholder="请输入课程名称" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="课程类型" prop="Type">
                        <el-input v-model.trim="formItem1.Type" placeholder="请输入课程类型" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="课程编号" prop="LessonsNum">
                        <el-input-number v-model="formItem1.LessonsNum" :min="0" :max="100000"
                            label="请输入课程编号"></el-input-number>
                    </el-form-item>
                    <el-form-item label="学分" prop="Grade">
                        <el-input-number v-model="formItem1.Grade" :min="0" :max="100000"
                            label="请输入学分"></el-input-number>
                    </el-form-item>
                    <el-form-item label="课程简介" prop="Description">

                        <div ref="editor" id="websiteEditorElem" style="height:300px;background-color: #fff;"></div>
                    </el-form-item>
                </el-form>
                <div class="demo-drawer__footer" v-if="!isedit2">
                    <el-button type="primary" @click="submitForm2('ruleForm2')">提交</el-button>
                    <el-button @click="resetForm2('ruleForm2')">重置</el-button>
                </div>
                <div class="demo-drawer__footer" v-if="isedit2">
                    <el-button type="primary" @click="editsubmitForm2('ruleForm2')">提交</el-button>
                    <el-button @click="editresetForm2('ruleForm2')">重置</el-button>
                </div>

            </div>
        </el-drawer>

        <el-dialog title="选择教师" v-model="teachershow" center draggable destroy-on-close>
            <teacher-select @funval="numberval" :showteacherselect="showteacherselect"
                :activwshow="activwshow"></teacher-select>
        </el-dialog>
    </div>
</template>

<script>
// 引入组件
import E from 'wangeditor';
import { getDefaultTime } from "@/utils/common.js"
import teacherSelect from "@/components/teacherselect.vue";
import { getclassinfoData, getCourseinfoData, delClassinfo, delCourseinfo, getStudentlevel, postClassInfoAddinfo, postClassInfoeditinfo, getClassInfodetail, postCourseInfoAddinfo, postCourseInfoeditinfo, getCourseInfodetail } from "@/api/collegeinformation.js";
export default {
    name: "classandcourse",
    components: {
        teacherSelect
        // "year-range": YearRangePicker,
    },
    directives: {

    },
    data() {
        return {
            activwshow: 0,
            teachershow: false,
            showteacherselect: false,
            phoneEditor: null,
            mtname: "",
            mtid: "",
            collegeId: '',
            collegeNam: '',

            queryParams: {
                clname: '',
                coursename: '',
                type: 0,
            },
            formItem: {
                MajorId:1,
                TrainingStartTime:'',
                TrainingEndTime:'',
                collegeId: "",
                selectId: "",
                ClassinfoGrade: "",
                Counselor: "",
                ClassRemark: "",
                Name: "",
                ClassInfoId: '',
                Type: '',
            },

            formItem1: {
                collegeId: "",
                selectId: "",
                LessonsNum: 0,
                Name: "",
                Type: "",
                Grade: 0,
                Description: "",
                CourseId: ''
            },
            collegeList: [],
            majorList: [],
            tableData: [],
            isedit1: false,
            drawerform1: false,
            drawerformtitle: "",
            drawerformtitle1: '',
            isedit2: false,
            drawerform2: false,
            drawerformtitle2: '',
            pageobj: {
                oldTotal: 0,
                oldCurrent: 1,
                Total: 0,
                pageSize: 10,
                pageNum: 1,
                pageSizeOptions: [10, 20, 50, 100, 150, 200],
                majorName:'培训班'
            },
            rules: {
                Name: [
                    { required: true, message: '请输入班级名称', trigger: 'blur' },
                    //{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                TeacherName: [
                    { required: true, message: '请选择教师', trigger: 'blur' },
                ],
                TrainingStartTime: [
                    { required: true, message: '请选择培训开始时间', trigger: 'blur' },
                ],
                TrainingEndTime: [
                    { required: true, message: '请选择培训结束时间', trigger: 'blur' },
                ],
                collegeId: [
                    { required: true, message: '请选择学院', trigger: 'blur' },
                    //{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                selectId: [
                    { required: true, message: '请选择专业', trigger: 'blur' },
                    //{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
            },
            rules2: {
                Name: [
                    { required: true, message: '请输入课程名称', trigger: 'blur' },
                    //{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                collegeId: [
                    { required: true, message: '请选择学院', trigger: 'blur' },
                    //{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                selectId: [
                    { required: true, message: '请选择专业', trigger: 'blur' },
                    //{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],

                Type: [
                    {
                        required: true, message: '请输入课程类型', trigger: 'blur'
                    },
                    //{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],

            },
        };
    },
    computed: {
        // 当前富文本实例

    },
    methods: {
        modelteacher() {
            this.activwshow = 1;
            this.teachershow = true;
            this.showteacherselect = true;
        },
        numberval(data) {
            // 传值赋值
            // debugger;
            this.formItem.TeacherName = data.Name;//教师
            this.formItem.TeacherNumber = data.Number;//教师工号
            this.teachershow = false;
        },
        classmajorList() {
            this.getlevemajorList(this.formItem.collegeId, "c");
        },
        clickTabsitem(e) {
            // 点击切换标签
            //  debugger
            this.pageobj.pageNum = 1;
            this.pageobj.pageSize = 10;
            if (this.queryParams.type == 0) {
                this.getclassinfoDatainfo(1);//获取班级

            } else {
                this.getCourseinfoDatainfo(1);//获取课程
            }

        },
        handleCurrentChange(e) {
            //切换页码
            // debugger
            this.pageobj.pageNum = Math.ceil(e);
            if (this.queryParams.type == 0) {
                this.getclassinfoDatainfo(this.pageobj.pageNum);//获取班级

            } else {
                this.getCourseinfoDatainfo(this.pageobj.pageNum);//获取课程
            }
        },
        handleSizeChange(e) {
            //切换每页显示数
            this.pageobj.pageSize = Math.ceil(e);
            this.pageobj.pageNum = 1

            if (this.queryParams.type == 0) {
                this.getclassinfoDatainfo(this.pageobj.pageNum);//获取班级

            } else {
                this.getCourseinfoDatainfo(this.pageobj.pageNum);//获取课程
            }
        },
        getlevecolegelist() {
            //获取学院
            getStudentlevel({ SelectCollegeList: '', isAll: false })
                .then((res) => {
                    this.collegeList = res;
                    this.getlevemajorList(this.formItem.collegeId, "c");
                })
        },
        getlevemajorList(id, s, isAll = false) {
            //获取专业
            getStudentlevel({
                CollegeId: id,
                Signal: s,
                isAll: isAll,
            })
                .then((res) => {
                    this.majorList = res;
                })
        },
        resetForm(formName) {
            //新增重置

            this.$refs[formName].resetFields();
            this.formItem.collegeId = Number(this.collegeId);
            this.formItem.selectId = Number(this.mtid);
        },
        editresetForm(formName) {


            this.getclinfodetail(this.formItem.ClassInfoId);
        },

        resetForm2(formName) {
            //新增重置

            this.$refs[formName].resetFields();
            this.formItem.collegeId = Number(this.collegeId);
            this.formItem.selectId = Number(this.mtid);
        },
        editresetForm2(formName) {

            this.getcuinfodetail(this.formItem1, this.formItem1.CourseId);

        },
        addbox1() {
            //新增班级信息
            this.isedit1 = false;
            this.drawerform1 = true;
            //获取
            setTimeout(() => {
                // debugger
                this.$data.formItem = JSON.parse(JSON.stringify(this.$options.data().formItem));
                this.$refs['ruleForm'].resetFields();
                this.drawerformtitle1 = '新增班级信息';
                this.formItem.collegeId = Number(this.collegeId);
                this.formItem.selectId = Number(this.mtid);
                this.getlevecolegelist();//获取学院                        

                //this.setcreate();//创建夫文本编辑框
            }, 200);
        },
        editclassitem(info) {
            //获取修改详情
            this.isedit1 = true;
            this.drawerform1 = true;
            this.getlevecolegelist();//获取学院      
            this.getclinfodetail(info.ClassInfoId,info.HeadTeacherNum);
            this.drawerformtitle1 = '编辑班级信息';

            
        },
        addbox2() {
            //新增课程信息
            this.isedit2 = false;
            this.drawerform2 = true;
            //获取
            setTimeout(() => {
                // debugger
                this.$refs['ruleForm2'].resetFields();
                this.drawerformtitle2 = '新增课程信息';
                this.formItem1.collegeId = Number(this.collegeId);
                this.formItem1.selectId = Number(this.mtid);
                this.getlevecolegelist();//获取学院                        
                this.setcreate();//创建夫文本编辑框
                //this.setcreate();//创建夫文本编辑框
            }, 200);
        },
        setcreate() {
            // this.closedrawer();
            //创建夫文本编辑框
            // 绑定div上的IDwebsiteEditorElem
            // editor.destroy()
            //if ( this.phoneEditor == null) return
            //  debugger
            if (this.phoneEditor == null) {
                // this.phoneEditor = new E('#websiteEditorElem')
                this.phoneEditor = new E(this.$refs.editor)

                // 获取输入的内容
                this.phoneEditor.config.onchange = (html) => {
                    // 打印输入的内容
                    // console.log(html);
                }
                // 上传图片到服务器，base64形式
                this.phoneEditor.config.uploadImgShowBase64 = true
                // 隐藏网络图片
                this.phoneEditor.config.showLinkImg = false
                // 创建一个富文本编辑器
                // this.phoneEditor.txt.text('');

                this.phoneEditor.create()
                this.phoneEditor.txt.clear();
                // 富文本内容
            } else {
                // this.phoneEditor.txt.text('')
                this.phoneEditor.txt.clear();
            }
            //编辑里面赋值还没写好



        },
        editCourseitem(info) {
            //获取修改详情
            //debugger

            this.drawerform2 = true;
            this.isedit2 = true;
            this.getlevecolegelist();//获取学院      
            this.getcuinfodetail(info, info.CourseId);
            this.drawerformtitle2 = '编辑课程信息';
        },
        getclinfodetail(id,HeadTeacherNum) {
            //获取编辑信息
            getClassInfodetail({ gcid: id }).then((res) => {
                let data = res;
                this.formItem = {
                    collegeId: data.CollegeId,
                    selectId: data.MajorId,
                    ClassinfoGrade: data.Grade || '',
                    Counselor: data.CounselorNum || '',
                    ClassRemark: data.ClassRemark || '',
                    Name: data.Name,
                    ClassInfoId: data.ClassInfoId,
                    TrainingStartTime:data.TrainingStartTime,
                    TrainingEndTime:data.TrainingEndTime,
                    TeacherName:HeadTeacherNum,
                    HeadTeacherNum:data.HeadTeacherNum
                };
                
            })
                .catch((err) => {
                    this.$message({
                        message: '详情获取失败！',
                        type: 'error'
                    });
                });
        },
        submitForm(formName) {
            //班级提交
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    // debugger
                    //let content = this.phoneEditor.txt.html();//htm标签加文字
                    // let content = this.phoneEditor.txt.text();//文字
                    let datas = {
                        classinfoName: this.formItem.Name,
                        CounselorNum: '',
                        collegeId:1,
                        TrainingStartTime: this.formItem.TrainingStartTime,
                        TrainingEndTime: this.formItem.TrainingEndTime,
                        MajorId: 1,
                        TeacherName:this.formItem.TeacherName,
                        ClassRemark:this.formItem.ClassRemark,
                        ClassinfoGrade: '1',//this.formItem.ClassinfoGrade
                        HeadTeacherNum: this.formItem.TeacherNumber
                    };

                    postClassInfoAddinfo(datas).then((res) => {
                        let data = res;
                        if (data == 1) {
                            this.$message({
                                message: '新增成功',
                                type: 'success'
                            });
                            this.drawerform1 = false;
                            if (this.queryParams.type == 0) {
                                this.getclassinfoDatainfo(this.pageobj.pageNum);//获取班级

                            } else {
                                this.getCourseinfoDatainfo(this.pageobj.pageNum);//获取课程
                            }
                        } else if (data == 2) {
                            this.$message({
                                message: '班级名称不可为空',
                                type: 'error'
                            });
                        } else if (data == 3) {
                            this.$message({
                                message: '专业不正确',
                                type: 'error'
                            });
                        } else if (data == 4) {
                            this.$message({
                                message: '不可以添加其他学校的班级',
                                type: 'error'
                            });
                        } else if (data == 5) {
                            this.$message({
                                message: '该用户不存在',
                                type: 'error'
                            });
                        } else if (data == 6) {
                            this.$message({
                                message: '没有添加班级的权限',
                                type: 'error'
                            });
                        } else if (data == 7) {
                            this.$message({
                                message: '不可添加别的学校的班级',
                                type: 'error'
                            });
                        } else if (data == 8) {
                            this.$message({
                                message: '新增班级名已存在',
                                type: 'error'
                            });
                        } else if (data == 9) {
                            this.$message({
                                message: '输入的班主任工号不正确',
                                type: 'error'
                            });
                        } else if (data == 10) {
                            this.$message({
                                message: '输入的辅导员工号不正确',
                                type: 'error'
                            });
                        } else {
                            this.$message({
                                message: '新增失败',
                                type: 'error'
                            });
                        }



                    })
                        .catch((err) => {
                            // console.log(err);
                        });
                } else {
                    // console.log('error submit!!');
                    return false;
                }
            });
        },

        editsubmitForm(formName) {
            //修改提交
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    // let content = this.phoneEditor.txt.text();//文字
                    let datas = {
                        ClassinfoId: this.formItem.ClassInfoId,
                        Name: this.formItem.Name,
                        //HeadTeacherNum: this.formItem.HeadTeacherNum,

                        TrainingStartTime: this.formItem.TrainingStartTime,
                        TrainingEndTime: this.formItem.TrainingEndTime,
                        TeacherName:this.formItem.TeacherName,
                        ClassRemark:this.formItem.ClassRemark,

                        Grade: '1',// 年级
                        collegeId:1,
                        MajorId: 1,
                        CounselorNum: '',

                        HeadTeacherNum: this.formItem.TeacherNumber
                    };
                    
                    debugger
                    console.log(datas);
                    
                    postClassInfoeditinfo(datas).then((res) => {
                        let data = res;
                        // debugger
                        if (data == 1) {
                            //   debugger
                            this.$message({
                                message: '修改成功',
                                type: 'success'
                            });
                            this.drawerform1 = false;
                            //debugger
                            if (this.queryParams.type == 0) {
                                this.getclassinfoDatainfo(this.pageobj.pageNum);//获取班级

                            } else {
                                this.getCourseinfoDatainfo(this.pageobj.pageNum);//获取课程
                            }
                        } else if (data == 2) {
                            this.$message({
                                message: '班级名称不可为空',
                                type: 'error'
                            });
                        } else if (data == 3) {
                            this.$message({
                                message: '专业不正确',
                                type: 'error'
                            });
                        } else if (data == 4) {
                            this.$message({
                                message: '不可以修改其他学校的班级',
                                type: 'error'
                            });
                        } else if (data == 5) {
                            this.$message({
                                message: '该用户不存在',
                                type: 'error'
                            });
                        } else if (data == 6) {
                            this.$message({
                                message: '没有修改班级的权限',
                                type: 'error'
                            });
                        } else if (data == 7) {
                            this.$message({
                                message: '所修改的班级选择的专业不是该用户所属学校的（不可修改别的学校的班级）',
                                type: 'error'
                            });
                        } else if (data == 8) {
                            this.$message({
                                message: '修改后的班级名已存在',
                                type: 'error'
                            });
                        } else if (data == 9) {
                            this.$message({
                                message: '班级ID错误',
                                type: 'error'
                            });
                        } else {
                            this.$message({
                                message: '修改失败',
                                type: 'error'
                            });
                        }

                    })
                        .catch((err) => {
                            // console.log(err);
                        });

                } else {
                    // console.log('error submit!!');
                    return false;
                }
            });
        },
        // 课程

        getcuinfodetail(obj, id) {
            //获取编辑信息
            getCourseInfodetail({ gcid: id }).then((res) => {
                debugger

                let data = res;
                if (data) {
                    this.formItem1 = {
                        collegeId: data.CollegeId,
                        selectId: data.MajorId,
                        LessonsNum: data.LessonsNum,
                        Name: data.Name,
                        Type: data.Type,
                        Grade: data.Grade,
                        Description: data.Description,
                        CourseId: data.CourseId
                    };
                } else {
                    this.formItem1 = {
                        collegeId: Number(this.collegeId),
                        selectId: Number(this.mtid),
                        LessonsNum: obj.LessonsNum,
                        Name: obj.Name,
                        Type: obj.Type,
                        Grade: obj.Grade,
                        Description: obj.Description,
                        CourseId: obj.CourseId
                    };
                }


                setTimeout(() => {
                    this.setcreate();//创建夫文本编辑框
                    this.phoneEditor.txt.text(this.formItem1.Description);
                }, 200);

            })
                .catch((err) => {
                    this.$message({
                        message: '详情获取失败！',
                        type: 'error'
                    });
                });
        },
        submitForm2(formName) {
            //班级提交
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    // debugger
                    //let content = this.phoneEditor.txt.html();//htm标签加文字
                    let content = this.phoneEditor.txt.text();//文字
                    let datas = {
                        LessonsNum: this.formItem1.LessonsNum,
                        MajorId: this.formItem1.selectId,
                        Name: this.formItem1.Name,
                        // Type: encodeURI(this.formItem1.Type).replace(/\+/g, "%2B"),
                        Type: this.formItem1.Type,
                        Grade: this.formItem1.Grade,
                        // Description: this.formItem1.Description
                        Description: content

                    };
                    postCourseInfoAddinfo(datas).then((res) => {
                        let data = res;
                        if (data == 1) {
                            this.$message({
                                message: '新增成功',
                                type: 'success'
                            });
                            this.drawerform2 = false;
                            if (this.queryParams.type == 0) {
                                this.getclassinfoDatainfo(this.pageobj.pageNum);//获取班级

                            } else {
                                this.getCourseinfoDatainfo(this.pageobj.pageNum);//获取课程
                            }
                        } else if (data == 2) {
                            this.$message({
                                message: '课程名称不可空',
                                type: 'error'
                            });
                        } else if (data == 3) {
                            this.$message({
                                message: '该专业下存在此课程',
                                type: 'error'
                            });
                        } else if (data == 4) {
                            this.$message({
                                message: '课程类型不能为空',
                                type: 'error'
                            });
                        } else {
                            this.$message({
                                message: '新增失败',
                                type: 'error'
                            });
                        }



                    })
                        .catch((err) => {
                            // console.log(err);
                        });
                } else {
                    // console.log('error submit!!');
                    return false;
                }
            });
        },

        editsubmitForm2(formName) {
            //修改提交
            //  debugger
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    // debugger
                    let content = this.phoneEditor.txt.text();//文字
                    let datas = {
                        CourseId: this.formItem1.CourseId,
                        LessonsNum: this.formItem1.LessonsNum,
                        MajorId: this.formItem1.selectId,
                        Name: this.formItem1.Name,
                        Type: this.formItem1.Type,
                        Grade: this.formItem1.Grade,
                        Description: content
                        //  Description: this.formItem1.Description


                    };
                    postCourseInfoeditinfo(datas).then((res) => {
                        let data = res;
                        // debugger
                        if (data == 1) {
                            //   debugger
                            this.$message({
                                message: '修改成功',
                                type: 'success'
                            });
                            this.drawerform2 = false;
                            //debugger
                            if (this.queryParams.type == 0) {
                                this.getclassinfoDatainfo(this.pageobj.pageNum);//获取班级

                            } else {
                                this.getCourseinfoDatainfo(this.pageobj.pageNum);//获取课程
                            }
                        } else if (data == 2) {
                            this.$message({
                                message: '课程名称不可空',
                                type: 'error'
                            });
                        } else if (data == 3) {
                            this.$message({
                                message: '该专业下存在此课程',
                                type: 'error'
                            });
                        } else if (data == 4) {
                            this.$message({
                                message: '课程类型不能为空',
                                type: 'error'
                            });
                        } else {
                            this.$message({
                                message: '修改失败',
                                type: 'error'
                            });
                        }

                    })
                        .catch((err) => {
                            // console.log(err);
                        });

                } else {
                    // debugger
                    // console.log('error submit!!');
                    return false;
                }
            });
        },
        delclassitem(info) {
            // debugger
            //删除班级数据
            delClassinfo({ id: info.ClassInfoId, }).then((res) => {
                let data = res;
                if (data == 1) {
                    this.$message({
                        message: '删除成功',
                        type: 'success'
                    });
                    this.getclassinfoDatainfo(this.pageobj.pageNum);
                } else {
                    this.$message({
                        message: '删除失败',
                        type: 'error'
                    });
                }

            }).catch((err) => {
                // console.log(err);
            });
        },
        delCourseitem(info) {
            // debugger
            //删除课程数据
            delCourseinfo({ dcid: info.CourseId, }).then((res) => {
                let data = res;
                if (data == 1) {
                    this.$message({
                        message: '删除成功',
                        type: 'success'
                    });
                    this.getCourseinfoDatainfo(this.pageobj.pageNum);
                } else {
                    this.$message({
                        message: '删除失败',
                        type: 'error'
                    });
                }

            }).catch((err) => {
                // console.log(err);
            });
        },

        // 已完成 数据备份table中的信息
        getclassinfoDatainfo(pageNum) {
            //  debugger
            this.pageobj.pageNum = pageNum;
            getclassinfoData({
                oldTotal: this.pageobj.oldTotal,
                oldCurrent: this.pageobj.oldCurrent,
                pageSize: this.pageobj.pageSize,
                pageNum: pageNum,
                classname: this.queryParams.clname,
                majorname: '培训班',

            }).then((res) => {
                let data = res;
                if (data.length > 0) {
                    this.pageobj.Total = data[0].total;
                } else {
                    this.pageobj.Total = 0;
                    this.pageobj.pageNum = 1;
                }
                this.tableData = data;

            })
                .catch((err) => {
                    // console.log(err);
                    this.$message({
                        message: '列表信息获取失败',
                        type: 'error'
                    });
                });
        },
        // 已完成 数据恢复table中的信息
        getCourseinfoDatainfo(pageNum) {
            //  debugger  
            this.pageobj.pageNum = pageNum;
            getCourseinfoData({
                oldTotal: this.pageobj.oldTotal,
                oldCurrent: this.pageobj.oldCurrent,
                pageSize: this.pageobj.pageSize,
                pageNum: pageNum,
                coursename: this.queryParams.coursename,
                majorname: this.mtname,

            }).then((res) => {
                let data = res;
                if (data.length > 0) {
                    this.pageobj.Total = data[0].total;
                } else {
                    this.pageobj.Total = 0;
                    this.pageobj.pageNum = 1;
                }
                this.tableData = data;

            })
                .catch((err) => {
                    // console.log(err);
                    this.$message({
                        message: '列表信息获取失败',
                        type: 'error'
                    });
                });
        },


    },
    // 

    mounted() {

        //   this.setDefaultTime();//初始化时间
        // this.gettableinfo(1);

        let routeParams = this.$route.query;
        if (routeParams) {
            this.mtname = routeParams.majorName;
            this.mtid = routeParams.majorId;
            this.collegeId = routeParams.collegeId;
            this.collegeNam = routeParams.collegeNam;
        }
        this.getclassinfoDatainfo(1);//获取班级

    },
    activated() {
    },
    created() {
    },
};
</script>