<template>
 <!-- 未扫描  缺考  已上传  列表页面  -->
  <div class="content_main">
    <div class="scan_content_left">
        <div class="right_tab_underline" v-if="scanState == 1">
            
            <div class="tab_item" :class="showUploadReview == 0?'tab_item_cur':''" @click="ChangeUploadShow(0)" >
                考生详情
            </div>
            <div class="tab_item" :class="showUploadReview == 1?'tab_item_cur':''" @click="ChangeUploadShow(1)">
                复查识别
            </div>
        </div>
        <div class="right_user_tab" v-else>
            <!-- 按考场 1  按班级 2 -->
            <div class="tab_system_user" :class="activeName == 1?'select_cur':''" @click="ChangeRoomType(1)" >
                按考场
            </div>
            <div class="tab_temporay_user" :class="activeName == 2?'select_cur':''" @click="ChangeRoomType(2)">
                按班级
            </div>
        </div>
        <div class="page_jg_20"></div>
        <div class="left_tree page_tree" v-if="markType==0 || showUploadReview==0">
            <el-tree  :highlight-current="true" class="filter-tree" :data="treeData" default-expand-all :props="defaultProps" :default-expanded-keys="defaultExKey" node-key="id" ref="classTree" @node-click="TreeHandleNodeClick"></el-tree>

        </div>
        <div v-else class="left_question">
            <!-- 手阅卡下拉列表 -->
            <div class="question_item" :class="reviewQuestionIndex=='objectiveIndex'?'question_item_cur':''" @click="ReviewObject()">
                客观题
            </div>
            <div class="question_item" :class="reviewQuestionIndex==item.subjectiveIndex?'question_item_cur':''" v-for="(item,index) in reviewQuestionList" :key="index" @click="ReviewChangeQuestion(item)">
                <div>  {{item.subjectiveName}} </div>
                <div>  {{item.subjectiveScore}}分 </div>
            </div>
        </div>
    </div>
    <!-- 列表界面 -->
    <div class="scan_content_right" v-if="showUploadReview == 0">
        <div class="right_search">
            <div class="search_input">
                <el-input type="text" v-model="keyWord" placeholder="学生姓名、考号" >
                    <el-button slot="append" icon="el-icon-search" ></el-button>
                </el-input>
            </div>
            <div class="search_button el_button">
                <el-button class="refresh_btn" @click="RefreshList()" ><i class="iconfont icon_shuaxin"></i>刷新</el-button>
                <el-button class="marke_miss_exam_btn" @click="AllMarkedMiss()" v-if="scanState == 0" >全部标缺</el-button>
                <el-button  class="refresh_btn" @click="ExportData()"><i class="iconfont icon_export" style="margin-right: 5px;"></i>导出</el-button>
                <el-button style="padding:0px 10px;"  @click="OpenReldentify()" v-if="scanState == 1">重新识别客观题</el-button>
                <el-button :class="multiSelection.length>0?'marke_normal_btn':'marke_normal_btn_disable'" @click="MarkStudent(0)"  v-if="scanState == 2" :disabled="!multiSelection.length">标记为正常</el-button>
                <el-button :class="multiSelection.length>0?'marke_anomaly_btn':'marke_anomaly_btn_disable'" @click="MarkCardNumberAbnormal()"  v-if="scanState == 1" :disabled="!multiSelection.length>0">标记为异常</el-button>
                <el-button :class="multiSelection.length>0?'delete_btn':'delete_btn_disable'"  @click="MarkStudent(4)" v-if="scanState == 1" :disabled=" !multiSelection.length"> 批量删除</el-button>
            </div>
        </div>
        <div class="page_table table_row_42" style="width: calc(100% - 40px); margin: auto;" v-loading="isLoading" element-loading-text="加载中……" element-loading-spinner="el-icon-loading" element-loading-background="#ffffff">
            <el-table ref="popupTable" :key="scanState" @select-all="SelectCheckAll" @selection-change="HandleSelectionChange"  :data="studentTableData" :height="tableHeight" stripe >
                <el-table-column align="center" 
                        
                    type="selection" width="50" v-if="scanState != 0" ></el-table-column>
                <el-table-column align="center" type="index" width="50" label="序号" :index="HandleIndexMethod"></el-table-column>
                <el-table-column align="center" prop="studentBatch" label="扫描批次" v-if="scanState == 3"></el-table-column>  
                <el-table-column align="center" prop="studentCode" label="学号"></el-table-column>
                <el-table-column align="center" prop="examCode" label="考号"></el-table-column>
                <el-table-column align="center" prop="studentName" label="姓名"></el-table-column>
                <el-table-column align="center" prop="adminClassName" label="行政班"></el-table-column>
                <el-table-column align="center" prop="teachingClassName" label="教学班"></el-table-column>
                <el-table-column align="center" prop="registrationTypeName" label="学生类型"></el-table-column>
                <el-table-column align="center"  label="考场">
                    <template #default="scope">
                        <!-- 提的bug  沒没有考场显示行政班 -->
                        <span v-if="scope.row.examRoomName">{{scope.row.examRoomName}}</span>
                        <span v-else>{{scope.row.adminClassName}}</span>

                    </template>
                </el-table-column>
                <el-table-column align="center"  label="填涂标记" v-if="scanState==2">
                    <template #default="scope">
                        
                        <div class="miss_img" v-if="scope.row.paperUrl">
                        <img :src="scope.row.paperUrl"  alt="">
                        </div>
                        <span v-else>-</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="scannedStatus" label="状态" key="scannedStatus">
                    <template #default="scope">
                        <div class="table_row_scan_state" v-if="scanState == 0">
                            <div class="state_no_scan"></div>未扫描
                        </div>
                        <div class="table_row_scan_state" v-if="scanState == 2">
                            <div class="state_miss_exam"></div>缺考
                        </div>
                        <div class="table_row_scan_state" v-if="scanState == 1">
                            <div class="state_success_upload"></div>已上传
                        </div>
                    </template>
                </el-table-column>
                
                
                <el-table-column align="center" label="操作" width="160" >
                    <template #default="scope">
                            <!-- 未扫描 -->
                        <div class="table_row_option" v-if="scanState == 0">
                            <span class="option_button_editor" @click="MarkToMiss(scope.row)">标记为缺考</span>
                        </div>
                        <!-- 缺考 -->
                        <div class="table_row_option" v-if="scanState == 2">
                            <span class="el_button_editor"  @click="OptionView(scope.row)" v-if="scope.row.paperUrl">查看</span>
                            <span class="option_button_editor"  @click="MarkToNormal(scope)">标记为正常</span>
                        </div>
                        <!-- 已上传 -->
                        <div class="table_row_option" v-if="scanState == 1">
                            <span class="el_button_editor"  @click="OptionView(scope.row)">查看</span>
                            <span class="el_button_delete" @click="UploadDelete(scope.row)">删除</span>
                        </div>
                    </template>
                </el-table-column>
                
            </el-table>
            <div class="page_pagination" v-show="studentList.length>10">
                <el-pagination
                    @current-change="ChangePage"
                    background
                    
                    :page-sizes="[10,50,100]"
                    layout="sizes,prev, pager, next"
                    @size-change="HandleSizeChange"
                    :current-page="pageInfo.pageNum"
                    :total="pageInfo.total">
                </el-pagination>
            </div>
        </div>
    </div>
    <div class="scan_content_rights" v-else>
        <!-- 复查界面 -->
        <div class="rights_center page_search" v-if="showReviewType==0">

            <div class="center_search search_content" v-if="markType==1">
                <div class="content_left">
                    <div class="search_item">
                        班级：  
                        <el-select  v-model="reviewObjectClassCode" placeholder="请选择"  style="width: 120px;" @change="ChangeObjectClassCode()">
                            <el-option value="" label="全部班级"></el-option>
                            <el-option v-for="(item,index) in reviewObjectClassList" :key="index" :value="item.examRoomCode" :label="item.examRoomName"></el-option>
                        </el-select>
                        
                    </div>
                    
                </div>
                <div class="content_right">
                    <el-input type="text" style="width: 100%;" @keyup.enter.native="GetObjectSearchStudent" v-model="searchContent" @input="GetObjectSearchStudent" placeholder="学生姓名、考号" >
                        <el-button slot="append" icon="el-icon-search" style="width:68px;"  @click="GetObjectSearchStudent"></el-button>
                    </el-input>
                </div>
                
            </div>
            <div class="page_jg_20" v-if="markType==1">
            </div>
            <!-- 客观题复查 -->
            <div :class="markType==1?'center_image':'center_images'" >   
                <!-- <ActionImage ref="ActionCanvas" :isDrag="true" :paperInfo="currentPageInfo"  :paperImgUrl="currentImageUrl" :drawData="currentDrawData"></ActionImage> -->
            </div>
            
            <div class="left_bottom">
                <div class="bottom_draggable draggable_width_100" >
                    <!-- <draggable class="move_container" v-model="myArray"  chosenClass="chosen" forceFallback="true" group="people" animation="1000" > -->
                        <div v-for="(item,index) in studentPaperList" class="bottom_img_item"  :class="currentImageUrl == item.recognizeUrl?'img_item_cur':''" @click="StudentChanageCurrentPaperUrl(index, item)" :key="'paper_'+index">
                            
                            <img style="width: 100%;height: 100%" :src="item.recognizeUrl" alt="" >
                            <div class="bottom_img_item_number" v-if="abnormalType==2">{{index+1}}</div>
                            <div class="bottom_img_item_number" v-else>
                                <span v-if="item.pageNo>0">{{item.pageNo}}</span>
                                <span v-else></span>
                            </div>
                        </div>  
                    <!-- </draggable> -->
                </div>
            
            </div>
        </div>
        <!-- 主观题复查 -->
        <div class="rights_center page_search"  v-else>
            <div class="center_search search_content">
                <div class="content_left">
                    <div class="search_item">
                        班级：  
                        <el-select  v-model="reviewClassIdCode" placeholder="请选择"  style="width: 120px;" @change="ChangeScoreSearch()">
                            <el-option value="" label="全部班级"></el-option>
                            <el-option v-for="(item,index) in reviewClassList" :key="index" :value="item.value" :label="item.label"></el-option>
                        </el-select>
                        
                    </div>
                    <div class="search_item">
                        分数区间： 
                        <el-select  v-model="reviewMinScore" placeholder="请选择"  style="width: 100px;margin-right: 6px;"  @change="ChangeScoreSearch()">
                            <el-option v-for="(i,index) in scoreOptions" :key="index" :value="index" :label="i"></el-option>
                        </el-select>至
                        <el-select  v-model="reviewMaxScore" placeholder="请选择" style="width: 100px;margin-left: 5px;"  @change="ChangeScoreSearch()">
                            <el-option v-for="(i,index) in scoreOptions" :key="index" :value="index" :label="i"></el-option>
                        </el-select>
                    </div>
                </div>
                <div class="content_right">
                    <el-input placeholder="学生姓名、考号"  v-model="reviewKeyWord" @input="ChangeScoreSearch" @change="ChangeScoreSearch()" class="input_width">
                        <el-button @click="GetMarkReviewStudentList()"  slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </div>
            </div>
            <div class="center_list mark_score_center" ref="reviewList" v-loading="reviewLoading" element-loading-text="加载中……" element-loading-spinner="el-icon-loading" element-loading-background="#ffffff">
                <div class="center_item" :id="`student-${item.id}`" :class="reviewStudentId==item.id?'center_item_cur':''" v-for="(item,index) in reviewStudentList" :key="index">
                    <div class="item_header">
                        <div class="header_student_name">
                            <span>{{HandleIndexMethod(index)}}.{{item.studentName}} ({{item.exCode}})</span>
                            <span>{{item.adminClassName}}</span>
                            <span class="view_paper" @click="OptionScorePaper(item)">查看答题卡</span>
                        </div>
                        <div class="header_student_score">得分：{{item.score}}</div>
                    </div>
                    <div class="item_image">
                        <!-- <img :src="item.url" alt=""> -->
                        <!-- <MarkScore :drawData="reviewQuestionScoreList" :fullScore="reviewQuestionScore" :score="item.score" :paperImgUrl="item.url" @GetClickItem="(score) => GetClickItem(score,item, index)"></MarkScore> -->
                    </div>
                </div>
            </div>
            <div class="page_score_pagination" >
                <el-pagination
                    @current-change="ChangeReviewPage"
                    background
                    
                    :page-sizes="[20,50,100]"
                    layout="total,sizes,prev, pager, next"
                    @size-change="HandleSizeReviewChange"
                    :current-page="pageInfo.pageNum"
                    :total="pageInfo.total">
                </el-pagination>
            </div>
        </div>
        <div class="rights_right" v-if="showReviewType==0">
            <div class="page_jg_20" v-if="markType==0"></div>
            <div  class="right_search el_button" style="width: calc(100% - 40px); margin: auto;" v-if="markType==0">
                <el-input type="text" style="width: 100%;" @keyup.enter.native="GetObjectSearchStudent" v-model="searchContent" @input="GetObjectSearchStudent" placeholder="学生姓名、考号" >
                    <el-button slot="append" icon="el-icon-search" style="width:68px;"  @click="GetObjectSearchStudent"></el-button>
                </el-input>
                
            </div>
            <div class="page_jg_20"></div>
            <div class="right_table" ref="objectQuestionTables">   
                <el-table ref="studentTable" @row-click="RightStudentRowClick" :row-class-name="StudentTableClassName" :data="objectTableData" max-height="238" border >
                    <el-table-column align="center" type="index" label="序号" width="50">
                        
                    </el-table-column>  
                    <el-table-column align="center"  prop="studentName"   label="姓名" show-overflow-tooltip></el-table-column>
                    <el-table-column align="center" prop="exCode"  label="考号" show-overflow-tooltip></el-table-column>
                    <el-table-column align="center" width="50" prop="adminClassName"  label="班级"></el-table-column>
                </el-table>
                <div class="right_title">
                    <div>
                    客观题复查 <span @click="ClearValue()"  class="clear_value">清空</span>
                    </div> 
                </div>
            </div>
            <div class="answer_table">
                <el-table :data="currentQuestionList" :height="objectTableHeights" border  :row-class-name="ObjectTableClassName" :key="tableKey" >
                    <el-table-column align="center" prop="objectiveName" label="题号" width="90"></el-table-column>  
                    <el-table-column align="center" prop="studentName"  label="选项">
                        <template v-slot="scope">
                            <div class="table_row_answer_choose" v-if="scope.row.questionType==3">
                                <!-- 判断题 -->
                                <div class="answer_item" @click="ChooseAnswer(scope.row,GetLetterToNumberTF(item))" :class="IsCunzai(scope.row.selectValue,GetLetterToNumberTF(item))?'choose':''" v-for="(item,index) in scope.row.optionNum" :key="index">
                                    {{GetLetterToNumberTF(item)}}
                                </div>
                            </div>
                            <div class="table_row_answer_choose" v-else>
                                <div class="answer_item" @click="ChooseAnswer(scope.row,GetLetterToNumber(item))" :class="IsCunzai(scope.row.selectValue,GetLetterToNumber(item))?'choose':''" v-for="(item,index) in scope.row.optionNum" :key="index">
                                    {{GetLetterToNumber(item)}}
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                </el-table> 
            </div>
            <div class="right_button el_button">
                <div class="bottom_button_item">
                    <!-- <el-button @click="MarkPositionAbnormal" class="abnormal_other_btn">标记定位异常</el-button> -->
                    <el-button @click="StudentObjectiveCheck" class="re_cut_btn_100">校正完成</el-button>
                </div>
            </div>
        </div>
        <div class="rights_right" v-else>
            <!-- 主观题校正 -->
            <div class="page_jg_20"></div>
            <div class="answer_table">
                <el-table ref="subjectReviewTable" :data="reviewStudentList" :height="subjectReviewTableHeight" border  :row-class-name="ObjectTableClassName" :key="tableKey" >
                    <el-table-column align="center" type="index" label="序号" width="60">
                        <template slot-scope="scope">
                            <span v-text="HandleIndexMethod(scope.$index)"></span>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="studentName"  label="姓名">

                    </el-table-column>
                    <el-table-column align="center" prop="score"  label="得分">
                        <template v-slot="scope">
                            <el-input v-model="scope.row.score" @focus="ScoreFocus(scope.row)" :class="parseFloat(scope.row.score)>parseFloat(reviewQuestionScore)?'input_error':''" placeholder=""  maxlength="5"></el-input>
                        </template>
                    </el-table-column>
                </el-table> 
            </div>
            <div class="right_button el_button">
                <div class="bottom_button_item">
                    <!-- <el-button @click="MarkPositionAbnormal" class="abnormal_other_btn">标记定位异常</el-button> -->
                    <el-button @click="SubjectiveReviewCheck()" :loading="correctionLoading" class="re_cut_btn_100">校正完成</el-button>
                </div>
            </div>
        </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { useExamStore } from '@/store/exam'
