<template>
	<div class="page">
		<BaseTable
			ref="baseTable"
			:action="requestMethod.page"
			:columns="columns"
			:max-operation="3"
			:operation="operation"
			:search="search"
			:use-keywords="false"
		>
			<template v-slot:operation>
				<a-button v-if="checkPermission('新增')" type="primary" @click="useManageMethod.handleUpdate(undefined)"> 新增 </a-button>
			</template>
		</BaseTable>
		<dc-drawer
			:closable="true"
			:maskClosable="false"
			:showBottom="!update.id"
			:title="update.title"
			:visible="update.visible"
			:width="update.width"
			destroyOnClose
			placement="right"
			@close="update.visible = false"
		>
			<Add :id="update.id" @cancel="update.visible = false" @refresh="useManageMethod.refresh()" />
		</dc-drawer>
	</div>
</template>

<script lang="ts" setup>
import { defineAsyncComponent, ref } from 'vue'
import requestMethod from '../../../api/system/menu'
import BaseTable from '../../../components/table/BaseTable.vue'
import columns from './columns'
import search from './search'
import { OperationProps } from '../../../components/table/table-helper'
import { confirmMethod, messageMethod } from '../../../utils/message-util'
import { SystemMenu } from '../../../entity/system/system-menu'
import { manageMethod } from '../../../components/form/method'
import { checkPermission } from '../../../utils/permission-util'

const Add = defineAsyncComponent(() => import('./Add.vue'))

const useManageMethod = manageMethod<SystemMenu>()

// 修改面板参数
const update = useManageMethod.update

// 获取当前的数据表
const baseTable = ref<InstanceType<typeof BaseTable>>(null)

// 列表操作信息
const operation = ref<OperationProps<SystemMenu>[]>([
	{
		title: '修改',
		permission: true,
		action: useManageMethod.handleUpdate
	},
	{
		title: '删除',
		danger: true,
		permission: true,
		action: async (vo: SystemMenu) => {
			confirmMethod.info('确认删除？', () => {
				requestMethod.delete(vo.id).then(data => {
					messageMethod.success(data.message)
					useManageMethod.refresh()
				})
			})
		}
	}
])
</script>

<style scoped>
.page {
	height: 100%;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
}
</style>
