<template>
    <div class="app-container">
        <el-dialog title="查询" :visible.sync="query" width="50%" append-to-body>
            <el-form ref="queryParams" :model="queryParams" label-width="96px" class="search">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="姓名" prop="teacherName">
                            <el-input v-model="queryParams.teacherName" placeholder="请输入" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学年" prop="schoolYear">
                            <el-select v-model="queryParams.schoolYear" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.yearda" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="届别" prop="year">
                            <el-select v-model="queryParams.year" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.rankda" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item></el-col>
                    <el-col :span="12">
                        <el-form-item label="学期" prop="semester">
                            <el-select v-model="queryParams.semester" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.semester_jsdzda" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="年级" prop="grade">
                            <el-select v-model="queryParams.grade" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.grade_da" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学科" prop="sub">
                            <el-select v-model="queryParams.sub" clearable placeholder="请选择" style="width: 100%">
                                <el-option v-for="dict in dict.type.teaching_subjects" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="班级类型" prop="classType">
                            <el-select v-model="queryParams.classType" clearable placeholder="请选择" style="width: 100%">
                                <el-option v-for="dict in dict.type.class_type" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="班级" prop="className">
                            <el-input v-model="queryParams.className" placeholder="请输入" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="德育考核成绩" prop="moralEduCheckAchievement">
                            <el-input v-model="queryParams.moralEduCheckAchievement" placeholder="请输入" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="智育考核成绩" prop="intellEduCheckAchievement">
                            <el-input v-model="queryParams.intellEduCheckAchievement" placeholder="请输入" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item class="dialog-footer" style="display: flex; justify-content: center; align-items: center">
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-search" size="mini" @click="handleQuerycx">查询</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table :data="assessmentList" @selection-change="handleSelectionChange"
            :default-sort="{ prop: 'schoolYear', order: 'descending' }" :row-style="{ height: '1px' }"
            :cell-style="{ padding: '0px' }" :header-cell-style="{ height: '50px', fontSize: '12px', padding: '0 0' }">
            <el-table-column type="selection" width="30" align="center" />
            <el-table-column type="index" label="序号" width="30" align="center" sortable fixed="left"
                show-overflow-tooltip />
            <el-table-column label="学年" align="center" prop="schoolYear" sortable fixed="left" width="80px
            " show-overflow-tooltip />
            <el-table-column label="学期" align="center" prop="semester" sortable fixed="left" width="80px"
                show-overflow-tooltip>
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.semester_jsdzda" :value="scope.row.semester" />
                </template>
            </el-table-column>
            <el-table-column label="届别" align="center" prop="year" sortable show-overflow-tooltip width="70px" />
            <el-table-column label="年级" align="center" prop="grade" sortable show-overflow-tooltip width="60px">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.grade_da" :value="scope.row.grade" />
                </template>
            </el-table-column>
            <el-table-column label="班级" align="center" prop="className" sortable show-overflow-tooltip width="70px" />
            <el-table-column label="班级类型" align="center" prop="classType" sortable width="90px" show-overflow-tooltip>
                <template slot-scope="scope">
                    <span v-if="getSelectedTypes(scope.row.classType).length > 0">
                        <span v-for="(option, index) in getSelectedTypes(scope.row.classType)" :key="index">
                            {{ option.label }}
                            <span v-if="index !== getSelectedTypes(scope.row.classType).length - 1">, </span>
                        </span>
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="姓名" align="center" prop="teacherName" sortable show-overflow-tooltip width="90px" />
            <el-table-column label="学科" align="center" prop="sub" sortable show-overflow-tooltip width="80px">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.teaching_subjects" :value="scope.row.sub" />
                </template>
            </el-table-column>
            <el-table-column label="德育考核成绩" align="center" prop="moralEduCheckAchievement" sortable width="110px"
                show-overflow-tooltip />
            <el-table-column label="智育考核成绩" align="center" prop="intellEduCheckAchievement" sortable width="110px"
                show-overflow-tooltip />
            <el-table-column label="考核结果" align="center" prop="assessmentResults" sortable width="130px">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.assessment_results" :value="scope.row.assessmentResults" />
                </template>
            </el-table-column>
            <!-- <el-table-column label="总考核成绩" align="center" prop="totalCheckAchievement" sortable fixed="right"
                width="130px" /> -->
            <el-table-column label="备注" align="center" prop="remark" sortable show-overflow-tooltip />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150px">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['system:assessment:edit']">查看</el-button>

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

        <!-- 添加或修改班主任考核对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="110px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="学期" prop="semester">
                            <el-select v-model="form.semester" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.semester_jsdzda" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="届别" prop="year">
                            <el-select v-model="form.year" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.rankda" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="学年" prop="schoolYear">
                            <el-select v-model="form.schoolYear" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.yearda" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="年级" prop="grade">
                            <el-select v-model="form.grade" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.grade_da" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="班级" prop="className">
                            <el-select v-model="form.className" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.class_num" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="教师姓名" prop="teacherName">
                            <el-input v-model="form.teacherName" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="12">
                        <el-form-item label="身份证号" prop="idCard">
                            <el-input v-model="form.idCard" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="德育考核成绩" prop="moralEduCheckAchievement">
                            <el-input v-model="form.moralEduCheckAchievement" type="number" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="12">
                        <el-form-item label="智育考核成绩" prop="intellEduCheckAchievement">
                            <el-input v-model="form.intellEduCheckAchievement" type="number" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="考核结果" prop="assessmentResults">
                            <el-select v-model="form.assessmentResults" clearable placeholder="请选择" style="width: 100%;">
                                <el-option v-for="dict in dict.type.assessment_results" :key="dict.value"
                                    :label="dict.label" :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <!-- <el-form-item label="总考核成绩" prop="totalCheckAchievement">
                            <el-input v-model="form.totalCheckAchievement" type="number" placeholder="请输入" clearable />
                        </el-form-item> -->
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="12">
                        <el-form-item label="班级类型" prop="classType">
                            <el-select v-model="form.classType" placeholder="请选择" clearable style="width: 100%">
                                <el-option v-for="dict in dict.type.class_type" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <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.teaching_subjects" :key="dict.value" :label="dict.label"
                                    :value="dict.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="备注" prop="remark">
                            <el-input v-model="form.remark" type="textarea" placeholder="请输入" clearable />
                        </el-form-item>
                    </el-col>
                </el-row>


            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>
