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

// 获取字典分类列表
export function getDictionary(id) {
  return fetch({
    url: '/dicItem/getData?dicTypeCode=' + id,
    method: 'get'
  });
}

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

// 获取用户企业信息
export function getCompanyInfo() {
  return fetch({
    url: '/api/tasks/getEnterpriseUserInfo',
    method: 'get'
  });
}

// 获取任务领域
export async function getTaskCategory() {
  let res = await fetch({
    url: '/api/taskCategory/getTaskCategory',
    method: 'get',
  });
  if (Array.isArray(res.data.rows)) {
    return res.data.rows;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

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

// 管理员任务列表查询
export async function getTaskAdminList(params) {
  let res = await fetch({
    url: '/api/tasks/backend/list',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

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

// 我参与的任务列表查询
export async function getJoinTaskList(params) {
  let res = await fetch({
    url: '/api/myTasks/myPapers',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}



// 详情查询
export async function getTaskDetail(id) {
  let res = await fetch({
    url: '/api/tasks/getTask/' + id,
    method: 'get',
  });
  if (res.data) {
    return res.data;
  } else {
    if(res.message&&res.message.indexOf('exist')>-1){
      notification.open({
        message: "提示",
        description: "未查到该任务",
      });
    }else{
      notification.open({
        message: "提示",
        description: res.message || '请求错误',
      });
    } 
  }
}

//新增任务
export function addTask(data) {
  return fetch({
    url: '/api/tasks/add',
    method: 'post',
    data: data
  });
}

//更新任务
export function updateTask(data) {
  return fetch({
    url: '/api/tasks/',
    method: 'PUT',
    data: data
  });
}

//删除
export function deleteTask(id, isDelete) {
  return fetch({
    url: '/api/tasks/' + id + '?isDelete=' + isDelete,
    method: 'DELETE',
  });
}

//推荐
export function recommendTask(id, recommend) {
  return fetch({
    url: '/api/tasks/backend/changeTaskRecommendedStatus/' + id + '?recommend=' + recommend,
    method: 'PUT',
  });
}

//新增成果
export function addPaper(data) {
  return fetch({
    url: '/api/paper/',
    method: 'post',
    data: data
  });
}

// 任务成果
export async function getTaskPaper(params) {
  let res = await fetch({
    url: '/api/paper/',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

// 审核任务成果
export async function readyCheckPapers(params) {
  let res = await fetch({
    url: '/api/paper/admin/readyCheckPapers',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

// 我的成果
export async function myPapers(params) {
  let res = await fetch({
    url: '/api/paper/my',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

//更新成果
export function updatePaper(data) {
  return fetch({
    url: '/api/paper/',
    method: 'put',
    data: data
  });
}

// 删除
export function deletePaper(id) {
  return fetch({
    url: `api/paper/${id}`,
    method: 'delete',
  });
}


//应征者名单公示
export function makePublic(id) {
  return fetch({
    url: `/api/tasks/makeApplicantListPublic/${id}`,
    method: 'put',
  });
}

//举报成果
export function reportPaper(data) {
  return fetch({
    url: `/api/paper/${data.paperId}/paperReport`,
    method: 'post',
    data: data
  });
}

//点赞成果
export function thumbUpPaper(id) {
  return fetch({
    url: `/api/paper/${id}/thumbUp`,
    method: 'post',
    data: { paperId: id }
  });
}

// 检查用户是否同意协议
export function checkAgreement(taskId) {
  return fetch({
    url: `/api/paper/${taskId}/agreement`,
    method: 'get'
  });
}

// 检查用户是否提交了成果
export function checkHavePaper(taskId) {
  return fetch({
    url: `/api/paper/${taskId}/check`,
    method: 'get'
  });
}

// 新增协议
export function agreementAdd(data) {
  return fetch({
    url: '/api/paper/agreementSettings/',
    method: 'post',
    data,
  });
}

// 修改协议
export function agreementEdit(data) {
  return fetch({
    url: '/api/paper/agreementSettings/',
    method: 'put',
    data
  });
}

// 获取协议
export function getAgreement(params) {
  return fetch({
    url: `/api/paper/agreementSettings/${params==1?params:''}`,
    method: 'get',
    params:params!=1?params:null
  });
}

// 同意协议
export function agreement(taskId) {
  return fetch({
    url: `/api/paper/${taskId}/agreement`,
    method: 'post',
    data: { taskId }
  });
}

// 新增评论
export function commentAdd(data) {
  return fetch({
    url: `/api/paper/${data.paperId}/comment`,
    method: 'post',
    data,
  });
}


//管理员审核任务
export function checkTask(data) {
  return fetch({
    url: `/api/tasks/backend/adminCheck`,
    method: 'post',
    data: data
  });
}


// 审核成果/评论
export function checkPaper(data) {
  return fetch({
    url: `/api/paper/admin/complainPaper/${data.paperId}`,
    method: 'post',
    data: data.auditingVo
  });
}

// 成果申诉
export function complainPaper(data) {
  return fetch({
    url: `/api/paper/complainInfo/${data.paperId}`,
    method: 'post',
    data: data.params
  });
}

// 审核申诉材料列表查询
export async function complainPaperList(params) {
  let res = await fetch({
    url: '/api/paper/admin/readyComplaintPapers',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

// 审核申诉材料
export function checkComplain(data) {
  return fetch({
    url: `/api/paper/admin/complainMaterial/${data.paperId}`,
    method: 'post',
    data: data.auditingVo
  });
}


// 佐证上传
export function proofAdd(data) {
  return fetch({
    url: `/api/taskResultProof/addTaskResultProof`,
    method: 'post',
    data,
  });
}

// 审核佐证材料列表查询
export async function proofList(params) {
  let res = await fetch({
    url: '/api/tasks/backend/proofList',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

// 审核佐证
export function checkProof(data) {
  return fetch({
    url: `/api/taskResultProof/adminCheckResultAndProof`,
    method: 'post',
    data,
  });
}

// 应征者公示期申诉
export function publicityComplain(data) {
  return fetch({
    url: `/api/myTasks/applicantComplaintDuringPublicity`,
    method: 'post',
    data,
  });
}

// 审核公示期申诉列表查询
export async function publicityComplainList(params) {
  let res = await fetch({
    url: '/api/tasks/backend/complaintMaterialList',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

// 审核公示期申诉
export function checkPublicity(data) {
  return fetch({
    url: `/api/tasks/backend/adminCheck/complaintMaterialDuringPublicity`,
    method: 'post',
    data,
  });
}

// 选择签订协议的方式
export function signMethod(data) {
  return fetch({
    url: `/api/sign/method/${data.taskId}/${data.method}`,
    method: 'post',
  });
}

// 上传委托协议
export function uploadAgreeRequire(data) {
  return fetch({
    url: `/api/sign/task/contract/${data.taskId}`,
    method: 'post',
    data: data.params
  });
}

// 审核委托协议列表
export async function agreementList(params) {
  let res = await fetch({
    url: '/api/sign/task/contract',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

// 审核协议
export function adminCheckAgreement(data) {
  return fetch({
    url: `/api/sign/admin/${data.type === 1 ? 'task' : 'paper'}/contract/${data.agreementId}`,
    method: 'post',
    data: data.params
  });
}


// 上传委托协议
export function uploadAgreePaper(data) {
  return fetch({
    url: `/api/sign/paper/contract/${data.paperId}`,
    method: 'post',
    data: data.params
  });
}


// 上传凭证列表查询
export async function uploadPayProofList(params) {
  let res = await fetch({
    url: '/api/sign/admin/paper/payOrders',
    method: 'get',
    params,
  });
  if (res.data) {
    return res.data;
  } else {
    notification.open({
      message: "提示",
      description: res.message || '请求错误',
    });
  }
}

// 管理员上传支付凭证
export function uploadPayProof(data) {
  return fetch({
    url: `/api/sign/admin/paper/payment/${data.paperId}`,
    method: 'post',
    data: data.params
  });
}


// 胜出者确认收款
export function confirmReceipt(paperId) {
  return fetch({
    url: `/api/sign/paper/money/${paperId}`,
    method: 'post',
  });
}


// 下载协议签订凭证
export function downAgreement(params) {
  return fetch({
    url: `/api/myTasks/getWinnersContractsByTaskId`,
    method: 'get',
    params,
  });
}

// 管理员修改任务公示方式
export function changeShowUserMode(data) {
  return fetch({
    url: `/api/tasks/backend/changeShowUserMode`,
    method: 'post',
    data,
  });
}

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

// 延期
export function delayTask(data) {
  return fetch({
    url: `/api/tasks/backend/admin/task/delay/${data.taskId}`,
    method: 'post',
    data: data.params,
  });
}

// 关闭
export function closeTask(taskId) {
  return fetch({
    url: `/api/tasks/backend/admin/task/close/${taskId}`,
    method: 'post',
  });
}

// 任务添加专家评审流程,expertReview: 1 加入 -1 不加入
export function addExpertReview(taskId,expertReview){
  return fetch({
    url: `/api/tasks/backend/joinExpertReview/${taskId}?expertReview=${expertReview}`,
    method: 'put',
  });
}

//发布评审任务
export function publishExpertsAndRules(taskId, containerType){
  return fetch({
    url: `/api/taskRuleCriteria/publishExpertsAndRules?containerId=${taskId}&containerType=${containerType}&status=-1`,
    method: 'put'
  })
}

// 管理页面修改创业