import { useUserStore } from '@/store/user'
import { useRouter } from 'vue-router'
import { onMounted ,ref,nextTick,onUnmounted,computed, watch} from 'vue';
import { getExamStudentList,updateScannedStatus,updateExamNumberException } from '@/api/exam';
import { ElMessageBox, ElMessage } from 'element-plus'
// 实例化 Store
const examStore = useExamStore()
const userStore = useUserStore()
const router = useRouter()

// 定义 Props
const props = defineProps({
  
  scanState: {
    type: Number,
    default: 0,
  }, // 状态 状态  0  未扫描  1 已上传 2  缺考  3 异常
  showTool: {
    type: Boolean,
    default: false,
  }, // 是否显示工具栏
  showDraw: {
    type: Boolean,
    default: false,
  }, // 是否显示绘图框
  answerData: {
    type: Object,
    default: () => ({}),
  }, // 答案
})

//监听props变化
watch(() => props.scanState, (newState) => {

    console.log("扫描状态变更为",newState);
    pageInfo.value.pageNum=1;
    GetExamStudentList();//获取考生列表
});

// 考试科目 ID
const examSubjectId = computed(() => {
  return examStore.currentExam?.id
})//计算属性

//考试科目code
const examSubjectCode=computed(() => {
    return examStore.currentExam?.examSubjectCode
})
//当前登录人姓名
const currentUserName=computed(() => {
    return userStore.userName;
})

