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

//  调拨管理 列表  分页
export const allocateBillList = (params) => {
  const url = `/allocateBill/queryPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('列表查询')
    }
  })
}
// 调拨退货抓单-选产品列表
export const allocDetailQueryPageForReturn = (params) => {
  const url = `/allocateBill/detail/queryPageForReturn/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('可选产品列表查询')
    }
  })
}

// 批量修改部门信息
export const updateBatchDepartment = params => {
  return axios({
    url: '/allocateBill/detail/updateBatchDepartment',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('批量设置费用归属部门')
    }
  })
}
// 调拨管理  新增
export const allocateBillSave = params => {
  return axios({
    url: '/allocateBill/save',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('新增')
    }
  })
}
// 调拨管理  删除
export const allocateBillDel = params => {
  return axios({
    url: `/allocateBill/delete/${params.sn}`,
    data: {},
    method: 'get',
    headers: {
      'module': encodeURIComponent('删除')
    }
  })
}
// 调拨管理  详情
export const allocateBillDetail = params => {
  return axios({
    url: `/allocateBill/findBySn/${params.sn}`,
    data: {},
    method: 'get',
    headers: {
      'module': encodeURIComponent('查看详情')
    }
  })
}
// 调拨管理  审核
export const allocateBillAudit = params => {
  return axios({
    url: `/allocateBill/audit/${params.sn}/${params.state}`,
    data: {},
    method: 'get',
    headers: {
      'module': encodeURIComponent('审核')
    }
  })
}
// 允许打印
export const allocateBillAblePrint = params => {
  return axios({
    url: `/allocateBill/ablePrint/${params.sn}`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('允许打印')
    }
  })
}
// 对单通过
export const allocateBillCheck = params => {
  return axios({
    url: `/allocateBill/check/${params.sn}`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('对单通过')
    }
  })
}
// 调拨管理  提交
export const allocateBillSubmit = params => {
  return axios({
    url: `/allocateBill/submit`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('提交')
    }
  })
}
//  调拨管理 导出
export const allocateBillExport = (params) => {
  return axios({
    url: '/allocateBill/exportExcel',
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent('导出')
    }
  })
}
//  调拨管理  明细 列表  分页
export const allocateBillDetailList = (params) => {
  const url = `/allocateBill/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 allocateBillDetailCount = (params) => {
  return axios({
    url: '/allocateBill/detail/queryCount',
    data: params,
    method: 'post'
  })
}
// 调拨管理  详情  删除
export const allocateBillDetailDel = params => {
  return axios({
    url: `/allocateBill/detail/delete/${params.id}`,
    data: {},
    method: 'get',
    headers: {
      'module': encodeURIComponent('删除')
    }
  })
}
// 调拨管理  详情  整单删除
export const allocateBillDetailDelAll = params => {
  return axios({
    url: `/allocateBill/detail/deleteAll/${params.sn}`,
    data: {},
    method: 'get',
    headers: {
      'module': encodeURIComponent('整单删除')
    }
  })
}
// 调拨管理  详情  保存
export const allocateBillDetailSave = params => {
  return axios({
    url: '/allocateBill/detail/save',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('修改数量或费用归属部门')
    }
  })
}
// 调拨管理 详情  打印
export const allocateBillDetailPrint = params => {
  const url = `/allocateBill/print/${params.printType}`
  const mid = params.printType.indexOf('_TYPE') >= 0 ? '调拨分类打印' : '调拨打印'
  delete params.printType
  delete params.isPreview
  return axios.request({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent(mid)
    }
  })
}
// 调拨管理  详情  打印  产品列表
export const allocateBillProductTypeList = params => {
  const url = `/allocateBill/queryProductTypeList/${params.sn}`
  delete params.sn
  return axios({
    url: url,
    data: params,
    method: 'post'
  })
}
// 调拨管理 下载模板
export const allocateBillDownload = params => {
  return axios.request({
    url: `/allocateBill/detail/downloadExcel`,
    method: 'post',
    responseType: 'blob'
  })
}
// 调拨管理  解析导入的文件
export const allocateBillParseProducts = params => {
  return axios({
    url: '/allocateBill/detail/parseProducts',
    data: params,
    method: 'post'
  })
}
// 调拨管理  批量插入
export const allocateBillBatchInsert = params => {
  return axios({
    url: '/allocateBill/detail/batchInsert',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('导入产品')
    }
  })
}
//  调拨管理 导入产品  导出错误项
export const allocateBillFailExcel = (params) => {
  return axios({
    url: '/allocateBill/detail/downloadFailExcel',
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent('导出错误项')
    }
  })
}
//  调拨 详情  导出
export const allocateBillDetailExcel = (params) => {
  return axios({
    url: `/allocateBill/detail/exportExcel/${params.printType}`,
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent(params.printType.indexOf('_TYPE') >= 0 ? '调拨分类导出' : '导出Excel')
    }
  })
}
//  调拨 列表  更改（暂不打印、取消打印）打印状态
export const updatePrintState = params => {
  return axios({
    url: '/allocateBill/updatePrintState',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('更改打印状态')
    }
  })
}

// 调拨一览表  列表分页
export const queryOverviewPage = (params) => {
  const url = `/allocateBill/queryOverviewPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('列表查询')
    }
  })
}

// 调拨  分页查询产品列表
export const queryStockProductPage = (params) => {
  const url = `/allocateBill/queryStockProductPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('列表查询')
    }
  })
}
