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

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

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

// 列表查询信息的api
const action = ref(requestMethod.page)

const useManageMethod = manageMethod<LogVersion>()

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

// 列表操作信息
const operation = ref<OperationProps<LogVersion>[]>([
	{
		title: '修改',
		permission: true,
		action: useManageMethod.handleUpdate
	},
	{
		title: '删除',
		permission: true,
		action: (vo: LogVersion) => {
			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;
}
</style>
