import request from '@/utils/request'
import {httpRequest} from '@/utils/request/axios'
const baseUrl = 'https://api.1024api.com/api-interface/app'

// api地址
const api = {
  todoCounts: 'order/todoCounts',
  list: 'order/list',
  detail: 'order/detail',
  express: 'order/express',
  cancel: 'order/cancel',
  receipt: 'order/receipt',
  pay: 'order/pay'
}

// 当前用户待处理的订单数量
export function todoCounts(param, option) {
  return request.get(api.todoCounts, param, option)
}

// 我的订单列表
export function list(param, option) {
  return request.get(api.list, param, option)
}

// 订单详情
export function detail(orderId, param) {
  return request.get(api.detail, { orderId, ...param })
}

// 获取物流信息
export function express(orderId, param) {
  return request.get(api.express, { orderId, ...param })
}

// 取消订单
export function cancel(orderId, data) {
  return request.post(api.cancel, { orderId, ...data })
}

// 确认收货
export function receipt(orderId, data) {
  return request.post(api.receipt, { orderId, ...data })
}

// 获取买家地址
export const apiGetAddressList = (data) => {
    return httpRequest.post(
      `${baseUrl}/buyer/address/list`,
      data
    );
  }

// 新增或更新买家地址
export const apiInsertOrUpdateAddress = (data) => {
    return httpRequest.post(
      `${baseUrl}/buyer/address/insertOrUpdate`,
      data
    );
  }

// 下单
export const apiOrderAdd = (data) => {
    return httpRequest.post(
      `${baseUrl}/order/add`,
      data
    );
  }

// 获取订单列表
export const apiGetOrderList = (data) => {
    return httpRequest.post(
      `${baseUrl}/order/list`,
      data
    );
  }

// 订单操作
export const apiActionOrder = (url, data) => {
    url = url.startsWith('/app') ? url.substring(4) : url
    return httpRequest.post(
      `${baseUrl}${url}`,
      data
    );
  }

// 获取购物车列表
export const apiGetCartList = (data) => {
    return httpRequest.post(
      `${baseUrl}/shipping/cart/list`,
      data
    );
  }

// 获取订单详情
export const apiGetOrderDetail = (data) => {
    return httpRequest.post(
      `${baseUrl}/order/detail`,
      data
    );
  }

// 获取订单物流信息
export const apiGetOrderLogistics = (data) => {
    return httpRequest.post(
      `${baseUrl}/logistics/query`,
      data
    );
  }

// 我的个人中心获取订单数量
export const apiGetOrderCount = (data) => {
    return httpRequest.post(
      `${baseUrl}/order/count`,
      data
    );
  }


