import { getDeleteBoxApi } from "@/api/modules/boxCode";
import { ElMessageBox } from "element-plus";
import { msgHtml } from "./msgHtml";

//刪除接口
const getDeleteBox = async (datas: any, index: any) => {
    const { boxId, materialNumber, serialNumber, twoSerialNumber } = datas.formTableData[index];
    const result = await getDeleteBoxApi({
        boxId,
        materialNumber,
        serialNumber,
        twoSerialNumber
    });
    if (result.status === 200) {
        datas.formTableData.splice(index, 1);
        msgHtml("刪除成功 !");
        datas.isBtnClick = true;
    }
};
export const initDelete = (datas: any, scope: any) => {
    ElMessageBox.confirm("您确定删除该条数据吗?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "custom-message-box"
    })
        .then(() => {
            if (datas.formTableData[scope.$index].isOldData) {
                getDeleteBox(datas, scope.$index);
            } else {
                datas.formTableData.splice(scope.$index, 1);

                msgHtml("刪除成功 !");
            }
        })
        .catch(() => {});
};
