<template>
    <div>
        <TableHeader ref="TableHeaderRef" showExport showCustomColumn>
            <template #select>
                <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 categoryList = dictData.getBasicData('Power_Category')
const stationTypeList = dictData.getBasicData('Power_Station_Type')
const generationList = dictData.getBasicData('Power_Generation')
const voltageList = dictData.getBasicData('Dev_Voltage')
const modeList = dictData.getBasicData('Connection_Mode')
const statList = dictData.getBasicData('Ecc_Stat')

const tableStore = new TableStore({
    url: '/device-boot/generationUser/getPowerGenerationUserPageList',
    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: 'id', title: '用户编号', minWidth: 150 },
        { field: 'name', title: '用户名称', minWidth: 180 },
        { field: 'orgName', title: '组织机构名称', minWidth: 150 },
        { field: 'operationName', title: '运维单位名称', minWidth: 150 },
        {
            field: 'powerCategory',
            title: '电源类别',
            minWidth: 120,
            formatter: (row: any) => {
                return categoryList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        {
            field: 'powerStationType',
            title: '电站类型',
            minWidth: 120,
            formatter: (row: any) => {
                return stationTypeList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        {
            field: 'powerGenerationMode',
            title: '发电方式',
            minWidth: 100,
            formatter: (row: any) => {
                return generationList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        {
            field: 'voltageLevel',
            title: '并网电压等级',
            minWidth: 90,
            formatter: (row: any) => {
                return voltageList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        { field: 'sourceCapacity', title: '总装机容量(KVA)', minWidth: 100 },
        { field: 'connectionDate', title: '并网日期', minWidth: 120 },
        {
            field: 'connectionMode',
            title: '能源消纳方式',
            minWidth: 130,
            formatter: (row: any) => {
                return modeList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        {
            field: 'gcStat',
            title: '客户状态',
            minWidth: 120,
            formatter: (row: any) => {
                return statList.filter(item => item.id == row.cellValue)[0]?.name || '/'
            }
        },
        {
            field: 'isUpToGrid',
            title: '是否上送网公司监测点',
            minWidth: 110,
            formatter: (row: any) => {
                return row.cellValue==1?'是':'否'
            }
        }
    ],

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

tableStore.table.params.searchValue = ''

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

defineExpose({
    setSearchValue
})
</script>
