<template>
    <el-form ref="queryRef" :model="queryParams" :rules="rules" label-width="68px" inline>
        <el-form-item label="批次" prop="batchId">
            <el-select v-model="batchId" clearable @change="handleQuery" style="width: 172px">
                <el-option v-for="b in batchList" :label="formatBatchName(b)" :value="b.batchId"/>
            </el-select>
        </el-form-item>
        <el-form-item label="考生类型" prop="examType">
            <el-select v-model="examType" clearable @change="handleQuery" style="width: 172px">
                <el-option v-for="e in examTypes" :label="e.dictLabel" :value="e.dictValue"/>
            </el-select>
        </el-form-item>
        <el-form-item label="院校">
            <el-select v-model="universityId" clearable @change="handleQuery" style="width: 172px">
                <el-option v-for="u in universities" :label="u.name" :value="u.id"/>
            </el-select>
        </el-form-item>
        <el-form-item label="专业组">
            <el-select v-model="majorGroup" clearable @change="handleQuery" style="width: 172px">
                <el-option v-for="g in majorGroups" :label="g" :value="g"/>
            </el-select>
        </el-form-item>
        <el-form-item label="专业">
            <el-select v-model="majorPlanId" clearable @change="handleQuery" style="width: 172px">
                <el-option v-for="m in majors" :label="m.majorName" :value="m.id"/>
            </el-select>
        </el-form-item>
        <el-form-item label="班级" prop="classId">
            <el-select v-model="classId" clearable @change="handleQuery" style="width: 172px">
                <el-option v-for="c in classList" :label="c.name" :value="c.classId"/>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<!--            <el-button icon="Refresh" @click="resetQuery">重置</el-button>-->
        </el-form-item>
    </el-form>
    <Table :data="list" :columns="columns" :actions="actions" @get-list="getList" @action="handleAction">
        <template #batchName="{row}">
            <span>{{ getBatchDisplayName(row) }}</span>
        </template>
    </Table>
    <el-drawer v-model="drawer" title="班级详情" size="1000px">
        <class-detail v-if="drawer" :data="drawerObj" exact-mode />
    </el-drawer>
</template>

<script setup name="ListExactHand">
import consts from "@/utils/consts.js";
import {useProvidePaperList} from "@/views/dz/papers/hooks/usePaperList.js";
import {useProvidePaperExactCondition} from "@/views/dz/papers/hooks/usePaperExactCondition.js";
import {usePaperDownload} from "@/views/dz/papers/hooks/usePaperDownload.js";
import Table from "@/components/Table/index.vue";
import ClassDetail from "@/views/dz/papers/components/plugs/class-detail.vue";

const columns = [
    {label: '组卷类型', prop: 'buildTypeName'},
    {label: '班级', prop: 'className'},
    {label: '批次', prop: 'batchName', type: 'slot', slotName: 'batchName'},
    {label: '班级人数', prop: 'total'},
    ...consts.config.exactColumns.slice(0, 3)
]
const actions = [
    {label: '详情', key: 'detail', permission: ['learn:test:list']},
    // {label: '下载', key: 'download', permission: ['learn:paper:download']}
]

const drawer = ref(false)
const drawerObj = ref(null)
const type = consts.enums.buildType.ExactHand
const {
    batchList,
    batchId,
    examTypes,
    examType,
    universityId,
    universities,
    majorGroup,
    majorGroups,
    majorPlanId,
    majors,
    conditionArgs,
    formatBatchName,
    getBatchDisplayName
} = useProvidePaperExactCondition(type)
const classId = ref('')
const queryParams = computed(() => ({
    ...toValue(conditionArgs),
    classId: toValue(classId)
}))
const {rules, handleQuery, resetQuery, list, total, getList, classList} = useProvidePaperList(queryParams)
const {handleDownload} = usePaperDownload(queryParams)

const handleAction = async function (action, row) {
    switch (action.key) {
        case "detail":
            drawer.value = true
            drawerObj.value = row
            break;
        case "download":
            await handleDownload(row.paperId, row.paperName)
            break;
        default:
            throw new Error(`Action key '${action.key}' not support.`)
            break
    }
}
</script>

<style scoped>

</style>