<template>
    <div :class="isAdd ? 'common-btn-box2 font12' : 'common-btn-box1 font12'" @click="handleBtnClick()">
        <span>新增</span>
    </div>
</template>

<script setup lang="ts">
import { ElMessageBox } from "element-plus";
import { useMsg } from "@/hooks/useMsg";

const props = defineProps<{
    selectionList?: any[];
    handleChildBtnCallback?: () => void;
    ruleForm: any;
    isAdd?: any;
    isSubmit?: any;
    isGenerate?: any;
}>();
const emits = defineEmits<{
    (e: "handleChildBtnCallback", result: Record<string, any>): void;
}>();

// 提交事件
const handleBtnClick = () => {
    if (props.isAdd) {
        return;
    }
    if (props.isSubmit || props.isGenerate) {
        useMsg("success", "操作成功 ！");
        emits("handleChildBtnCallback", {
            type: "Add"
        });
        return;
    }
    if (!props.isGenerate) {
        ElMessageBox.confirm("新增操作将会重置已填写的数据,确定要进行该操作?", "温馨提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
        })
            .then(() => {
                useMsg("success", "操作成功 ！");
                emits("handleChildBtnCallback", {
                    type: "Add"
                });
            })
            .catch(() => {});
        return;
    }
    if (!props.isSubmit) {
        ElMessageBox.confirm("新增操作将会重置已填写的数据,确定要进行该操作?", "温馨提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
        })
            .then(() => {
                useMsg("success", "操作成功 ！");
                emits("handleChildBtnCallback", {
                    type: "Add"
                });
            })
            .catch(() => {});
        return;
    }
};
</script>

<style scoped>
@import "../index.scss";
</style>