const showUploadReview = ref(0)//0 考生详情  1 复查识别
const showReviewType=ref(0);//复查题目类型 0-客观题 1-主观题

const activeName = ref(1);//1 按考场 2 按班级
const markType=ref(0)//0 网阅卡 1 手阅卡
const reviewQuestionIndex=ref('');//当前选择的题目索引

// 修改后：显式声明类型为 any[]，或者定义具体的 Interface
interface TreeNode {
  id: string | number;
  label: string;
  children?: TreeNode[];
  studentList?: any[];
  [key: string]: any; // 允许其他属性
}

const treeData = ref<TreeNode[]>([]); // 树形结构数据
const defaultExKey=ref(['all']);//
const selectNodeId=ref('all');//选择的节点id
const defaultProps={
    children: 'children',
    label: 'label'
};

const keyWord=ref('');//搜索关键词
const reviewKeyWord=ref('');//复查搜索关键词

const multiSelection=ref([]);//多选数据
const isLoading=ref(false);//表格加载状态
// 学生表格数据（前端分页处理）
const studentTableData = computed(() => {

  if(keyWord.value=='')
  {
    const start = (pageInfo.value.pageNum - 1) * pageInfo.value.pageSize;
    const end = start + pageInfo.value.pageSize;
    return studentList.value.slice(start, end);
  }
  else
  {
    return studentList.value.filter(student=>{
        return (
            student.studentName.toLowerCase().includes(keyWord.value.toLowerCase()) 
            ||
            student.exCode.toLowerCase().includes(keyWord.value.toLowerCase())
        );
    })
  }
  
});

