<template>
    <div class="default-main">
        <TableHeader area ref="TableHeaderRef" showExport  showCustomColumn>
            <template #select>
                <!-- <el-form-item label="统计类型:">
                    <el-select v-model="tableStore.table.params.statisticalType" placeholder="请选择统计类型" value-key="id">
                        <el-option v-for="item in classificationData" :key="item.id" :label="item.name" :value="item">
                        </el-option>
                    </el-select>

                </el-form-item> -->

                <el-form-item label="终端厂家">
                    <el-select
                        v-model="tableStore.table.params.manufacturer"
                        filterable
                        multiple
                        collapse-tags
                        clearable
                        placeholder="请选择终端厂家"
                        value-key="id"
                    >
                        <el-option
                            v-for="item in terminaloption"
                            :key="item.id"
                            :label="item.name"
                            :value="item"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="数据筛选">
                    <el-input
                        v-model="tableStore.table.params.searchValue"
                        clearable
                        placeholder="输入市公司、变电站、用户"
                    />
                </el-form-item>

                <el-form-item label="通讯状态">
                    <el-select
                        v-model="tableStore.table.params.comF"
                        filterable
                        multiple
                        collapse-tags
                        clearable
                        placeholder="请选择通讯状态"
                    >
                        <el-option
                            v-for="item in communicationstatus"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="终端状态">
                    <el-select
                        v-model="tableStore.table.params.runF"
                        filterable
                        multiple
                        collapse-tags
                        clearable
                        placeholder="请选择终端状态"
                    >
                        <el-option
                            v-for="item in terminalstatus"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="干扰源类型">
                    <el-select
                        v-model="tableStore.table.params.loadType"
                        filterable
                        multiple
                        collapse-tags
                        clearable
                        placeholder="请选择干扰源类型"
                        value-key="id"
                    >
                        <el-option
                            v-for="item in interfereoption"
                            :key="item.id"
                            :label="item.name"
                            :value="item"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="电压等级">
                    <el-select
                        v-model="tableStore.table.params.scale"
                        filterable
                        multiple
                        collapse-tags
                        clearable
                        placeholder="请选择电压等级"
                        value-key="id"
                    >
                        <el-option
                            v-for="item in voltageleveloption"
                            :key="item.id"
                            :label="item.name"
                            :value="item"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </template>
        </TableHeader>
        <Table ref="tableRef" />
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide, nextTick } 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'
defineOptions({
    name: 'harmonic-boot/run/terminalmessage'
})

const dictData = useDictData()

const view = ref(true)
const classificationData = dictData.getBasicData('Statistical_Type', ['Report_Type', 'Voltage_Level', 'Load_Type'])
const voltageleveloption = dictData.getBasicData('Dev_Voltage_Stand')
const terminaloption = dictData.getBasicData('Dev_Manufacturers')
const interfereoption = dictData.getBasicData('Interference_Source')
const IS_LN = import.meta.env.VITE_NAME == 'LN' || import.meta.env.VITE_NAME == 'LNqr'

const communicationstatus = [
    { value: 0, label: '中断' },
    { value: 1, label: '正常' }
]
const terminalstatus = [
    { value: 0, label: '投运' },
    { value: 1, label: '检修' },
    { value: 2, label: '停运' }
]
const tableStore = new TableStore({
    url: '/device-boot/runManage/getRuntimeData',
    method: 'POST',
    column: [
        {
            field: 'index',
            title: '序号',
            width: '70',
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        {
            visible: !IS_LN,
            field: 'areaName',
            title: '省公司',
            minWidth: 100
        },
        {   visible: IS_LN,
            field: 'gdName', title: '市公司', minWidth: 120, formatter: (row: any) => {
                if (IS_LN) {
                    return row.cellValue.replace('国网', '').replace('供电公司', '')
                } else {
                    return row.cellValue
                }
            }
        },
        {
            field: 'bdName',
            title: '变电站',
            minWidth: 110
        },
        {
            field: 'objName',
            title: '监测点对象',
            minWidth: 110
        },
        { field: 'manufacturer', title: '厂家', minWidth: 100 },

        { field: 'devName', title: '终端名称', minWidth: 100 },
        { field: 'ip', title: '网络参数', width: 110 },
        { field: 'loginTime', title: '投运时间', minWidth: 90 },
        { field: 'devType', title: '终端型号', minWidth: 100 },
        { field: 'port', title: '端口', minWidth: 60 },
        { field: 'updateTime', title: '最新数据', minWidth: 110 },
        {
            field: 'runFlag',
            title: '终端状态',
            // effect: 'dark',
            render: 'tag',
            minWidth: 70,
            custom: {
                投运: 'success',
                检修: 'warning',
                停运: 'danger'
            }
        },
        {
            field: 'comFlag',
            title: '通讯状态',
            render: 'tag',
            // effect: 'dark',
            minWidth: 70,
            custom: {
                正常: 'success',
                中断: 'danger'
            }
        }
    ],

    beforeSearchFun: () => {
        tableStore.table.params.serverName = 'harmonic-boot'
        tableStore.table.params.statisticalType = {
            name: '电网拓扑',
            code: 'Power_Network'
        }

        tableStore.table.params.runFlag = []
        if (tableStore.table.params.runF != null && tableStore.table.params.runF != '') {
            tableStore.table.params.runFlag = tableStore.table.params.runF
        }
        tableStore.table.params.comFlag = []
        if (tableStore.table.params.comF != null && tableStore.table.params.comF != '') {
            tableStore.table.params.comFlag = tableStore.table.params.comF
        }
    }
})
tableStore.table.params.runF = ''
tableStore.table.params.comF = ''
tableStore.table.params.statisticalType = classificationData[0]
tableStore.table.params.serverName = 'harmonic-boot'
tableStore.table.params.comFlag = []
tableStore.table.params.runFlag = []
tableStore.table.params.searchValue = ''
tableStore.table.params.powerFlag = 2
tableStore.table.params.monitorFlag = 2
tableStore.table.params.scale = []
tableStore.table.params.manufacturer = []
tableStore.table.params.loadType = []

provide('tableStore', tableStore)
onMounted(() => {
    tableStore.index()
})
</script>
