import fetch,{main_web_site_url} from './fetch';
import { notification } from 'antd';

// 专家列表查询
export async function expertList(params) {
  let res = await fetch({
    url: '/api/experts/',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

//删除专家
export function deleteExpert(expertId) {
  return fetch({
    url: `/api/experts/${expertId}?isDelete=1`,
    method: 'delete'
  });
}

// 获取用户信息
export function getUserInfo() {
  return fetch({
    url: '/user/getUserInfo',
    method: 'get'
  });
}

// 查看当前登录用户专家信息
export function getCurrentExpert(params) {
  return fetch({
    url: '/api/experts/getCurrentExpert',
    method: 'get',
    params
  });
}

//专家注册
export async function expertRegister(data){
  let res = await fetch({
    url: '/api/experts/register',
    method: 'post',
    data,
  });
  return res;
}

//更新专家信息
export async function expertUpdate(data){
  let res = await fetch({
    url: '/api/experts/',
    method: 'put',
    data,
  });
  return res;
}

//管理员审核专家信息
export async function registerCheck(data){
  let res = await fetch({
    url: '/api/experts/adminCheckExpert',
    method: 'post',
    data,
  });
  return res;
}

// 获取文件信息
export function getFile(id) {
  return fetch({
    url: `/busiAttachments/${id}`,
    method: 'get'
  });
}

// 获取评审任务列表
export function getExpertTasks(params) {
  return fetch({
    url: `/api/taskExpert/getExpertTasksPageList`,
    method: 'get',
    params,
  });
}

// 获取竞赛作品列表
export function getCompetition(id) {
  return fetch({
    url: `${main_web_site_url}/api/v1/competitions/${id}/works`,
    method: 'get',
  });
}

// 获取竞赛详情接口
export function getCompetitionDetail(id) {
  return fetch({
    url: `${main_web_site_url}/api/v1/competitions/${id}`,
    method: 'get',
  });
}

// 查看竞赛/任务的评分细则
export function getScoringDetails(params) {
  return fetch({
    url: `/api/expertScoringDetails/getExpertScoringDetailsList`,
    method: 'get',
    params,
  });
}

// 查看最终得分排行
export function getFinalScoreRankingList(params) {
  return fetch({
    url: `/api/expertScoringDetails/getFinalScoreRankingList`,
    method: 'get',
    params,
  });
}

// 查看单个竞赛/任务的所有评分细则
export function getOpsScoringDetails(params) {
  return fetch({
    url: `/api/expertScoringDetails/getOpsExpertScoringDetailsList`,
    method: 'get',
    params,
  });
}

// 初始化评分细则
export function initScoringDetails(data){
  return fetch({
    url: '/api/expertScoringDetails/initExpertScoringDetails',
    method: 'post',
    data,
  })
}

// 更新评分细则
export function updateScoringDetails(data){
  return fetch({
    url: '/api/expertScoringDetails/',
    method: 'put',
    data,
  });
}

//评选胜出者和公示者
export function selectWinnersAndPublicists(data){
  return fetch({
    url: '/api/expertScoringDetails/selectWinnersAndPublicists',
    method: 'post',
    data,
  });
}

//查看胜出者和公示名单
export function getWinnersAndPublicists(params) {
  return fetch({
    url: `/api/expertScoringDetails/getWinnersAndPublicists`,
    method: 'get',
    params,
  });
}

//获取创客任务评审规则
export async function getRules(params){
  let response = await fetch({
    url: `/api/taskRuleCriteria/getRuleAndCriteria`,
    method: 'get',
    params
  });
  if(response && response.message === "success"){
    let criterias = [];
    response.data.criteriaOne && (criterias[criterias.length] = (criterias.length+1)+"、"+response.data.criteriaOne);
    response.data.criteriaTwo && (criterias[criterias.length] = (criterias.length+1)+"、"+response.data.criteriaTwo);
    response.data.criteriaThree && (criterias[criterias.length] = (criterias.length+1)+"、"+response.data.criteriaThree);
    response.data.criteriaFour && (criterias[criterias.length] = (criterias.length+1)+"、"+response.data.criteriaFour);
    response.data.criteriaFive && (criterias[criterias.length] = (criterias.length+1)+"、"+response.data.criteriaFive);
    response.data.criterias = criterias;
    response.data.reviewData = response.data.reviewStartOn.substring(0,response.data.reviewStartOn.length-3) + " ~ " + response.data.reviewEndOn.substring(0,response.data.reviewEndOn.length-3)
  }
  return response;
}

//编辑评审规则(第一次)
export async function editRules(data){
  let res = await fetch({
    url: '/api/taskRuleCriteria/editRuleAndCriteria',
    method: 'post',
    data,
  });
  return res;
}

//更新评审规则(第一次)
export async function updateRules(data){
  let res = await fetch({
    url: '/api/taskRuleCriteria/',
    method: 'put',
    data,
  });
  return res;
}

//为创客任务添加评审专家
export async function assignExperts(data){
  let res = await fetch({
    url: '/api/taskExpert/assignExperts',
    method: 'post',
    data,
  });
  return res;
}

//删除指派专家
export function deleteExperts(taskExpertId,isDelete) {
  return fetch({
    url: `/api/taskExpert/${taskExpertId}?isDelete=${isDelete}`,
    method: 'delete'
  });
}

//已选专家列表
export function selectExpertList(params) {
  return fetch({
    url: `/api/taskExpert/selectedExpertPageList`,
    method: 'get',
    params
  });
}

//竞赛任务列表
export function getCompetitionList(params) {
  return fetch({
    url: `/api/competitionExpert/getCompetitionList`,
    method: 'get',
    params
  });
}

// 修改竞赛是否加入专家评审流程
export function updateCompetitionReview(data) {
  return fetch({
    url: `${main_web_site_url}/api/v1/competitions/update_expert_audit`,
    method: 'post',
    data,
  });
}