<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" inline>
      <el-form-item label="年级">
        <el-select v-model="queryParams.gradeValue" @keyup.enter.native="handleQuery" clearable placeholder="选择年级">
          <el-option v-for="dict in dict.type.Grade" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="班级">
        <el-select v-model="queryParams.classValue" @keyup.enter.native="handleQuery" clearable placeholder="选择班级">
          <el-option v-for="dict in dict.type.Class" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="班主任姓名">
        <el-input v-model="queryParams.teacherName" @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入班主任姓名"></el-input>
      </el-form-item>
      <el-form-item label="班主任手机号">
        <el-input v-model="queryParams.teacherTel" @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入班主任手机号"></el-input>
      </el-form-item>

      <el-button class="ml20" type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
      </el-button>
      <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-search" size="mini" :disabled="single" @click="handleDetail">详情
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除
        </el-button>
      </el-col>
      <el-col :span="1.5" class="ml20">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport">导入
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExportClass">导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" @click="handleBatch">批量操作
        </el-button>
      </el-col>
      <el-col :span="1.5" style="position: absolute; float: right; right: 0px;">
        <el-select
          style="width: 100%;"
          size="mini"
          v-model="queryParams.schoolYear"
          @change="handleQuery">
          <el-option
            v-for="item in yearList"
            :key="item.value"
            :value="item.value"
            :label="item.label"
          ></el-option>
        </el-select>
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      stripe
      :data="ClassList"
      :cell-style="{padding: '5px'}"
      @selection-change="handleSelectionChange"
      width="100%">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column header-align="center" align="center" prop="picUrl" label="班徽" min-width="80"
                       v-if="columns[0].visible">
        <template slot-scope="scope">
          <el-image
            style="width: 36px; height: 36px"
            :src="baseUrl+scope.row.picUrl"
            :preview-src-list="[baseUrl+scope.row.picUrl]"
            fit="fill">
            <div slot="error" class="image-slot">
            </div>
          </el-image>
        </template>
      </el-table-column>

      <el-table-column header-align="center" align="center" prop="schoolYear" label="当前学年" min-width="80px">
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="classAlias" label="班级别名" min-width="80"
                       show-overflow-tooltip>
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="gradeValue" label="年级" min-width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.Grade" :value="scope.row.gradeValue"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="classValue" label="班级" min-width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.Class" :value="scope.row.classValue"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="teacherName" min-width="100" label="班主任姓名"
                       show-overflow-tooltip>
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="teacherTel" min-width="150" label="班主任手机号">
      </el-table-column>
      <el-table-column header-align="center" align="center" prop="houseName" min-width="150" label="所在教学楼"
                       show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="250px" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:grade:edit']">编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="teachersListEdit(scope.row)"
            v-hasPermi="['system:grade:edit']">任课教师列表
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:grade:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 添加或修改学校班级对话框 -->
    <el-dialog :title="title" :visible.sync="dialogVisibleforClass" width="800px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        :disabled="!isEdit"
        label-width="140px">
        <el-form-item
          prop="picUrl"
          label-width="0"
          style="display: flex;text-align: center;justify-content: center;">
          <el-upload
            v-loading="uploadLoading"
            class="avatar-uploader"
            action="#"
            accept="image/*"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
            :http-request="uploadImage"
          >
            <!--            <img v-if="imageUrl" :src="imageUrl" class="avatar">-->
            <img v-if="form.picUrl" :src="baseUrl + form.picUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <div><b>班 徽</b></div>
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="当前学年：" prop="schoolYear">
              <el-date-picker
                v-model="form.schoolYear"
                type="year"
                value-format="yyyy"
                placeholder="选择学年"
                style="width: 100%;"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年级：" prop="gradeValue">
              <el-select
                placeholder="请选择年级"
                v-model="form.gradeValue"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="dict in dict.type.Grade"
                  :key="dict.value"
                  :label="dict.label"
                  :value="Number(dict.value)">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="班级：" prop="classValue">
              <el-select v-model="form.classValue" clearable placeholder="请选择班级" style="width: 100%;">
                <el-option v-for="dict in dict.type.Class" :key="dict.value" :label="dict.label"
                           :value="Number(dict.value)">{{ dict.label }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级别名：">
              <el-input :value="resolveClassName(form)" readonly placeholder="请输入班级别名"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="班主任：" prop="teacherName">
              <el-input v-model="form.teacherName" placeholder="请输入班主任姓名" clearable
                        @click.native="selectTeacher"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班主任手机号：" prop="teacherTel">
              <el-input disabled v-model.number="form.teacherTel" :maxlength="TEXT_SIZE_TEL" clearable
                        placeholder="请输入班主任手机号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="所在教学楼：" prop="houseName">
              <el-input v-model="form.houseName" clearable placeholder="请输入所在教学楼"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级口号：">
              <el-input
                v-model="form.classSlogan"
                type="textarea"
                resize="none"
                :autosize="true"
                :maxlength="TEXT_SIZE_ONE_HU"
                placeholder="请输入班级口号"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否重点班：" prop="keyClass">
              <el-radio v-model="form.keyClass" label="0">是</el-radio>
              <el-radio v-model="form.keyClass" label="1">否</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="选课套餐：">
              <el-select
                v-model="form.chooseCourse"
                placeholder="请选择选课套餐"
                clearable
                style="width: 100%;"
              >
                <el-option
                  v-for="dict in dict.type.section_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="班主任寄语：" prop="teacherWord">
              <el-input
                type="textarea"
                placeholder="请输入班主任寄语"
                :maxlength="TEXT_SIZE_ONE_TH"
                :show-word-limit="true"
                :autosize="{minRows:2}"
                v-model="form.teacherWord"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button v-show="isEdit" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">{{ !isEdit ? '退 出' : '取 消' }}</el-button>
      </div>
    </el-dialog>
    <!-- 学员导入对话框-->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
                 :action="upload.url" :disabled="upload.isUploading"
                 :on-progress="handleFileUploadProgress"
                 :on-success="handleFileSuccess"
                 :auto-upload="false"
                 drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
                   @click="importTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 老师信息选择对话框框 -->
    <TeacherSelect v-if="teacherOptions.open" :openSelect.sync="teacherOptions.open" :title="teacherOptions.title"
                   @getTeacherList="getTeacherList" @setTeacherInfo="setTeacherInfo"></TeacherSelect>
    <!-- 批量设置对话框 -->
    <el-dialog :title="title" :visible.sync="dialogVisibleforBatch" width="400px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        label-width="120px"
        :rules="rules"
      >
        <el-row :gutter="20">
          <el-col :span="22">
            <el-form-item label="学年：" prop="schoolYear">
              <el-date-picker
                v-model="form.schoolYear"
                type="year"
                style="width: 95%"
                value-format="yyyy"
                placeholder="选择学年"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="22">
            <el-form-item label="高一班级数量：" prop="classNum1">
              <el-input-number v-model="form.classNum1" :min="0" :max="32"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="22">
            <el-form-item label="高二班级数量：" prop="classNum2">
              <el-input-number v-model="form.classNum2" :min="0" :max="32"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="22">
            <el-form-item label="高三班级数量：" prop="classNum3">
              <el-input-number v-model="form.classNum3" :min="0" :max="32"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormForBatch">确 定</el-button>
        <el-button @click="cancelForBatch">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getNewYear} from "@/api/smartSchool/teachAffairAdministration/affairClassView";
