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

const { createConfirm } = useMessage();

enum Api {
  list = '/metric/metricReport/list',
  save='/metric/metricReport/add',
  edit='/metric/metricReport/edit',
  deleteOne = '/metric/metricReport/delete',
  deleteBatch = '/metric/metricReport/deleteBatch',
  importExcel = '/metric/metricReport/importExcel',
  exportXls = '/metric/metricReport/exportXls',
  queryList = '/metric/metricReport/queryList',
  queryAllList = '/metric/metricReport/queryAllList',

  saveAddBatch='/metric/metricReport/addBatch',
  exeCaluculat='/metric/formulaCalculat/exeCaluculat',
  dataApprovalList='/metric/dataApproval/list',

  batchSaveApproval='/metric/dataApproval/batchSaveApproval',

  queryByMtrcNo = '/metric/metricMonitorSet/queryByMtrcNo',

}
/**
 * 导出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 queryList = (params) =>
  defHttp.get({url: Api.queryList, params});

export const queryAllList = (params) =>defHttp.get({url: Api.queryAllList, params});

export const queryByMtrcNo = (params) =>defHttp.get({url: Api.queryByMtrcNo, 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,handleSuccess) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params}).then(() => {
    if(handleSuccess) {
      handleSuccess();
    }
  });
}

export const saveAddBatch = (params,handleSuccess) => {
  let url = Api.saveAddBatch;
  return defHttp.get({url: url, params}).then(() => {
    if(handleSuccess) {
      handleSuccess();
    }
  });
}

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


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


export const batchSaveApproval = (params,handleSuccess) => {
  let url = Api.batchSaveApproval;
  return defHttp.post({url: url, params}).then(() => {
    if(handleSuccess) {
      handleSuccess();
    }
  });
}




