<template>
    <div class="default-main">
        <TableHeader ref="TableHeaderRef" showCustomColumn>
            <template #select>
                <el-form-item label="新能源场站名称">
                    <el-input v-model="tableStore.table.params.name" clearable placeholder="输入关键字筛选" />
                </el-form-item>
            </template>
            <template #operation>
                <el-button icon="el-icon-Plus" type="primary" @click="add">新增</el-button>
            </template>
        </TableHeader>
        <Table ref="tableRef" />
        <!--弹框-->
        <addForm ref="addFormRef" @onSubmit="tableStore.index()" />
    </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 addForm from './components/addForm.vue'
import { useDictData } from '@/stores/dictData'
import { useAdminInfo } from '@/stores/adminInfo'
import { delNewStation } from '@/api/device-boot/newEnergy'
defineOptions({
    name: 'newEnergy/newEnergyLedger'
})
const dictData = useDictData()
//获取登陆用户姓名和部门
const adminInfo = useAdminInfo()
const newEnergy = dictData.getBasicData('new_station_type')
const scaleList = dictData.getBasicData('Dev_Voltage_Stand')
const tableRef = ref()
const TableHeaderRef = ref()
const addFormRef = ref()
const tableStore = new TableStore({
    url: '/device-boot/newStation/queryPage',
    method: 'POST',
    column: [
        {
            title: '序号',
            width: '80',
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { field: 'name', title: '新能源场站名称' },
        {
            field: 'stationType',
            title: '新能源场站类型',

            formatter: (row: any) => newEnergy.filter(item => item.id == row.cellValue)[0]?.name
        },
        {
            field: 'scale',
            title: '电压等级',

            formatter: (row: any) => scaleList.filter(item => item.id == row.cellValue)[0]?.name
        },
        { field: 'ratedPower', title: '额定有功功率(kW)' },
        { field: 'longitude', title: '经度' },
        { field: 'latitude', title: '纬度' },
        {
             title: '操作',fixed: 'right',
            align: 'center',
            render: 'buttons',
          
            buttons: [
                {
                    name: 'edit',
                    title: '修改',
                    type: 'primary',
                    icon: 'el-icon-edit',
                    render: 'basicButton',
                    click: row => {
                        addFormRef.value.open({
                            title: '修改',
                            row: row
                        })
                    }
                },
                {
                    name: 'delete',
                    title: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除该数据吗？'
                    },
                    click: row => {
                        delNewStation({ ids: row.id }).then(() => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ],
    beforeSearchFun: () => {
        tableStore.table.params.currentPage = tableStore.table.params.pageNum
    },
    loadCallback: () => {}
})
tableStore.table.params.name = ''
const add = () => {
    addFormRef.value.open({
        title: '新增'
    })
}
provide('tableStore', tableStore)

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

<style scoped lang="scss"></style>
