import request from '@/config/axios'

// 销售订单 VO
export interface SaleOrderVO {
  id: number
  no: string // 销售单编号
  status: number // 销售状态
  customerId: number // 客户编号
  orderTime: Date // 下单时间
  totalCount: number // 合计数量
  totalPrice: number // 合计价格，单位：元
  totalProductPrice: number // 合计产品价格，单位：元
  remark: string // 备注
}
// ERP 销售订单项 VO
export interface SaleOrderItemsVO {
  id: number // 编号
  orderId: number // 销售订单编号
  productId: number // 产品编号
  productName: number // 产品编号
  productUnitId: number // 产品单位单位
  unitName: number // 产品单位单位
  productPrice: number // 产品单价
  count: number // 数量
  totalPrice: number // 总价
  remark: string // 备注
  outCount: number // 销售出库数量
  returnCount: number // 销售退货数量
}
// 销售订单 API
export const SaleOrderApi = {
  // 查询销售订单分页
  getSaleOrderPage: async (params: any) => {
    return await request.get({ url: `/mes/sale-order/page`, params })
  },

  // 查询销售订单详情
  getSaleOrder: async (id: number) => {
    return await request.get({ url: `/mes/sale-order/get?id=` + id })
  },

  // 新增销售订单
  createSaleOrder: async (data: SaleOrderVO) => {
    return await request.post({ url: `/mes/sale-order/create`, data })
  },

  // 修改销售订单
  updateSaleOrder: async (data: SaleOrderVO) => {
    return await request.put({ url: `/mes/sale-order/update`, data })
  },

  // 删除销售订单
  deleteSaleOrder: async (id: number) => {
    return await request.delete({ url: `/mes/sale-order/delete?id=` + id })
  },

  // 导出销售订单 Excel
  exportSaleOrder: async (params) => {
    return await request.download({ url: `/mes/sale-order/export-excel`, params })
  },

// ==================== 子表（销售订单项） ====================

  // 获得销售订单项分页
  getSaleOrderItemsPage: async (params) => {
    return await request.get({ url: `/mes/sale-order/sale-order-items/page`, params })
  },
  // 新增销售订单项
  createSaleOrderItems: async (data) => {
    return await request.post({ url: `/mes/sale-order/sale-order-items/create`, data })
  },

  // 修改销售订单项
  updateSaleOrderItems: async (data) => {
    return await request.put({ url: `/mes/sale-order/sale-order-items/update`, data })
  },

  // 删除销售订单项
  deleteSaleOrderItems: async (id: number) => {
    return await request.delete({ url: `/mes/sale-order/sale-order-items/delete?id=` + id })
  },

  // 获得销售订单项
  getSaleOrderItems: async (id: number) => {
    return await request.get({ url: `/mes/sale-order/sale-order-items/get?id=` + id })
  },
  // 获得销售订单项
  getSaleOrderItemsByOrderId: async (orderId: number) => {
    return await request.get({ url: `/mes/sale-order/sale-order-items/getByOrderId?orderId=` + orderId })
  },
}
