<template>
    <div class="default-main">
        <TableHeader area ref="TableHeaderRef" showExport showCustomColumn> 
            <template #select>
                <el-form-item label="运行状态">
                    <el-select filterable multiple collapse-tags v-model="tableStore.table.params.runFlag" clearable
                               placeholder="请选择运行状态">
                        <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.comFlag" 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.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>
                <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-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-input style="width: 240px"
                              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" />

        <!-- 限值查看弹框 -->
        <LimitDialog ref="limitDialogRef" />
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted, provide, nextTick, watch } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import LimitDialog  from './monitorLimit.vue'
import { useDictData } from '@/stores/dictData'

const dictData = useDictData()
const TableHeaderRef = ref()
const IS_LN = import.meta.env.VITE_NAME == 'LN' || import.meta.env.VITE_NAME == 'LNqr'
const interfereoption = dictData.getBasicData('Interference_Source')
const terminaloption = dictData.getBasicData('Dev_Manufacturers')
const voltageleveloption = dictData.getBasicData('Dev_Voltage_Stand')
const limitDialogRef = ref()
const tableStore = new TableStore({
    url: '/device-boot/runManage/getLineLedgerComm',
    method: 'POST',
    filename: '监测点台账',
    column: [
        {
            title: '序号',
            width: 80,
            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: 150, formatter: (row: any) => {
                if (IS_LN) {
                    return row.cellValue.replace('国网', '').replace('供电公司', '')
                } else {
                    return row.cellValue
                }
            }
        },
        {
            field: 'bdName',
            title: '所属变电站',
            minWidth: 150
        },
        {
            field: 'objName',
            title: '监测对象名称',
            minWidth: 150,
            formatter: (row: any) => {
                return row.cellValue ? row.cellValue : '/'
            }
        },
        { field: 'lineName', title: '监测点名称', minWidth: 130 },
        { field: 'scale', title: '监测点电压等级', minWidth: 80 },

        { field: 'loadType', title: '干扰源类型', minWidth: 120 },

        {
            field: 'manufacturer',
            title: '终端厂家',
            minWidth: 100,
            formatter: (row: any) => {
                return row.cellValue ? row.cellValue : '/'
            }
        },
        {
            field: 'runFlag',
            title: '运行状态',
            minWidth: 80,
            render: 'tag',
            custom: {
                投运: 'success',
                停运: 'danger',
                检修: 'warning',
                调试: 'warning',
                退运: 'danger'
            }
        },
        {
            field: 'comFlag',
            title: '通讯状态',
            render: 'tag',
            // effect: 'dark',
            minWidth: 70,
            custom: {
                正常: 'success',
                中断: 'danger'
            }
        },
        {
            field: 'shortCapacity',
            title: '最小短路容量(MVA)',
            minWidth: 100
        },
        {
            field: 'devCapacity',
            title: '供电设备容量(MVA )',
            minWidth: 100
        },
        {
            field: 'dealCapacity',
            title: '用户协议容量(MVA)',
            minWidth: 100
        },

        { field: 'id', title: '监测点序号', minWidth: 70 },

        { field: 'devName', title: '监测终端编号 ', minWidth: 140 },
        { field: 'ptType', title: '监测终端接线方式', minWidth: 140 },
        {
            field: 'voltageDev',
            title: '电压偏差上限(%)',
            minWidth: 80
        },
        {
            field: 'uvoltageDev',
            title: '电压偏差下限(%)',
            minWidth: 80
        },

           {
                title: '操作',
               minWidth: 80,
               fixed: 'right',
               render: 'buttons',
               buttons: [
                   {
                       name: 'productSetting',
                       title: '查看限值',
                       type: 'primary',
                       icon: 'el-icon-EditPen',
                       render: 'basicButton',
                       click: row => {
                           // 打开限值查看弹框
                           limitDialogRef.value?.open(row)
                       }
                   }
               ]
           }
    ],

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


    }
})

tableStore.table.params.runFlag = []
tableStore.table.params.comFlag = []
tableStore.table.params.powerFlag = 2
tableStore.table.params.monitorFlag = 2
tableStore.table.params.searchValue = ''
tableStore.table.params.scale = []
tableStore.table.params.manufacturer = []
tableStore.table.params.loadType = []
const runFlagList = [
    { id: 0, name: '投运' },
    { id: 1, name: '检修' },
    { id: 2, name: '停运' }

]

const communicationstatus = [
    { value: 0, label: '中断' },
    { value: 1, label: '正常' }
]

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


</script>
