<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 { commitListApi } from "@/api/modules/global";
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;
    ruleForm: any;
}>();
// 接口地址映射
const URLS: Record<string, string> = {
    ofInboundInstructionsList: "InStockTask/Export", //入库单任务列表
    outboundOrderList: "OutStock/Export", //出库单列表
    warehouseReceiptList: "InStock/Export", //入库单列表
    boxModificationsList: "ChangeBoxRecord/Export", //改箱列表
    movingBoxesList: "MoveBoxRecord/Export", //移箱列表
    inventoryList: "TakeStock/Export", //盘点列表
    inboundOutboundRollbackList: "BackRecord/Export", //出入库回退列表
    immediately: "Inventory/ExportInventory", //即时库存
    material: "Inventory/ExportInOrOut", //物料收发
    boxStorage: "Inventory/ExportBox", //箱库存查询
    finishedProductIndex: "ProductInventory/Export" //成品仓即时库存
};

// 提交事件
const handleBtnClick = async () => {
    // 根据不同的路由进行不同的参数解构
    console.log(props.ruleForm);
    // 内部处理好了请求后的数据再返回到父页面;
    const result = await commitListApi(URLS[routeName], { ...props.ruleForm });
    if (result.status === 200) {
        useMsg("success", "导出成功请前往导出列表中进行下载 ！");
    } else {
        useMsg("warning", "导出失败,请稍后重试 ！");
    }
};
//渲染按钮
const isBtnShow = computed(() => {
    const btnShowObj: any = {
        ofInboundInstructionsListExport: false, //入库单任务列表
        outboundOrderListExport: false, //出库单列表
        warehouseReceiptListExport: false, //入库单列表
        boxModificationsListExport: false, //改箱列表
        movingBoxesListExport: false, //移箱列表
        inventoryListExport: false, //盘点列表
        inboundOutboundRollbackListExport: false, //出入库回退列表
        immediatelyExport: false, //即时库存
        materialExport: false, //物料收发
        boxStorageExport: false, //箱库存查询
        finishedProductIndexExport: false //成品即时仓库
    };
    let btnName = routeName + "Export";
    btnShowObj[routeName] = authStore.btnsAuthList.includes(btnName);
    return btnShowObj;
});
</script>

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