import { axios } from '@/utils/request'

//  散件入库 列表  分页
export const sparePartsList = (params) => {
  const url = `/spareParts/queryPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('列表查询')
    }
  })
}
// 导出
export const sparePartsDetailExport = (params) => {
  return axios({
    url: '/report/spareParts/exportDetail',
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent('导出明细')
    }
  })
}

// 审核
export const sparePartsAudit = (params) => {
  return axios({
    url: `/spareParts/audit/${params.sn}`,
    method: 'get',
    headers: {
      'module': encodeURIComponent('审核')
    }
  })
}
// 批量审核
export const sparePartsBatchAudit = (params) => {
  return axios({
    url: `/spareParts/batchAudit`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('批量审核')
    }
  })
}
// 多审核校验
export const sparePartsAuditVerify = (params) => {
  return axios({
    url: `/spareParts/auditVerify`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('审核校验')
    }
  })
}
// 导出审核错误项
export const sparePartsAuditFail = (params) => {
  return axios({
    url: `/spareParts/downloadAuditFail`,
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent('导出审核错误项')
    }
  })
}

// 删除
export const sparePartsDelete = (params) => {
  return axios({
    url: `/spareParts/delete/${params.sn}`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('删除')
    }
  })
}

// 删除明细
export const sparePartsDeleteDetail = (params) => {
  return axios({
    url: `/spareParts/deleteDetail/${params.sn}`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('删除')
    }
  })
}

// 分页列表明细
export const sparePartsDetailList = (params) => {
  const url = `/spareParts/queryDetailPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('明细列表查询')
    }
  })
}

// 分页列表明细合计
export const sparePartsPageCount = (params) => {
  return axios({
    url: `/spareParts/queryDetailPageCount`,
    data: params,
    method: 'post'
  })
}
//  散件入库 明细列表  基础信息
export const queryDetailCount = (params) => {
  const url = `/spareParts/queryBySn/${params.sn}`
  return axios({
    url: url,
    method: 'post',
    headers: {
      'module': encodeURIComponent('基础信息')
    }
  })
}

// 新增散件入库单
export const sparePartsSave = (params) => {
  return axios({
    url: `/spareParts/save`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent(params.id ? '编辑' : '新增')
    }
  })
}

// 保存明细
export const sparePartsSaveDetail = (params) => {
  return axios({
    url: `/spareParts/saveDetail`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent(params.id ? '编辑' : '新增产品')
    }
  })
}
// 明细  详情
export const sparePartsDetailD = (params) => {
  return axios({
    url: `/spareParts/queryDetailBySn/${params.sn}`,
    data: params,
    method: 'post'
  })
}
// 散件入库 下载模板
export const sparePartsDetailDownload = params => {
  return axios.request({
    url: `/spareParts/detail/downloadExcel`,
    method: 'post',
    responseType: 'blob'
  })
}
// 散件入库  解析导入的文件
export const sparePartsDetailParseProducts = params => {
  return axios({
    url: '/spareParts/detail/parseProducts',
    data: params,
    method: 'post'
  })
}
// 散件入库  批量插入
export const sparePartsDetailBatchInsert = params => {
  return axios({
    url: '/spareParts/detail/batchInsert',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('导入')
    }
  })
}
//  散件入库 导入产品 导出错误项
export const sparePartsDetailFailExcel = (params) => {
  const url = `/spareParts/detail/downloadFailExcel`
  return axios.request({
    url: url,
    method: 'post',
    data: params.list,
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent('导出错误项')
    }
  })
}

// 明细库存分页列表
export const queryDetailStockPage = (params) => {
  const url = `/spareParts/queryDetailStockPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('明细列表查询')
    }
  })
}
