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

const { createConfirm } = useMessage();

enum Api {
  list = '/metric/metricMonitorSet/list',
  save='/metric/metricMonitorSet/add',
  edit='/metric/metricMonitorSet/edit',
  deleteOne = '/metric/metricMonitorSet/delete',
  deleteBatch = '/metric/metricMonitorSet/deleteBatch',
  importExcel = '/metric/metricMonitorSet/importExcel',
  exportXls = '/metric/metricMonitorSet/exportXls',
  batchAdd = '/metric/metricMonitorSet/batchAdd',
  metricList = '/act.metric/stMetric/list',
  queryForCurUser = '/metric/metricMonitorSet/queryForCurUser',
  queryAllMetric = '/metric/metricMonitorSet/queryAllMetric',
  queryAllMetricNoPage = '/metric/metricMonitorSet/queryAllMetricNoPage',

  batchImmportBase='/metric/metricMonitorSet/batchImmportBase',
  batchImmportCalculate='/metric/metricMonitorSet/batchImmportCalculate',

  caluculatAllMetric = '/metric/formulaCalculat/caluculatAllMetric'

  
  
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => {
  params["mtrcCtp"] =1
  return defHttp.get({url: Api.list, params});
}

export const listCombined = (params) => {
  params["mtrcCtp"] = 2
  return defHttp.get({url: Api.list, params});
}

export const listAll = (params) => {
  return defHttp.get({url: Api.list, 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) => {
  let url = params.id ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

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

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

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

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


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

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


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

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




  
