/* eslint-disable no-param-reassign */

const send_request = require('../utils/sendRequest')

/** 商品下单 */
export function createOrder(orderList) {
  let userInfo = wx.getStorageSync("userInfo")
  // orderList 结构为 [ { goodId, count }, ... ]
  return send_request({
    url: '/shop/order/miniprogram/createOrder',
    method: "POST",
    data: {
      "userId": userInfo.id,
      "orderList": orderList
    }
  })
}

/** 获取订单详情 */
export function getOrderDetail(orderId) {
  return send_request({
    url: '/shop/order/miniprogram/orderDetail',
    method: "GET",
    data: {
      "orderId": orderId
    }
  })
}

/** 我的订单 */
export function listUserOrder(filter) {
  let userInfo = wx.getStorageSync("userInfo")
  return send_request({
    url: '/shop/order/miniprogram/listUserOrder',
    method: "GET",
    data: {
      "userId": userInfo.id,
      "filter": filter || "",
    }
  })
}

/** 订单支付 */
export function payOrder(orderId) {
  return send_request({
    url: '/shop/order/miniprogram/payOrder',
    method: "POST",
    data: {
      "orderId": orderId,
    }
  })
}

/** 取消订单 */
export function cancelOrder(orderId) {
  return send_request({
    url: '/shop/order/miniprogram/cancelOrder',
    method: "POST",
    data: {
      "orderId": orderId,
    }
  })
}

/** 确认收货 */
export function confirmOrder(orderId) {
  return send_request({
    url: '/shop/order/miniprogram/confirmOrder',
    method: "POST",
    data: {
      "orderId": orderId,
    }
  })
}
