<template>
  <div class="page_user page_search">
    <div class="page_jg_20"></div>
    <div class="search_content">
      <div class="content_left">
        <el-select class="select_year" v-model="selectSchoolYearId" placeholder="请选择" @change="ChangeSchoolYear">
          <el-option
            v-for="item in selectSchoolYearList"
            :key="item.id"
            :label="item.schoolYearName"
            :value="item.id">
          </el-option>
        </el-select>
        <el-select class="select_width" v-model="selectSchoolYearGradeId" placeholder="请选择" @change="ChangeGradeYear">
          <el-option
            v-for="item in selectGradeYearList"
            :key="item.id"
            :label="item.gradeName"
            :value="item.id">
          </el-option>
        </el-select>
        <el-input class="input_width" v-model="keyWord" placeholder="请输入姓名或学号" @input="GetSearchStudent()" >
          <el-button slot="append" icon="el-icon-search" ></el-button>
        </el-input>
      </div>
      <div class="content_right">
        <el-tooltip  effect="dark" content="同一学期下教学班和行政班的班级编号都不允许重复" placement="top">
          <el-button  @click="AddClass()" type="primary" plain>新增班级</el-button>
        </el-tooltip>
        <el-button @click="EditClass()">编辑班级</el-button>
        <el-tooltip  effect="dark" content="点击会删除当前选中的班级及班级下所有学生及任课教师关系，用户登录不影响！" :disabled="isTooltipDisabled" placement="top">
          <el-button  @click="DeleteClass()" type="danger" plain>删除班级</el-button>
        </el-tooltip>
        <!-- <el-button size="mini" @click="upClass">班级升级</el-button> -->
        <!-- <el-button size="mini" @click="templeteDownLoadData">模板下载</el-button> -->
        <el-tooltip  effect="dark" content="导入的学生密码默认为：学校编号+@+学号，如：19000@20180101" placement="top">
          <el-button  @click="BatchImport()">批量导入</el-button>
        </el-tooltip>
        <el-button  @click="BatchExport()">批量导出</el-button>
        <el-button  @click="AddStudent()" type="primary" plain>新增学生</el-button>

      </div>
    </div>
    <div class="page_jg_18"></div>
    <div class="class_container">
      <div class="container_left page_tree " :style="{height:treeHeight+'px'}">
        <!-- 拖拽排序的逻辑未处理 放后 -->
        <el-tree 
          :data="classTreeData" 
          :props="defaultPropsClass" 
          :check-on-click-node="false"
          :highlight-current="true"
          node-key="id"
          :default-expanded-keys="defaultExKey"
          draggable
          @node-drop="handleDrop"
          :allow-drop="allowDrop"
          @node-click="TreeNodeClick"
          ref="treeRef"
        >
         <!-- @click="() => treeNodeClick(data)" -->
          <div class="custom-tree-node" slot-scope="{ node, data }">
            <div class="tree-label" :class="(data.isSelect ? 'node-label_select' : '')">
              <span class="label_name">{{ node.label }}</span>
              <i v-if="node.level === 3" class="iconfont icon_paixu" :style="data.isSelect ? 'display: block;' : ''"></i>
            </div>
          </div>
          <!-- <span class="custom-tree-node" slot-scope="{ node, data }">
            <span>{{ data.className }}</span>
            <span v-if="node.isLeaf && node.parent">
              <i class="iconfont icon_paixu"></i>
            </span>
          </span> -->
        </el-tree>
      </div>
      <div class="container_right">
        <div class="page_table">
          <el-table :data="computedTableData" border stripe  :height="tableHeight"
          :key="tableKey"
          v-loading="tableLoading"
          element-loading-text="拼命加载中……"
            element-loading-spinner="el-icon-loading"
            element-loading-background="#ffffff"
           row-key="studentId">
           
            <el-table-column type="index" label="序号" :index="GetIndexNumber"   align="center" width="50"  fixed="left"></el-table-column>
            <el-table-column prop="registrationCode" label="账号" align="center" min-width="120" show-overflow-tooltip fixed="left">
                <template slot-scope="scope">
                    <span>{{ scope.row.registrationCode || '-' }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="studentCode" label="学号" align="center" show-overflow-tooltip fixed="left">
                <template slot-scope="scope">
                    <div>{{ scope.row.studentCode?scope.row.studentCode:'-' }}</div>
                </template>
            </el-table-column>
            <el-table-column prop="studentName" label="姓名" align="center" show-overflow-tooltip fixed="left">
                <template slot-scope="scope">
                    <div>{{ !scope.row.studentName?'-':scope.row.studentName }}</div>
                </template>
            </el-table-column>
            <el-table-column  label="考号" align="center" show-overflow-tooltip>
                <template slot-scope="scope">
                    <span>{{ scope.row.examCode || '-' }}</span>
                </template>
            </el-table-column>
            <el-table-column  label="学籍类型" align="center" show-overflow-tooltip>
                <template slot-scope="scope">
                    <span>{{ scope.row.registrationTypeName || '-' }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="adminClassName" label="行政班" align="center"  show-overflow-tooltip>
                
            </el-table-column>
            <el-table-column :label="column.courseName" align="center" v-for="(column,index) in tableColumn" show-overflow-tooltip>
                <template slot-scope="scope" >
                    <span v-if="scope.row.teachClasses">{{ scope.row.teachClasses[index].className || '-' }}</span>
                    <span v-else>-</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" fixed="right" min-width="120">
                <template slot-scope="scope">
                  <div class="table_row_option">
                  
                      <div  class="button_editor"  @click="EditorStudent(scope.row)">编辑</div>
                    
                      <div  class="button_delete"  @click="DeleteStudent(scope.row)">删除</div>
                  </div>
                </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="page_pagination" v-show="tableData.length>10">
            <el-pagination
                @current-change="ChangePage"
                background
                
                :page-sizes="[20,50,100]"
                layout="sizes,prev, pager, next"
                @size-change="HandleSizeChange"
                :current-page="pageInfo.pageNum"
                :total="pageInfo.total">
            </el-pagination>
        </div>
        <div class="class_number">
          {{ treeItem?.customLabel }}
        </div>
      </div>
    </div>
    <div class="page_dialog">
      <!-- 新增班级 -->
      <el-dialog title="新增班级" center :visible.sync="addClassData.dialogShow" width="480px">
        <div class="dialog_center padding_20">
          <el-form :model="addClassData"  :rules="addClassRules" ref="addClassData" label-width="140px">
            <!-- <el-form-item label="当前学年学期:" prop="gradeName" v-show="false">
              <el-input :value="selTermList.name" disabled></el-input>
            </el-form-item> -->
            <el-form-item label="班级起始编号：" prop="startClassNum">
             
                  <el-input   v-model="addClassData.startClassNum" placeholder="请输入" class="input_91"></el-input>
              
                  <span class="span_center">至</span>
               
                  <el-input  v-model="addClassData.endClassNum" placeholder="请输入" class="input_91"></el-input>
                
            </el-form-item>
            <el-form-item label="班级名称：" prop="className" >
              <div class="default_pass">
                <el-input v-model="addClassData.className"></el-input>*班
                  <p>*示例：XX1班，XX2班，XX3班</p>
              </div>
            </el-form-item>
            <el-form-item label="班级类型：" prop="classType" >
              <el-radio-group v-model="addClassData.classType" @change="ChangeClassType">
                <el-radio label="0">行政班</el-radio>
                <el-radio label="1">教学班</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="教学科目：" prop="courseCode" v-show="addClassData.classType=='1'" >
              <el-select  v-model="addClassData.courseCode" placeholder="请选择教学班的科目" @change="ChangeCourse">
                <el-option v-for="(item,index) in teachingClassSubjectData" :key="item.courseCode" :label="item.courseName" :value="item.courseCode"></el-option>
              </el-select>
            </el-form-item>
          </el-form>    
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="addClassData.dialogShow = false">取 消</el-button>
          <el-button type="primary" @click="ConfirmClassAdd">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 班级编辑 -->
      <el-dialog title="编辑班级" center :visible.sync="editClassData.dialogShow" width="480px">
        <div class="dialog_center padding_20">
          <el-form :model="editClassData"  :rules="editClassRules" ref="editClassData" label-width="150px">
            <el-form-item label="当前班级ID：">
              <el-input :value="editClassData.classId" disabled></el-input>
            </el-form-item>
            <!-- <el-form-item label="班级编号:" v-show="false">
              <el-input  v-model="editClassData.classCode" disabled ></el-input>
            </el-form-item> -->
            <el-form-item label="当前班级名称：" prop="schoolClassName">
              <el-input  v-model="editClassData.className" ></el-input>
            </el-form-item>
          </el-form>    
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editClassData.dialogShow = false">取 消</el-button>
          <el-button type="primary" @click="ConfirmClassEdit">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 班级编辑end -->
      <!-- 班级升级 -->
      <el-dialog title="学期升级" center  :visible.sync="editClassUp.dialogShow" custom-class="editCourseDialog">
        <el-container class="courseDialogBox">
          <el-form :model="editClassUp" style="flex:1;" :rules="editClassUpRules" ref="editClassUp" label-width="140px">
            <el-form-item label="当前学年学期:" prop="termName">
              <el-input :value="editClassUp.nowGradeAndTermName" disabled></el-input>
            </el-form-item>
            <el-form-item label="升级到的学年:" prop="classStartCode">
              <el-select :popper-append-to-body="false" v-model="editClassUp.gradeId" size="small" placeholder="请选择" style="width:130px;margin-right:10px;">
                <el-option
                  v-for="item in selectGradeYearList"
                  :key="item.id"
                  :label="item.schoolYearName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="升级到的学期:" prop="termId">
              <el-select :popper-append-to-body="false" v-model="editClassUp.termId" size="small" placeholder="请选择需要升级到的学期" style="width:180px;margin-right:10px;">
                <el-option
                  v-for="item in selTermList.arr"
                  :key="item.termId"
                  :label="item.termName"
                  :value="item.termId">
                </el-option>
              </el-select>
            </el-form-item> -->
            <el-form-item label="是否升级教师:" prop="isUpteacher">
              <el-switch 
                active-value="0"
                inactive-value="1"
                v-model="editClassUp.isUpteacher">
              </el-switch>
            </el-form-item>
            <el-form-item label="是否覆盖已有:" prop="isCover">
              <el-switch 
                active-value="0"
                inactive-value="1"
                v-model="editClassUp.isCover">
              </el-switch>
            </el-form-item>
          </el-form>    
        </el-container>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editClassUp.dialogShow = false">取 消</el-button>
          <el-button type="primary" >确 定</el-button>
        </div>
      </el-dialog>
      <!-- 新增学生 -->
      <el-dialog :title="editStudentData.isEdit?'编辑学生':'新增学生'" center  :visible.sync="editStudentData.dialogShow" 
        :width="teachingClassData.length < 3 ? '540px' : '820px'">
        <div class="dialog_center padding_20">
          <el-form :model="editStudentData"  label-width="120px" :rules="editStudentRules" ref="editStudentData">

            <!-- <el-form-item label="账号：" prop="registrationCode" >
              <el-input v-model="editStudentData.registrationCode" placeholder="请输入" @change="GetStudentInfo" @input="validateNumber('registrationCode')" :disabled="editStudentData.isEdit"></el-input>
            </el-form-item> -->
            <el-form-item label="学号：" prop="studentCode">
              <el-input v-model="editStudentData.studentCode" placeholder="请输入" @change="GetStudentInfo" @input="validateNumber('studentSchoolCode')" :disabled="editStudentData.isEdit"></el-input>
            </el-form-item>
            <el-form-item label="姓名：" prop="studentName">
              <el-input v-model="editStudentData.studentName" placeholder="请输入" maxlength='10'></el-input>
            </el-form-item>
            <el-form-item label="考号：" prop="examCode">
              <el-input v-model="editStudentData.examCode" placeholder="请输入" @input="validateNumber('examCode')"></el-input>
            </el-form-item>
            <el-form-item label="行政班：" prop="adminClassId" >
              <el-select v-model="editStudentData.adminClassId" placeholder="请选择" >
                <el-option v-for="item in adminClassData" :key="item.classId"  :label="item.className" :value="item.classId"></el-option>
              </el-select>
            </el-form-item>
            
            <el-form-item label="教学班：" v-if="teachingClassData.length>0 && !editStudentData.isEdit">
              <!--  -->
              <div class="list_content" v-if="selectExportFlag=='ALL' || editStudentData.isEdit==false">
                  <div v-for="(item,index) in teachingClassData" :key="item.id" class="select_item">
                    <el-checkbox v-model="item.isChecked" :label="item.courseName" @change="ChangeTeachingClassCode(item)" >
                      <span>{{item.courseName}}</span>
                    </el-checkbox>
                    <el-select v-model="item.selectClassId" placeholder="请选择"  :disabled="!item.isChecked">
                      <el-option
                        v-for="option in item.courseClasses"
                        :key="option.classId"
                        :label="option.className"
                        :value="option.classId">{{option.className}}
                      </el-option>
                    </el-select>
                  </div>
                  
              </div>
              <div class="list_content" v-if="selectExportFlag=='TEACH' && editStudentData.isEdit==true">
                  <div v-for="(item,index) in teachingClassData" :key="item.id" class="select_item" v-if="selectCourseCode==item.courseCode">
                    <el-checkbox v-model="item.isChecked" :label="item.courseName" @change="ChangeTeachingClassCode(item)" >
                      <span>{{item.courseName}}</span>
                    </el-checkbox>
                    <el-select v-model="item.selectClassId" placeholder="请选择"  :disabled="!item.isChecked">
                      <el-option
                        v-for="option in item.courseClasses"
                        :key="option.classId"
                        :label="option.className"
                        :value="option.classId">{{option.className}}
                      </el-option>
                    </el-select>
                  </div>
                  
              </div>
                
              
            </el-form-item>
            <el-form-item label="教学班：" v-if="teachingClassData.length>0 && editStudentData.isEdit && (selectExportFlag=='ALL' || selectExportFlag=='TEACH')">
              <!--  -->
              <div class="list_content" v-if="selectExportFlag=='ALL'">
                  <div v-for="(item,index) in teachingClassData" :key="item.id" class="select_item">
                    <el-checkbox v-model="item.isChecked" :label="item.courseName" @change="ChangeTeachingClassCode(item)" >
                      <span>{{item.courseName}}</span>
                    </el-checkbox>
                    <el-select v-model="item.selectClassId" placeholder="请选择"  :disabled="!item.isChecked">
                      <el-option
                        v-for="option in item.courseClasses"
                        :key="option.classId"
                        :label="option.className"
                        :value="option.classId">{{option.className}}
                      </el-option>
                    </el-select>
                  </div>
                  
              </div>
              <div class="list_content" v-if="selectExportFlag=='TEACH'">
                  <div v-for="(item,index) in teachingClassData" :key="item.id" class="select_item" v-if="selectCourseCode==item.courseCode">
                    <el-checkbox v-model="item.isChecked" :label="item.courseName" @change="ChangeTeachingClassCode(item)" >
                      <span>{{item.courseName}}</span>
                    </el-checkbox>
                    <el-select v-model="item.selectClassId" placeholder="请选择"  :disabled="!item.isChecked">
                      <el-option
                        v-for="option in item.courseClasses"
                        :key="option.classId"
                        :label="option.className"
                        :value="option.classId">{{option.className}}
                      </el-option>
                    </el-select>
                  </div>
                  
              </div>
            </el-form-item>
            <el-form-item label="学籍类型：" prop="registrationTypeCode" v-if="registrationTypesList.length>0">
              <el-select v-model="editStudentData.registrationTypeCode" placeholder="请选择" @change="ChangeRegistrationTypeCode" clearable>
                <el-option v-for="option in registrationTypesList"  :key="option.value"  :label="option.label" :value="option.value">
                  {{option.label}}
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>    
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editStudentData.dialogShow = false">取 消</el-button>
          <el-button type="primary" @click="ConfirmStudentAdd" :loading="buttonLoading">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 重置密码 -->
      <el-dialog title="重置密码" center :visible.sync="editPassWordData.dialogShow" custom-class="editCourseDialog">
        <el-form :model="editPassWordData" label-width="80px" :rules="editPassWordDataRules" ref="editPassWordData">
          <el-form-item label="重置范围">
            <el-input :value="editPassWordData.name" disabled/>
          </el-form-item>
          <el-form-item label="新密码" prop="newPassWord">
            <el-input v-model="editPassWordData.newPassWord"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="editPassWordData.dialogShow = false">取 消</el-button>
          <el-button size="small" type="primary" @click="confirmPassWord">确 定</el-button>
        </div>
      </el-dialog>
      <!-- 批量导入 -->
      <el-dialog title="学生批量导入" center  :visible.sync="batchImportData.dialogShow">
        <div class="dialog_center padding_20">
          <el-form :model="batchImportData" label-width="160px" :rules="batchImportDataRules" ref="batchImportData" >
            <el-form-item label="当前学年学期：">
              <el-input :value="batchImportData.selectSchoolYearName" disabled  style="width:300px;"/>
            </el-form-item>
            <el-form-item label="是否年级覆盖：" prop="isOverGrade">
              <!-- <el-switch v-model="batchImportData.isOverGrade"></el-switch> -->
              <el-radio-group v-model="batchImportData.isOverGrade">
                
                <el-radio :label="true">覆盖</el-radio>
                <el-radio :label="false">不覆盖</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="班级类型：" prop="schoolClassType">
              <el-radio-group v-model="batchImportData.schoolClassType" @change="ChangeSchoolClassType">
                
                <el-radio label="0">行政班</el-radio>
                <el-radio label="1">教学班</el-radio>
                <el-radio label="2">行政班+教学班</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="选择科目：" prop="" v-show="batchImportData.schoolClassType=='1' || batchImportData.schoolClassType=='2'">
              <el-checkbox-group  v-model="batchImportData.checkCourseList" @change="UpdateTableColumns">
                <el-checkbox v-for="item in teachingClassSubjectData" :label="item.courseName" :key="item.courseInfoId"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            
            <el-form-item label="选择文件：">
              <div class="">
                <el-button type="primary" size="small" @click="OpenUpload" >点击上传</el-button>
                <span class="upload_file_name">{{batchImportData.fileName}}</span>
                <!-- <el-input style="width:240px;" v-model="batchImportData.fileName" clearable size="mini"></el-input> -->

                <input type="file" ref="uploadStudents" @change="uploadChange" enctype="multipart/form-data" style="display:none;"/>
              </div>
                
            </el-form-item>
            <el-form-item label="下载模板：">
              <el-button size="small"  @click="ConfirmtempleteDownLoad">模板下载</el-button>
            </el-form-item>
            <div class="dialog_table page_table table_row_42">
                <el-table :data="importData" border  :key="importTableKey">
                  <el-table-column  align="center" v-for="(column,columnIndex) in columns" :key="column.prop" :label="column.title" :prop="column.prop" min-width="100px"></el-table-column>
                </el-table>
            </div>
            <div class="import_message">
              <!--  -->
                <template v-if="batchImportData.schoolClassType=='1'">
                  *必填项字段：学号、姓名
                  <span v-for="(item,index) in batchImportData.checkCourseList">、{{item}}</span></template>
                <template v-else-if="batchImportData.schoolClassType=='0'">*必填项字段：学号、姓名、行政班</template>
                <template v-else>*必填项字段：学号、姓名、行政班</template>
                <span style="margin-left: 10px;"> 非必填字项：考号、学籍类型</span>

            </div>
              
           
          </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="CancelBatchImport">取 消</el-button>
          <el-button size="small" type="primary" @click="ConfirmBatchImport" :disabled="isSubmitting"><i class="el-icon-loading" v-if="isSubmitting"></i>确 定</el-button>
        </div>
      </el-dialog>
      <!-- 模板下载 -->
      <el-dialog title="模板下载" center :visible.sync="templeteDownLoad.dialogShow" custom-class="editCourseDialog3">
        <el-form :model="templeteDownLoad" label-width="120px" :rules="templeteDownLoadRules" ref="templeteDownLoad">
          <el-form-item label="班级类型:" prop="schoolClassType">
            <el-radio-group v-model="templeteDownLoad.schoolClassType">
              <el-radio :label="3">班级总名单</el-radio>
              <el-radio :label="0">行政班</el-radio>
              <el-radio :label="1">教学班</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item :label="templeteDownLoad.schoolClassType==3?'分层科目:':'选择科目:'" prop="" v-show="!templeteDownLoad.schoolClassType?false:true">
            <el-checkbox-group  v-model="checkedCities">
              <el-checkbox v-for="item in courseDataInfo" :label="item.courseName" :key="item.courseInfoId"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="templeteDownLoad.dialogShow = false">取 消</el-button>
          <el-button size="small" type="primary" @click="ConfirmtempleteDownLoad">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    
  </div>
</template>
<script>

import { throttle } from "lodash";
import { RecycleScroller } from 'vue-virtual-scroller'; //引入虚拟滚动组件 减少一次性的表格渲染
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';

export default{
  components:{
    RecycleScroller
  },
  data(){
    return {
      keyWord:'',//搜索学生 学号
      defaultPropsClass:{
        children: 'childClassTrees',
        label: 'customLabel',
        labelId:'id'
      },//树形结构数据映射
      addClassData:{
        dialogShow:false,
        startClassNum:'',//班级开始编号
        endClassNum:"",//班级结束编号
        className:"",//班级名称
        classType:'0',//0-行政班 1-教学班
        courseCode:'',//科目code
        courseName:'',//科目名称
      },//新增班级数据
      addClassRules:{
        startClassNum:[
          { required: true, message: '请输入起始班级编号', trigger: 'blur' },
          { validator: this.validateClassCodes, trigger: 'blur' }
        ],
        endClassNum: [
          { required: true, message: '请输入结束班级编号', trigger: 'blur' },
        ],
        classType:[
          { required: true, message: '请选择班级类型', trigger: 'blur' },
        ],
       
       
      },//新增班级规则

      editClassData:{
        dialogShow:false,
        classId:'',//班级ID
        className:"",//班级名称
       
      },//编辑班级数据
      editClassRules:{
        className:[
          { required: true, message: '请输入班级名称', trigger: 'blur' },
        ],
      },//编辑班级级规则
      editClassUp:{
        dialogShow:false,
        gradeId:"",
        termId:"",
        isUpTeacher:1,
        isCover:1
      },
      editClassUpRules:{
        gradeName:[
            { required: true, message: '请输入学年名称', trigger: 'blur' },
          ],
          gradeId:[
            { required: true, message: '请输入起始班级编号', trigger: 'blur' },
        ],
        SemesterName: [
            { required: true, message: '请输入结束班级编号', trigger: 'blur' },
        ]
      },


      editStudentData:{
        dialogShow:false,
        isEdit:false,//是否编辑
        adminClassId:'',//行政班id
        examCode:'',//考号
        registrationCode:'',//账号
        registrationTypeCode:'',//学籍类型CODE
        registrationTypeName:'',//学籍类型名称
        studentCode:'',//学号
        studentId:'',//学生id
        studentName:'',//学生姓名
        teachClassId:'',//教学班id集合
      },//编辑学生

      editStudentRules:{
        studentName:[
          { required: true, message: '请输入学生姓名', trigger: 'submit' },
        ],
        studentCode:[
          { required: true, message: '请输入学号', trigger: 'submit' },
        ],
        registrationCode:[
          { required: true, message: '请输入账号', trigger: 'submit' },
        ],
       
        // adminClassId:[
        //   { required: true, message: '请选择行政班', trigger: 'submit' },
        // ]
      },//编辑学生规则


  
      teachingClassData:[],//教学班班级列表数据
      adminClassData:[],//行政班班级列表数据
      registrationTypesList:[],//学籍类型列表数据



      selectedClass:
      {  
        classType:"", 
        className:"",
        classId:"",
        courseId:"",
      }, //左侧树形数据班级选择的数据

      editPassWordData:{
        dialogShow:false,
        name:"",
        id:"",
        newPassWord:""
      },
      editPassWordDataRules:{
        newPassWord:[
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
        ],
      },//密码重置规则验证
      batchImportData:{
        dialogShow:false,
        selectSchoolYearId:'',//当前的学年
        selectSchoolYearName:'',//当前的学年名称
        selectSchoolYearGradeId:'',//当前的年级id
        selectSchoolYearGradeCode:'',//当前的年级code
        selectSchoolYearGradeName:'',//当前的年级名称
        schoolClassType:'0',//0-行政班 1-教学班  默认行政班
        checkCourseList:[],//选择的课程
        isOverGrade:true, //是否覆盖
        excelUrl:"",
        fileName:"",//文件名
      },
      batchImportDataRules:{
        excelUrl:[
          {required: true, message: '请上传文件', trigger: 'blur'}
        ]
      },
      templeteDownLoad:{
        dialogShow:false,
        classType:"",
        schoolClassType:0,
      },
      templeteDownLoadRules:{
        excelUrl:[
          {required: true, message: '请上传文件', trigger: 'blur'}
        ]
      },
      uploadExcel:[], //上传列表
      pageInfo:{
        total:0,
        pageSize:20,
        pageNum:1,
      },
      //教学班科目
      teachingClassSubjectData:[],//教学班科目数据
      teachingClassArr:[],//添加学生选择教学班级
      manaClassArr:[], //添加学生选择行政班级
      registrationTypeData:[],//学籍类型
      checkedCities: [],
      checkedCities1: [],
      popoverVisible:false,
      activeNames:[],
      gridData: [],

  
      courseDataInfo:[],
      isSubmitting:false,
      tableHead:[],
      
      
      loading: false,//表格加载loading
      buttonLoading:false,//按钮加载loading

      expandedKeys:[],//当前展开的节点key数据
      savedExpandedKeys:[],//保存的展开的状态
      defaultExKey:['-1'],
      mainHeight:0,
      tableBodyWrapper: null,
      observer:null,
      // 防抖函数
      debouncedUpdateMainHeight: this.debounce(this.updateMainHeight, 100),
      timer: null,
      isActive: false,

      tableData:[],//表格数据
      originalTableData: [], // 原始数据
      tableKey:0,//table刷新key
      tableLoading:false,//加载动画
      tableColumn:[],//table动态列数据
      classTreeData:[],//班级树数据
      selectSchoolYearList:[],//选择学年的列表
      selectGradeYearList:[],//选择年级的列表
      selectSchoolYearId:'',//学年Id
      selectSchoolYearName:'',//学年名称
      selectSchoolYearGradeId:'',//年级Id
      selectSchoolYearGradeCode:'',//年级Code
      selectSchoolYearGradeName:'',//年级名称

      selectNodeId:'-1',//选择的节点id
      selectClassId:'',//选择的班点id
      selectCourseCode:'',//选择的教学班code
      selectExportFlag:'',//选择的节点的导出标识
      exportFlag:'',//导出标识

      treeHeight:0,//年级树高度
      tableHeight:0,//表格高度
      columns: [
        // { prop: 'studentRegistrationCode', title: '账号', },
        { prop: 'studentUserCode', title: '学号', },
        { prop: 'userName', title: '姓名', width: 70,},
        { prop: 'studentExamCode', title: '考号', },
        { prop: 'studentRegistrationType', title: '学籍类型', },
        { prop: 'schoolClassName', title: '行政班', }
      ],
      importData:[
        {
          studentRegistrationCode: '',
          studentUserCode:'123456789',
          userName:'学生姓名',
          studentExamCode:'',
          studentRegistrationType:'',
          schoolClassName:'行政班名称',
          teachClassName: '教学班名称',
        },
      ],

      importTableKey:0,

      idCounter:0,//初始化全局唯一id计数器
      unwatchHover: null,
      selectedNode: null,
      hoveredNode: null,
      dragEnabled: false,

            treeItem: {},
            isTooltipDisabled: false

    }
  },
  computed:{
      computedTableData()
      {
        
        const tableData = this.tableData;
        const {pageSize,pageNum}=this.pageInfo;
        
        // if(this.keyWord) {
        //   return this.tableData.filter(student=>{
        //     return (
        //       student.studentName.toLowerCase().includes(this.keyWord.toLowerCase()) ||
        //       student.studentCode.toLowerCase().includes(this.keyWord.toLowerCase())
        //     );
        //   })
        //   console.log()
        // } else {
          const start = (pageNum - 1) * pageSize;
          const end = start+pageSize;
          return tableData.slice(start,end);
        // }
        
      },//学生表格数据
  },
  mounted(){
    this.GetClassListTree();//获取班级列表树结构
    // this.GetOlnyClassListTree();//获取班级树结构数据
    // this.GetSchoolAllCourse();//获取教学班所有科目
    this.SetTableHeight(); //设置表格高度
    window.addEventListener("resize", this.HandleResize); //监听窗口大小变化


    // 监听鼠标悬停事件
    const treeEl = this.$refs.treeRef.$el;
    treeEl.addEventListener('mouseenter', (e) => {
      const nodeEl = e.target.closest('.el-tree-node');
      if (nodeEl) {
        const nodeKey = nodeEl.getAttribute('data-node-key');
        if (nodeKey) {
          const node = this.$refs.treeRef.getNode(nodeKey);
          if (node) node.isHover = true;
        }
      }
    });
    
    treeEl.addEventListener('mouseleave', (e) => {
      const nodeEl = e.target.closest('.el-tree-node');
      if (nodeEl) {
        const nodeKey = nodeEl.getAttribute('data-node-key');
        if (nodeKey) {
          const node = this.$refs.treeRef.getNode(nodeKey);
          if (node) node.isHover = false;
        }
      }
    });
  },
  beforeDestroy() 
  {
    // 组件销毁移除监听 防止内存泄漏
    window.removeEventListener("resize", this.HandleResize);
  },
  methods:{

      //搜索学生
      GetSearchStudent()
      {
        const keyword = this.keyWord.trim();

        if(!keyword) {
          this.pageInfo.pageNum = 1;
          this.tableData = [...this.originalTableData];//恢复原始数据
          this.pageInfo.total = parseInt(this.originalTableData.length)
        } else {

          this.pageInfo.pageNum = 1
           // 前端过滤逻辑
          const filteredData = this.originalTableData.filter(item => {
            // 匹配字段：姓名、账号
            const nameMatch = item.studentName?.includes(keyword);       // 姓名
            const codeMatch = item.studentCode?.includes(keyword); // 学号
            // const classNameMatch = item.className?.includes(keyword);         // 班级

            return nameMatch || codeMatch;
          });
          this.tableData = filteredData;
          this.pageInfo.total = parseInt(this.tableData.length)
        }
        
        // this.GetTranscriptData();//重新加载表格数据
        //前端搜索
      },
      //加载节点
      LoadNode(node, resolve) 
      {
        // if (node.level === 0) {
        //   return resolve([{ id: 1, label: 'Root' }]);
        // }
        // // 模拟异步请求
        // setTimeout(() => {
        //   const data = [
            
        //   ];
        //   resolve(data);
        // }, 500);
      },
      GetSelectNewData(node, id) {
        if (!node || !Array.isArray(node)) {
          return null
        }
        for (let item of node){
          if(item.classId == id) {
            return item
          }
          if(item.childClassTrees && item.childClassTrees.length > 0) {
            const found = this.GetSelectNewData(item.childClassTrees, id)
            if(found) {
              return found
            }
          }
        }
        return null
      },
      // 监听窗口大小变化，重新计算表格高度 使用节流防止频繁改变窗口大小导致计算量过大而页面卡顿
      HandleResize: throttle(function () {
        this.SetTableHeight();
      }, 500), // 节流 500 毫秒内最多执行一次
      //设置表格高度
      SetTableHeight() 
      {
          let windowViewHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
          this.$nextTick(() => {
              this.treeHeight = windowViewHeight - 226;//60+20 + 20 +26+20+20+60
              this.tableHeight = windowViewHeight - 270;
          });
      },
      handleDrop(draggingNode, dropNode, dropType) {
        console.log('tree drop draggingNode: ', draggingNode);
        console.log('tree drop dropNode: ', dropNode);
        console.log('tree drop dropType: ', dropType);
        // 排序班级所在节点排序后list
        let arr = dropNode.parent.data.childClassTrees.map(item => item.classId)
        this.$api.user.moveClassSort({ classIds: arr })

      },
      allowDrop(draggingNode, dropNode, position) {
        // console.log("拖拽事件",draggingNode);
        // console.log("拖拽事件",dropNode);
        // console.log("拖拽事件",position);

        if(draggingNode.parent !== dropNode.parent) {
          return false
        }
        if(position === 'inner') {
          return false
        }
        if (dropNode && !dropNode.data.classCode) {
          return false
        }
        if(!dropNode || !dropNode.parent) {
          return false
        }
        return true
      },
      // treeNodeClick(data) {
      //   console.log(data)
      //   this.treeItem.isSelect = false;
      //   this.$set(data, 'isSelect', !data.isSelect);
      //   this.treeItem = data;
      // },
    // 树形数据拖拽 方法  结束

    //递归方法 为树节点添加customlabel 字段
    AddCustomLabelToTreeNodes(treeData)
    {
      if(treeData && treeData.length>0)
      {
        treeData.forEach((item)=>{
          // // 添加 customLabel 字段，这里假设 customLabel 的值来源于 className 字段 和人数
          // item.id=`node_${this.idCounter++}`;;//添加唯一节点id
          // console.log("打印item",item);
          // if(item.pcClassStudentVOS.length>0)
          if(item.studentSize)
          {
            item.customLabel = item.className +'(' +item.studentSize+'人)';
          }
          else
          {
            item.customLabel = item.className +'(0人)';
          }
          // 如果节点有子节点，递归调用
          if (item.childClassTrees && item.childClassTrees.length > 0) {
            this.AddCustomLabelToTreeNodes(item.childClassTrees);
          }
        });
      }
    },


    //只获取所有班级树结构
    GetClassListTree()
    {
      let param={
        schoolYearGradeId:this.selectSchoolYearGradeId,//学年下的年级ID
        schoolYearId:this.selectSchoolYearId,//学年ID
        // classId:'',//班级id
        // courseCode:'',//科目code
        // exportFlag:false,//查询某个节点下的学生标识
      };

      this.$api.user.getOlnyClassListTree(param).then((res)=>{
        console.log("打印班级列表只有树结构的数据",res);
        if(res.code == 200 && res.data!=null)
        {
          if(res.data.pcClassTreeVO)
          {
            this.classTreeData =  [res.data.pcClassTreeVO];
            // //为树节点添加customLabel字段
            this.AddCustomLabelToTreeNodes(this.classTreeData);
            if(this.selectClassId=='')
            {
              this.selectClassId=this.classTreeData[0].classId || '';//选择的班级节点id
              this.selectCourseCode=this.classTreeData[0].courseCode || '';//选择的教学班code
              this.selectExportFlag=this.classTreeData[0].exportFlag;//选择的节点的导出标识
            } else {
              const newSelectClass = this.GetSelectNewData(this.classTreeData, this.selectClassId)
              if(newSelectClass) {
                this.treeItem = newSelectClass
                this.selectedClass = newSelectClass
              } else {
                this.treeItem = {}
                this.selectedClass = {}
              }
            }
          }
          
          // this.tableData=res.data.pcClassTreeVO.pcClassStudentVOS || [];
          // this.tableLoading=false;
          // this.selectedClass=res.data.pcClassTreeVO;//选择的树节点数据

          //获取学年的数据
          if(res.data.pcSchoolYearVOS)
          {
            this.selectSchoolYearList = res.data.pcSchoolYearVOS || [];
            this.selectSchoolYearId=res.data.schoolYearId;
            this.selectSchoolYearGradeId=res.data.schoolYearGradeId;
            const selectedSchoolYear= this.selectSchoolYearList.find(year => year.id === this.selectSchoolYearId);
            this.selectSchoolYearName = selectedSchoolYear.schoolYearName;
            this.selectGradeYearList = selectedSchoolYear.schoolYearGradeVOS || [];
            
            const selectedSchoolYearGrade=this.selectGradeYearList.find(grade => grade.id===this.selectSchoolYearGradeId);
            this.selectSchoolYearGradeCode = selectedSchoolYearGrade.gradeCode || '';
            this.selectSchoolYearGradeName = selectedSchoolYearGrade.gradeName || '';
            this.GetAddStudentSelectList();//获取新增学生时的下拉数据
          }

          //获取新增班级的时候下拉弹窗选择的教学科目数据
          if(res.data.pcGradeCourseVOS)
          {
            this.teachingClassSubjectData = res.data.pcGradeCourseVOS || [];

            console.log("打印获取新增班级的时候下拉弹窗选择的教学科目数据",this.teachingClassSubjectData);
          }
          console.log("打印选择的selectNodeId",this.selectNodeId);
          this.$nextTick(() => {
            this.$refs.treeRef.setCurrentKey(this.selectNodeId);
            this.defaultExKey=['-1'];
          });
          this.GetStudentListByNode();
          
        }
      })
    },

    //根据节点获取对应的学生信息数据
    GetStudentListByNode()
    {
      let param={
        schoolYearGradeId:this.selectSchoolYearGradeId,//学年下的年级ID
        schoolYearId:this.selectSchoolYearId,//学年ID
        classId:this.selectClassId,//班级id
        courseCode:this.selectCourseCode,//科目code
        exportFlag:this.selectExportFlag,//查询某个节点下的学生标识
      };
      console.log("打印节点参数",param);
      this.tableLoading=true;
      this.tableData=[];
      this.$api.user.getTreeStudentList(param).then(res=> {
        console.log("获取对应节点下的学生列表",res);
        this.tableLoading=false;
        if(res.code==200)
        {
          this.tableData = res.data.pcClassStudentVOS || [];//学生列表
          this.originalTableData = res.data.pcClassStudentVOS || []
          this.tableColumn=res.data.header || [];//表头
          this.tableKey++;
          // this.pageInfo.pageNum=1;//默认第一页
          this.pageInfo.total=this.tableData.length;
          
        }
      })
    },

    //获取新增学生时的下拉数据
    GetAddStudentSelectList()
    {
      let param={
        schoolYearGradeId:this.selectSchoolYearGradeId,//年级ID
        schoolYearId:this.selectSchoolYearId,//学年ID
      };
      this.$api.user.getAddClassSelectList(param).then((res)=>{
        console.log("打印添加学生时的下拉数据",res);
        if(res.code == 200)
        {
          this.adminClassData = res.data.adminClasses || [];//行政班级
          let teachingList = res.data.teachClasses || [];//教学班科目
          this.registrationTypesList=res.data.registrationTypes || [];//学籍类型下拉列表
          console.log("打印学籍类型list",this.registrationTypesList);
          teachingList.forEach(item=>{
            item.isChecked = false;//是否勾选
            item.selectClassId = "";//选择的行政班级id
          });
          this.teachingClassData=teachingList;
          console.log("打印教学班科目数据",this.teachingClassData);
        }
      })

    },
    //树形节点点击事件
    TreeNodeClick(item)
    {
      console.log("点击了树形节点",item);
      this.treeItem.isSelect = false;
      this.$set(item, 'isSelect', !item.isSelect);
      this.treeItem = item;
      // this.tableData=item.pcClassStudentVOS || [];
      // this.tableColumn=item.header || [];
      // console.log("打印表头数据",this.tableColumn);
      // console.log("打印tableData",this.tableData);
      this.selectedClass=item;//选择的树节点数据
      this.exportFlag=item.exportFlag;//导出的标识
      this.selectNodeId=item.id;//选择的节点id
      this.selectClassId=item.classId || '';//选择的班级节点id
      this.selectCourseCode=item.courseCode || '';//选择的教学班code
      this.selectExportFlag=item.exportFlag;//选择的节点的导出标识
      console.log("打印选择的节点",this.selectNodeId);
      this.pageInfo.pageNum=1;
      this.GetStudentListByNode();
    },

    //节点展开事件
    HandleNodeExpand(data,node)
    {
      if (!this.expandedKeys.includes(node.key)) {
        this.expandedKeys.push(node.key)
      }
      console.log("打印展开的节点key",this.expandedKeys);
    },

    //节点收起事件
    HandleNodeCollapse(data,node)
    {
      const index = this.expandedKeys.indexOf(node.key)
      if (index > -1) {
        this.expandedKeys.splice(index, 1)
      }
    },

    //切换学年
    ChangeSchoolYear()
    {
      
      //切换学年  更新年级数据
      this.selectNodeId='-1';
      const selectedSchoolYear= this.selectSchoolYearList.find(year => year.id === this.selectSchoolYearId);
      this.selectSchoolYearName = selectedSchoolYear.schoolYearName;

      this.selectGradeYearList = selectedSchoolYear.schoolYearGradeVOS || [];
      // console.log("打印学年",this.selectSchoolYearId);
      // console.log("打印之前的年级code",this.selectSchoolYearGradeCode);
      // console.log("打印年级列表",this.selectGradeYearList);
      //根据之前的年级code，获取对应的年级id
      this.selectGradeYearList.forEach(item=>{
        if(item.gradeCode == this.selectSchoolYearGradeCode)
        {
          this.selectSchoolYearGradeId=item.id;
        }
      })
      this.GetClassListTree();//获取树形数据
      this.GetAddStudentSelectList();//获取新增学生时的下拉数据
    },

    //切换年级
    ChangeGradeYear()
    {

      this.selectNodeId='-1';
      this.selectGradeYearList.forEach(item=>{
        
        if(item.id == this.selectSchoolYearGradeId)
        {
          
          this.selectSchoolYearGradeCode=item.gradeCode;
          this.selectSchoolYearGradeName=item.gradeName;
          this.selectSchoolYearGradeId=item.id;
        }
        
      })
      this.GetClassListTree();//获取树形数据
      this.GetAddStudentSelectList();//获取新增学生时的下拉数据
    },

    //搜索学生
    SearchStudent()
    {
      
      if(!this.keyWord)
      {
        //如果为空，恢复原始数据
        this.tableData=this.selectedClass.pcClassStudentVOS || [];
      }
      else
      {
        //使用filter方法进行模糊搜索
        console.log("打印this.selected",this.selectedClass);
        this.tableData=this.selectedClass.pcClassStudentVOS.filter(student=>{
          return (
            student.studentName.toLowerCase().includes(this.keyWord.toLowerCase()) ||
            student.registrationCode.toLowerCase().includes(this.keyWord.toLowerCase())
          );
        })
      }
    },
    //获取序号
    GetIndexNumber(index) 
    {

      let indexCount = (this.pageInfo.pageNum - 1) * this.pageInfo.pageSize + index + 1;
      return indexCount

    },

    //切换班级类型
    ChangeClassType()
    {
      
    },

    //切换科目
    ChangeCourse()
    {
      
      for(var i=0;i<this.teachingClassSubjectData.length;i++)
      {
        if(this.addClassData.courseCode==this.teachingClassSubjectData[i].courseCode)
        {
          this.addClassData.courseName=this.teachingClassSubjectData[i].courseName;
        }
      }
      console.log("打印选择科目",this.addClassData)
    },

    //分页切换
    ChangePage(value)
    {
      this.pageInfo.pageNum=value;
    },

    //设置每页显示数量
    HandleSizeChange(value)
    {
      this.pageInfo.pageSize = value;
    },

    
    //校验学生考号账号学号只能输入数字
    validateNumber(field) 
    {
       
    },

    //获取学生信息
    GetStudentInfo()
    {
      let param={
        // registrationCode:this.editStudentData.registrationCode,//账号
        studentCode:this.editStudentData.studentCode,//学号
        schoolYearId:this.selectSchoolYearId,//学年ID
      };
      this.$api.analysis.getExamStudentByRegistrationCode(param).then(res => {
        console.log("打印根据学生账号获取学生信息返回",res);
        if(res.code==200 && res.data)
        {
          console.log("打印根据学生账号获取学生信息返回",this.editStudentData);
          //注释 新增学生 回显信息   新增只需要回显学籍 姓名 学号 考号
          //1.新增学生的时候，根据账号查询个人信息(不包括班级)
          // 2.回显个人信息(不包括ID，ID需要去掉)
          // 然后提交行了，剩下的我会去判断
          // this.editStudentData.studentId=res.data.studentId;
          this.editStudentData.studentCode=res.data.studentCode;
          this.editStudentData.studentName=res.data.studentName;
          this.editStudentData.examCode=res.data.examCode;

          //根据学籍code去查询 
          let registrationItem=this.registrationTypesList.find(option => option.value === res.data.registrationTypeCode);
          console.log("打印学籍类型",registrationItem);
          if(registrationItem)
          {

            this.editStudentData.registrationTypeName=registrationItem.label;
            this.editStudentData.registrationTypeCode=registrationItem.value;
          }
          else
          {
            this.editStudentData.registrationTypeName="";
            this.editStudentData.registrationTypeCode="";
          }
          // this.editStudentData.adminClassId=res.data.adminClassId;//行政班id

          // console.log("打印编辑学生信息teachingClassData",this.teachingClassData)
          // for(var i=0;i<this.teachingClassData.length;i++)
          // {
          //   this.teachingClassData[i].isChecked=false;
          //   this.teachingClassData[i].selectClassId="";
          //   res.data.classTblVOS.forEach(item=>{

          //     if(item.classCode==this.teachingClassData[i].classCode)
          //     {
          //       //有值 代表选中
          //       this.teachingClassData[i].isChecked=true;
          //       this.teachingClassData[i].selectClassId=item.classId;
          //     }
          //   })
          // }
          console.log("打印编辑学生信息",this.teachingClassData); 
          // this.editStudentData.
        }
      })
    },

    //切换学校类型
    ChangeSchoolClassType()
    {
      // if(this.batchImportData.schoolClassType=='0')
      // {
      //   //切换行政班
      //   this.columns=[
      //     { prop: 'studentRegistrationCode', title: '账号', },
      //     { prop: 'studentUserCode', title: '学号', },
      //     { prop: 'studentExamCode', title: '考号', },
      //     { prop: 'studentRegistrationType', title: '学籍类型', },
      //     { prop: 'userName', title: '姓名', width: 70,},
      //     { prop: 'schoolClassName', title: '行政班', }
      //   ];
      // }
      this.batchImportData.checkCourseList=[];
      if(this.batchImportData.schoolClassType=='1')
      {
        //切换教学班
        this.columns=[
          // { prop: 'studentRegistrationCode', title: '账号', },
          { prop: 'studentUserCode', title: '学号', },
          { prop: 'userName', title: '姓名', width: 70,},
          { prop: 'studentExamCode', title: '考号', },
          { prop: 'studentRegistrationType', title: '学籍类型', },
        ];
      }
      else
      {
        //切换行政班+教学班
        this.columns=[
          // { prop: 'studentRegistrationCode', title: '账号', },
          { prop: 'studentUserCode', title: '学号', },
          { prop: 'userName', title: '姓名', width: 70,},
          { prop: 'studentExamCode', title: '考号', },
          { prop: 'studentRegistrationType', title: '学籍类型', },
          { prop: 'schoolClassName', title: '行政班', }
        ];

      }

      this.importTableKey++;
    },

    //更新动态列的
    UpdateTableColumns() 
    {

      //0 行政班 1 教学班  2  行政班+教学班
      if(this.batchImportData.schoolClassType=='1')
      {
        //切换教学班
        this.columns=[
          // { prop: 'studentRegistrationCode', title: '账号', },
          { prop: 'studentUserCode', title: '学号', },
          { prop: 'userName', title: '姓名', width: 70,},
          { prop: 'studentExamCode', title: '考号', },
          { prop: 'studentRegistrationType', title: '学籍类型', },
        ];
      }
      else
      {
        //切换行政班+教学班
        this.columns=[
          // { prop: 'studentRegistrationCode', title: '账号', },
          { prop: 'studentUserCode', title: '学号', },
          { prop: 'userName', title: '姓名', width: 70,},
          { prop: 'studentExamCode', title: '考号', },
          { prop: 'studentRegistrationType', title: '学籍类型', },
          { prop: 'schoolClassName', title: '行政班', }
        ];

      }
      // // 清空已存在的动态列
      // this.columns=[
      //   { prop: 'studentRegistrationCode', title: '账号', },
      //   { prop: 'studentUserCode', title: '学号', },
      //   { prop: 'studentExamCode', title: '考号', },
      //   { prop: 'username', title: '姓名', width: 70,},

      // ];
      // 根据 courseDataInfo 的顺序添加新的列
      this.teachingClassSubjectData.forEach(courseItem => {
        if (this.batchImportData.checkCourseList?.includes(courseItem.courseName)) {
          this.columns.push({
            prop: 'teachClassName',
            title: courseItem.courseName,
            width: '70',
            align: 'center'
          });
        }
      });
    },
    handleChange(value){
      this.editStudentData.schoolClassName=value;
    },
    
    handleFocus() {
      this.popoverVisible = true;
    },
    handleBlur() {
      setTimeout(() => {
        this.popoverVisible = false;
      }, 200); // 让下拉列表有时间关闭
    },
    handleInput() {
        // 输入时保持弹出框可见
        if(this.editStudentData.queryStydentInfo){
          this.activeNames=[];
          let param = {
            "queryStr":this.editStudentData.queryStydentInfo,
          }
          this.$api.school.getStudentList(param).then((res)=>{
            if(res.code == 200){
                this.gridData = res.data.records;
                if(this.gridData.length>0){
                  this.gridData.forEach(temp => {
                      this.activeNames.push(temp.id);
                      let str;
                      for (let head in temp) {
                        str = this.setStudentData(head,temp);
                      }
                      temp["tags"]=[
                        {name:'平台号:'+temp.platformNumber,type:'info'},
                        {name:'账号:'+temp.studentRegistrationCode,type:'info'},
                        {name:'学号:'+temp.studentRegistrationCode,type:'info'},
                        {name:'考号:'+temp.studentExamCode,type:'info'},
                        {name:'班级:行政'+temp.schoolClassName+str,type:'info'},
                      ]
                  });
                }
                this.popoverVisible = true;
                setTimeout(()=>{
                    let listItems = this.$refs.useHover;
                    listItems.forEach(item => {
                      item.addEventListener('mouseover', () => {
                          item.firstElementChild.firstElementChild.style.color = "#2e64fa";
                          item.firstElementChild.lastElementChild.firstElementChild.style.color="#fff";
                          item.firstElementChild.lastElementChild.firstElementChild.style.borderColor="rgba(46, 100, 250, 1)";
                          item.firstElementChild.lastElementChild.firstElementChild.style.background="rgba(46, 100, 250, 1)";
                          let childElements = item.lastElementChild.querySelectorAll('span')
                          childElements.forEach(element => {
                            element.style.color = '#2e64fa';
                          });
                      });
      
                      item.addEventListener('mouseout', () => {
                        item.firstElementChild.firstElementChild.style.color = "#303133";
                        let childElements = item.lastElementChild.querySelectorAll('span')
                        childElements.forEach(element => {
                          element.style.color = '#909399';
                        });
                        item.firstElementChild.lastElementChild.firstElementChild.style.color="rgba(46, 100, 250, 1)";
                        item.firstElementChild.lastElementChild.firstElementChild.style.borderColor="rgba(46, 100, 250, 1)";
                        item.firstElementChild.lastElementChild.firstElementChild.style.background="#fff";
                      });
                  });
                },500)
            }else{
              this.$message.error(res.msg);
            }
          })
          
      }
        

    },

    selectOption(option) {
      this.editStudentData.queryStydentInfo = option.name;
      this.popoverVisible = false;
    },


    //根据课程名称获取课程code
    GetCourseCodesByNames(courseNames)
    {
      const courseCodes = [];
      courseNames.forEach(name => {
        const course = this.teachingClassSubjectData.find(item => item.courseName === name);
        if (course) {
          courseCodes.push(course.courseCode);
        }
      });
      return courseCodes;
    },

    //批量导入下载模板
    ConfirmtempleteDownLoad()
    {
      let courseCodes='';
      if(this.batchImportData.schoolClassType=='1')
      {
        // console.log("this.batchImportData",this.batchImportData);
        if(this.batchImportData.checkCourseList.length==0)
        {
          this.$message.warning("请选择科目!");
          return
        }
        else
        {
          // console.log("teachingClassSubjectData",this.teachingClassSubjectData);
          let courseCodeList=this.GetCourseCodesByNames(this.batchImportData.checkCourseList);
          // console.log("courseCodeList",courseCodeList);
          courseCodes=courseCodeList.join(',');
        }
      }
      
      let param = {
        classType:this.batchImportData.schoolClassType,//班级类型 0-行政班 1-教学班
        courseCodes:courseCodes,//如果是教学班，此字段必传 字符串
        schoolYearGradeId:this.batchImportData.selectSchoolYearGradeId//学年下的年级ID
      }
      this.$api.user.exportClassStudentTemplate(param).then((res)=>{

          const blob = new Blob([res.data], {
              type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
          });
          const a = document.createElement("a");
          a.href = URL.createObjectURL(blob);
          a.download = decodeURIComponent(res.headers["content-disposition"].split("filename=")[1]);
          a.click();
          URL.revokeObjectURL(a.href);
          a.remove();
      })
    },

    //起始编号验证
    validateClassCodes(rule, value, callback) {
      if (!this.addClassData.startClassNum || !this.addClassData.endClassNum) 
      {
        callback(new Error('起始班级编号和结束班级编号不能为空'));

      } 
      else 
      {
        callback();
      }
    },

    updateMainHeight() {
        let mainElement = document.querySelectorAll('.layout')[0].parentElement;
        let mainElement1 = document.querySelectorAll('.asideStyleTree')[0];  
        let resetElement = document.querySelectorAll('.headerBox')[0].offsetHeight;
        let height=0;
        // 计算主高度
        if (mainElement) {
            this.mainHeight = mainElement.offsetHeight - (6*resetElement);
            height = mainElement.offsetHeight - (3.8*resetElement);
        } else {
            this.mainHeight = window.innerHeight - (6*resetElement);
            height = window.innerHeight - (3.8*resetElement);
        }
        // 动态设置 .el-table__body-wrapper.is-scrolling-none 的高度
        if (this.tableBodyWrapper) {
          if(this.$refs.scrollContainer.$el.querySelector('.vxe-table--body-wrapper.body--wrapper table tbody').innerHTML==''){
            this.$refs.scrollContainer.$el.querySelector('.vxe-table--main-wrapper').style.height = (mainElement.offsetHeight - (4.9*resetElement)) +'px';
          }
          this.tableBodyWrapper.style.maxHeight = this.mainHeight +'px';
          // this.$refs.scrollContainer.$el.querySelector('.vxe-table--empty-placeholder').style.height = this.mainHeight +'px !important';
          mainElement1.style.height = height +'px';
        }
    },
    debounce(func, wait) {
        let timeout;
        return function (...args) {
            const context = this;
            clearTimeout(timeout);
            timeout = setTimeout(() => func.apply(context, args), wait);
        };
    },
    //获取教学班所有科目
    GetSchoolAllCourse()
    {
     
      this.$api.user.getSchoolAllCourse().then((res)=>{
        console.log("打印教学班的所有科目",res);
        if(res.code == 200)
        {
          // this.teachingClassSubjectData = res.data;
        }
      })
    },






    


    //编辑班级确定
    ConfirmClassEdit()
    {
      if(!this.editClassData.className)
      {
        this.$message.error("请输入班级名称");
        return;
      }
      let params =  {
        classId:this.editClassData.classId,
        className:this.editClassData.className,
      }
      this.$api.user.updateClass(params).then((res)=>{
        if(res.code == 200){
          this.$message.success("修改成功");
          this.editClassData.dialogShow = false;
          this.GetClassListTree();
          this.GetAddStudentSelectList();//获取新增学生时的下拉数据
        }else{
          this.$message.error(res.msg);
        }
      })
    },

    //确定新增班级
    ConfirmClassAdd()
    {
      this.$refs["addClassData"].validate((valid) => {
        if (valid) {
          let param={
            "className":this.addClassData.className,// 班级名称
            "classType": this.addClassData.classType,// 班级类型 0-行政班 1-教学班
            "courseCode": this.addClassData.courseCode,// 科目code
            "courseName": this.addClassData.courseName,// 科目名称
            "endClassNum": this.addClassData.endClassNum,//结束编号
            "gradeCode": this.selectSchoolYearGradeCode,//年级code
            "schoolYearGradeId": this.selectSchoolYearGradeId,//学年年级id
            "schoolYearId": this.selectSchoolYearId,//学年id
            "startClassNum": this.addClassData.startClassNum//开始编号
          };
          
          this.$api.user.addClassData(param).then((res)=>{
            if(res.code==200)
            {
              this.addClassData.dialogShow = false;
              console.log("打印新增班级结果",res);
              this.$message.success("添加成功!");
              this.GetClassListTree();
              this.GetAddStudentSelectList();//获取新增学生时的下拉数据
            }
            else
            {
              this.$message.error(res.msg);
            
            }
           
          })
          
        }
      });
      
    },

    //新增班级
    AddClass()
    {
      if(!this.selectSchoolYearId || !this.selectSchoolYearGradeId){
          this.$message.warning('未选择学年和年级！');
          return;
      }
      this.addClassData = {
        dialogShow:true,
        startClassNum:'',//班级开始编号
        endClassNum:"",//班级结束编号
        className:"",//班级名称
        classType:'0',//0-行政班 1-教学班
        courseCode:'',//科目code
        courseName:'',//科目名称
      }
    },

    //编辑班级
    EditClass() {
      console.log("打印选择的班级",this.selectedClass);
      if(this.selectedClass.classId) {
        this.editClassData={
          dialogShow:true,
          className:this.selectedClass.className,
          classId:this.selectedClass.classId
        };
      }
      else
      {
        this.$message.error("请选择一个班级!")
      }
    },

    //删除班级
    DeleteClass()
    {
      console.log("打印this.selectedClass",this.selectedClass);
      if(this.selectedClass.className == '班级名单' || this.selectedClass.className == '')
      {
        this.$message.error("请选择一个班级!")
        return;
      }
      if(this.selectedClass.classId )
      {
        this.isTooltipDisabled = true;
        this.$confirm(`您确定要删除【${this.selectedClass.className}】信息及班级所包含的学生和任课关系，当前删除只删除关系，不会影响用户的登录！`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            customClass:'page_dialog',
          }).then(() => {
            let param={
              id: this.selectedClass.classId
            };
            this.$api.user.deleteClass(param).then((res)=>{
              if(res.code == 200)
              {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
                this.GetClassListTree();//更新树数据
                this.GetAddStudentSelectList();//获取新增学生时的下拉数据
              }
              else
              {
                this.$message({
                  type: 'error',
                  message: '删除失败!'+res.msg
                });
              }
            })
            
          }).catch(() => {
              
          }).finally(() => {
            setTimeout(() => {
              this.isTooltipDisabled = false;
            }, 100);
          })
      }
      else
      {
        this.isTooltipDisabled = true;
        //批量删除班级
        this.$confirm(`您确定要删除【${this.selectedClass.className}】下的所有班级信息吗，当前删除只删除关系，不会影响用户的登录！`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            customClass:'page_dialog',
          }).then(() => {
            console.log("打印this.selectedClass",this.selectedClass);
            let classList=this.selectedClass.childClassTrees || [];
            let classIds=[];
             classList.forEach(item=>{
              classIds.push(item.classId);
            });
            let param={
              ids: classIds
            };
            this.$api.user.batchDeleteClass(param).then((res)=>{
              if(res.code == 200)
              {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
                this.GetClassListTree();//更新树数据
              }
              else
              {
                this.$message({
                  type: 'error',
                  message: '删除失败!'+res.msg
                });
              }
            })
            
          }).catch(() => {
              
          }).finally(() => {
            setTimeout(() => {
              this.isTooltipDisabled = false;
            }, 100);
          })
      }
    },

    //批量导入
    BatchImport()
    {
      // selectSchoolYearId:'',//学年Id
      // selectSchoolYearName:'',//学年名称
      // selectSchoolYearGradeId:'',//年级Id
      // selectSchoolYearGradeCode:'',//年级Code
      // selectSchoolYearGradeName:'',//年级名称
      console.log("打印批量导入数据",this.batchImportData);
      console.log("打印选择selectSchoolYearId",this.selectSchoolYearId);
      console.log("打印选择selectSchoolYearName",this.selectSchoolYearName);
      console.log("打印选择selectSchoolYearGradeId",this.selectSchoolYearGradeId);
      console.log("打印选择selectSchoolYearGradeCode",this.selectSchoolYearGradeCode);
      console.log("打印选择selectSchoolYearGradeName",this.selectSchoolYearGradeName);
      this.batchImportData.selectSchoolYearId=this.selectSchoolYearId;
      this.batchImportData.selectSchoolYearName=this.selectSchoolYearName +'     '+ this.selectSchoolYearGradeName;
      this.batchImportData.selectSchoolYearGradeId=this.selectSchoolYearGradeId;//当前的年级id
      this.batchImportData.selectSchoolYearGradeCode=this.selectSchoolYearGradeCode;//当前的年级code
      this.batchImportData.selectSchoolYearGradeName=this.selectSchoolYearGradeName;//当前的年级名称

      //清空之前的选择
      this.batchImportData.schoolClassType='0';//默认行政班
      this.batchImportData.checkCourseList=[];
      this.ChangeSchoolClassType();
      this.batchImportData.dialogShow=true;
    },


    //新增学生
    AddStudent()
    {
      this.editStudentData={
        dialogShow:true,
        isEdit:false,//是否编辑
        adminClassId:'',//行政班id
        examCode:'',//考号
        registrationCode:'',//账号
        registrationTypeCode:'',//学籍类型CODE
        registrationTypeName:'',//学籍类型名称
        studentCode:'',//学号
        studentId:'',//学生id
        studentName:'',//学生姓名
        teachClassId:'',//教学班id集合
      };
      for(var i=0;i<this.teachingClassData.length;i++)
      {
        
        this.teachingClassData[i].isChecked=false;
        this.teachingClassData[i].selectClassId="";//清空
      }
    },

    //编辑学生
    EditorStudent(item)
    {

      
      console.log("打印编辑学生信息",item); 
      // this.GetAddStudentSelectList();//获取新增学生时的下拉数据
      // console.log("打印选择的selectCourseCode",this.selectCourseCode);
      let registrationTypeName=this.registrationTypesList.find(option => option.value === item.registrationTypeCode)?.label || '';
      // console.log("打印registrationTypeName",this.registrationTypesList);
      this.editStudentData={
        dialogShow:true,
        isEdit:true,//是否编辑
        adminClassId:item.adminClassId,//行政班id
        examCode:item.examCode,//考号
        registrationCode:item.registrationCode,//账号
        registrationTypeCode:item.registrationTypeCode,//学籍类型CODE
        registrationTypeName:registrationTypeName,//学籍类型名称
        studentCode:item.studentCode,//学号
        studentId:item.studentId,//学生id
        studentName:item.studentName,//学生姓名
        teachClassId:item.teachClassId,//教学班id集合
      };
      // console.log("打印editStudentData",this.editStudentData);
      // console.log("打印teachingClassData",this.teachingClassData)
      
      for(var i=0;i<this.teachingClassData.length;i++)
      {
        this.teachingClassData[i].isChecked=false;
        this.teachingClassData[i].selectClassId="";
      }

      if(item.teachClasses)
      {
        item.teachClasses.forEach((classItem,index)=>{
          this.teachingClassData.forEach((courseItem,courseIndex)=>{
            if(courseItem.courseCode==classItem.courseCode)
            {
                //有值 代表选中
              courseItem.isChecked=true;
              courseItem.selectClassId=classItem.classId;
            }
          })
        });
        
      }
      console.log("打印teachingClassData",this.teachingClassData); 
    },

    //删除学生
    DeleteStudent(item)
    {
      // console.log("打印删除学生信息",item);
      // console.log("selectCourseCode",this.selectCourseCode);
      // console.log("selectExportFlag",this.selectExportFlag);
      // console.log("selectClassId",this.selectClassId);
        this.$confirm(`确定要删除   ${item.studentName}(${item.registrationCode})吗?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            customClass:'page_dialog',
        }).then(() => {
            let list=[];
            // console.log("打印this.selectExportFlag",this.selectExportFlag);
            if(this.selectExportFlag=='TEACH')
            {
              //教学班
              if(item.teachClasses)
              {
                item.teachClasses.forEach((classItem,index)=>{
                  list.push(classItem.classId);
                });
              
              }
            }
            else if(this.selectExportFlag=='ADMIN')
            {
              //行政班
              list.push(item.adminClassId);//添加行政班
            }
            else
            {
              //教学班
              if(item.teachClasses)
              {
                item.teachClasses.forEach((classItem,index)=>{
                  list.push(classItem.classId);
                });
              
              }
             
              if(item.adminClassId)
              {
                list.push(item.adminClassId);//添加行政班
              }
            }
            
            console.log("this.exportFlag",this.selectExportFlag);
            console.log("打印删除学生信息",list);

            let param = {
                // adminClassId: item.adminClassId,
                classIds: list,
                studentId: item.studentId
            }
            this.$api.user.removeClassStudent(param).then((res)=>{
                if(res.code == 200)
                {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.GetClassListTree();//更新树数据
                    this.GetStudentListByNode();//跟新学生数据
                }
                else
                {
                    this.$message({
                        type: 'error',
                        message: res.message
                    });
                }
            }).catch()
            
        }).catch(() => {
            //取消         
        });
    },


   //切换教学班勾选
   ChangeTeachingClassCode(item)
   {
      console.log("切换教学班",item);
      if(!item.isChecked)
      {
        item.selectClassId="";
      }
   },


   //切换京籍类型
   ChangeRegistrationTypeCode()
   {
    console.log("打印切换京籍类型事件",this.editStudentData);
    const selectOption=this.registrationTypesList.find(option=>option.value===this.editStudentData.registrationTypeCode);
    console.log("打印切换京籍类型事件",selectOption);
    if (selectOption) 
    {
        this.editStudentData.registrationTypeName = selectOption.label;
    } 
    else 
    {
        this.editStudentData.registrationTypeName = '';
    }
   },

   //确定添加学生
    ConfirmStudentAdd()
    {
      this.$refs["editStudentData"].validate((valid) => {
        if (valid) 
        {
          const teachClassId=[];
          console.log("editStudentData",this.editStudentData);
          
          if(this.editStudentData.adminClassId=='')
          {
            this.$message.error("请选择行政班!");
            return;
          }
          for(var i=0;i<this.teachingClassData.length;i++)
          {
            if(this.teachingClassData[i].isChecked)
            {
              if(this.teachingClassData[i].selectClassId)
              {
                teachClassId.push(this.teachingClassData[i].selectClassId);
              }
              else
              {
                this.$message.error("请选择一个"+this.teachingClassData[i].courseName+"教学班级");
                return
              }
              
            }
          }
          let param ={
            "schoolYearId":this.selectSchoolYearId,//学年id
            "adminClassId": this.editStudentData.adminClassId,//行政班ID
            "examCode": this.editStudentData.examCode,//考号
            "courseCode":this.selectCourseCode,//选择的节点courseCode
            "registrationCode": this.editStudentData.registrationCode,//账号
            "registrationTypeCode": this.editStudentData.registrationTypeCode,//学籍类型CODE registrationTypeCode
            "registrationTypeName": this.editStudentData.registrationTypeName,//学籍类型名称
            "schoolYearGradeId":this.selectSchoolYearGradeId,//学年年级id
            "studentCode": this.editStudentData.studentCode,//学号
            "studentId": this.editStudentData.studentId,//主键ID
            "studentName": this.editStudentData.studentName,//学生姓名
            "teachClassId":teachClassId,//教学班ID集合
            "exportFlag":this.selectExportFlag,//标识
          };
          console.log("打印editStudentData",this.editStudentData);
          console.log("打印编辑或新增学生参数",param);
          console.log("打印编辑或新增学生参数",this.teachingClassData);
          
          this.buttonLoading=true;
          this.$api.user.addClassStudent(param).then(res=> {
            console.log("打印编辑或新增学生返回",res);
            this.buttonLoading=false;
            if(res.code==200)
            {
              this.editStudentData.dialogShow=false;
              this.GetClassListTree();//获取学生列表
              this.$message.success("保存成功");
            }
            else
            {
              this.$message.error(res.msg);
            }
          })
          
        }
      });
    },


    confirmPassWord(){
      this.editPassWordData.dialogShow = false;
      let param = {
        classId:this.editPassWordData.id,
        password:this.editPassWordData.newPassWord,
        semesterId:this.selTermList.value
      }
      // if(){}
      this.$api.school.resetStudentsClassPassWord(param).then((res)=>{
        if(res.code ==200){
          this.$message.success("重置成功");
        }

      }).catch((err)=>{})
      
    },
    // 批量导入
    batchImport(){
      if(!this.selGradeYear.value || !this.selTermList.value){
          this.$message.warning('未选择学年学期！');
          return;
      }
      let selectedOption = this.selTermList.arr.find(option => option.id == this.selTermList.value);
      if (selectedOption) {
          this.batchImportData.className = selectedOption.schoolSemesterName;
      }
      this.checkedCities1=[];
      this.batchImportData.dialogShow = true;
    },
    // 模板下载
    templeteDownLoadData(){
      this.templeteDownLoad.dialogShow = true;
      this.checkedCities=[];
    },
    //取消批量导入
    CancelBatchImport()
    {
      this.batchImportData.dialogShow = false;
      this.batchImportData.fileName="";
    },
    //确定学生批量导入
    ConfirmBatchImport()
    {
      if (this.isSubmitting) return;
      this.isSubmitting = true;
      let formdata = new FormData();
      let classType = this.batchImportData.schoolClassType;
      formdata.append("file",this.$refs.uploadStudents.files[0]);
      formdata.append("overWrite",this.batchImportData.isOverGrade);
      formdata.append("schoolYearGradeId",this.batchImportData.selectSchoolYearGradeId);
      formdata.append("classType",classType);
      console.log("打印选择的科目",this.batchImportData.checkCourseList);

      if(this.batchImportData.schoolClassType==1 || this.batchImportData.schoolClassType==2)
      {
        let courseCodeList=this.GetCourseCodesByNames(this.batchImportData.checkCourseList);
        console.log("打印科目的codelist",courseCodeList);
        formdata.append("courseCode",courseCodeList);
      }
      
      try {
          this.$api.user.importClassStudentList(formdata).then((res)=>{
            console.log("打印导入结果",res);
            this.isSubmitting = false;
          if(res.code == 200)
          {
            this.batchImportData.dialogShow = false;
            this.$message.success("导入成功!");

            //导入成功 清空选择的节点信息
            this.selectedClass='';//选择的树节点数据
            this.exportFlag='';//导出的标识
            this.selectNodeId='-1';//选择的节点id
            this.selectClassId='';//选择的班级节点id
            this.selectCourseCode='';//选择的教学班code
            this.selectExportFlag='';//选择的节点的导出标识
            this.batchImportData.fileName="";
            this.GetClassListTree();//获取班级列表树结构
            this.GetAddStudentSelectList();//获取新增学生时的下拉数据
          }
          else
          {
            let msg=res.msg;
            if(msg.length>50)
            {
              msg=msg.substring(0,50)+"...";
            }
            this.batchImportData.fileName="";
            this.$message.warning(msg);
          }
        })
      } catch (error) {
        
      }finally {
        // 请求完成后重新启用按钮
        // this.isSubmitting = false;
      }
    },


    //批量导出
    BatchExport()
    {
      if(!this.selectSchoolYearGradeId || !this.selectSchoolYearId){
          this.$message.warning('未选择学年学期！');
          return;
      }
      if(this.exportFlag=='')
      {
        this.$message.warning('请选择一个班级！');
        return;
      }
      let param = {
        schoolYearGradeId:this.selectSchoolYearGradeId,//学年下的年级ID
        schoolYearId:this.selectSchoolYearId,//学年ID
        exportFlag:this.exportFlag,//导出标识
        classId:this.selectClassId,//班级id
        courseCode:this.selectCourseCode,//科目code
        
      }
      this.$api.user.exportClassStudentList(param).then((res)=>{
        if(res.status==200)
        {
          console.log("打印导出的结果",res);
          const blob = new Blob([res.data], {
              type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
          });
          // 尝试从 content-disposition 头中提取文件名
          const contentDisposition = res.headers["content-disposition"];
          let filename = "default_filename.xlsx"; // 默认文件名
          if(contentDisposition) 
          {
            const filenameMatch = contentDisposition.match(/filename="?(.+)"?/);
            if (filenameMatch && filenameMatch[1]) 
            {
              filename = decodeURIComponent(filenameMatch[1]);
            }
          }
          const a = document.createElement("a");
          a.href = URL.createObjectURL(blob);
          a.download = filename;
          a.click();
          URL.revokeObjectURL(a.href);
          a.remove();

        }
        
        

          
      })
    },
    //上传文件
    OpenUpload(){
      this.$refs.uploadStudents.value = null;
      this.$refs.uploadStudents.click();
    },
    //上传excel
    uploadChange(){
      this.batchImportData.fileName = this.$refs.uploadStudents.files[0].name;

    },
  },
}
</script>
<style lang="scss" scoped>
.class_container
{
  width: 100%;
  height: calc(100% - 56px);
  display: flex;
  justify-content: space-between;
  .container_left
  {
    width: 200px;
    height: 100%;
    // background-color: red;
  }

  .container_right
  {
    width: calc(100% - 220px);
    height: auto;
    position: relative;
    .class_number {
      position: absolute;
      bottom: 10px;
      left: 0;
    }
  }
}
.tree-label {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .label_name {
    max-width: 125px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
.el-tree-node__content:hover {
  .iconfont.icon_paixu {
    display: block;
  }
}
.iconfont.icon_paixu {
  display: none;
  margin-left: 8px;
}
.node-label_select {
  // background: #e3eeff;
  color: #2e64fa;
}
.el-tree ::v-deep .el-tree-node__content .el-tree-node__expand-icon.is-leaf {
  opacity: 0;
  padding: 0;
  margin-left: -5px;
}
.select_item {
  width: 208px !important;
}
</style>