const pageInfo=ref({ pageNum: 1, pageSize: 10, total: 0 });//分页信息
const studentPaperList=ref([]);//学生试卷列表
const allStudentList=ref([]);//所有学生列表数据存储
const studentList=ref<any[]>([]);//学生列表数据

const reviewObjectClassCode=ref('');//班级代码
const reviewObjectClassList=ref([]);//班级列表
const searchContent=ref('');//搜索内容
const currentImageUrl=ref('');//当前试卷图片url
const reviewClassIdCode=ref('');//班级代码
const reviewClassList=ref([]);//班级列表
const reviewMinScore=ref('');//分数区间最小值
const reviewMaxScore=ref('');//分数区间最大值
const scoreOptions=ref([]);//分数选项
const reviewLoading=ref(false);//复查加载状态

const reviewStudentList=ref([]);//复查学生列表
const tableHeight=ref(200);//学生表格高度
const subjectReviewTableHeight=ref(200);//主观题复查表格高度
const tableKey=ref(0);//表格key

//全部标缺
const AllMarkedMiss=async()=>{
    if(studentList.value.length==0)
    {
        return;
    }

    // 1. 增加二次确认弹窗
    await ElMessageBox.confirm(
        `确定要将当前列表下的 ${studentList.value.length} 名学生全部标记为缺考吗？`,
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    );
    let studentScanIds=[];
    for(let i=0;i<studentList.value.length;i++)
    {
        studentScanIds.push(studentList.value[i].id);   
    }
    UpdateScanStatus(studentScanIds,2);//修改状态 0 未扫描 1 已上传 2  缺考  3 异常   0-未扫描 2-缺考(修改时传，删除不传)
    

}

