<template>
    <div class="bigBox" :style="{ height: bigHeight }">
        <div class="right" style="width: 100%;">
            <!-- 头部 -->
            <div class="headBox">
                <div class="title">{{ sjRow.name }}-考试情况</div>
                <div class="btnBox">
                    <el-button type="primary" @click="CloseEvent">
                        <span><el-icon>
                                <DocumentDelete />
                            </el-icon>
                            关闭</span>
                    </el-button>
                </div>
            </div>
            <div class="tabBox">
                <el-table ref="multipleTableRef" :data="list" v-loading="tableloading" element-loading-text="数据加载中..."
                    style="width: 100%;" height="72vh" border>
                    <el-table-column type="index" width="75" label="序号" />
                    <el-table-column label="姓名" property="username"></el-table-column>
                    <el-table-column label="得分" property="score"></el-table-column>
                    <el-table-column label="状态" property="status">
                        <template #default="{ row }">
                            <span>{{ row.status == 1 ? '参加' : '未考试' }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="排名" property="rank"></el-table-column>
                    <el-table-column label="操作" width="150px">
                        <template #default="{ row }">
                            <span class="operesee" @click="showDetail(row)" v-if="row.status == 1"><el-icon>
                                    <View />
                                </el-icon>查看详情</span>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="fenye">
                    <el-pagination class="pagination" @size-change="handleSizeChange"
                        @current-change="handleCurrentChange" :current-page="listQuery.pageCurrent"
                        :page-sizes="[2, 5, 10, 20]" :page-size="listQuery.pageSize"
                        layout="total, prev, pager, next, sizes, jumper" :total="total"></el-pagination>
                </div>
            </div>
        </div>
        <el-dialog class="exam-dialog" v-model="examListShow"
            :title="`${currentRow.username || ''}（${props.sjRow.name}）试卷列表`" width="80%"
            :before-close="examBeforeClose">
            <div class="exam-container">
                <!-- <div style="font-size: 18px;font-weight: 600;margin:20px 10px;">{{ currentRow.username || '个人' }}试卷列表
                </div> -->
                <el-table :data="examList" border>

                    <el-table-column label="用户名字" property="userName"></el-table-column>
                    <el-table-column label="错题数量" property="examErrorCount"></el-table-column>
                    <el-table-column label="开始时间" property="startTime"></el-table-column>
                    <el-table-column label="结束时间" property="endTime"></el-table-column>
                    <el-table-column label="考试次数" property="examCount"></el-table-column>
                    <el-table-column label="所得分数" property="examScore"></el-table-column>
                    <el-table-column label="合格分数" property="hgfs"></el-table-column>
                    <el-table-column label="是否合格" #="{ row }">
                        <span style="color: #008000;" v-if="row.examScore >= row.hgfs">合格</span>
                        <span style="color: #FF0000;" v-else>不合格</span>
                    </el-table-column>
                    <el-table-column label="操作" width="150px">
                        <template #default="{ row }">
                            <span class="operesee" @click="showExamListDetail(row)"><el-icon>
                                    <View />
                                </el-icon>查看详情</span>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div style="display:flex;justify-content: flex-end;margin-top: 20px;">
                <el-button type="primary" @click="examBeforeClose">关闭</el-button>
            </div>
        </el-dialog>
        <!-- 试卷预览 -->
        <div v-if="examShow" class="dialog-box">
            <Examdaio @close="examShow = false" :Row="info" type="exam" :userId="currentRow.id"
                :username="currentRow.username" :sjRow="sjRow" />
        </div>
    </div>
</template>

<script setup>
import { onMounted, ref, defineEmits, defineProps } from "vue";
import { ElTable } from 'element-plus';
import { getApi } from "@/api/tobAcco_api.js";
import Examdaio from "./examdaio.vue";
const props = defineProps({
    id: String,
    /** 试卷选中行 */
    sjRow: Object,
});
const listQuery = ref({
    pageCurrent: 1,
    pageSize: 20,
    id: props.id
})
const total = ref(0)
const info = ref({})
const emits = defineEmits(["close"]);
const tableloading = ref(false)
const list = ref([])
const multipleTableRef = ref()
const bigHeight = ref(); //整个高度
const treeHeight = ref(""); // 树高度
const examShow = ref(false)
/** 当前行 */
const currentRow = ref({})
/** 试卷预览列表 */
const examListShow = ref(false)
/** 试卷预览列表 */
const examList = ref([])
onMounted(() => {
    bigHeightFn();
    getList()
})
/** 列表详情 */
const showDetail = (row) => {
    // info.value = row
    // info.value.examId = props.id
    // examShow.value = true
    currentRow.value = row
    const params = { examId: props.id, userId: row.id }
    getApi(params, '/mosty-jcgl/paper/getPersonInfoList').then(res => {
        if (res) {
            examList.value = Array.isArray(res) ? res : []
        }
    })
    examListShow.value = true
}
/** 弹框[详情]点击 */
const showExamListDetail = (row) => {
    examListShow.value = false
    info.value = row
    info.value.examId = row.id
    examShow.value = true
}
const examBeforeClose = () => {
    examListShow.value = false
}
// 方法
const bigHeightFn = () => {
    bigHeight.value = window.innerHeight - 147 + "px";
    treeHeight.value = window.innerHeight - 187 + "px";
};
//	查询试卷已关联的试题
const getList = () => {
    tableloading.value = true
    getApi(listQuery.value, '/mosty-jcgl/paper/getScoreListDetail').then(res => {
        if (res.records) {
            list.value = res.records;
            total.value = res.total
            tableloading.value = false
        }
    })
}
const CloseEvent = () => {
    emits("close");
};
//分页
const handleSizeChange = (currentSize) => {
    listQuery.value.pageSize = currentSize;
    getList();
};
const handleCurrentChange = (currentPage) => {
    listQuery.value.pageCurrent = currentPage;
    getList();
};
</script>

<style lang="scss" scoped>
.bigBox {
    display: flex;

    .title {
        height: 60px;
        line-height: 60px;
        font-size: 18px;
        color: #0f3916;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .el-icon {
            cursor: pointer;
        }
    }

    .left {
        width: 300px;
        background: #FFFFFF;
        box-shadow: 0px 2px 10px 0px rgba(107, 107, 107, 0.1);
        border-radius: 0px 0px 0px 0px;
        opacity: 1;

        .treeBox {
            overflow: auto;
        }
    }

    .right {
        padding: 0 10px;
        margin: 0px 14px;
        background: #fff;

        .headBox {
            display: flex;
            align-items: center;
            justify-content: space-between
        }

        .btnBox {
            .el-select {
                margin-right: 10px;
            }

            .header-right {
                display: flex;
                align-items: center;
            }

            .btnBox {
                display: flex;
                width: 500px;
                justify-content: space-between;
                align-items: center;
            }
        }
    }
}


.tabBox {
    height: calc(100% - 70px);
    border-left: 0 !important;

    .fenye {
        top: 95%;
    }
}

.exam-container {
    min-height: 500px;
    padding: 20px 10px;
}

// 弹窗主题颜色
::v-deep .el-dialog__header {
    height: 47px;

    .el-dialog__headerbtn {
        color: #fff;

        .el-icon.el-dialog__close {
            color: #fff;
        }
    }
}
</style>
