import { useMsg } from "@/hooks/useMsg";
import { getSubscribeResetListApi, getSubscribeResetListExportApi } from "@/api/modules/warehousing";
import { cloneDeep } from "lodash-es";
// 导出
export const handleExport = async (data: any) => {
    const { initParam } = data;
    let params = cloneDeep(initParam);
    params.org_number =
        Array.isArray(params?.org_number) && params?.org_number?.length ? params.org_number.join(",") : params.org_number;
    const result = await getSubscribeResetListExportApi(params);
    if (result?.code === 0) {
        useMsg("success", "导出成功 ！");
    }
};
// proTable: any
export const handleReSet = async (params: any) => {
    const { proTable, selectionList } = params;
    let length = selectionList.length;
    if (length && length > 100) {
        useMsg("warning", "选中刷新数据最大100条 ！");
        return;
    }
    let ids: any = [];
    selectionList.forEach((item: any) => {
        ids.push(item.id);
    });

    let id = ids.join(",");
    const result = await getSubscribeResetListApi({ id });
    if (result?.code === 0) {
        useMsg("success", "数据刷新成功 ！");
        proTable?.value!.getTableList();
    }
};

export const btnClick: any = {
    export: handleExport,
    reset: handleReSet
};
