<template>
    <div class="app-container">
        <el-form :model="queryForm" ref="queryForm" size="small" :inline="true" label-width="88px">
            <el-form-item label="预约时间段" prop="time">
                <el-date-picker v-model="queryForm.startTime" type="date" placeholder="选择" value-format="yyyy-MM-dd">
                </el-date-picker>
                <el-date-picker v-model="queryForm.endTime" type="date" placeholder="选择" value-format="yyyy-MM-dd">
                </el-date-picker>
            </el-form-item>
            <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.applyName" placeholder="请输入"></el-input>
            </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="sub" label="学科">
                <template slot-scope="{ row }">
                    <div>{{ selectDictLabel(dict.type.lab_sub, row.sub) }}</div>
                </template>
            </el-table-column>
            <el-table-column align="center" prop="grade" label="级部" />
            <el-table-column align="center" prop="schoolYear" 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="experimentName" label="实验名称" />
            <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="labName" label="实验室" />
            <el-table-column align="center" prop="chapterContent" label="章节内容" />
            <el-table-column align="center" prop="applyName" label="申请老师" />
            <el-table-column align="center" prop="applyState" label="申报状态">
                <template slot-scope="scope">
                    <span v-if="scope.row.applyState === '1'">已确认</span>
                    <span v-else>未确认</span>
                </template>
            </el-table-column>

            <el-table-column align="center" fixed="right" label="操作" width="150">
                <template slot-scope="scope">
                    <div v-if="scope.row.applyState === '1'">
                        <el-button @click="handleLook(scope.row)" type="text" size="small">查看</el-button>
                    </div>
                    <div v-else>
                        <el-button @click="handleLook(scope.row)" type="text" size="small">查看</el-button>
                        <el-button @click="handleApprove(scope.row)" type="text" size="small">审批</el-button>
                    </div>

                </template>
            </el-table-column>
        </el-table>
        <!-- 查看实验室记录 -->
        <el-dialog title="申请信息" :visible.sync="dialogTableVisible" width="50%">
            <el-form :model="form" ref="form" size="small" label-width="100px" :disabled="isEdit">
                <el-row :gutter="30">
                    <el-col :span="8">
                        <el-form-item label="学科" prop="sub">
                            <el-select v-model="form.sub" placeholder="请选择" clearable style="width: 100%;">
                                <el-option v-for="dict in dict.type.lab_sub" :key="dict.value" :label="dict.label"
                                    :value="dict.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="级部">
                            <el-input v-model="form.grade" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="学年">
                            <el-input v-model="form.schoolYear" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="30">
                    <el-col :span="8">
                        <el-form-item label="班级">
                            <el-input v-model="form.className" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="节次">
                            <el-input v-model="form.section" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="实验时间">
                            <el-input v-model="form.experimentTime" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="30">
                    <el-col :span="8">
                        <el-form-item label="实验名称">
                            <el-input v-model="form.labName" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="实验分类" prop="experimentClassify">
                            <el-select v-model="form.experimentClassify" placeholder="请选择" clearable>
                                <el-option v-for="dict in dict.type.experiment_classify" :key="dict.value"
                                    :label="dict.label" :value="dict.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="实验室">
                            <el-input v-model="form.labName" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>

                </el-row>
                <el-row :gutter="30">
                    <el-col :span="8">
                        <el-form-item label="章节内容">
                            <el-input v-model="form.chapterContent" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>


                </el-row>
                <el-row :gutter="30">
                    <el-col :span="8">
                        <el-form-item label="附件">
                            <li class="el-upload-list__item ele-upload-list__item-content" v-for="file in fileList"
                                :key="file.id">
                                <el-link :href="`${baseUrl}${file.accessoryUrl}`" :underline="false" target="_blank">
                                    <span class="el-icon-document"> {{ file.accessoryName }} </span>
                                </el-link>
                            </li>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="30">
                    <el-col :span="20">
                        <el-form-item label="实验用品">
                            <el-input v-model="form.experimentUseGoods" type="textarea" placeholder="请输入"
                                clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: center;">
                <el-button type="primary" @click="cancle">取 消</el-button>
            </div>
        </el-dialog>
        <!-- 审批老师申请预约 -->
        <el-dialog title="申请信息" :visible.sync="open" width="50%">
            <el-form :model="form" ref="form" size="small" label-width="100px">
                <el-row :gutter="30">
                    <el-col :span="8">
                        <el-form-item label="实验名称">
                            <el-input v-model="form.experimentName" placeholder="请输入" clearable :disabled="isEdit" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="章节内容">
                            <el-input v-model="form.chapterContent" placeholder="请输入" clearable :disabled="isEdit" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="实验分类" prop="experimentClassify">
                            <el-select v-model="form.experimentClassify" placeholder="请选择" clearable :disabled="isEdit">
                                <el-option v-for="dict in dict.type.experiment_classify" :key="dict.value"
                                    :label="dict.label" :value="dict.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="30">
                    <el-col :span="8">
                        <el-form-item label="实验室">
                            <el-input v-model="form.labName" placeholder="请输入" clearable :disabled="isEdit" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="学科" prop="sub">
                            <el-select v-model="form.sub" placeholder="请选择" clearable style="width: 100%;"
                                :disabled="isEdit">
                                <el-option v-for="dict in dict.type.lab_sub" :key="dict.value" :label="dict.label"
                                    :value="dict.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="级部">
                            <el-input v-model="form.grade" placeholder="请输入" clearable :disabled="isEdit" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="30">
                    <el-col :span="8">
                        <el-form-item label="班级">
                            <el-input v-model="form.className" placeholder="请输入" clearable :disabled="isEdit" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="学年">
                            <el-input v-model="form.schoolYearSemester" placeholder="请输入" clearable :disabled="isEdit" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="实验时间">
                            <el-input v-model="form.experimentTime" placeholder="请输入" clearable :disabled="isEdit" />
                        </el-form-item>
                    </el-col>

                </el-row>

                <el-row :gutter="30">
                    <el-col :span="24">
                        <el-form-item label="实验用品">
                            <el-input v-model="form.experimentUseGoods" type="textarea" placeholder="请输入" clearable
                                :disabled="isEdit"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: center;">
                <el-button type="primary" @click="submitForm">提 交</el-button>
                <el-button type="primary" @click="cancle">取 消</el-button>
            </div>
        </el-dialog>
        <pagination v-show="total > 0" :total="total" :page.sync="queryForm.pageNum" :limit.sync="queryForm.pageSize"
            @pagination="getList" />
    </div>
