<template>
    <div class="app-container">
        <el-form :model="queryForm" ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="教师">
                <el-input v-model="queryForm.applyName" 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-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" prop="applyName" label="教师" />
            <el-table-column align="center" prop="schoolYear" label="学年" />
            <el-table-column align="center" prop="fzcount" label="分组实验" />
            <el-table-column align="center" prop="sycount" label="演示实验" />
            <el-table-column align="center" prop="sjcount" label="探究实验" />
            <el-table-column align="center" prop="ywccount" label="已完成实验数" />

        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryForm.pageNum" :limit.sync="queryForm.pageSize"
            @pagination="getList" />



    </div>
</template>

<script>
import {
    getList,
    getSemester
} from '@/api/smartSchool/laboratoryManagement/leadlaboratoryRecords'
export default {
    name: 'index',
    data() {
        return {
            queryForm: {
                pageNum: 1,
                pageSize: 10,
                semester: "",
                schoolYear: "",
                applyName: "",
            },
            //表格数据
            tableData: [

            ],

            total: 0,
        }
    },
    created() {
        this.getSemesterAndList();
    },
    methods: {
        async getSemesterAndList() {
            try {
                await this.getSemester(); // 等待获取学年信息
                this.getList(); // 获取默认数据
            } catch (error) {
                console.log(error);
                // 处理错误情况
            }
        },

        getList() {
            const params = {
                schoolYear: this.queryForm.schoolYear,
                applyName: this.queryForm.applyName,
                semester: this.queryForm.semester,
            };
            getList(params)
                .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.schoolYear = response.schoolYear + '';
                        resolve(); // 成功获取学年信息
                    })
                    .catch(error => {
                        console.log(error);
                        reject(error);
                    });
            });
        },

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


    },
}
</script>

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