<template>
    <div>
        <TableHeader  ref="TableHeaderRef" showExport>
            <template #select>
                <!-- <el-form-item label="数据类型">
                    <el-select v-model="tableStore.table.params.dataType" clearable placeholder="请选择运行状态">
                        <el-option label="主网" value="0"></el-option>
                        <el-option label="配网" value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="监测点类别">
                    <el-select v-model="tableStore.table.params.lineType" clearable placeholder="请选择运行状态">
                        <el-option
                            v-for="item in lineList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item> -->
                <el-form-item label="筛选数据">
                    <el-input
                        style="width: 240px"
                        placeholder="请输入台区名称/组织机构名称/监测线路名称"
                        v-model="tableStore.table.params.searchValue"
                        clearable
                    ></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, watch } 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 lineList = dictData.getBasicData('Line_Type')
const AreaList = dictData.getBasicData('Area')
const UseNatureList = dictData.getBasicData('Device_UseNature')
const StateList = dictData.getBasicData('Line_State')

const tableStore = new TableStore({
    url: '/device-boot/distributionArea/getPowerDistributionAreaList',
    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: 'id', title: '台区编号', minWidth: 150 },
        { field: 'name', title: '台区名称', minWidth: 180 },
        {
            field: 'orgName',
            title: '组织机构名称',
            minWidth: 150
        },
        { field: 'operationName', title: '运维单位', minWidth: 150 },
        { field: 'powerrName', title: '变电站名称', minWidth: 150 },
        { field: 'lineName', title: '监测线路名称', minWidth: 190 },
        { field: 'pcapacity', title: '配变容量(KVA)', minWidth: 80 },
        {
            field: 'regionalism',
            title: '地区特征',
            minWidth: 80,
            formatter: (row: any) => {
                return AreaList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        {
            field: 'ifRuralPowerGrid',
            title: '是否农网',
            minWidth: 80,
            formatter: (row: any) => {
                return row.row.ifRuralPowerGrid == 1 ? '是' : '否'
            }
        },
        {
            field: 'natureOfUse',
            title: '使用性质',
            minWidth: 80,
            formatter: (row: any) => {
                return UseNatureList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        { field: 'lineLength', title: '供电线路总长度(km)', minWidth: 100 },
        {
            field: 'state',
            title: '运行状态',
            minWidth: 80,
            formatter: (row: any) => {
                return StateList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        { field: 'distributedPhotovoltaicNum', title: '用户数', minWidth: 90 },
        { field: 'photovoltaicCapacity', title: '总装机容量(MW)', minWidth: 100 },
        { field: 'apLoadType', title: '接入负荷类型', minWidth: 130 }
    ],

    beforeSearchFun: () => {
        tableStore.table.params.orgId = tableStore.table.params.deptIndex
    }
})

tableStore.table.params.searchValue = ''
tableStore.table.params.dataType = ''
tableStore.table.params.lineType = ''

provide('tableStore', tableStore)
onMounted(() => {
    tableStore.index()
})
const setSearchValue = (val: string) => {
    tableStore.table.params.searchValue = val
    tableStore.index()
}

defineExpose({
    setSearchValue
})
</script>
