<template>
    <div class="mt10">
        <TableHeader :showReset="false" ref="TableHeaderRef" showExport showCustomColumn>
            <template #select>
                <el-form-item label="变压器型号">
                    <el-input v-model="tableStore.table.params.searchValue" clearable placeholder="请输入变压器型号" show-word-limit
                    maxlength="32"/>
                </el-form-item>
            </template>
            <template #operation>
                <el-button type="primary" icon="el-icon-Plus" @click="add">新增</el-button>
                <el-button type="primary" icon="el-icon-Delete" @click="del">删除</el-button>
                <!-- <el-button type="primary" icon="el-icon-Download">模版下载</el-button>
                <el-button type="primary" icon="el-icon-Upload">导入</el-button> -->
            </template>
        </TableHeader>
        <Table ref="tableRef"></Table>
        <!-- 表单 -->
        <Form ref="formRef" @submit="tableStore.index()" />
    </div>
</template>
<script setup lang="ts">
import TableStore from '@/utils/tableStore'
import TableHeader from '@/components/table/header/index.vue'
import Table from '@/components/table/index.vue'
import { transformerDelete } from '@/api/advance-boot/assess'
import { useDictData } from '@/stores/dictData'
import Form from './form.vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive, onMounted } from 'vue'
const dictData = useDictData()
//字典电压等级
const voltageLevelList = dictData.getBasicData('Dev_Voltage_Stand')
const tableStore = new TableStore({
    url: '/advance-boot/assessDicTransformer/page',
    method: 'POST',
    publicHeight: 115,
    filename: '变压器参数',
    column: [
        {
            width: '60',
            type: 'checkbox'
        },
        {
            title: '序号',
            width: 80,
            field: 'name',
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { title: '变压器型号', field: 'transtypeName', minWidth: '130' },
        { title: '额定容量(kVA)', field: 'transCapa', minWidth: '80' },
        {
            title: '高压侧电压(kV)',
            field: 'transhighScale',
            minWidth: '80',
            formatter: (row: any) => {
                return voltageLevelList.find((item: any) => item.id == row.row.transhighScale)?.name
            }
        },
        {
            title: '低压侧电压(kV)',
            field: 'translowScale',
            minWidth: '80',
            formatter: (row: any) => {
                return voltageLevelList.find((item: any) => item.id == row.row.translowScale)?.name
            }
        },
        { title: '联结组标号', field: 'trnasNo', minWidth: '80' },
        { title: '空载损耗(kW)', field: 'noloadLoss', minWidth: '80' },
        { title: '负载损耗(kW)', field: 'loadLoss', minWidth: '80' },
        { title: '空载电流(A)', field: 'noloadCur', minWidth: '80' },
        { title: '短路阻抗(%)', field: 'shortCircuitImpedance', minWidth: '80' },
        {
             title: '操作',fixed: 'right',
            width: '180',
           
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '编辑',
                    type: 'primary',
                    icon: 'el-icon-Open',
                    render: 'basicButton',

                    click: row => {
                        formRef.value.open('编辑变压器参数字典', row)
                    }
                },
                // {
                //     name: 'edit',
                //     title: '查看',
                //     type: 'primary',
                //     icon: 'el-icon-Open',
                //     render: 'basicButton',

                //     click: row => {}
                // }
            ]
        }
    ],
    loadCallback: () => {}
})
const formRef = ref()
provide('tableStore', tableStore)
tableStore.table.params.searchValue = ''
// 新增
const add = () => {
    formRef.value.open('新增变压器参数字典')
}

//删除
const del = () => {
    if (tableStore.table.selection.length == 0) {
        ElMessage({
            type: 'warning',
            message: '请选择要删除的数据'
        })
    } else {
        ElMessageBox.confirm('此操作将永久删除, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            transformerDelete(tableStore.table.selection.map(item => item.transtypeId)).then(res => {
                ElMessage({
                    type: 'success',
                    message: '删除成功!'
                })
                tableStore.index()
            })
        })
    }
}
onMounted(() => {
    tableStore.index()
})
</script>
<style lang="scss" scoped></style>
