<template>
    <el-dialog v-model="dialogVisible" :title="parameter.title" :width="parameter.width">
        <slot />
        <template #footer>
            <el-button @click="handleCancel">取消</el-button>
            <el-button type="primary" @click="handleConfirm">确认</el-button>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
export interface IParams {
    title: string
    width?: string | number
    data: { [key: string]: any }
}
const emit = defineEmits(['handleCancel', 'handleConfirm'])

const dialogVisible = ref(false)
// 父组件传递过来的参数
const parameter = ref<IParams>({
    title: '',
    width: '50%',
    data: {}
})
const openDialog = (params: IParams) => {
    parameter.value = { ...parameter.value, ...params }
    dialogVisible.value = true
}

const handleCancel = () => {
    emit('handleCancel', closeDialog)
}
const handleConfirm = () => {
    emit('handleConfirm', closeDialog)
}
const closeDialog = () => {
    dialogVisible.value = false
}
defineExpose({
    openDialog,
    dialogVisible
})
</script>
<style scoped></style>
