<!-- 系统管理-菜单管理-删除 -->
<template>
    <app-drawer title="提示" v-model:show="show" :loading="loading" :refresh="refresh">
        <div class="g-text-message">是否删除该菜单？</div>
        <template #footer>
            <el-button @click="onCancel(false)">取消</el-button>
            <el-button type="primary" @click="onSubmit">确认</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { deleteMenus } from '@/services/api/user'
import AppDrawer from '@pc/components/base/drawer/index.vue'

const props = defineProps({
    record: {
        type: Object as PropType<Model.MenusRsp>,
        required: true
    }
})

const show = shallowRef(true)
const refresh = shallowRef(false)
const loading = shallowRef(false)

const onCancel = (isRefresh = false) => {
    show.value = false
    refresh.value = isRefresh
}

const onSubmit = () => {
    loading.value = true
    deleteMenus({
        data: {
            resourceCode: props.record.resourceCode
        }
    }).then(() => {
        ElMessage.success('删除成功')
        onCancel(true)
    }).catch((err) => {
        ElMessage.error('删除失败：' + err)
        onCancel()
    }).finally(() => {
        loading.value = false
    })
}
</script>