// src/axios/api.js
import ApiConstant from "@/utils/ApiConstant";
import axiosInstance from '@/utils/http';

export const getScore = () =>{
  axiosInstance({
    url: ApiConstant.Score.getScore,
    method: 'get',
    params: {},
    showLoading: false,//是否显示加载图标
  }).then((response) => {
    return response.data
  }).then((data) => {
    if(data.success){
      //将成绩信息保存到缓存中
      localStorage.setItem('scoreInfo',JSON.stringify(data.result.scoreInfo))
      localStorage.setItem('fillVolunteer',JSON.stringify(data.result.fillVolunteer))
      localStorage.setItem('volunteer',JSON.stringify(data.result.volunteer))
    }
    //有数据情况下
  }).catch((error: any) => {
    console.log(error);
  }).finally(() => {
  });
}
export const getRulesEnrollrobabilityMenuList =async (professionalCategory:string) =>{
  try {
    const response = await axiosInstance({
      url: ApiConstant.Major.rulesEnrollrobabilityMenuList,
      method: 'get',
      params: { professionalCategory: professionalCategory },
      showLoading: false, // 是否显示加载图标
    });
    const data = response.data;
    if (data.success) {
      // 将成绩信息保存到缓存中
      return data.result;
    } else {
      return [];
    }
  } catch (error) {
    console.log(error);
    return [];
  }
}

export const checkPhoneAvailable = (phone: any) => {
  return axiosInstance({
    url: ApiConstant.User.checkPhoneAvailable,
    method: 'get',
    params: { phone: phone },
    showLoading: false, // 是否显示加载图标
  }).then((response) => {
    return response.data;
  }).then((data) => {
    if (data.success) {
      // 将成绩信息保存到缓存中
      return data.result;
    }
    // 有数据情况下
  }).catch((error: any) => {
    console.log(error);
    throw error; // 抛出错误以便在调用处处理
  });
};

// 获取资讯信息列表
export const getArticleList = async (type:any,pageNum:Number) =>{
  if(!pageNum){
    pageNum = 1;
  }
  try {
    const response =await axiosInstance({
      url: ApiConstant.Article.articlePage,
      method: 'get',
      params: {
        type: type,
        pageNum:pageNum,
        pageSize:5
       },
      showLoading: false, // 是否显示加载图标
    });
    const data = response.data;
    if (data.success) {
      // 将成绩信息保存到缓存中
      return data.result.records;
    } else {
      return [];
    }
  } catch (error) {
    console.log(error);
    return [];
  }
}

// // 登录
// export const Login = (data) => {
//   return service({
//     url: "/login",
//     method: "post",
//     data,
//   });
// };

// // Get请求
// export const Get = (url, data) => {
//   return service({
//     url,
//     method: "get",
//     params: data,
//   });
// };

// // Delete请求
// export const Delete = (url) => {
//   return service({
//     url,
//     method: "delete",
//   });
// };

// // Post请求
// export const Post = (url, data) => {
//   return service({
//     url,
//     method: "post",
//     data,
//   });
// };

// // 上传文件请求
// export const PostFile = (url, data, onUploadProgress) => {
//   return service({
//     url,
//     method: "post",
//     data,
//     headers: {
//       "Content-Type": "multipart/form-data",
//     },
//     onUploadProgress,
//   });
// };

// // Put请求
// export const Put = (url, data) => {
//   return service({
//     url,
//     method: "put",
//     data,
//   });
// };

// // Patch请求
// export const Patch = (url, data) => {
//   return service({
//     url,
//     method: "patch",
//     data,
//   });
// };
