<template>
	<el-dialog title="快速添加页面和权限" v-model="visible" :width="500" destroy-on-close @closed="emit('closed')" :close-on-click-modal="false">
		<el-form :model="form" ref="dialogForm" label-width="100px" label-position="right">
			<el-form-item label="菜单名称" prop="title">
				<el-input v-model="form.title" placeholder="测试页面" clearable></el-input>
			</el-form-item>
			<el-form-item label="菜单图标" prop="icon">
				<pi-icon-select v-model="form.icon" clearable></pi-icon-select>
			</el-form-item>
			<el-form-item label="页面名称" prop="name">
				<el-input v-model="form.name" placeholder="systemDemo" clearable></el-input>
			</el-form-item>
			<el-form-item label="路由地址" prop="path">
				<el-input v-model="form.path" placeholder="system/demo" clearable></el-input>
			</el-form-item>
			<el-form-item label="权限标识" prop="flag">
				<el-input v-model="form.flag" placeholder="demo" clearable></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script setup>
import piIconSelect from '@/components/piIconSelect'
import {ref, getCurrentInstance} from "vue"
import api from "@/api"
const emit = defineEmits(['closed', 'success']);

defineExpose({
	open
})

const {proxy} = getCurrentInstance()
let visible = ref(false)
let isSaveing = ref(false)

let form = ref({
	parent_id: 0,
	title: '',
	name: '',
	path: '',
	flag: '',
	icon: ''
})

function open(parent_id) {
	form.value.parent_id = parent_id || 0
	visible.value = true
}

async function submit() {
	const res = await api.system.menu.quick(form.value)
	proxy.$message.success(res.msg)
	visible.value = false
	emit('success')
}

</script>

<style scoped>

</style>
