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

// 销售 统计查询
export const salesCount = (params) => {
  return axios({
    url: `/sales/queryCount`,
    data: params,
    method: 'post'
  })
}
//  销售 列表  有分页
export const salesList = (params) => {
  const url = `/sales/queryPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('列表查询')
    }
  })
}
// 第三方库存
export const getThirdStockQty = (params) => {
  return axios({
    url: `/sunFulcess/getStockQty`,
    data: params,
    method: 'post'
  })
}

// 是否已转采购单
export const getCreatePurchaseFlag = (params) => {
  return axios({
    url: `/sales/getCreatePurchaseFlag`,
    data: params,
    method: 'post'
  })
}
// 转采购单
export const allCreatePurchase = (params) => {
  return axios({
    url: `/sales/allCreatePurchase`,
    data: params,
    method: 'post'
  })
}
//  销售 待转费用单列表  有分页
export const salesConvertExpenseList = (params) => {
  const url = `/salesPromo/queryBatchConvertExpenseAccountPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('待转费用报销单列表')
    }
  })
}
//  销售 新增
export const salesSave = (params) => {
  return axios({
    url: '/sales/insert',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('新增销售单')
    }
  })
}
// 销售 编辑
export const salesModify = (params) => {
  return axios({
    url: '/sales/modifyWarehouse',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('修改仓库')
    }
  })
}
//  销售 详情bysn
export const salesDetailBySn = (params) => {
  return axios({
    url: `/sales/findBaseBySn/${params.salesBillSn}`,
    method: 'get'
  })
}
export const getSalesDetail = (params) => {
  return axios({
    url: `/sales/findBySn/${params.salesBillSn}`,
    method: 'get'
  })
}
// 查询客户名称
export const salesDetailByNo = (params) => {
  return axios({
    url: `/sales/findBySaleBillNo/${params.salesBillNo}`,
    method: 'get',
    headers: {
      'module': encodeURIComponent('查询客户信息')
    }
  })
}
//  销售 删除
export const salesDel = (params) => {
  return axios({
    url: `/sales/delete/${params.salesBillSn}`,
    method: 'get',
    headers: {
      'module': encodeURIComponent('删除')
    }
  })
}
//  销售 取消
export const salesCancle = (params) => {
  return axios({
    url: `/sales/cancle/${params.salesBillSn}`,
    method: 'get',
    headers: {
      'module': encodeURIComponent('取消')
    }
  })
}

// 根据销售单sn查询参加的活动
export const salesPromoQueryList = (params) => {
  return axios({
    url: `/salesPromo/queryExtList`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('查询销售单参加的活动统计信息')
    }
  })
}
// 销售单活动统计列表-新
export const salesPromoQueryStatisticsList = (params) => {
  return axios({
    url: `/salesPromo/querySortListBySalesBillSn`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('查询销售单参加的活动统计信息')
    }
  })
}
// 特价规则优先级-新
export const salesPromoDiscountSort = (params) => {
  return axios({
    url: `/salesPromo/queryStackDiscountPromo/${params.salesBillSn}`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('特价规则优先级排序')
    }
  })
}
// 保存特价排序-新
export const salesPromoSaveSort = (params) => {
  return axios({
    url: `/sales/detail/sortPromoList`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('保存特价活动排序')
    }
  })
}

// 更换促销，可更换活动列表
export const salesPromoMatchProduct = (params) => {
  return axios({
    url: `/salesPromo/queryMatchProduct`,
    data: params,
    method: 'post'
  })
}

// 判断是否有新的活动
export const salesQueryUnPartPromo = (params) => {
  return axios({
    url: `/salesPromo/queryUnPartPromo/${params.salesBillSn}`,
    data: params,
    method: 'post'
  })
}
// 活动优惠明细接口
export const salesPromoQueryCount = (params) => {
  return axios({
    url: `/salesPromo/queryCount`,
    data: params,
    method: 'post'
  })
}

// 提交时活动规则校验
export const salesPromoValidaSubmit = (params) => {
  return axios({
    url: `/salesPromo/validationSubmit/${params.salesBillSn}`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('提交前活动规则校验')
    }
  })
}

// 审核时活动规则校验
export const salesPromoValidaAudit = (params) => {
  return axios({
    url: `/salesPromo/validationSubmit/${params.salesBillSn}`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('审核前活动规则校验')
    }
  })
}

//  销售 审核通过
export const salesWriteAuditPass = (params) => {
  return axios({
    url: '/sales/auditPass',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('审核通过')
    }
  })
}
//  销售 审核驳回
export const salesWriteAuditReject = (params) => {
  return axios({
    url: '/sales/auditReject',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('审核驳回')
    }
  })
}
// 销售 审核通过 待上级审核
export const salesWriteUpAuditPass = (params) => {
  return axios({
    url: '/sales/upAuditPass',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('审核通过，待上级审核')
    }
  })
}
// 销售 审核不通过 待上级审核
export const salesWriteUpAuditReject = (params) => {
  return axios({
    url: '/sales/superiorAuditReject',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('审核不通过，待上级审核')
    }
  })
}
//  销售 一键审核下推
export const salesWriteAuditPush = (params) => {
  return axios({
    url: '/sales/auditPush',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('一键审核')
    }
  })
}
//  销售 提交
export const salesWriteSubmit = (params) => {
  return axios({
    url: '/sales/submit',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('提交')
    }
  })
}