//单个标缺
const MarkToMiss=(item:any)=>{ 
    console.log("打印选择的学生数据",item);
    ElMessageBox.confirm(
        `确定要将 ${item.studentName} 标记为缺考吗？`,
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
        // 确定按钮点击事件处理
        let studentScanIds=[];
        studentScanIds.push(item.id);   
        UpdateScanStatus(studentScanIds,2);//修改状态 0 未扫描 1 已上传 2  缺考  3 异常   0-未扫描 2-缺考(修改时传，删除不传)
    }).catch(() => {
        // 取消按钮点击事件处理
    });

}

//标记状态
const MarkStudent=(status:number)=>{ 
    console.log("打印选择的学生数据",multiSelection.value);
    if(multiSelection.value.length==0)
    {
        ElMessage.warning("请选择需要操作的学生");
        return;
    }
    let statusStr=status==2?'缺考':'正常';

    //二次弹窗提示
    ElMessageBox.confirm(
        `确定要将选择的 ${multiSelection.value.length} 名学生标记为${statusStr}吗？`,
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
        // 确定按钮点击事件处理
        let studentScanIds=[];
        for(let i=0;i<multiSelection.value.length;i++)
        {
            studentScanIds.push(multiSelection.value[i].id);   
        }
        UpdateScanStatus(studentScanIds,status);//修改状态 0 未扫描 1 已上传 2  缺考  3 异常   0-未扫描 2-缺考(修改时传，删除不传)
    })

}

