<template>
    <TableHeader>
        <template v-slot:operation>
            <el-button type='primary' @click='addMenu'>新增</el-button>
        </template>
    </TableHeader>
    <Table ref='tableRef' :pagination='false' />
    <popupForm ref='popupRef'></popupForm>
</template>
<script setup lang='ts'>
import { ref, onMounted, provide } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import popupForm from './popupForm.vue'

defineOptions({
    name: 'auth/menu'
})
const tableRef = ref()
const popupRef = ref()
const tableStore = new TableStore({
    url: '/user-boot/function/functionTree',
    column: [
        { type: 'selection', align: 'center', width: '60' },
        { label: '菜单名称', prop: 'title', align: 'left' },
        {
            label: '图标',
            prop: 'icon',
            align: 'center',
            width: '60',
            render: 'icon'
        },
        {
            label: '操作',
            align: 'center',
            width: '130',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '编辑',
                    type: 'primary',
                    icon: 'el-icon-EditPen',
                    render: 'tipButton',
                    click: (row) => {
                        popupRef.value.open('编辑菜单', row)
                    }
                },
                {
                    name: 'del',
                    title: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText:'确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除该菜单吗？',
                    },
                    click: (row) => {
                        popupRef.value.open('编辑菜单', row)
                    }
                }
            ]
        }
    ]
})
provide('tableStore', tableStore)

onMounted(() => {
    tableStore.table.ref = tableRef.value
    tableStore.index()
})
const addMenu = () => {
    console.log(popupRef)
    popupRef.value.open('新增菜单')
}
</script>
