import { getClearBoxApi } from "@/api/modules/boxCode";
import { ElMessageBox } from "element-plus";
import { cloneDeep } from "lodash-es";
import { FORM_TABLE_DATA_INIT } from "../constant/list";
import { msgHtml } from "./msgHtml";

//清空装箱接口
export const getClearBox = (datas: any, formTableRef: any) => {
    if (!datas.boxBillNoObj.id) {
        msgHtml("箱号不能为空 !");
        return;
    }

    let is = datas.formTableData.some((item: any) => {
        return item.materialNumber;
    });
    if (!is) {
        msgHtml("当前箱号没有物料信息 !");
        return;
    }
    ElMessageBox.confirm("确认清空已装箱数据?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "custom-message-box"
    })
        .then(async () => {
            const result = await getClearBoxApi({
                boxId: datas.boxBillNoObj.id
            });
            if (result.status === 200) {
                msgHtml("清空成功 !");
                datas.formTableData = [];
                datas.formTableData.push(cloneDeep(FORM_TABLE_DATA_INIT));
                formTableRef.value.inputElement[0].focus();
                return true;
            } else {
                msgHtml(result.message);
            }
        })
        .catch(() => {});
};