import { listAssessmentall, getAssessment, delAssessment, addAssessment, updateAssessment } from "@/api/smartSchool/electronicArchives/teacherAssessment";
import { getToken } from "@/utils/auth";
export default {
    name: "Assessment",
    dicts: ["teaching_subjects", 'semester_jsdzda', 'exam_typeda', 'grade_da', 'class_type', 'yearda', 'rankda', 'appointment_situation', 'appointment_positions', 'class_num', 'audit_states', 'assessment_results'],
    data() {
        return {
            importing: false,
            uploadOpen: false,
            upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                // 弹出层标题（用户导入）
                title: "",
                // 是否禁用上传
                isUploading: false,
                // 是否更新已经存在的用户数据
                updateSupport: 0,
                // 设置上传的请求头部
                headers: { Authorization: "Bearer " + getToken() },
                // 上传的地址
                url:
                    process.env.VUE_APP_BASE_API + "/assessment/importData",
            },
            uploadForm: {},
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 班主任考核表格数据
            assessmentList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            query: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                semester: null,
                year: null,
                schoolYear: null,
                grade: null,
                className: null,
                teacherName: null,
                idCard: null,
                moralEduCheckAchievement: null,
                intellEduCheckAchievement: null,
                totalCheckAchievement: null,
                classType: null,
                sub: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                semester: [
                    { required: true, message: "学期不能为空", trigger: "change" }
                ],
                year: [
                    { required: true, message: "届别不能为空", trigger: "change" }
                ],
                schoolYear: [
                    { required: true, message: "学年不能为空", trigger: "change" }
                ],
                grade: [
                    { required: true, message: "年级不能为空", trigger: "change" }
                ],
                className: [
                    { required: true, message: "班级不能为空", trigger: "blur" }
                ],
                teacherName: [
                    { required: true, message: "姓名不能为空", trigger: "blur" }
                ],
                idCard: [
                    { required: true, message: "身份证号不能为空", trigger: "blur" }
                ],
                moralEduCheckAchievement: [
                    { required: true, message: "德育考核成绩不能为空", trigger: "blur" }
                ],
                intellEduCheckAchievement: [
                    { required: true, message: "智育考核成绩不能为空", trigger: "blur" }
                ],
                totalCheckAchievement: [
                    { required: true, message: "总成绩考核不能为空", trigger: "blur" }
                ],
                classType: [
                    { required: true, message: "班级类型不能为空", trigger: "blur" }
                ],
                sub: [
                    { required: true, message: "学科不能为空", trigger: "blur" }
                ],
                assessmentResults: [
                    { required: true, message: "考核结果不能为空", trigger: "blur" }
                ],

            }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询班主任考核列表 */
        getList() {
            this.loading = true;
            listAssessmentall(this.queryParams).then(response => {
                this.assessmentList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        getSelectedTypes(classType) {
            return this.dict.type.class_type.filter(option => classType.split(',').includes(option.value.toString()));
        },
        /** 搜索按钮操作 */
        handleQuerycx() {
            this.query = true;


        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        handleImport() {
            this.reset();
            this.title = "导入";
            this.uploadOpen = true;
        },
        handleFileUploadProgress(event, file, fileList) {
            this.upload.isUploading = true;
            this.importing = true;
        },
        // 提交上传文件
        submitFileForm() {
            this.$refs.upload.submit();
        },
        cancelFile() {
            this.uploadOpen = false;
            this.upload.isUploading = false;
            this.$refs.upload.clearFiles();
        },
        // 文件上传成功处理
        handleFileSuccess(response, file, fileList) {
            this.uploadOpen = false;
            this.upload.isUploading = false;
            this.importing = false;
            this.$refs.upload.clearFiles();
            this.$alert(
                "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
                response.msg +
                "</div>",
                "导入结果",
                { dangerouslyUseHTMLString: true }
            );
            this.getList();
        },
        //下载模版
        importTemplate() {
            this.download(
                "/assessment/download",
                {},
                `班主任考核_${Date.now()}.xlsx`
            );
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                semester: null,
                year: null,
                schoolYear: null,
                grade: null,
                className: null,
                teacherName: null,
                idCard: null,
                moralEduCheckAchievement: null,
                intellEduCheckAchievement: null,
                totalCheckAchievement: null,
                classType: null,
                sub: null,
                remark: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                delFlag: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
            this.query = false;
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryParams");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加班主任考核";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids
            getAssessment(id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改班主任考核";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateAssessment({ ...this.form }).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addAssessment({ ...this.form }).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除班主任考核编号为"' + ids + '"的数据项？').then(function () {
                return delAssessment(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('/assessment/export', {
                ...this.queryParams
            }, `班主任考核_${new Date().getTime()}.xlsx`)
        }
    }
};
</script>
<style lang="less" scoped>
::v-deep .el-form-item {
    margin-bottom: 0px;
}

::v-deep .el-input--medium .el-input__inner {
    height: 26px;
    line-height: 26px;
}

::v-deep .el-dialog__body {
    padding: 10px 20px
}

::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 4vh !important;
}

.search ::v-deep .el-form-item__content {
    width: 200px
}

.mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.mask-content {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1a74be;
    font-size: 15px;
}

::v-deep .el-table .el-table__cell {
    padding: 0;
}

::v-deep .el-table .cell {
    padding: 0;
}

::v-deep .el-table th.el-table__cell>.cell {
    padding: 0;

}
</style>