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

const { createConfirm } = useMessage();

enum Api {
  list = '/plan.main/stPlanMan/list',
  save='/plan.main/stPlanMan/add',
  edit='/plan.main/stPlanMan/edit',
  deleteOne = '/plan.main/stPlanMan/delete',
  deleteBatch = '/plan.main/stPlanMan/deleteBatch',
  importExcel = '/plan.main/stPlanMan/importExcel',
  exportXls = '/plan.main/stPlanMan/exportXls',
  handle = '/plan.main/stPlanMan/handle',
  changelist = '/plan.change/stPlanMan/list',
  handleChange = '/plan.change/stPlanMan/handleChange',
  handleRepeal = '/plan.change/stPlanMan/handleRepeal',
  trancelist = '/plan.trance/stPlanTrance/list',
  listflow = '/plan.main/stPlanMan/listflow',
  
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>{
  return defHttp.get({url: Api.list, params});
}


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


export const trancelist = (params) =>
defHttp.get({url: Api.trancelist, 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 changeOrRepeal = (params, isChange) => {
  let url = isChange ? Api.handleChange : Api.handleRepeal;
  return defHttp.post({url: url, params});
}

/**
 * 计划处理
 * @param params
 */
export const handlePlan = (params,handleSuccess) => {
  return defHttp.post({url: Api.handle, params}).then(() => {
    handleSuccess();
  });
}

/**
 * 计划变更
 * @param params
 */
export const handleChange = (params,handleSuccess) => {
  return defHttp.post({url: Api.handleChange, params}).then(() => {
    handleSuccess();
  });
}


/**
 * 计划废止
 * @param params
 */
export const handleRepeal = (params,handleSuccess) => {
  return defHttp.post({url: Api.handleRepeal, params}).then(() => {
    handleSuccess();
  });
}

/**
 * 列表接口
 * @param params
 */
 export const listflow = (params) =>{
  return defHttp.get({url: Api.listflow, params});
}