<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 Form from './form.vue'
import { cableDelete } from '@/api/advance-boot/assess'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive, onMounted } from 'vue'
const tableStore = new TableStore({
    url: '/advance-boot/assessDicCableType/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: 'linetypeName', minWidth: '130' },
        {
            title: '线缆类型',
            field: 'linetypeType',
            minWidth: '80',
            formatter: (row: any) => {
                return row.cellValue == '01' ? '架空线' : '电缆'
            }
        },
        { title: '正序电阻R1(Ω/km)', field: 'posR1', minWidth: '80' },
        { title: '正序电抗X1(Ω/km)', field: 'posX1', minWidth: '80' },
        { title: '正序电纳Y1(S/km)', field: 'posY1', minWidth: '80' },
        { title: '零序电阻R0(Ω/km)', field: 'zeroR0', minWidth: '80' },
        { title: '零序电抗X0(Ω/km)', field: 'zeroX0', minWidth: '80' },
        { title: '零序电纳Y0(S/km)', field: 'zeroY0', 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(() => {
            cableDelete(tableStore.table.selection.map(item => item.linetypeId)).then(res => {
                ElMessage({
                    type: 'success',
                    message: '删除成功!'
                })
                tableStore.index()
            })
        })
    }
}
onMounted(() => {
    tableStore.index()
})
</script>
<style lang="scss" scoped></style>