// 是否更新价格判断
export const submitCheck = (params) => {
  return axios({
    url: '/sales/submitCheck',
    method: 'post',
    data: params
  })
}
// 改单弹窗价格列表
export const changeBillCheck = (params) => {
  return axios({
    url: '/sales/changeBillCheck',
    method: 'post',
    data: params
  })
}
// 更新改单数据
export const changeBillCheckUpdatePrice = (params) => {
  return axios({
    url: '/sales/changeBillCheckUpdatePrice',
    method: 'post',
    data: params
  })
}

// 当前价格  提交
export const updateBatch = (params) => {
  return axios({
    url: '/sales/detail/updateBatch',
    method: 'post',
    data: params,
    headers: {
      'module': encodeURIComponent('价格批量更新')
    }
  })
}

// 销售详情列表所有包括活动产品不分页
export const salesDetailAllList = (params) => {
  const url = `/sales/detail/queryAll`
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('销售单明细列表查询')
    }
  })
}

// 查询可生成的费用报销单
export const queryCreateBySalesBillSn = (params) => {
  return axios({
    url: `/expenseAccount/queryCreateBySalesBillSn/${params.salesBillSn}`,
    data: params,
    method: 'post'
  })
}

// 批量查询可生成的费用报销单
export const queryBatchCreateBySalesBillSn = (params) => {
  return axios({
    url: `/expenseAccount/queryBatchCreateBySalesPromoSnList`,
    data: params,
    method: 'post'
  })
}
// 批量查询合并后的报销单
export const queryBatchCreateBySalesPromoSnListGroupType = (params) => {
  return axios({
    url: `/expenseAccount/queryBatchCreateBySalesPromoSnListGroupType`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('销售单合并后转费用报销单')
    }
  })
}
// 保存合并选项
export const expenseAccountSaveGroupType = (params) => {
  return axios({
    url: `/expenseAccount/saveCreateGroupType`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('销售单转费用报销单，确定合并')
    }
  })
}
// 保存费用报销单
export const expenseAccountSave = (params) => {
  return axios({
    url: `/expenseAccount/saveCreate`,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('转费用报销单')
    }
  })
}

//  销售 打印
export const salesPrint = (params) => {
  return axios({
    url: '/sales/print',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('销售打印')
    }
  })
}
//  销售 打印预览
export const salesPrintPreview = (params) => {
  return axios({
    url: '/sales/printPreview',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('销售打印预览')
    }
  })
}
// 销售  详情  该销售单的产品二级分类
export const salesDetailProductType = (params) => {
  return axios({
    url: `/sales/detail/queryProductType/${params.sn}`,
    method: 'get'
  })
}
// 销售 详情  打印
export const salesDetailPrint = params => {
  const url = `/sales/print/${params.priceType}`
  const id = params.priceType.indexOf('_TYPE') >= 0 ? '销售分类打印' : '销售打印'
  delete params.priceType
  return axios.request({
    url: url,
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent(id)
    }
  })
}
// 销售 详情  导出
export const salesDetailExcel = params => {
  const url = `/sales/excel/${params.priceType}`
  delete params.priceType
  return axios.request({
    url: url,
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent('导出Excel')
    }
  })
}
// 销售 详情  分类导出
export const salesDetailTypeExcel = params => {
  const url = `/sales/detail/typeExcel`
  return axios.request({
    url: url,
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent('销售分类导出')
    }
  })
}

// 仓库销售单
//  按仓库查询销售单 列表  有分页
export const queryPageForWarehouse = (params) => {
  const url = `/sales/queryPageForWarehouse/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('列表查询')
    }
  })
}
// 获取按仓库查询销售单数量
export const queryCountForWarehouse = (params) => {
  return axios({
    url: '/sales/queryCountForWarehouse',
    method: 'post',
    data: params
  })
}
// 按仓库查询销售明细 列表
export const queryPageForWarehouseDetail = (params) => {
  const url = `/sales/detail/queryPageForWarehouse/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('明细列表查询')
    }
  })
}

// 获取按仓库查询销售单明细数量
export const queryCountForWarehouseDetail = (params) => {
  return axios({
    url: '/sales/detail/queryCountForWarehouse',
    method: 'post',
    data: params
  })
}
// 按仓库导出销售单
export const exportForWarehouse = params => {
  const url = `/sales/exportForWarehouse`
  return axios.request({
    url: url,
    data: params,
    method: 'post',
    responseType: 'blob',
    headers: {
      'module': encodeURIComponent('导出')
    }
  })
}
// 销售一览表 列表
export const salesOverviewQueryPage = (params) => {
  const url = `/salesOverview/queryPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('列表查询')
    }
  })
}

// 累计产品选择列表
export const salesDetailQueryBorrowPageList = (params) => {
  const url = `/sales/detail/queryWaitBorrowPage/${params.pageNo}/${params.pageSize}`
  delete params.pageNo
  delete params.pageSize
  return axios({
    url: url,
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('选择累计产品列表')
    }
  })
}

// 导入累计产品
export const salesDetailImportBorrow = (params) => {
  return axios.request({
    url: '/sales/detail/importBorrow',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('导入累计产品')
    }
  })
}

//查看累计、同款产品 买赠产品列表
export const queryRegularProductShortfallList = (params) => {
  return axios.request({
    url: '/salesPromo/queryRegularProductShortfallList',
    data: params,
    method: 'post',
    headers: {
      'module': encodeURIComponent('买赠产品列表')
    }
  })
}
