import axios from "axios";
import  {i18n}  from '../language/index.js'
//axios.defaults.baseURL = "http://inspur.dev.umayle.com/";
axios.defaults.baseURL = config.url;
// axios.defaults.baseURL = "http://192.168.4.202:8085"
// axios.defaults.baseURL = "http://10.10.74.235:10014/";
export const SaveUserAnswer = (data) => {
  return axios.post(
    `/Handler/Config.ashx?action=updatecache&mark=${data.mark}&user_id=${data.user_id}&mark_value=${data.mark_value}&step=${data.step}`
  );
};
// export const GetAnswers = (data) => {
//   return axios({
//     method: "post",
//     url: "/Handler/Config.ashx?action=updatecache",
//     data: { data },
//     headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
//   })
// };
export const GetUserAnswer = (data) => {
  return axios.get(
    `/Handler/Config.ashx?action=querycache&mark=${data.mark}&user_id=${data.user_id}`
  );
};
export const GetTree = (data) => {
  return axios.get(
    `/Handler/Config.ashx?action=queryacquisition&user_id=${data.user_id}&type=${data.type}`
  );
};
export const SendTree = (data) => {
  let lang = ''
  if (i18n.locale == 'zh') {
    lang = '1'
  }else{
    lang = '0'
  }
  return axios.get(
    `/Handler/Config.ashx?action=updateacquisition&user_id=${data.user_id}&data=${data.data}&type=${data.type}&lang=${lang}`
  );
};
//获取各模块分数
export const getGrade = (data) => {
  return axios.get(
    `/Handler/Config.ashx?action=displaychart&user_id=${data.user_id}`
  );
};
// 获取正确答案和默认值的接口
export const getQueryAnswer = (data) => {
  return axios.get(
    `/Handler/Config.ashx?action=queryanswer&mark=${data.mark}&user_id=${data.user_id}`
  );
}
// 用户获取理论考试
export const getKnowledgeTest = (data) => {
  return axios.post(
    `/Handler/User.ashx?action=logintheory&user_id=${data.userId}&PageIndex=${data.PageIndex}&PageSize=${data.PageSize}&State=${data.state}`
  );
}
// 获取批次试卷题目列表信息
export const getTestTopic = (data) => {
  return axios.post(
    `/Handler/Boat.ashx?action=theorylist&batch_id=${data.id}&kind=${data.kind}`
  );
}
//获取题目选项信息
export const getTopicDetail = (data) => {
  return axios.post(
    `/Handler/Boat.ashx?action=theorybase&theory_base_id=${data.theoryBaseId}`
  );
}
// 提交理论考试答案
export const savaTestAnswer = (data) => {
  return axios({
    url: `/Handler/Boat.ashx?action=savetheory`,
    data: data,
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' }
  });
}
// 获取缓存数据
export const getTestCache = (params) => {
  return axios.get(
    `/Handler/Boat.ashx?action=gettheorycache`, { params: params }
  );
}
// 保存缓存数据
export const saveTestCache = (data) => {
  return axios.post(
    `/Handler/Boat.ashx?action=savetheorycache`, data, { headers: { 'Content-Type': 'multipart/form-data' } }
  );
}


//获取科目类别
export const GetSubjectType = (data) => {
  return axios.get(
    `/Handler/Boat.ashx?action=GetSubjectType`, { params: data }
  );
}
//获取练习列表
export const GetPractice = (data) => {
  return axios.get(
    `/Handler/User.ashx?action=loginlianxi`, { params: data }
  );
}

//获取练习题目
export const getPracticeTopic = (data) => {
  return axios.get(
    `/Handler/Boat.ashx?action=theorylist&lianxi=1`, { params: data }
  );
}

//提交练习
export const submitPracticeTopic = (data) => {
  return axios({
    url: `/Handler/Boat.ashx?action=savelianxi`,
    data: data,
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' }
  });
}

//通过id获取考试记录
export const getPracticeRecords = (data) => {
  return axios.get(
    `/Handler/Boat.ashx?action=querylianxilist`, { params: data }
  );
}

//查询考试详情
export const getPracticeDetails = (data) => {
  return axios.get(
    `/Handler/Boat.ashx?action=querylianxidetails`, { params: data }
  );
}
//查询考试人名
export const getUserName = (data) => {
  return axios.get(
    `/Handler/Boat.ashx?action=queryuser`, { params: data }
  );
}

//通过resultId查询考试基本详情
export const getDetailsMap = (data) => {
  return axios.get(
    `/Handler/Boat.ashx?action=querylianxiresult`, { params: data }
  );
}


//简答题传图片
//练习上传图片
export const uploadImg = (data) => {
  return axios({
    url: `/Handler/Files.ashx?action=addlianxi`,
    data: data,
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' }
  });
}
//获取练习时的result_id
export const getResultId = (data) => {
  return axios.get(
    `/Handler/Boat.ashx?action=getid`, { params: data }
  );
}

//查询简答题图片
export const getImgUrl = (data) => {
  return axios.get(
    `/Handler/Files.ashx?action=querylianxi`, { params: data }
  );
}
//通过文件id删除图片
export const delImg = (data) => {
  return axios.get(
    `/Handler/Files.ashx?action=dellianxi`, { params: data }
  );
}

//获取简答题正确答案得图片
export const getCorrectImg= (data) => {
  return axios.get(
    `/Handler/Files.ashx?action=querylianxi`, { params: data }
  );
}
