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

/*
 * 采购退货 列表
 * 采购退货 列表分页
 */
export const sparePartsReturnList = (params) => {
  const url = `/sparePartsReturn/queryPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent('列表查询')
    }
  })
}

// 删除采购退货信息
export const sparePartsReturnDelete = (params) => {
  return axios({
    url: `/sparePartsReturn/delete/${params.sn}`,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent('删除')
    }
  })
}

// 再次提交
export const againSubmit = (params) => {
  return axios({
    url: `/sparePartsReturn/againSubmit`,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent('再次提交')
    }
  })
}

/*
 * 采购退货 详情
 * 采购退货详情基础信息
 */
export const sparePartsReturnInfo = params => {
  return axios({
    url: `/sparePartsReturn/queryBySn/${params.sn}`,
    data: {},
    method: 'get'
  })
}

// 货详情分页列表
export const sparePartsReturnQueryPage = (params) => {
  const url = `/sparePartsReturn/detail/queryPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent('明细列表查询')
    }
  })
}

// 采购退货详情金额统计
export const queryPageCount = (params) => {
  return axios({
    url: `/sparePartsReturn/detail/queryPageCount`,
    data: params,
    method: 'post'
  })
}

/*
 * 采购退货 新增
 * 采购退货保存
 */
export const sparePartsReturnSave = (params) => {
  return axios({
    url: `/sparePartsReturn/save`,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent('新增')
    }
  })
}

// 采购退货 提交
export const sparePartsReturnSubmit = (params) => {
  return axios({
    url: `/sparePartsReturn/submit`,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent('提交')
    }
  })
}

// 明细删除
export const sparePartsReturnDetailDelete = (params) => {
  return axios({
    url: `sparePartsReturn/detail/delete/${params.detailSn}`,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent('删除')
    }
  })
}

// 明细保存  （明细中添加/编辑产品）
export const sparePartsReturnDetailSave = (params) => {
  return axios({
    url: `/sparePartsReturn/detail/save`,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent(params.sparePartsReturnDetailSn ? '编辑申请退货数量':'添加')
    }
  })
}

// 导出明细
export const sparePartsReturnExportDetail = (params) => {
  return axios({
    url: `/report/sparePartsReturn/exportDetail`,
    data: params,
    method: 'post',
    responseType: 'blob',
    headers:{
      'module': encodeURIComponent('导出明细')
    }
  })
}
// 批量保存
export const sparePartsReturnDetailSaveBatch = (params) => {
  return axios({
    url: `/sparePartsReturn/detail/saveBatch`,
    data: params,
    method: 'post',
    headers:{
      'module': encodeURIComponent('批量添加')
    }
  })
}

// 禁止选择重复列表
export const queryDetailSnListBySn = params => {
  const url = `/sparePartsReturn/detail/queryDetailSnListBySn/${params.sn}`
  delete params.sn
  return axios({
    url: url,
    data: params,
    method: 'post'
  })
}
