<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="b.name" :value="b.batchId"/>
            </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" />
    <el-drawer v-model="drawer" title="班级详情" size="1000px">
        <class-detail v-if="drawer" :data="drawerObj" exact-mode />
    </el-drawer>
</template>

<script setup name="ListExactIntelligent">

import consts from "@/utils/consts.js";
import {useProvidePaperBatchCondition} from "@/views/dz/papers/hooks/usePaperBatchCondition.js";
import {useProvidePaperList} from "@/views/dz/papers/hooks/usePaperList.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'},
    {label: '班级人数', prop: 'total'},
    ...consts.config.exactColumns
]
const actions = [
    {label: '查看详情', key: 'detail', permission: ['']}
]

const drawer = ref(false)
const drawerObj = ref(null)
const type = consts.enums.buildType.ExactIntelligent
const {batchList, batchId} = useProvidePaperBatchCondition(type)
const classId = ref('')
const queryParams = computed(() => ({buildType: type, batchId: toValue(batchId), classId: toValue(classId)}))
const {rules, handleQuery, resetQuery, list, total, getList, classList} = useProvidePaperList(queryParams)

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

<style scoped>

</style>