<template>
    <div class="common-btn-box font12" @click="handleBtnClick()" v-if="isBtnShow[routeName]">
        <span>同步成功</span>
    </div>
</template>

<script setup lang="ts">
import { useMsg } from "@/hooks/useMsg";
import { useAuthStore } from "@/stores/modules/auth";
const authStore = useAuthStore();
const $router = useRouter();
const routeName: string = $router.currentRoute.value.name as string;

const props = defineProps<{
    selectionList: any[];
    handleChildBtnCallback?: () => void;
}>();
const emits = defineEmits<{
    (e: "handleChildBtnCallback", result: Record<string, any>): void;
}>();
// 提交事件
const handleBtnClick = async () => {
    if (!props.selectionList.length) {
        useMsg("warning", "请选择需要修改状态的数据 ！");
        return;
    }
    let isSuccess = props.selectionList.some((item: any) => {
        return item.successSyncStatus == 1;
    });
    if (isSuccess) {
        useMsg("warning", "请选择同步结果为“同步失败和同步中”的数据修改同步结果 ！");
        return false;
    }
    emits("handleChildBtnCallback", {
        type: "Synchronous"
    });
};

//渲染按钮
const isBtnShow = computed(() => {
    const btnShowObj: any = {
        warehouseReceiptList: false
    };

    let btnName = routeName + "Synchronous";
    btnShowObj[routeName] = authStore.btnsAuthList.includes(btnName);
    return btnShowObj;
});
</script>

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