import { useMessage } from "/@/hooks/web/useMessage";
import { defHttp } from '/@/utils/http/axios';

const { createConfirm } = useMessage();

enum Api {
  list = '/compliane.item/stComplianeItem/list',
  listca = '/compliane.item/stComplianeItem/listca',
  save='/compliane.item/stComplianeItem/add',
  edit='/compliane.item/stComplianeItem/edit',
  deleteOne = '/compliane.item/stComplianeItem/delete',
  deleteBatch = '/compliane.item/stComplianeItem/deleteBatch',
  importExcel = '/compliane.item/stComplianeItem/importExcel',
  exportXls = '/compliane.item/stComplianeItem/exportXls',
  saveItemCa='/compliane.item/stComplianeItem/addItemCa',
  importFromFile = '/compliane.item/stComplianeItem/importFromFile',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

export const listca = (params) =>
  defHttp.get({url: Api.listca, params});
/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

export const saveItemCa = (params) => {
  return defHttp.post({url: Api.saveItemCa, params});
}

export const importFromFile = (params) => {
  return defHttp.post({url: Api.importFromFile, params});
}
