<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="node_name">
                    <el-input class="w-[280px]" v-model="queryParams.node_name" clearable placeholder="请输入节点名称" />
                </el-form-item>
                <el-form-item label="节点类型" prop="node_type">
                    <el-select class="flex-1" v-model="queryParams.node_type" clearable placeholder="请选择节点类型">
                        <el-option v-for="(item, index) in dictData.check_item_node_type" :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" row-key="id"
                    @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" v-if="!node_type" />
                    <el-table-column label="项目名称" prop="project_name" show-overflow-tooltip />
                    <el-table-column label="节点名称" prop="node_name" show-overflow-tooltip />
                    <el-table-column label="节点类型" prop="node_type_text" show-overflow-tooltip />
                    <el-table-column label="节点编号" prop="node_code" show-overflow-tooltip />
                    <el-table-column label="检查依据" prop="inspection_basis" show-overflow-tooltip />
                    <el-table-column label="参考法规" prop="reference_law" show-overflow-tooltip />
                </el-table>
            </div>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
            <div class="flex justify-end mt-4" v-if="!node_type">
                <el-button type="primary" @click="confirm">确定</el-button>
            </div>
        </el-card>
    </div>
</template>
  
<script lang="ts" setup>
import { usePaging } from "@/hooks/usePaging"
import { apiSupervisionCheckItemLists } from '@/api/supervision_check_item'
import { defineEmits } from "vue"
import { useDictData } from '@/hooks/useDictOptions'

const props = defineProps({
    project_id: Number,
    node_type: Number
})
// 查询条件
// 查询条件
const queryParams = reactive({
    node_name: '',
    node_type: '',
    project_id: props.project_id || "",
    node_type: props.node_type || ""
})
const { dictData } = useDictData('check_item_node_type')
const multipleSelection = ref([])

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

// 选中数据子父传递
const handleCurrentChange = (value: any) => {
    if (!props.node_type) return

    emits("customEvent", value);
};
const handleSelectionChange = (val) => {
    multipleSelection.value = val
}
const confirm = () => {
    emits("customEvent", multipleSelection.value);
}

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

getLists();
</script>