<template>
    <el-dropdown v-if="isBtnShow[routeName]">
        <div class="common-btn-box font12" style="border: none">导出</div>
        <template #dropdown>
            <el-dropdown-menu>
                <el-dropdown-item @click="handleBtnClick()"> 单据信息</el-dropdown-item>
                <el-dropdown-item @click="handleBtnClick1()">出库信息</el-dropdown-item>
            </el-dropdown-menu>
        </template>
    </el-dropdown>
</template>

<script setup lang="ts" name="Exprots">
import { useMsg } from "@/hooks/useMsg";
import { commitListApi } from "@/api/modules/global";
import { useAuthStore } from "@/stores/modules/auth";
const authStore = useAuthStore();
const $router = useRouter();
const props = defineProps<{
    selectionList: any[];
    handleChildBtnCallback?: () => void;
    ruleForm: any;
}>();
// const routeName: any = ref($router.currentRoute.value.name);
const routeName: string = $router.currentRoute.value.name as string;
const emits = defineEmits<{
    (e: "handleChildBtnCallback", result: Record<string, any>): void;
}>();

//接口地址映射
const URLS: Record<string, string> = {
    outboundTaskList: "OutStockTask/Export" //出库单任务列表
};
const URLS1: Record<string, string> = {
    outboundTaskList: "OutStockTask/ExportInfo" //出库单任务列表
};
// 提交事件;
const handleBtnClick = async () => {
    // 根据不同的路由进行不同的参数解构
    // 内部处理好了请求后的数据再返回到父页面;
    const result = await commitListApi(URLS[routeName], { ...props.ruleForm });
    if (result.status === 200) {
        useMsg("success", "导出成功请前往导出列表中进行下载 ！");
        emits("handleChildBtnCallback", {
            type: "Retransmission"
        });
    } else {
        useMsg("warning", "导出失败,请稍后重试 ！");
    }
};
const handleBtnClick1 = async () => {
    if (!props.selectionList.length) {
        useMsg("warning", "请选择要导出的出库信息 ！");
        return;
    }
    let ids: any = [];
    props.selectionList.forEach((item: any) => {
        ids.push(item.id);
    });
    const result = await commitListApi(URLS1[routeName], { ...props.ruleForm, ids: ids });
    if (result.status === 200) {
        useMsg("success", "导出成功请前往导出列表中进行下载 ！");
        emits("handleChildBtnCallback", {
            type: "Retransmission"
        });
    } else {
        useMsg("warning", "导出失败,请稍后重试 ！");
    }
};
//渲染按钮
const isBtnShow = computed(() => {
    const btnShowObj: any = {
        outboundTaskList: false
    };
    let btnName = routeName + "Export";
    btnShowObj[routeName] = authStore.btnsAuthList.includes(btnName);
    return btnShowObj;
});
</script>

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