<template>
    <div class="mt10">
        <TableHeader :showReset="false" ref="TableHeaderRef" showExport>
            <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 { mainHeight } from '@/utils/layout'
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { loadDelete } from '@/api/advance-boot/assess'
import Form from './form.vue'
import { useDictData } from '@/stores/dictData'
const dictData = useDictData()
//字典电压等级
const List = dictData.getBasicData('Interference_Source')
const tableStore = new TableStore({
    url: '/advance-boot/assessDicShockLoad/page',
    method: 'POST',
    filename: '冲击负荷参数',
    publicHeight: 115,
    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: 'inpactloadtypeName', minWidth: '130' },
        // {
        //     title: '负荷类型',
        //     field: 'inpactloadtypeId',
        //     minWidth: '130',
        //     // formatter: (row: any) => {
        //     //     return List.find((item: any) => item.id == row.row.inpactloadtypeId)?.name
        //     // }
        // },
        { title: '启动方式', field: 'inpactloadStartup', minWidth: '80' },
        { title: '启动容量倍数', field: 'inpactloadMultiple', 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)
                    }
                }
            ]
        }
    ],
    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(() => {
            loadDelete(tableStore.table.selection.map(item => item.inpactloadtypeId)).then(res => {
                ElMessage({
                    type: 'success',
                    message: '删除成功!'
                })
                tableStore.index()
            })
        })
    }
}
onMounted(() => {
    tableStore.index()
})
</script>
<style lang="scss" scoped></style>
