import { qs } from '@/utils'
import { http } from '@/utils/http'

const pre = import.meta.env.VITE_SERVER_BASEURL_PREFIX
/**
 * 商品预下单
 * @returns
 */
export function preOrder(data: any) {
  return http.post<any>(`${pre}/app/order/pre/order`, data)
}
/**
 * 加载预下单
 * @returns
 */
export function loadPre(data: any) {
  return http.post<any>(`${pre}/app/order/load/pre?${qs(data)}`)
}
/**
 * 计算订单价格
 * @returns
 */
export function computedPrice(data: any) {
  return http.post<any>(`${pre}/app/order/computed/price`, data)
}
/**
 * 创建订单
 * @returns
 */
export function createOrder(data: any) {
  return http.post<any>(`${pre}/app/order/add`, data)
}
/**
 * 支付
 * @returns
 */
export function payOrder(data: any) {
  return http.post<any>(`${pre}/app/order/goPay`, data)
}
/**
 * 订单列表
 * @returns
 */
export function orderList(data: any) {
  return http.post<any>(`${pre}/app/order/app/list`, data)
}

/**
 * 订单状态值枚举
 * @returns
 */
export function orderStatusEnum(data: any) {
  return http.get<any>(`${pre}/app/common/getEnum`, data)
}

/**
 * 订单详情
 * @returns
 */
export function orderDetail(data: any) {
  return http.get<any>(`${pre}/app/order/detail`, data)
}
/**
 * 订单详情-拼团
 * @returns
 */
export function orderPink(data: any) {
  return http.get<any>(`${pre}/app/pink/orderPink`, data)
}
/**
 * 取消订单
 * @returns
 */
export function orderCancel(data: any) {
  return http.post<any>(`${pre}/app/order/cancel?orderNo=${data.orderNo}`)
}

/**
 * 订单绑定地址
 * @param data { orderId: number, addressId: number }
 * @returns
 */
export function bindingAddress(data: any) {
  return http.put<any>(`${pre}/app/order/binding/address`, data)
}

/**
 * 订单待处理红点标识
 * @returns
 */
export function pendingRedDots() {
  return http.get<any>(`${pre}/app/order/pendingRedDots`)
}

/**
 * 可回收订单数
 * @returns
 */
export function userCanRecycleNum() {
  return http.get<any>(`${pre}/app/order/app/userCanRecycleNum`)
}

/**
 * 回收订单
 * @param data { orderNos: string[] }
 * @returns
 */
export function recycleOrder(data: { orderNos: string[] }) {
  return http.post<any>(`${pre}/app/order/app/recycleOrder`, data)
}
