<template>
    <div class="font12" style="display: flex; align-items: center; margin-left: 12px">
        <div style="margin-right: 4px">
            <span>选择数字序列号模板</span>
        </div>

        <el-switch v-model="numberCodeValue" @change="handleBtnClick" :disabled="isGenerate" />
    </div>
</template>

<script setup lang="ts">
import { ElMessageBox } from "element-plus";
const props: any = defineProps<{
    selectionList?: any[];
    handleChildBtnCallback?: () => void;
    ruleForm: any;
    isGenerate: any;
    isNumberSwitch: any; //点击新增按钮时关闭开关
}>();
const numberCodeValue = ref(false);
const emits = defineEmits<{
    (e: "handleChildBtnCallback", result: Record<string, any>): void;
}>();
const handleEmits = () => {
    emits("handleChildBtnCallback", {
        type: "numberCode",
        data: numberCodeValue.value
    });
};
// 提交事件
const handleBtnClick = () => {
    if (props.ruleForm.beginNumber && !numberCodeValue.value) {
        ElMessageBox.confirm("当前数据未生成箱唛, 确认放弃新增数据?", "温馨提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
        })
            .then(() => {
                handleEmits();
            })
            .catch(() => {
                numberCodeValue.value = !numberCodeValue.value;
                handleEmits();
            });
        return;
    }
    handleEmits();
};
watch(
    () => props.isNumberSwitch,
    newVal => {
        if (!newVal) {
            console.log(newVal, "======newVal=======");
            numberCodeValue.value = false;
        }
    },
    {
        immediate: true,
        deep: true
    }
);
</script>

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