</template>

<script>
import {
    getTeacherlist,
    getTeacherxq,
    updateState,
} from '@/api/smartSchool/laboratoryManagement/teacherApplication'
import {
    getGradelist
} from '@/api/smartSchool/gradeWork/laboratoryManagement/classDetails'
export default {
    name: 'index',
    dicts: ['experiment_classify', 'lab_sub'],
    data() {
        return {
            queryForm: {
                startTime: "",
                endTime: "",
                gradeId: "",
                applyName: "",
            },
            gradeLists: [],
            schoolAccessoryList: [],
            baseUrl: process.env.VUE_APP_BASE_API,
            //表格数据
            tableData: [

            ],
            //学科分类
            options: {

            },
            form: {

            },
            total: 0,
            isEdit: false,
            dialogTableVisible: false,
            open: false,
            fileList: [],
        }
    },
    created() {
        this.getList();
        this.getGradelist();

    },
    methods: {
        //表单查询
        getList() {
            getTeacherlist(this.queryForm).then(response => {
                this.tableData = response.rows;
                this.total = response.total
                this.loading = false
            })
        },
        //查询级部搜索
        getGradelist() {
            getGradelist().then(response => {
                this.loading = false;
                this.gradeLists = response.data;

            });
        },

        //查看按钮操作
        handleLook(row) {
            const id = row.id || this.ids;
            getTeacherxq(id).then(response => {
                this.form = response.data;
                this.fileList = response.data.schoolAccessoryList;
                console.log('this.schoolAccessoryList', this.schoolAccessoryList);
                console.log('this.form', this.form);
                this.isEdit = true;
                this.loading = false;
            })
            this.dialogTableVisible = true;
        },
        resetQuery() {
            this.queryForm = {
                startTime: "",
                endTime: "",
                gradeId: "",
                applyName: "",
            },
                this.getList();
        },
        handleApprove(row) {
            this.open = true;
            const id = row.id || this.ids;
            getTeacherxq(id).then(response => {
                this.form = response.data;
                this.fileList = response.data.schoolAccessoryList;
                this.isEdit = true;
                console.log('this.schoolAccessoryList', this.schoolAccessoryList);
                console.log('this.form', this.form);
                this.loading = false
            })

        },
        // 取消按钮
        cancle() {
            this.dialogTableVisible = false;
            this.open = false;
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs['form'].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        const params = {
                            id: this.form.id,
                            applyState: '1',
                        };
                        updateState(params).then(response => {
                            console.log(params, params);
                            this.$modal.msgSuccess('提交成功');
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        }

    },
}
</script>

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