import { nextTick } from "vue";
import { getBoxRestartApi, getPrintBoxApi } from "@/api/modules/boxCode";
//打印
import { boxCodePrint } from "@/utils/print/boxCode/index.js";
import { msgHtml } from "./msgHtml";
const getBoxRestart = async (datas: any, proTable: any) => {
    let ids: any = [];
    datas.selectionList.forEach((item: any) => {
        ids.push(item.id);
    });
    const result = await getBoxRestartApi({ ids });
    if (result.status === 200) {
        msgHtml("操作成功 !");
        proTable.value!.getTableList();
    } else {
        msgHtml(result.message);
    }
};
const getPrintBox = async (ids: any) => {
    const result = await getPrintBoxApi({ ids });
    if (result.status === 200 && result.isSuccess) {
    }
};
export const btnsEvent = (datas: any, type: string, refInput: any, proTable: any) => {
    if (type === "Generate") {
        datas.generateVisible = true;
    }
    if (type === "Print") {
        if (!datas.selectionList.length) {
            msgHtml("请选择需要打印的数据 !");
            return;
        }
        let ids: any = [];
        datas.selectionList.forEach((item: any) => {
            ids.push(item.id);
        });

        setTimeout(() => {
            nextTick(() => {
                boxCodePrint(datas.selectionList, () => {
                    getPrintBox(ids);
                });
            });
        }, 200);
    }
    if (type === "Packing") {
        //开始装箱
        datas.startVisible = true;
        setTimeout(() => {
            nextTick(() => {
                refInput.value.focus();
            });
        }, 200);
    }
    if (type === "Refresh") {
        getBoxRestart(datas, proTable);
    }
};