//标记考号异常
const MarkCardNumberAbnormal=()=>{ 
    ElMessageBox.confirm(
        `确定要将选择的 ${multiSelection.value.length} 名学生标记为考号异常吗？`,
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
        // 确定按钮点击事件处理
        let studentScanIds=[];
        for(let i=0;i<multiSelection.value.length;i++)
        {
            studentScanIds.push(multiSelection.value[i].id);   
        }
        const params={
            examSubjectId:examSubjectId.value,
            studentScanIds:studentScanIds,
        };
        updateExamNumberException(params).then((res)=>{
            if(res.code==200)
            {
                ElMessage.success("操作成功")
                GetExamStudentList();
            }
            else
            {
                ElMessage.error(res.msg)
            }
        })
        
    })
}


//修改学生状态
const UpdateScanStatus=async( studentIds:any, status:number )=>{
    
    const params={
        examSubjectId:examSubjectId.value,
        ids:studentIds,
        scannedStatus:status,//0 未扫描 1 已上传 2  缺考  3 异常   0-未扫描 2-缺考(修改时传，删除不传)
    };
    let res=await updateScannedStatus(params);
    console.log("批量修改状态返回结果",res);
    if(res.code==200)
    {
        ElMessage.success("操作成功")
        GetExamStudentList();
    }
    else
    {
        ElMessage.error(res.msg)
    }
}