import {
  getClassList,
  getDetailInfo,
  addClass,
  editClass,
  deleteClass,
  allBY, editBatch,
} from "@/api/smartSchool/teachAffairAdministration/affairClassManage/index";
import TeacherSelect from '@/views/components/moduleComponets/TeacherSelect/index.vue'
import {teacherListInform} from "@/api/smartSchool/teacherManage/teacherInformation";
import PicAvatar from "@/views/smartSchool/schoolManage/introduce/schoolInfo/profile/picAvatar";
import {commonUpload} from "@/api/common";
import {getYearList} from "@/utils/utilLibrary/getYearList";
import {getToken} from "@/utils/auth";
import {TempGrades, TEXT_SIZE_ONE_HU, TEXT_SIZE_ONE_TH, TEXT_SIZE_TEL} from "@/enums/common";

export default {
  name: "AffairClassManage",
  dicts: ["Class", "Grade", "grade_type", "section_type"],
  components: {TeacherSelect, PicAvatar},
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      // 文本域
      TEXT_SIZE_ONE_HU,
      TEXT_SIZE_ONE_TH,
      TEXT_SIZE_TEL,
      //获取子组件传来的信息
      pic: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学校班级表格数据
      ClassList: [],
      // 弹出层标题
      title: "",
      // 添加或修改学校班级对话框
      dialogVisibleforClass: false,
      // 批量操作对话框
      dialogVisibleforBatch: false,
      // 任课教师列表对话框
      dialogVisibleForTeachers: false,
      // 教师对话框标题
      titleInform: '',
      // 老师信息选择对话框
      openTeacherInform: false,
      // 班级导入参数
      upload: {
        // 是否显示弹出层（班级导入）
        open: false,
        // 弹出层标题（班级导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/schoolClass/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        classValue: undefined,
        gradeAlias: undefined,
        houseName: undefined,
        teacherName: undefined,
        teacherTel: undefined,
        isUsed: undefined,
        schoolYear: new Date().getFullYear()
      },
      // 表单参数
      form: {},
      batchForm: {},
      // 表单校验
      rules: {
        schoolYear: [{required: true, message: '学年不能为空', trigger: 'change'}],
        gradeValue: [{required: true, message: '年级不能为空', trigger: 'change'}],
        classValue: [{required: true, message: '班级不能为空', trigger: 'change'}],
        // teacherName: [{required: true, message: '班主任姓名不能为空', trigger: 'change'}],
        // teacherTel: [{required: true, message: '班主任手机号不能为空', trigger: 'change'}],
        // houseName: [{required: true, message: '所在教学楼不能为空', trigger: 'change'}],
        classNum1: [{required: true, message: '高一班级数量不能为空', trigger: 'blur'}],
        classNum2: [{required: true, message: '高二班级数量不能为空', trigger: 'blur'}],
        classNum3: [{required: true, message: '高三班级数量不能为空', trigger: 'blur'}],
        // teacherWord: [{required: true, message: '寄语不能为空', trigger: 'blur'}],
      },

      // 任课教师列表表单
      teachersListForm: {},
      // 教师列表
      teachersList: [],
      // 新增或修改老师对话框
      teacherPerForm: {},
      // 控制表格属性的显示与隐藏
      columns: [
        {key: 0, label: `班徽`, visible: true},
        {key: 1, label: `当前学年`, visible: true},
        {key: 2, label: `类型`, visible: false},
        {key: 3, label: `年级`, visible: true},
        {key: 4, label: `班级`, visible: true},
        {key: 5, label: `班级别名`, visible: true},
        {key: 6, label: `所在教学楼`, visible: true},
        {key: 7, label: `班主任姓名`, visible: true},
        {key: 8, label: `班主任手机号`, visible: true},
        {key: 9, label: `班级口号`, visible: true},
        {key: 10, label: `班主任寄语`, visible: false},
        {key: 11, label: `是否毕业`, visible: true},
        {key: 12, label: `备注`, visible: false},
      ],
      // 选择老师对话框
      teacherOptions: {
        open: false,
        title: '选择老师'
      },

      // 上传图片的加载效果
      uploadLoading: false,
      // imageUrl: '',
      // 年份列表数据
      yearList: [],
      // 表单是否可以修改、
      isEdit: true,
    };
  },
  created() {
    this.yearList = getYearList();
    //获取最新年份
    this.newYear()

  },
  computed: {
    resolveClassName() {
      return form => {
        // const result = ['*', '*', '*'];
        const result = [];
        const {classValue, gradeValue, schoolYear} = form;
        classValue && (result[1] = this.dict.type.Class.find(item => item.value == classValue).label);
        gradeValue && (result[0] = TempGrades.find(item => item.value == gradeValue).label);
        // schoolYear && (result[0] = schoolYear);
        form.gradeName = result[0];
        form.className = result[1];
        form.classAlias = result.join('');
        return form.classAlias;
      }
    }
  },
  watch: {
    'form.schoolYear'(val) {
      this.form.schoolYear = '' + val;
    },
    pic: {
      handler(newValue, oldValue) {
        this.isUploadPic = newValue[3]
      }
    }
  },
  methods: {
    schoolYearChange() {
      console.log("日期改变", this.form.schoolYear)
    },
    newYear() {
      getNewYear().then((res) => {
        this.queryParams.schoolYear = res.schoolYear
        this.handleQuery();
      })
    },
    /** 查询学校班级列表 */
    getList() {
      this.loading = true;
      getClassList(this.queryParams).then((response) => {
        this.ClassList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.dialogVisibleforClass = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        picUrl: '',
        schoolYear: '',
        classNum1: 0,
        classNum2: 0,
        classNum3: 0,
        gradeValue: '',
        classValue: '',
        classAlias: '',
        teacherName: '',
        houseName: '',
        remark: '',
        teacherTel: '',
        classSlogan: '',
        teacherWord: ''
      };

      // this.imageUrl = '';
      //表单可编辑
      this.isEdit = true;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        classValue: undefined,
        classAlias: undefined,
        houseName: undefined,
        teacherName: undefined,
        teacherTel: undefined,
        isUsed: undefined,
      };
      this.newYear();
      //
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    //获取图片信息
    getClassInfoPic(val) {
      this.pic = val
    },
    /** 新增班级按钮操作 */
    handleAdd() {
      this.reset();
      this.dialogVisibleforClass = true;
      this.title = "添加班级信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      this.$modal.loading('正在加载数据，请稍等...');
      getDetailInfo(id).then((response) => {
        this.$modal.closeLoading();
        this.form = response.data;
        this.dialogVisibleforClass = true;
        this.title = "修改班级信息";
      }).catch(error => {
        this.$modal.closeLoading();
      })
    },

    /** 查看详情 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids;
      this.$modal.loading('正在加载数据，请稍等...');
      getDetailInfo(id).then(response => {
        this.$modal.closeLoading();
        this.form = response.data;
        this.dialogVisibleforClass = true;
        this.title = "班级详情";
        this.isEdit = false;
      }).catch(error => {
        this.$modal.closeLoading();
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // 将年级和班级信息赋值
          this.handleBaseInfo();
          this.$modal.loading('正在上传数据，请稍等...');
          if (this.form.id != null) {
            editClass(this.form).then((response) => {
              this.$modal.closeLoading();
              this.$modal.msgSuccess("修改班级成功");
              this.dialogVisibleforClass = false;
              this.getList();
            }).catch(error => {
              this.$modal.closeLoading();
            })
          } else {
            addClass({
              ...this.form,
              gradeType: 4
            }).then((response) => {
              this.$modal.closeLoading();
              this.$modal.msgSuccess("新增班级成功");
              this.dialogVisibleforClass = false;
              this.getList();
            }).catch(error => {
              this.$modal.closeLoading();
            })
          }
        }
      });
    },
    handleBaseInfo() {
      this.form.gradeName = this.dict.type.Grade.find(item => item.value == this.form.gradeValue).label;
      this.form.className = this.dict.type.Class.find(item => item.value == this.form.classValue).label;
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除所选班级？').then(() => {
        this.$modal.loading('正在删除，请稍等...');
        return deleteClass(ids);
      }).then(response => {
        this.$modal.closeLoading();
        this.$modal.msgSuccess("删除班级成功");
        this.getList();
      }).catch(error => {
        this.$modal.closeLoading();
      })
    },

    // // 批量毕业
    // handleGraduation() {
    //   allBY(this.ids).then((reponse) => {
    //     this.$modal.msgSuccess("操作成功");
    //     this.getList();
    //   });
    // },

    // 批量操作
    handleBatch() {
      this.reset();
      this.dialogVisibleforBatch = true;
      this.title = "批量操作";
    },
    // 取消按钮
    cancelForBatch() {
      this.dialogVisibleforBatch = false;
      this.reset();
    },
    submitFormForBatch() {
      console.log("点击提交")
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.$modal.loading('正在上传数据，请稍等...');
          editBatch(this.form).then((response) => {
            this.$modal.closeLoading();
            this.$modal.msgSuccess("批量修改成功");
            this.dialogVisibleforBatch = false;
            this.getList();
          }).catch(error => {
            this.$modal.closeLoading();
          })

        }
      });
    },

    // 下载班级模板
    importTemplate() {
      this.download(
        "/schoolClass/importTemplate",
        {},
        `班级管理.xlsx`
      );
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "班级导入";
      this.upload.open = true;
    },

    /** 导出班级按钮操作 */
    handleExportClass() {
      const length = this.ids.length;
      const ids = this.ids;
      if (!length) {
        this.download(
          "/schoolClass/export",
          {
            ...this.queryParams,
          },
          `班级管理.xlsx`
        );
      } else {
        this.download(
          "/schoolClass/export/" + ids,
          {
            ...this.queryParams,
          },
          `class_${new Date().getTime()}.xlsx`
        );
      }
    },
    // 获取教师信息
    teacherInfoList() {
      this.teacherOptions.open = true;
    },
    /** 选择老师(打开对话框) */
    selectTeacher() {
      this.teacherOptions.open = true;
    },

    /** 获取老师信息列表 */
    getTeacherList(queryForm, callback) {
      teacherListInform({...queryForm, employeeType: 0}).then(response => {
        callback(response.rows, response.total);
      }).catch(error => {
        callback([], 0);
      })
    },
    /** 设置老师信息 */
    setTeacherInfo(item) {
      // this.form.teacherName = item.teacherName;
      this.$set(this.form, 'teacherName', item.teacherName);
      this.$set(this.form, 'teacherTel', item.teacherTel);
      this.$set(this.form, 'teacherId', item.id);

    },
    // 任课教师列表
    teachersListEdit(row) {
      this.$router.push({
        path: "/jwClassManage/teacherlists",
        query: {
          gradeId: row.id,
          routeBack: 0
        },
      });
    },
    // 是否毕业按钮切换
    changeSwitch(row) {
      // const ids=this.ids||row.id
      let text = row.isGraduated === "1" ? "毕业" : "取消毕业";
      this.$modal.confirm('确认要' + text + '"' + row.classAlias + '"班级吗？').then(function () {
        return allBY(row.id, row.isGraduated);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function () {
        row.isGraduated = row.isGraduated === "0" ? "1" : "0";
      });
    },

    // 图片上传功能
    uploadImage(file) {
      const fileData = file.file;
      const formData = new FormData();
      formData.append('file', fileData);
      this.uploadLoading = true;
      commonUpload(formData).then(response => {
        this.uploadLoading = false;
        this.$modal.msgSuccess('上传成功');
        // this.imageUrl = this.baseUrl + response.fileName;
        this.form.picUrl = response.fileName;
      }).catch(error => {
        this.uploadLoading = false;
      })
    },
    // 上传图片之前的钩子函数
    beforeAvatarUpload() {
    },
    // 上传成功
    handleAvatarSuccess() {

    },
    /** 上传过程 */
    handleFileUploadProgress() {
      this.upload.isUploading = true;
    },
    /** 上传成功 */
    handleFileSuccess(response) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
      this.getList();
    },
    /** 提交 */
    submitFileForm() {
      this.$refs.upload.submit();
    }

  },
};
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;

}
</style>
