import request from '@/router/axios';
import {getToken} from '@/util/auth'
// import { toDoller } from "@/util/money";
/*获取招聘中 任务中 已完成任务列表*/
export const getList = (current, size, params) => {
  return request({
    url: '/api/jobslink-api/missions/mission/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}

/*获取已失效任务列表*/
export const getExpiredList = (current, size, params) => {
  return request({
    url: '/api/jobslink-api/missions/mission/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}

/*新增任务*/
export const add = (row) => {
  return request({
    url: '/api/jobslink-api/missions/mission/save',
    method: 'post',
    data: row
  })
}

/*编辑任务*/
export const update = (row) => {
  return request({
    url: '/api/jobslink-api/missions/mission/update',
    method: 'post',
    data: row
  })
}

/*删除任务*/
export const remove = (ids) => {
  return request({
    url: '/api/jobslink-api/missions/mission/remove',
    method: 'post',
    params: {
      ids
    }
  })
}

/*取消任务*/
export const cancel = (ids) => {
  return request({
    url: '/api/jobslink-api/missions/mission/cancel',
    method: 'post',
    params: {
      ids
    }
  })
}

/*复制任务*/
export const copy = (id) => {
  return request({
    url: '/api/jobslink-api/missions/mission/copy',
    method: 'post',
    data: {
      id
    }
  })
}

/*完成任务*/
export const complete = (id) => {
  return request({
    url: '/api/jobslink-api/missions/mission/complete',
    method: 'post',
    data: {
      id
    }
  })
}

/*任务详情*/
export const detail = (missionNo) => {
  return new Promise(function (resolve, reject) {
    request({
      url: '/api/jobslink-api/missions/mission/detail',
      method: 'get',
      params: {
        missionNo
      }
    })
      .then((res) => {
        const data = res.data.data;
        const selectedSkills = [];
        if (data.skillIds && data.skillNames) {
          var skillIds = data.skillIds.split(",");
          var skillNames = data.skillNames.split(",");
          for (var i = 0; i < skillIds.length; i++) {
            selectedSkills.push({
              'name': skillNames[i],
              'id': skillIds[i]
            })
          }
        }
        data['selectedSkills'] = selectedSkills;
        // data.wage = data.wage ? toDoller(data.wage) : null;
        resolve(data);
      })
      .catch(reject)
  })
}


/*获取待录用 已录用人员列表 */
export const employList = (current, size, params, missionNo) => {
  return request({
    url: '/api/jobslink-api/missions/mission/apply/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
      missionNo
    }
  })
}

/*录用人员 */
export const employ = (missionNo, ids, fpTitleId, fpAddressId) => {
  return request({
    url: '/api/jobslink-api/missions/mission/apply/employed/new',
    method: 'post',
    params: {
      missionNo,
      ids,
      fpTitleId,
      fpAddressId
    }
  })
}

/*取消录用*/
export const cancelEmploy = (missionNo, ids) => {
  return request({
    url: '/api/jobslink-api/missions/mission/apply/cancelEmployed',
    method: 'post',
    params: {
      missionNo,
      ids
    }
  })
}

/*评价列表 */
export const getRateList = (current, size, params, missionNo) => {
  return request({
    url: '/api/jobslink-api/missions/mission/tenant/score/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
      missionNo
    }
  })
}

/*获取评价详情 */
export const getRateDetail = (id) => {
  return request({
    url: '/api/jobslink-api/missions/mission/tenant/score/detail',
    method: 'get',
    params: {
      id
    }
  })
}

/*提交评价 */
export const submitRate = (form, missionNo, userId) => {
  return request({
    url: '/api/jobslink-api/missions/mission/tenant/score/submit',
    method: 'post',
    data: {
      ...form,
      missionNo,
      userId
    }
  })
}

/*评价列表 导入人才库 */
export const importTalents = (groupId, workTypeNames, data) => {
  return request({
    url: '/api/jobslink-api/tenant/talents/tenant/import-mission',
    method: 'post',
    params: {
      groupId,
      workTypeNames
    },
    data: data
  })
}

/*获取推荐列表 */
export const getCommendList = (current, size, params, missionNo) => {
  return request({
    url: '/api/jobslink-api/tenant/talents/recommendList',
    method: 'get',
    params: {
      current,
      size,
      ...params,
      missionNo
    }
  })
}

/*邀请人员 */
export const invite = (rows) => {
  return request({
    url: '/api/jobslink-api/desk/user/notice/invite',
    method: 'post',
    data: rows
  })
}

/*批量邀请人员 */
export const inviteUser = (rows) => {
  return request({
    url: '/api/jobslink-api/missions/mission/apply/notice/inviteUser',
    method: 'post',
    data: rows
  })
}

/*邀请人员剩余次数 */
export const inviteCount = (idNumber, missionNo) => {
  return request({
    url: '/api/jobslink-api/missions/mission/apply/notice/list',
    method: 'get',
    params: {
      idNumber,
      missionNo
    }
  })
}


/*根据任务获取每个任务对应的已发工资人数 */
export const getWagePerson = (missionNo) => {
  return request({
    url: '/api/jobslink-api/payment/userOrder/queryCount',
    method: 'get',
    params: {
      missionNo
    }
  })
}
/*获取对比人才库列表 */
export const personCountList = () => {
  return request({
    url: '/api/jobslink-api/tenant/talents/group/tenant/personCountList',
    method: 'get',
  })
}
/*未申请任务的人才库人员列表接口 */
export const userLists = (missionNo, groupIds) => {
  return request({
    url: '/api/jobslink-api/missions/mission/apply/tenant/group/userlist',
    method: 'get',
    params: {
      missionNo,
      groupIds
    }
  })
}
/*未申请任务的人才库人员列表接口  导出*/
export const userListsExport = (missionNo, groupIds) => {
  return `jobslink-api/missions/mission/apply/tenant/group/userlist/export?missionNo=${missionNo}&groupIds=${groupIds}&Jobslink-Auth=${getToken()}`
}
/*未申请任务的人才库人员列表接口  导出*/
export const recommendExportList = (missionNo, name, worktypes, groupId) => {
  return `/api/jobslink-api/tenant/talents/recommend/exportList?missionNo=${missionNo}&name=${name}&worktypes=${worktypes}&groupId=${groupId}&Jobslink-Auth=${getToken()}`
}
//新增行业类型
export const tradeListAdd = (name) => {
  return request({
    url: '/api/jobslink-api/tenant/trade/base/company/add',
    method: 'post',
    data: {
      name
    }
  })
}
//新增工种
export const workListAdd = (tradeId, name) => {
  return request({
    url: '/api//jobslink-api/tenant/worktypes/base/company/add',
    method: 'post',
    data: {
      tradeId,
      name
    }
  })
}
//新增技能
export const skillListAdd = (worktypesId, name) => {
  return request({
    url: '/api/jobslink-api/tenant/skills/base/company/add',
    method: 'post',
    data: {
      worktypesId,
      name
    }
  })
}

//发布任务时获取上个任务信息
export const getLastTaskInfo = () => {
  return request({
    url: '/api/jobslink-api/missions/mission/getContactInfo',
    method: 'get'
  })
}

//获取某个自然月的天数
export const getMounthDays = (date) => {
  return request({
    url: '/api/jobslink-api/missions/mission/getMonthDays',
    method: 'get',
    params: {
      date
    }
  })
}


export const getDictionary = (params) => {
  return request({
    url: '/api/jobslink-api/system/dict-biz/dictionary',
    method: 'get',
    params
  })
}
export const listCompany = (params) => {
  return request({
    url: '/api/jobslink-api/tenant/company/list/company',
    method: 'get',
    params
  })
}

/*导入任务*/
export const upload = () => {
  return `/api/jobslink-api/missions/mission/importMission?isCovered=1`
}

export const missionHistory = () => {
  return request({
    url: `/api/jobslink-api/missions/mission/history`,
    method: 'get',
  })
}

export const jkWorksHistory = () => {
  return request({
    url: `/api/jobslink-api/jkWorks/jkWorks/history`,
    method: 'get',
  })
}

// 零工岗位审核接口
export const missionReview = (params) => {
  return request({
    url: `/api/jobslink-api/missions/mission/missionReview`,
    method: 'post',
    data:params
  })
}