<template>
    <div class="default-main">
        <TableHeader date-picker area>
            <template v-slot:select>
                <el-form-item label="统计类型">
                    <el-radio-group v-model="tableStore.table.params.comFlag">
                        <el-radio-button label="1">在线</el-radio-button>
                        <el-radio-button label="0">离线</el-radio-button>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="触发类型">
                    <el-select v-model.trim="tableStore.table.params.waveType" placeholder="请选择" clearable>
                        <el-option
                            v-for="item in triggerType"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
              

                <el-form-item label="筛选数据">
                    <el-input
                        v-model="tableStore.table.params.searchValue"
                        placeholder="根据变电站,终端编号,型号或网络参数查询"
                    />
                </el-form-item>
            </template>
            <template #operation>
                <el-button icon="el-icon-Download" type="primary" @click="exportEvent">导出</el-button>
            </template>
        </TableHeader>
        <Table ref="tableRef" />
    </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'
import { getEventReport } from '@/api/event-boot/report.ts'

defineOptions({
    name: 'Operationmanagement/terminalmanagement'
})
const dictData = useDictData()
const triggerType = dictData.getBasicData('Event_Statis')
const tableRef = ref()
const tableStore = new TableStore({
  
    url: '/event-boot/report/getEventReport',
    method: 'POST',
    column: [
        {
            title: '序号',
            type: 'seq',
            align: 'center',
            width: 60,
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        {
            field: 'startTime',
            title: '暂态事件发生时刻',
            width: '180'
        },
        { field: 'gdName', title: '供电公司' },
        { field: 'subName', title: '变电站' },
        { field: 'ip', title: '网络参数' },
        { field: 'lineName', title: '监测点' },
        {
            field: 'eventType',
            title: '触发类型',
            formatter: (row: any) => {
                return triggerType.filter(item => item.id === row.cellValue)[0].name
            }
        },
        {
            field: 'advanceType',
            title: '暂态类型'
        },
        {
            field: 'advanceReason',
            title: '暂态原因'
        },
        {
            field: 'voltageScale',
            title: '电压等级',
            width: '100'
        },
        {
            field: 'featureAmplitude',
            title: '暂降(骤升)幅值(%)',
            width: '140'
        },
        {
            field: 'duration',
            title: '持续时间(s)',
            width: '100'
        },
        { field: 'severity', title: '严重度' }
    ],

})
tableStore.table.params.comFlag = '1'
tableStore.table.params.monitorFlag = 0
tableStore.table.params.powerFlag = 1
tableStore.table.params.serverName = 'event-boot'
tableStore.table.params.waveType=''
tableStore.table.params.searchValue=''
tableStore.table.params.statisticalType = dictData.getBasicData('Statistical_Type', [
    'Report_Type',
    'Manufacturer',
    'Voltage_Level',
    'Load_Type'
])[0]

provide('tableStore', tableStore)

onMounted(() => {
    tableStore.index()
})
const exportEvent = () => {

    let form: any = JSON.parse(JSON.stringify(tableStore.table.params))
    form.pageNum = 1
    form.pageSize = tableStore.table.total
    getEventReport(form).then(res => {
        tableRef.value.getRef().exportData({
            filename: '事件报告', // 文件名字
            sheetName: 'Sheet1',
            type: 'xlsx', //导出文件类型 xlsx 和 csv
            useStyle: true,
            data: res.data.records, // 数据源 // 过滤那个字段导出
            columnFilterMethod: function (column, $columnIndex) {
                return !(column.$columnIndex === 0)
            }
        })
    })
}
</script>
