<template>
    <div class="guoYuSheShiShuJuTianBao-search">
        <BasicSearch ref="basicSearchRef" :searchList="searchList" :initial-values="initSearchData" :zhujianfujian="'zhu'"
            @finish="onSearchFinish" @values-change="onValuesChange" @reset="handleReset">
            <template #actions>
                <a-tooltip title="批量审批">
                    <a-button :disabled="selectedCount === 0" @click="$emit('batch-approve')">
                        <template #icon>
                            <CheckSquareOutlined />
                        </template>
                        批量审批
                    </a-button>
                </a-tooltip>

            </template>
        </BasicSearch>
    </div>
</template>

<script lang="ts" setup>
import { ref, computed, onMounted } from "vue";
import BasicSearch from "@/components/BasicSearch/index.vue"; // 确保路径正确
import { getDictItemsByCode } from '@/api/dict';
import {
    CheckSquareOutlined,
} from "@ant-design/icons-vue";
// --- Props & Emits ---
interface Props {
    selectedCount?: number;
}

const props = withDefaults(defineProps<Props>(), {
    selectedCount: 0
});

const emit = defineEmits<{
    (e: "reset", values: any): void;
    (e: "searchFinish", values: any): void;
    (e: "batch-approve"): void;
}>();


// 模拟 initSearchData
const initSearchData = {
    hbrvcd:'all',
    stcd:'',
    status: '',
};

const searchData = ref<any>({ ...initSearchData });

const searchList: any = computed(() => [
    {
        type: "waterStation",
        name: "hbrvcd",
        label: "流域",
        fieldProps: {
            allowClear: true,
        },
        options: [],
    },

    {
        type: "Select",
        name: "status",
        label: "审批状态",
        fieldProps: {
            allowClear: true,
        },
        options: statusData.value,
    },

]);
// --- Methods ---



// 2. 搜索表单逻辑
const onSearchFinish = (values: any) => {
    console.log(values);

    emit("searchFinish", values);
};
const handleReset = () => {
    emit("reset", initSearchData);
};

const onValuesChange = (changedValues: any, allValues: any) => {
    // 同步更新本地 searchData，以便其他逻辑使用
    searchData.value = { ...searchData.value, ...allValues };
};

// --- Lifecycle ---
onMounted(() => {
    emit("searchFinish", initSearchData);
    getstatusData()
});
const statusData = ref(false)
const getstatusData = () => {
    getDictItemsByCode({ dictCode: "approvalStatus" }).then((res) => {
        statusData.value = res.data;
    });
};
</script>
<style lang="scss"></style>