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

const { createConfirm } = useMessage();

enum Api {
  list = '/rate/rateTask/list',
  save='/rate/rateTask/add',
  edit='/rate/rateTask/edit',
  deleteOne = '/rate/rateTask/delete',
  deleteBatch = '/rate/rateTask/deleteBatch',
  importExcel = '/rate/rateTask/importExcel',
  exportXls = '/rate/rateTask/exportXls',
  taskDeptInit = '/rate/rateTask/taskDeptInit',
  updateRateTaskstatus = '/rate/rateTask/updateRateTaskstatus',
  domainScorelist = '/rate/rateTask/domainScorelist',
  ratelist = '/rate/rateTask/ratelist',
  rateReslist = '/rate/rateTask/rateReslist',
  domainResScorelist = '/rate/rateTask/domainResScorelist',
  exportResXls = '/rate/rateTask/exportResXls',
  rateStaiList = '/rate/rateTask/rateStaiList',
  rateStaikeyitemList = '/rate/rateTask/rateStaikeyitemList',
  rateStaiRatioList = '/rate/rateTask/rateStaiRatioList',
  updateUserRateTaskstatus = '/rate/rateTask/updateUserRateTaskstatus',
  rateUserscore = '/rate/rateUserscore/queUserScoreByTaskid',
  queScoreByTaskid = '/rate/rateDomainscore/queScoreByTaskid',
  rateStaiSum = '/rate/rateTask/rateStaiSum',
}
/**
 * 导出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 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});
}

/**
 * 任务分配数据初始化
 * @param params
 */
 export const taskDeptInit = (params) => {
  return defHttp.delete({url: Api.taskDeptInit, params}, {joinParamsToUrl: true}).then(() => {
    //handleSuccess();
  });
}

/**
 * 申请填报
 */
 export const updateRateTaskstatus = (params,handleSuccess) => {
  return defHttp.delete({url: Api.updateRateTaskstatus, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 申请填报
 */
 export const updateUserRateTaskstatus = (params,handleSuccess) => {
  return defHttp.delete({url: Api.updateUserRateTaskstatus, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

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

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

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



 /**
 * 导出Excel
 * @param params
 */
  export const getExporRestUrl = (params) =>{
    let options = {
      isTransformResponse:false, 
      isReturnNativeResponse:true
    }
    return defHttp.get({url: Api.exportResXls, params, responseType:'blob',},options)
    .then((response) => {
      const url = window.URL.createObjectURL(new Blob([response.data]));
      const link = document.createElement('a');
      link.href = url;
      link.setAttribute('download',"评估结果.xls");
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    })
    .catch((error) => {
      console.error('Failed to download XML file:', error);
    });
  }


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

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

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

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

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


