<template>
    <div>
        <TableHeader date-picker :showReset="false" showCustomColumn>
            <template #operation>
                <el-button icon="el-icon-Download" type="primary" @click="exportEvent">导出</el-button>
            </template>
        </TableHeader>
        <Table :isGroup="props.info.isGroup" ref="tableRef" />
    </div>
</template>

<script setup lang="ts">
import TableHeader from '@/components/table/header/index.vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import { ref, onMounted, provide, nextTick } from 'vue'
import { useDictData } from '@/stores/dictData'
import createAxios from '@/utils/request'
import { requestPayload } from '@/utils/request'
interface Props {
    info: any
}
const props = withDefaults(defineProps<Props>(), {})
const dictData = useDictData()
const tableRef = ref()
const tableStore = new TableStore({
    url: props.info.url,
    publicHeight: 62,
    method: 'POST',
    column: props.info.column,

    loadCallback: () => {}
})
tableStore.table.params.statisticalType = dictData.getBasicData('Statistical_Type', [
    'Report_Type',
    'Manufacturer',
    'Voltage_Level',
    'Load_Type'
])[0]
tableStore.table.params.deptIndex = dictData.state.area[0].id
tableStore.table.params.monitorFlag = 2
tableStore.table.params.powerFlag = 2
tableStore.table.params.serverName = 'event-boot'
tableStore.table.params.type = 0
provide('tableStore', tableStore)
nextTick(() => {
    tableStore.index()
})
// 导出
const exportEvent = () => {
    let form = JSON.parse(JSON.stringify(tableStore.table.params))
    form.pageNum = 1
    form.pageSize = tableStore.table.total
    createAxios(
        Object.assign(
            {
                url: props.info.url,
                method: 'post'
            },
            requestPayload('POST', form)
        )
    ).then(res => {
        tableRef.value.getRef().exportData({
            filename: props.info.name, // 文件名字
            sheetName: 'Sheet1',
            type: 'xlsx', //导出文件类型 xlsx 和 csv
            useStyle: true,
            data: res.data.records, // 数据源 // 过滤那个字段导出
            columnFilterMethod: function (column: any) {
                return !(column.$columnIndex === 0)
            }
        })
    })
}
</script>
