import request from '@/router/axios';
import axios from 'axios'


/*获取待核算 已过期任务列表 */
export const getList =
  (current, size, params) => {
    return request({
      url: '/api/jobslink-api/missions/mission/adjust/list',
      method: 'get',
      params: { ...params, current, size }
    })
  }


/*获取待核算人员列表 */
export const getPersonList =
  (missionNo) => {
    return request({
      url: '/api/jobslink-api/missions/mission/apply/adjust/userlist',
      method: 'get',
      params: { missionNo }
    })
  }

/*生成工资单*/
export const submit =
  (payrollId, missionNo, data) => {
    return request({
      url: '/api/jobslink-api/payment/mission/payroll/submit/payroll',
      method: 'post',
      params: { payrollId, missionNo },
      data: data
    })
  }

/*获取工资单列表*/
export const getPayRollList =
  (current, size, params) => {
    return request({
      url: '/api/jobslink-api/payment/mission/payroll/list',
      method: 'get',
      params: { ...params, current, size }
    })
  }

/*查看工资单详情列表*/
export const getPayInfoList =
  (current, size, params, payrollId) => {
    return request({
      url: '/api/jobslink-api/payment/mission/payroll/item/tenant/list',
      method: 'get',
      params: { ...params, current, size, payrollId }
    })
  }

/*工资单编辑时 获取已核算人员列表 */
export const getWageList =
  (missionNo, payrollId) => {
    return request({
      url: '/api/jobslink-api/payment/mission/payroll/item/wait/detail',
      method: 'get',
      params: { missionNo, payrollId }
    })
  }

/*工资单编辑时 获取已核算人员列表+未合并人员 */
export const getPayrollDetail =
  (missionNo, payrollId) => {
    return new Promise(function (resolve, reject) {
      axios.all([getPersonList(missionNo), getWageList(missionNo, payrollId)])
        .then(axios.spread(function (waiting, created) {
          resolve({ waiting, created })
        }))
        .catch(reject)
    })
  }

/*删除工资单*/
export const remove =
  (id) => {
    return request({
      url: '/api/jobslink-api/payment/mission/payroll/remove',
      method: 'post',
      params: { id }
    })
  }

/*批量生成订单*/
export const submitOrder = (fpAddressId, fpTitleId, ids) => {
  return request({
    url: '/api/jobslink-api/payment/mission/payroll/submit/order',
    method: 'post',
    params: { fpAddressId, fpTitleId, ids }
  })
}


/*下载工资单明细*/
export const download = (auth, payrollId) => {
  return `/api/jobslink-api/payment/mission/payroll/item/export-missionpayrollItem?Jobslink-Auth=${auth}&payrollId=${payrollId}`
}
