/**
 * 订单管理
 */

/**
 * [index 订单列表]
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
export function index(data) {
  return service.get('api/virtual/orders/index', {
    params: data
  });
}

/**
 * [exportOrders 订单列表]
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
export function exportOrders(data) {
  return service.get('api/virtual/orders/export', {
    params: data
  });
}

/**
 * [show 订单详情]
 * @param  {[type]} id [description]
 * @return {[type]}      [description]
 */
export function show(id) {
  return service.get(`api/virtual/orders/show/${id}`);
}

/**
 * [cards 卡清单列表]
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
export function cards(data) {
  return service.get('api/virtual/orders/cards', {
    params: data
  });
}

/**
 * [cardsExport 卡清单列表]
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
export function cardsExport(data) {
  return service.get('api/virtual/orders/cards-export', {
    params: data
  });
}
/**
 * [create 创建订单]
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
export function create(data) {
  return serviceForm.post('api/virtual/orders/create', data);
}

/**
 * [update 修改订单]
 * @param  {[type]} data [description]
 * @param  {[type]} id   [角色id]
 * @return {[type]}      [description]
 */
export function update(data, id) {
  return serviceForm.post(`api/virtual/orders/update/${id}`, data);
}

/**
 * [destroy 删除订单]
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
export function destroy(data) {
  return service.post('api/virtual/orders/destroy', data);
}

/**
 * [reset 重置订单]
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
export function reset(data) {
  return service.post('api/virtual/orders/reset', data);
}

/**
 * [ship 排单]
 * @param  {[type]} data [description]
 * @return {[type]}      [description]
 */
export function ship(data) {
  let config = {};
  let params = null;

  if (data.type === 1) {
    params = new FormData();

    for (const key in data) {
      if (data.hasOwnProperty(key)) {
        params.append(key, data[key]);
      }
    }

    config = {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    };
  } else {
    params = data;
  }

  return service.post('api/virtual/orders/ship', params, config);
}
