<template>
    <div class="page_search" ref="page_content">
        <div class="search_content">
            <div class="content_left">
                <el-button  class="tab_button"  @click="ActiveTab('enableUse')" :class="statusPage=='enableUse'?'select_cur':''">启用用户</el-button>
                <el-button  class="tab_button"  @click="ActiveTab('disabledUse')" :class="statusPage=='disabledUse'?'select_cur':''">禁用用户</el-button>
            </div>
        </div>
        <div class="page_jg"></div>
        <div class="search_content">
            <div class="content_left"> 
                <el-select  v-model="enrollmentYear" @change="ChangeYear" placeholder="入学年份" class="select_width">
                    <el-option label="入学年份" value=""></el-option>
                    <el-option
                        v-for="item in enrollmentYearList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>       
                </el-select>
                <el-select  v-model="levelCode"  @change="ChangeLevelCode" placeholder="选择学段" class="select_width">
                    <el-option label="全部学段" value=""></el-option>
                    <el-option
                        v-for="item in levelCodeList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
                <el-select  v-model="registration"  @change="ChangeFilter" placeholder="选择学籍" class="select_width" v-if="registrationList.length>0">
                    <el-option label="全部学籍" value=""></el-option>
                    <el-option
                        v-for="item in registrationList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
                <el-input class="input_width" v-model="keyWord" @input="ChangeFilter"  placeholder="学生姓名、学籍号"> <el-button @click="ChangeFilter" slot="append" icon="el-icon-search"></el-button></el-input>
            </div>
            <div class="content_right">
                <el-button   @click="ResetPassWords()">重置密码</el-button>
                <!-- <el-button size="mini"  @click="bathDisabled">{{ this.statusPage=='enableUse'? '批量禁用':'批量启用' }}</el-button> -->
                <!-- <el-button  >批量导出</el-button> -->
                <!-- <el-tooltip class="item" effect="dark" content="导入的学生密码默认为：学校编号@学生平台号，如：19000@20180101" placement="top">
                    <el-button    v-if="statusPage=='enableUse'">批量导入</el-button>
                </el-tooltip> -->
                <!-- <el-button size="mini"   @click="uploadImage" v-if="statusPage=='enableUse'">上传头像</el-button> -->
                
                <!-- <el-button  class="downTep" >下载模板</el-button> -->
                <!-- <el-button size="mini" type="primary" plain @click="addStudent" v-if="statusPage=='enableUse'">新增学生</el-button> -->
            </div>
        </div>
        <div class="page_jg_16"></div>
        <div class="page_table">
            <el-table ref="studentTable" :data="studentList" border stripe  :height="tableHeight">
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column type="index"  label="序号" :index="GetIndexNumber"  align="center" width="70"></el-table-column>
                <el-table-column prop="headPic" label="头像"  align="center" width="100">
                    <template slot-scope="scope">
                        <img :src="scope.row.headPic" alt=""  v-if="scope.row.headPic">
                        <div v-else>-</div>
                    </template>
                </el-table-column>
              
                <el-table-column prop="registrationCode" label="账号" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <span>{{ scope.row.registrationCode || '-' }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="studentCode" label="学号" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <span>{{ scope.row.studentCode || '-' }}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="studentName" label="姓名" align="center">
                    <template slot-scope="scope">
                        <div>{{ !scope.row.studentName?'-':scope.row.studentName }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="schoolEnrolDate" label="入学年份" align="center">
                    <template slot-scope="scope">
                        <div>{{ !scope.row.schoolEnrolDate?'-':scope.row.schoolEnrolDate }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="levelName" label="学段" align="center">
                    <template slot-scope="scope">
                        <div>{{ !scope.row.levelName?'-':scope.row.levelName }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="registrationTypeName" label="学籍类型" align="center" >
                    <template slot-scope="scope">
                        <div>{{ scope.row.registrationTypeName?scope.row.registrationTypeName:'-' }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="gender" label="性别" align="center">
                    <template slot-scope="scope">
                        <div>
                        {{  scope.row.gender == 1 ? '女' : scope.row.gender == 0 ? '男' : '-' }}
                        </div>
                    </template>
                    </el-table-column>
                <el-table-column  label="邮箱" align="center" >
                    <template slot-scope="scope">
                        <div class="page_table_row_name" :title="scope.row.email">{{ scope.row.email || '-' }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="status" label="状态" align="center">
                    <template slot-scope="scope">
                        <div class="table_row_status">
                            <div :class="statusPage == 'enableUse'?'normal_icon':'abnormal_icon'"></div>&nbsp;{{  statusPage == 'enableUse' ? '启用' : '禁用'}}  
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center"  width="240px">
                    <template slot-scope="scope">
                    <div class="table_row_option">
                        <!-- <el-button  type="text" size="mini"  @click="clearStudentEmail(scope.row)">{{!scope.row.email?'绑定邮箱':'解绑邮箱'}}</el-button> -->
                        <div  class="button_editor"  @click="EditorStudent(scope.row)">编辑</div>
                        <div  class="button_editor"  @click="ResetPassWord(scope.row)">重置密码</div>
                        <div  class="button_editor"  @click="ChangeStudentStatus(scope.row)">{{statusPage=='enableUse'?'禁用':'启用'}}</div>
                        <div  class="button_delete"  @click="DeleteStudent(scope.row)">删除</div>
                    </div>
                    </template>
                </el-table-column>
            </el-table> 
        </div>
        <div class="page_pagination" style=" margin-bottom: 10px;">
            <el-pagination
                @current-change="ChangePage"
                background
                layout="sizes,prev, pager, next"
                @size-change="HandleSizeChange"
                :page-sizes="[20,50,100]"
                :current-page="pageInfo.pageNum"
                :total="pageInfo.total">
            </el-pagination>
        </div>
        <div class="page_dialog">
            <!-- 编辑学生 -->
            <el-dialog title="编辑学生" :visible.sync="editStudentData.dialogShow" width="480px">
                <div class="dialog_center padding_20">
                    <el-form :model="editStudentData" style="flex:1;" label-width="110px" :rules="editStudentDataRules" ref="editStudentData"  class="labelWidth100">
                       
                        <el-form-item label="学籍号：" prop="studentRegistrationId">
                            <el-input v-model="editStudentData.studentRegistrationId" disabled></el-input>
                        </el-form-item>
                        
                        <el-form-item label="姓名：" prop="username">
                            <el-input v-model="editStudentData.username"></el-input>
                        </el-form-item>
                        <el-form-item label="学籍类型：" prop="studentRegistrationTypeName" v-if="editorRegistrationList.length>0">

                            <el-select  v-model="editStudentData.studentRegistrationCode" @change="ChangeStudentRegistrationCode" placeholder="选择学籍"  v-if="editorRegistrationList.length>0">
                                <el-option value="2" label="-"></el-option>
                                <el-option
                                    v-for="item in editorRegistrationList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="性别：" prop="gender">
                            <el-select v-model="editStudentData.gender" placeholder="请选择">
                                <el-option value="2" label="-"></el-option>
                                <el-option value="0" label="男"></el-option>
                                <el-option value="1" 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="ConfirmUpdateStudent()">确 定</el-button>
                </div>
            </el-dialog>
            <!-- 重置密码 -->
            <el-dialog title="重置密码" center  :visible.sync="editPassWordData.dialogShow" width="480px">
                <div class="dialog_center padding_20">
                    <el-form :model="editPassWordData" ref="editPassWordData"  label-width="110px" >
                        <el-form-item label="学生姓名：" prop="studentName" >
                            <el-input :value="editPassWordData.studentName" disabled/>
                        </el-form-item>
                       
                        <el-form-item label="重置方式：">
                            <el-radio-group v-model="useDefault" >
                                <el-radio :label="0">使用新密码</el-radio>
                                <el-radio :label="1">重置为默认密码</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="新密码：" v-if="useDefault==0">
                            <el-input v-model="editPassWordData.randomPassword" />
                        </el-form-item>
                        <el-form-item label="默认密码：" v-if="useDefault==1">
                            <div class="default_pass">
                                <el-input value="******" disabled/>
                                <p>默认密码：学校编号@学生学籍号</p>
                            </div>
                            
                        </el-form-item>
                        
                    </el-form>
                </div>
                <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" custom-class="editCourseDialog1">
                <el-form :model="batchImportData"  :rules="batchImportDataRules" ref="batchImportData"  class="labelWidth120">
                <el-form-item label="当前学年学期">
                    <el-input :value="batchImportData.className" disabled/>
                </el-form-item>
                <el-form-item label="是否年级覆盖" prop="isOverGrade">
                    <el-switch v-model="batchImportData.isOverGrade"></el-switch>
                </el-form-item>
                <el-form-item label="选择excel文件" prop="excelUrl">
                    <el-button type="primary" icon="el-icon-upload2" size="small"  >点击上传</el-button>
                   
                    <el-input  v-model="batchImportData.fileName" v-show="batchImportData.fileName" size="mini" class="inputStyle"></el-input>
                    <i class="el-icon-success" v-show="batchImportData.fileName"></i>
                    <!-- <span style="color:#666;padding-left:5px; font-size:12px;line-height:16px;">{{batchImportData.fileName }}</span> -->
                    <input type="file" ref="uploadStudents"  enctype="multipart/form-data" style="display:none;"/>
                </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button size="small" @click="batchImportData.dialogShow = false">取 消</el-button>
                <el-button size="small" type="primary" :disabled="isSubmitting"><i class="el-icon-loading" v-if="isSubmitting"></i>确 定</el-button>
                </div>
            </el-dialog>
            <!-- 批量禁用 -->
            <el-dialog :title="this.statusPage=='enableUse'?'批量禁用':'批量启用'" center  :visible.sync="batchDisabledData.dialogShow" custom-class="editCourseDialog1">
                <el-form :model="batchDisabledData"  ref="batchDisabledData" class="labelWidth80">
                <el-form-item label="学年:">
                    <el-select :popper-append-to-body="false" :value="selGradeYear.value"  placeholder="请选择">
                        <el-option
                        v-for="item in selGradeYear.arr"
                        :key="item.id"
                        :label="item.schoolYearName"
                        :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="学期:">
                    <el-select :popper-append-to-body="false" :value="selTermList.value"  placeholder="请选择">
                        <el-option
                        v-for="item in selTermList.arr"
                        :key="item.id"
                        :label="item.gradeName"
                        :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="禁用:" prop="isOverGrade">
                    <el-radio-group v-model="radioDisabled">
                        <el-radio :label="0">禁用</el-radio>
                        <el-radio :label="1">启用</el-radio>
                    </el-radio-group>
                </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button size="small" @click="batchDisabledData.dialogShow = false">取 消</el-button>
                    <el-button size="small" type="primary" >确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
  </template>
  <script>
import { throttle } from "lodash";
import { encrypt } from "@/utils/jsencrypt";
  export default{
    name:"studentName",
    data(){
      return {

        enrollmentYear:'',//入学年份
        enrollmentYearList:[],//入学年份列表
        levelCode:'',//学段
        levelCodeList:[],//学段列表
        registration:'',//京籍
        registrationList:[],//京籍列表
        editorRegistrationList:[],//编辑的学籍列表
        keyWord:'',//姓名或者学籍号

        selGradeYear:{
            value:"",
            name:"",
            arr:[]
        },
        selTermList:{
            value:"",
            name:"",
            schoolGradeId:"",
            arr:[]
        },

        studentList:[],//学生名单列表
        editStudentData:{
            "dialogShow":false,
            "title":"新增学生",
            "isEdit":false,
            "gender": '0',
            "studentRegistrationCode": "",//学籍类型code
            "username":"",
            "studentRegistrationTypeName": "",//学籍类型名称
            "email": "",
            "id":"",
            "studentId":"",//学生id
            "studentRegistrationId":""//账号
        },
        editStudentDataRules: {
           

            studentUserName: [
                { required: true, message: '请输入姓名', trigger: 'blur' },
            ],
            studentRegistrationTypeName: [
                { required: false, message: '', trigger: 'blur' },
            ],
            gender: [
                { required: false, message: '', trigger: 'blur' },
            ],
        },
        typeNameOptions:[],
        genderOptions:[
            {
                value: 2,
                label: '-'
            },
            {
                value: 0,
                label: '男'
            },
            {
                value: 1,
                label: '女'
            }],
        editPassWordData:{
            dialogShow:false,
            id:"",//用户id
            studentId:'',//学生id
            studentName:"",//学生姓名
            randomPassword:"",//新密码
           
        },//重置密码
        editPassWordDataRules:{
            randomPassword:[
                { required: true, message: '请输入新密码', trigger: 'blur' },
                { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
            ],
        },
        batchImportData:{
            dialogShow:false,
            classType:"",
            isOverGrade:true, //是否覆盖
            excelUrl:"",
            fileName:"",//文件名
            className:"",
        },
        bindEmailData:{
            dialogShow:false,
        },
        batchImportDataRules:{
            // excelUrl:[
            // {required: true, message: '请上传文件', trigger: 'blur'}
            // ]
        },
        batchDisabledData:{
            dialogShow:false,
        },
        pageInfo:{
            total:0,
            pageSize:20,
            pageNum:1,
        },
        radioDisabled:0,
        useDefault:1,//使用默认密码 0-否 1-是

       
        statusPage:"enableUse",
        isEdit:"",
  

        isSubmitting:false,
        loading: false,
        tableHeight:0,


      }
    },
    mounted(){
        this.SetTableHeight(); //设置表格高度
        window.addEventListener("resize", this.HandleResize); //监听窗口大小变化
        this.GetStudentList();//获取学生名单列表
        this.GetSelectLevelTypeList();//获取用户筛选列表
        
    },
    beforeDestroy() {
        // 组件销毁移除监听 防止内存泄漏
        window.removeEventListener("resize", this.HandleResize);
    },
    methods:{

        //获取序号
        GetIndexNumber(index) 
        {
          
            let indexCount=(this.pageInfo.pageNum - 1) * this.pageInfo.pageSize + index +1 ;
            return indexCount   
            
        },

        // 监听窗口大小变化，重新计算表格高度 使用节流防止频繁改变窗口大小导致计算量过大而页面卡顿
        HandleResize: throttle(function () {
            this.SetTableHeight();
        }, 500), // 节流 500 毫秒内最多执行一次
        //设置表格高度
        SetTableHeight() 
        {
            let windowViewHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
            
            this.$nextTick(() => {
                this.tableHeight = windowViewHeight - 365;
            });
        },

        //获取学生列表名单
        GetStudentList()
        {
            let param = {
                status:this.statusPage=='disabledUse'?0:1,//启用状态 状态 0=禁用 1=启用
                accountName:this.keyWord,//用户名称
                levelCode:this.levelCode,//学段code
                schoolEnrolDate:this.enrollmentYear,//入学年份
                registrationTypeCode:this.registration,//学籍类型
                pageNum: this.pageInfo.pageNum,
                pageSize: this.pageInfo.pageSize,
            };

            this.$api.user.getUserStudentList(param).then(res=>{
                if(res.code==200)
                {
                    this.studentList = res.data.records || [];
                    this.pageInfo.total = parseInt(res.data.total);
                }

            })
        },

        //切换入学年份
        ChangeYear()
        {
            this.enrollmentYearList.forEach(item=>{
                if(item.value==this.enrollmentYear)
                {
                    this.levelCodeList=item.child || [];
                    // this.levelCode=this.levelCodeList[0].value;
                    
                }
            })
            this.ChangeLevelCode();
            this.ChangeFilter();
        },

        //切换学段
        ChangeLevelCode()
        {
            this.levelCodeList.forEach(item=>{
                if(item.value==this.levelCode)
                {
                    this.registrationList=item.child || [];
                    if(this.registrationList.length>0)
                    {
                        // this.registration=this.registrationList[0].value;
                         this.registration='';
                    }
                    else
                    {
                        this.registration='';
                    }
                    
                }
            })
            this.ChangeFilter();
        },

        //筛选条件更新 重新更新列表数据
        ChangeFilter()
        {
            this.pageInfo.pageNum=1;//初始化分页
            this.GetStudentList();//获取学生列表
        },

        //获取筛选数据列表
        GetSelectLevelTypeList()
        {
            this.$api.user.getSelectLevelTypeList().then(res=>{
                if(res.code==200)
                {
                    this.enrollmentYearList = res.data || [];//入学年份
                    // this.registrationList=res.data.registrationTypes || [];//学籍列表
                    // console.log("打印学籍列表",this.registrationList);
                    // this.levelCodeList=res.data[0].child || [];//学段列表
                    let list=[];
                    res.data.forEach(item=>{
                        item.child.forEach(childItem=>{
                            
                            list.push(childItem);
                        })
                    });
                    let uniqueList = [...new Set(list.map(item => item.value))].map(value => {
                        return list.find(item => item.value === value);
                    });
                    uniqueList.sort((a, b) => a.value.localeCompare(b.value));
                    this.levelCodeList=uniqueList;

                }

            })
        },

        //tab切换  启用 和禁用
        ActiveTab(item){
            this.statusPage = item;
            this.loading=false;
            this.studentList=[];
            this.GetStudentList();
        },


        //页面分页切换改变
        ChangePage(e){
            this.pageInfo.pageNum = e;
            this.GetStudentList();
            this.TableScrollTop();
        },

        //页面分页切换改变
        HandleSizeChange(val)
        {
            this.pageInfo.pageSize = val;
            this.GetStudentList();
            this.TableScrollTop();
        },
        //重置表格滚动条
        TableScrollTop()
        {

            this.$nextTick(() => {
                if (this.$refs.studentTable) {
                const tableBody = this.$refs.studentTable.$el.querySelector('.el-table__body-wrapper');
                if (tableBody) {
                    tableBody.scrollTop = 0;
                }
                } 
            });
        },

        //编辑学生
        EditorStudent(item)
        {
            this.editStudentData.dialogShow = true;   
            this.editStudentData.studentRegistrationId=item.registrationCode;//账号     
            this.editStudentData.username=item.studentName;//姓名
            this.editStudentData.studentRegistrationCode=item.registrationTypeCode || '';
            this.editStudentData.studentRegistrationTypeName=item.registrationTypeName || '';
            this.editStudentData.gender=item.gender.toString() || '';
            this.editStudentData.id=item.id;//用户id
            this.editStudentData.studentId=item.studentId;
            const yearItem = this.enrollmentYearList.find(a => a.value === item.schoolEnrolDate);

            if (yearItem) {
                const levelCodeList = yearItem.child || [];

                const levelItem = levelCodeList.find(b => b.value == item.levelCode);
                if (levelItem) {
                    this.editorRegistrationList = levelItem.child || [];
                }
            }
        },
        //重置密码
        ResetPassWord(item)
        {
           
           this.editPassWordData={
                dialogShow:true,
                id:item.id,//用户id
                studentId:item.studentId,//学生id
                studentName:item.studentName,//学生姓名
                randomPassword:"",//新密码
           }
        },

        //批量重置密码
        ResetPassWords()
        {
            
        },
        //禁用或者启用学生账号
        ChangeStudentStatus(item)
        {
            let text=this.statusPage=='enableUse'?'禁用':'启用';
            this.$confirm(`确认要${text}用户   ${item.studentName}(${item.registrationCode}) 吗?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                customClass:'page_dialog',
            }).then(() => {
                let param = {
                    ids:[item.id],
                    status:this.statusPage=='enableUse'?0:1//状态 1-启用 0-禁用
                };
                this.$api.user.updateUserEnable(param).then((res)=>{
                    if(res.code == 200){
                    this.$message({
                        type: 'success',
                        message: text+'成功!'
                    });
                    this.GetStudentList();
                }
                })
                
            }).catch(() => {
                //取消         
            });

        },
        //切换学生学籍类型
        ChangeStudentRegistrationCode()
        {
            this.editStudentData.studentRegistrationTypeName=this.editorRegistrationList.find(option=>option.value===this.editStudentData.studentRegistrationCode).label;
        },
        //确定编辑学生信息
        ConfirmUpdateStudent()
        {
            let param={
                // "email": "",//邮箱
                "gender": this.editStudentData.gender,//性别 2-未知，0-男，1-女
                "id": this.editStudentData.id,//id
                // "levelCode": 0,//学段code
                // "levelName": "",//学段名称
                "registrationTypeCode": this.editStudentData.studentRegistrationCode,//学籍类型code
                "registrationTypeName": this.editStudentData.studentRegistrationTypeName,//学籍类型名称
                // "schoolEnrolDate": "",//入学年份
                "studentId": this.editStudentData.studentId,//学生id
                "studentName": this.editStudentData.username//学生姓名
            };
            this.$api.user.updateUserStudent(param).then(res=> {
                if(res.code==200)
                {
                    this.editStudentData.dialogShow=false;
                    this.GetStudentList();//获取学生列表
                    this.$message.success("保存成功");
                }

            })
        },

        //删除学生
        DeleteStudent(item){
            this.$confirm(`确定要删除   ${item.studentName}(${item.registrationCode})吗?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                customClass:'page_dialog',
            }).then(() => {
                let param = {
                    id:item.id//用户id
                }
                this.$api.user.deleteUserStudent(param).then((res)=>{
                    if(res.code == 200){
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.GetStudentList();//获取学生列表
                    }
                }).catch()
                
            }).catch(() => {
                //取消         
            });
        },

    



        
        //解绑和绑定邮箱
        clearStudentEmail(student){
            if(!student.email){
                this.$prompt('请输入邮箱', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
                    inputErrorMessage: '邮箱格式不正确'
                    }).then(({ value }) => {
                        let param={
                                "email": value,
                                "userId": student.id
                            }
                        this.$api.school.batchBindUserEmail([param]).then((res)=>{
                            if(res.code == 200){
                                if(res.data.length>0){
                                    this.$message.warning("该邮箱已被其他用户绑定过！")
                                }else{
                                    this.$message.success("绑定成功！")
                                }
                                this.loading=false;
                                this.resetPageData();
                                this.studentList=[];
                                this.getSchoolUserInfos(this.statusPage);
                            }
                        }).catch((err)=>{})
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '取消输入'
                        });       
                    });
            }else{
                this.$confirm(`确认要解绑学生${student.username}的邮箱绑定信息吗?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    customClass:'page_dialog',
                }).then(() => {
                    let param = {ids:[student.id]}
                    this.$api.school.batchUnBindUserEmail(param).then((res)=>{
                        if(res.code == 200){
                            this.$message.success("解绑成功！")
                            this.loading=false;
                            this.resetPageData();
                            this.studentList=[];
                            this.getSchoolUserInfos(this.statusPage);
                        }
                    }).catch((err)=>{})
                    
                }).catch(() => {
                    //取消         
                });
            }
        },
        
        
        //确认重置密码
        ConfirmPassWord()
        {
            if(this.useDefault==0)
            {
                let pass=this.editPassWordData.randomPassword.trim();
                if(pass.length<6)
                {
                    this.$message({
                        type: 'error',
                        message:"新密码不能少于6位!"
                    });
                    return;
                }
            }
            
            

            let param = {
                ids: [this.editPassWordData.id],
                password: encrypt(this.editPassWordData.randomPassword.trim()),
                useDefault: this.useDefault
            }
            this.$api.user.resetPassWord(param).then(res=>{
                if(res.code==200)
                {
                    this.$message({
                        type: 'success',
                        message:"重置成功!"
                    });
                    this.editPassWordData.dialogShow = false;
                }

            })
            
        },


    },
  }
  </script>
  <style lang="scss" scoped>
    
  </style>