import { useMsg } from "@/hooks/useMsg";
import { getQualityInspectReloadApi, getQualityInspectExportApi } from "@/api/modules/inspection";

//导出
const getQualityInspectExport = async (proTable: any, dataStore: any) => {
    const result = await getQualityInspectExportApi(dataStore.ruleForm);
    if (result?.code === 0) {
        useMsg("success", result?.msg);
        //请求成功后刷新列表
        proTable!.value?.getTableList();
    }
};
//刷新接口
const getQualityInspectReload = async (selectionList: any, proTable: any) => {
    const result = await getQualityInspectReloadApi({ id: selectionList });
    if (result?.code === 0) {
        useMsg("success", result?.msg);
        //请求成功后刷新列表
        proTable!.value?.getTableList();
    }
};
// 导出
export const handleExport = (params: any, dataStore: any) => {
    const { proTable } = params;
    getQualityInspectExport(proTable, dataStore);
};
// 刷新
export const handleRefresh = (params: any, dataStore: any) => {
    const { proTable } = params;
    if (!dataStore.selectionList.length) {
        useMsg("warning", "请勾选数据刷新 !");
        return;
    }
    if (dataStore.selectionList.length && dataStore.selectionList.length > 50) {
        useMsg("warning", "最多刷新50条 !");
        return;
    }
    getQualityInspectReload(dataStore.selectionList, proTable);
};

export const btnClick: any = {
    export: handleExport,
    refresh: handleRefresh
};
