<template>
    <div>
        <TableHeader>
            <template v-slot:select>
                <el-form-item label="名称">
                    <el-input
                        v-model="tableStore.table.params.searchValue"
                        clearable
                        placeholder="请输入搜索名称"
                        maxlength="32"
                        show-word-limit
                    />
                </el-form-item>
            </template>
        </TableHeader>
        <Table ref="tableRef" isGroup />
    </div>
</template>
<script setup lang="tsx">
import { ref, onMounted, provide, reactive } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { useDictData } from '@/stores/dictData'

const tableRef = ref()
const tableStore = new TableStore({
    url: '/supervision-boot/libModel/pageLibModelQuery',
    method: 'POST',
    publicHeight: 60,
    column: [
        {
            title: '谐波源',
            children: [
                {
                    field: 'index',
                    title: '序号',
                    width: '80',
                    formatter: (row: any) => {
                        return (
                            (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
                        )
                    }
                },
                { field: 'name', title: '名称', minWidth: 200 },
                { field: 'voltage', title: '电压等级', minWidth: 200 },
                { field: 'capacity', title: '容量', minWidth: 200 }
            ]
        },
        {
            title: '各次谐波电流含量（%）',
            width: 1800,
            children: Array.from({ length: 24 }, (_, i) => ({
                field: `i${i + 2}`,
                title: `${i + 2}次`,
                minWidth: 100
            }))
        }
    ],
    // 在请求发送前处理参数
    beforeSearchFun: () => {
        tableStore.table.params.pageSize = 100
    },
    resetCallback: () => {
        tableStore.table.params.searchValue = ''
    }
})

tableStore.table.params.type = 1
provide('tableStore', tableStore)

// 暴露查询方法给父组件调用
const queryData = () => {
    tableStore.index()
}

defineExpose({
    queryData
})
</script>