const SelectCheckAll=()=>{

}
const HandleSelectionChange=(selection:any)=>{
    console.log("打印选中的数据",selection);
    multiSelection.value=selection;
}

const TreeHandleNodeClick=(node:any)=>{

}



const ChangeUploadShow=(show:number)=>{
    showUploadReview.value=show
}

const ChangeRoomType=(type:number)=>{
    activeName.value=type
    GetExamStudentList();
}

const ChangeReviewType=(type:number)=>{
    showReviewType.value=type
}

//切换分页
const ChangePage=(pageNum:number)=>{
    pageInfo.value.pageNum=pageNum;
}


//设置每页显示数量
const HandleSizeChange=(size:number)=>{
    pageInfo.value.pageSize=size;
}
//序号自定义方法
const HandleIndexMethod=(index:number)=>{
    if(activeName.value==1){
        return index+1
    }else{
        return index+1
    }
}

//获取学生列表
const GetExamStudentList=async()=>{
    isLoading.value=true
    const params={
        examSubjectId:examSubjectId.value,
        type:activeName.value,
        scannedStatus:props.scanState,
        review:0,
        schoolId:0,
    };
    let res=await getExamStudentList(params)
    console.log("打印获取的扫描学生结果",res)
    isLoading.value=false
    if(res.code==200)
    {
       let childrenData:any[]=[];
       let allDatalist:any[]=[];   //全部学生列表
       let examInfoCount={
            unScanned:res.data.unScanned,
            examMissNum:res.data.examMissNum,
            scannedNum:res.data.scannedNum,
            abnormalNum:res.data.abnormalNum,
            examTotal:res.data.totalNum,
        };
        examStore.setExamInfoCount(examInfoCount);//设置扫描数据信息
       if(res.data.examRoomTypeTblVOS?.length>0)
        {
            res.data.examRoomTypeTblVOS.forEach((item:any)=> {
                let obj={
                    id:'index_'+item.examRoomCode, //考场id    
                    label:item.examRoomName+'('+item.totalStudentNum+'人)', //考场名称
                    studentList:item.scannedStudentTblVOS || [],//学生列表

                };
                allDatalist.push(...item.scannedStudentTblVOS);
                childrenData.push(obj);
            });
            reviewObjectClassList.value=res.data.examRoomTypeTblVOS || [];
        }
        let oneTreeData={
            id:'all',
            label:'全部'+'('+allDatalist.length+'人)',
            children:childrenData,
            studentList:allDatalist,
        };
        treeData.value=[oneTreeData];
        if(selectNodeId.value=='all')
        {
            studentList.value=allDatalist;
            pageInfo.value.total=allDatalist.length;
        }
        else
        {

        }
        console.log("打印获取的树形结构数据",treeData.value)

    }
}



//计算高度的函数
const CalculateTableHeight = () => {
  // nextTick 确保 DOM 更新后再获取尺寸
  nextTick(() => {
    // window.innerHeight 是浏览器可视区域高度

    // 简单算法：视窗高度 - 固定占用高度
    let computedHeight = window.innerHeight - 270;
    
    // 限制最小高度，防止太矮
    if(computedHeight < 200) 
    {
      computedHeight = 200;
    }

    tableHeight.value = computedHeight;
  });
}; 


onMounted(() => {
  
    if (!examStore.currentExam) {
        console.warn('当前没有选中的考试信息')
        // 可选：如果没有数据，可以重定向回列表页或提示用户
    }
    CalculateTableHeight()//计算表格高度
    GetExamStudentList();
    // 监听窗口大小变化
    window.addEventListener('resize', CalculateTableHeight);
})
// 卸载时移除监听，防止内存泄漏
onUnmounted(() => {
  window.removeEventListener('resize', CalculateTableHeight);
});

</script>
 
<style lang="scss" scoped>
.content_main
{
    height: 100% !important;
}
</style>