/**
 * 分包名录管理接口
 */
import request from '@/api/index'
const $route = useRoute()
// 不同状态列表分页
export function getListPage(params: any, statusName: string) {
  if (statusName === '全部') {
    return request({
      url: `/subcontractor/allPage?limit=${params.limit}&offset=${params.offset}`,
      method: 'post',
      data: params,
    })
  }
  else if (statusName === '已审批') {
    return request({
      url: `/subcontractor/approval/approvedListPage?limit=${params.limit}&offset=${params.offset}`,
      method: 'post',
      data: params,
    })
  }
  else if (statusName === '待审批') {
    return request({
      url: `/subcontractor/approval/toApprovalListPage?limit=${params.limit}&offset=${params.offset}`,
      method: 'post',
      data: params,
    })
  }
  else {
    return request({
      url: `/subcontractor/approval/listPage?limit=${params.limit}&offset=${params.offset}`,
      method: 'post',
      data: params,
    })
  }
}
// 详情
export function getDetail(params: object) {
  return request({
    url: '/subcontractor/detail',
    method: 'get',
    params,
  })
}
// 保存编辑
export function editDirectory(data: object, type: string) {
  console.log($route, 'route')
  if (type === '全部' && window.location.href.includes('update')) {
    return request({
      url: '/subcontractor/update',
      method: 'post',
      data,
    })
  }
  else {
    return request({
      url: '/subcontractor/approval/saveOrUpdate',
      method: 'post',
      data,
    })
  }
}
// 提交
export function submitDirectory(data: object) {
  return request({
    url: '/subcontractor/approval/submit',
    method: 'post',
    data,
  })
}
// 导出
export function exportDirectory(data: object) {
  return request({
    url: '/subcontractor/allExport',
    method: 'post',
    data,
    responseType: 'blob',
  })
}
// 删除记录
export function deleteDirectory(data: object, type: string) {
  if (type === '全部') {
    return request({
      url: `/subcontractor/remove?id=${data.id}`,
      method: 'post',
    })
  }
  else {
    return request({
      url: `/subcontractor/approval/delete?id=${data.id}`,
      method: 'post',
    })
  }
}
// 取消
export function cancelDirectory(data: object) {
  return request({
    url: '/subcontractor/approval/cancel',
    method: 'post',
    data,
  })
}
// 审批操作
export function handlerApproval(type: string, data: { processId?: string; taskId?: string; comments: string }) {
  return request({
    url: `/subcontractor/approval/${type}`,
    method: 'post',
    data,
  })
}
