<template>
    <div>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="任务名称" prop="unit_name">
                    <el-input class="w-[280px]" v-model="queryParams.name" clearable placeholder="请输入任务名称" />
                </el-form-item>
                <el-form-item label="上级类别" prop="qualification_grade">
                    <el-select class="flex-1" v-model="queryParams.superior_sort" clearable placeholder="请选择上级类别">
                        <el-option v-for="(item, index) in dictData.superior_category" :key="index" :label="item.name"
                            :value="parseInt(item.value)" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
            <div class="mt-4">
                <el-table :data="pager.lists" @cell-click="handleCurrentChange">
                    <el-table-column label="标识" prop="dataid" show-overflow-tooltip />
                    <el-table-column label="任务编号" prop="num" show-overflow-tooltip />
                    <el-table-column label="任务名称" prop="name" show-overflow-tooltip />
                    <el-table-column label="上级类别" prop="superior_sort" show-overflow-tooltip />
                    <el-table-column label="任务级次" prop="level" show-overflow-tooltip />
                    <el-table-column label="备注" prop="remarks" show-overflow-tooltip />
                </el-table>
            </div>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
  
<script lang="ts" setup>
import { usePaging } from "@/hooks/usePaging"
import { apiTaskTypeLists } from '@/api/task_type'
import { defineEmits } from "vue"
import { useDictData } from '@/hooks/useDictOptions'

const props = defineProps({
    project_id: Number
})
// 查询条件
const queryParams = reactive({
    name: '',
    superior_sort: '',
});
const { dictData } = useDictData('superior_category')

// 选中数据
const emits = defineEmits(["customEvent"]);

// 选中数据子父传递
const handleCurrentChange = (value: any) => {
    emits("customEvent", value);
};

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiTaskTypeLists,
    params: queryParams,
});

getLists();
</script>