<template>
    <div>
        <TableHeader area ref="TableHeaderRef" showExport showCustomColumn>
            <template #select>
                <el-form-item label="运行状态">
                    <el-select v-model="tableStore.table.params.runF" clearable placeholder="请选择运行状态" filterable>
                        <el-option
                            v-for="item in runFlagList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="通讯状态">
                    <el-select v-model="tableStore.table.params.comF" clearable placeholder="请选择通讯状态" filterable>
                        <el-option
                            v-for="item in comFlagList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="数据筛选">
                    <el-input
                        style="width: 200px"
                        placeholder="电站名称，终端名称，型号"
                        v-model="tableStore.table.params.searchValue"
                        clearable
                        maxlength="32"
                        show-word-limit
                    ></el-input>
                </el-form-item>
            </template>
            <template #operation>
                <!-- <el-button icon='el-icon-Download' type='primary'>导出</el-button> -->
            </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 { ElMessage, ElMessageBox } from 'element-plus'
import { mainHeight } from '@/utils/layout'
import { useDictData } from '@/stores/dictData'
import { addUse, updateUse, removeUse } from '@/api/advance-boot/bearingCapacity'

const dictData = useDictData()
const interferenceType = dictData.getBasicData('Interference_Source')
const istatusList = dictData.getBasicData('On-network_Status')
const TableHeaderRef = ref()
const areaOptionList = dictData.getBasicData('jibei_area')
const tableStore = new TableStore({
    url: '/device-boot/runManage/getDeviceLedger',
    publicHeight: 65,
    method: 'POST',
    filename: '终端台账',
    column: [
        {
            title: '序号',
            width: 80,
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        {
            field: 'areaName',
            title: '省公司',
            minWidth: 100
        },
        {
            field: 'gdName',
            title: '市公司',
            minWidth: 150
        },
        { field: 'bdName', title: '所属变电站', minWidth: 120 },
        { field: 'devName', title: '终端名称', minWidth: 110 },
        { field: 'loginTime', title: '投运时间', minWidth: 100 },
        { field: 'updateTime', title: '最新数据时间', minWidth: 150 },
        {
            field: 'manufacturer',
            title: '厂家',
            minWidth: 80
        },
        { field: 'devType', title: '终端型号', minWidth: 100 },

        { field: 'ip', title: '终端网络参数', width: '120px' },
        { field: 'powerFlag', title: '用户性质', width: '120px' },
        { field: 'port', title: '端口号', minWidth: 70 },
        {
            field: 'comFlag',
            title: '通讯状态',
            minWidth: 80,
            render: 'tag',
            custom: {
                正常: 'success',
                中断: 'danger',
                '/': 'primary'
            }
        },
        {
            field: 'runFlag',
            title: '运行状态',
            minWidth: 80,
            render: 'tag',
            custom: {
                投运: 'success',
                停运: 'danger',
                检修: 'warning',
                调试: 'warning',
                退运: 'danger'
            }
        }

        /*   {
                title: '操作',fixed: 'right',
               minWidth: 150,
               fixed: 'right',
               render: 'buttons',
               buttons: [
                   {
                       name: 'productSetting',
                       title: '流程详情',
                       type: 'primary',
                       icon: 'el-icon-EditPen',
                       render: 'basicButton',
                       click: row => {

                       }
                   }
               ]
           }*/
    ],

    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.runFlag = [tableStore.table.params.runF]
        }
        tableStore.table.params.comFlag = []
        if (tableStore.table.params.comF != null) {
            tableStore.table.params.comFlag = [tableStore.table.params.comF]
        }
    }
})

tableStore.table.params.runF = 0
tableStore.table.params.comF = ''
tableStore.table.params.runFlag = []
tableStore.table.params.searchValue = ''

const runFlagList = [
    { id: 0, name: '投运' },
    { id: 1, name: '检修' },
    { id: 2, name: '停运' },
    { id: 3, name: '调试' },
    { id: 4, name: '退运' }
]
const comFlagList = [
    { name: '正常', id: 1 },
    { name: '中断', id: 0 }
]

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