import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/mes/material/category/list',
  save = '/mes/material/category/add',
  edit = '/mes/material/category/edit',
  deleteOne = '/mes/material/category/delete',
  deleteBatch = '/mes/material/category/deleteBatch',
}

export const list = (params) => defHttp.get({ url: Api.list, params });
export const deleteOne = (params, handleSuccess) =>
  defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => handleSuccess());
export const batchDelete = (params, handleSuccess) =>
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    onOk: () => defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => handleSuccess()),
  });
export const saveOrUpdate = (params, isUpdate) => defHttp.post({ url: isUpdate ? Api.edit : Api.save, params });
