import { useMsg } from "@/hooks/useMsg";
import { getSubscribeDelApi } from "@/api/modules/subscribe";

// 直接导出函数，无需额外包装对象
export const handleDel = (params: any) => {
    const { selectionList, proTable } = params;
    let length = selectionList.length;
    if (!length) {
        useMsg("warning", "请选择需要删除的数据！");
        return;
    }
    ElMessageBox.confirm("您确定进行删除操作吗?", "温馨提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
    })
        .then(async () => {
            let ids: any = [];
            selectionList.forEach((item: any) => {
                ids.push(item.id);
            });
            const result = await getSubscribeDelApi(ids.join(","));
            if (result?.code === 0) {
                proTable.value!.getTableList();
                useMsg("success", "删除成功 ！");
            }
        })
        .catch(() => {});
};

export const handleAdd = (params: any) => {
    const { router } = params;
    router.push({
        path: "/foundation/subscribe/list/add",
        query: { title: "新增订阅" }
    });
};

export const btnClick: any = {
    del: handleDel,
    add: handleAdd
};
