<template>
    <div class="app-container">
        <el-form :model="queryForm" ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="实验级部">
                <el-select v-model="queryForm.gradeId" placeholder="请选择级部" clearable>
                    <el-option v-for="(item, index) in gradeLists" :key="index" :label="item.gradeName"
                        :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="班级">
                <el-input v-model="queryForm.className" placeholder="请选择级部" clearable></el-input>
            </el-form-item>
            <el-form-item label="学期">
                <el-date-picker v-model="queryForm.schoolYear" type="year" value-format="yyyy" placeholder="选择年">
                </el-date-picker>
                <el-select v-model="queryForm.semester" placeholder="请选择学期">
                    <el-option label="上学期" value="1"></el-option>
                    <el-option label="下学期" value="2"></el-option>
                </el-select>

            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column align="center" type="index" label="序号" width="55" />
            <el-table-column align="center" prop="grade" label="级部" />
            <el-table-column align="center" prop="schoolYearSemester" label="学期" />
            <el-table-column align="center" prop="className" label="班级" />
            <el-table-column align="center" prop="jhsys" label="计划实验数" />
            <el-table-column align="center" prop="ywcsys" label="已完成实验数" />
            <el-table-column align="center" prop="ratio" label="完成比列" />
            <el-table-column align="center" fixed="right" label="操作" width="150">
                <template slot-scope="scope">
                    <el-button @click="handleLook(scope.row)" type="text" size="small">查看班级完成详情</el-button>
                </template>
            </el-table-column>

        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryForm.pageNum" :limit.sync="queryForm.pageSize"
            @pagination="getList" />
        <!-- 查看弹窗 -->
        <el-dialog title="实验名称:物理研究" :visible.sync="dialogTableVisible" width="80%" height="1000px">
            <el-table :data="ExperimentalData" border>
                <el-table-column align="center" type="index" label="序号" width="55" />
                <el-table-column align="center" prop="experimentClassify" label="实验分类">
                    <template slot-scope="{ row }">
                        <div>{{ selectDictLabel(dict.type.experiment_classify, row.experimentClassify) }}</div>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="className" label="学期" />
                <el-table-column align="center" prop="className" label="级部" />
                <el-table-column align="center" prop="className" label="班级" />
                <el-table-column align="center" prop="experimentTime" label="实验时间" />
                <el-table-column align="center" prop="section" label="节次" />
                <el-table-column align="center" prop="className" label="实验名称" />
                <el-table-column align="center" prop="className" label="实验分类" />
                <el-table-column align="center" prop="section" label="章节内容" />

            </el-table>


        </el-dialog>


    </div>
</template>

<script>
import {
    getList,
    getSemester,
    getGradelist,
    getClassDetailsxq,
} from '@/api/smartSchool/gradeWork/laboratoryManagement/classDetails'
export default {
    dicts: ['experiment_classify', 'lab_sub'],
    name: 'index',
    data() {
        return {
            queryForm: {
                schoolYear: "",
                semester: "",
                gradeId: "",
                className: "",
                pageNum: 1,
                pageSize: 10,
            },
            //表格数据
            tableData: [

            ],
            gradeLists: [],
            ExperimentalData: [],
            dialogTableVisible: false,
            total: 0,
        }
    },
    created() {
        this.getSemesterAndList();
        this.getGradelist();
        this.getSemester();


    },
    methods: {
        async getSemesterAndList() {
            await this.getSemester(); // 等待获取学年信息
            this.getList(); // 获取默认数据
        },
        getList() {
            getList(this.queryForm)
                .then(response => {
                    this.tableData = response.rows;
                    console.log('response', response);
                    this.total = response.total;
                    this.loading = false;
                })
                .catch(error => {
                    this.loading = false;
                    console.log(error);
                });
        },
        getSemester() {
            return new Promise((resolve, reject) => {
                getSemester()
                    .then(response => {
                        this.queryForm.semester = response.semester;
                        this.queryForm.schoolYear = response.schoolYear + '';
                        resolve(); // 成功获取学年信息
                    })
                    .catch(error => {
                        console.log(error);
                        reject(error);
                    });
            });
        },
        //查询级部搜索
        getGradelist() {
            getGradelist().then(response => {
                this.loading = false;
                this.gradeLists = response.data;

            });
        },
        //查看按钮
        handleLook(row) {
            console.log(row);
            // 设置 dialogTableVisible 为 true，显示弹窗
            this.dialogTableVisible = true;
            // 根据 row 的数据构建请求参数
            const params = {
                schoolYear: row.schoolYear,
                semester: row.semester,
                gradeId: row.gradeId,
                classId: row.classId
            };
            console.log(params);
            getClassDetailsxq(params).then(response => {
                console.log(params);
                this.ExperimentalData = response.rows;
                this.loading = false;
            }).catch(error => {

            });
        },

        resetQuery() {
            this.queryForm = {
                pageNum: 1,
                pageSize: 10,
                schoolYear: "",
                applyName: "",
            };
            this.getList();
        },

    },
}
</script>

<style lang="scss" scoped></style>