orderActionUtil.js 2.19 KB
import event from '../../utils/event.js';
import OrderActionService from './orderActionService.js';
const DEL_ORDER = 'del_order';
const BUY_AGAIN = 'buy_again';
const CANCEL_ORDER = 'cancel_order';
const NOW_BUY = 'now_buy';
// const CONFIRM_ORDER = 'confirm_order';//确认收货
const CONFIRM_DELIVERY = 'confirm_delivery';//确认收货
//订单操作接口
const UFO_BUYER_DELETE_ORDER = 'ufo.buyer.delete';//删除订单
const UFO_BUYER_CANCEL_ORDER = 'ufo.buyer.cancel';//取消订单
const UFO_BUYER_CONFIRM_ORDER = 'ufo.buyer.confirm';//确认收货
const api = new OrderActionService();
let FROM_WHERE = 0;

/**
   * 订单操作
   */
// export const 
function actionOrder (orderCode, method) {
  let that = this;
  wx.showLoading({
    title: '加载中...',
  })
  let params = {
    method: method,
    orderCode: orderCode,
    // debug: 'XYZ',
  }
  api.actionOrder(params, () => {
    wx.hideLoading();
  }).then(data => {
    let currentPages = getCurrentPages();
    let length = 0;
    if(currentPages && currentPages.length > 0){
      length = currentPages.length;
    }
    if (FROM_WHERE == 1){
      wx.navigateBack({
        delta: 1
      })
    }
    event.emit('refresh-order');
    
    
  });
}
/**
 * 确认Dialog
 * fromWhere 0:订单列表;1:订单详情
 */
export const showDialog = function (orderCode, actionType, fromWhere) {
  FROM_WHERE = fromWhere;
  let that = this;
  let content = '';
  let method = '';
  if (actionType == DEL_ORDER) {
    content = '您确定删除订单?';
    method = UFO_BUYER_DELETE_ORDER;
  } else if (actionType == CANCEL_ORDER) {
    content = '您确定取消订单?';
    method = UFO_BUYER_CANCEL_ORDER;

  } else if (actionType == CONFIRM_DELIVERY) {
    content = '您确定收货?';
    method = UFO_BUYER_CONFIRM_ORDER;

  }
  wx.showModal({
    // title: title,
    content: content,
    showCancel: true,
    cancelText: "确定",
    cancelColor: '#E0E0E0',
    confirmText: "取消",
    confirmColor: '#000000',
    success: function (res) {
      if (res.cancel) {
        actionOrder(orderCode, method);
      } else {
        //点击取消,默认隐藏弹框
      }
    },
    fail: function (res) { },
    complete: function (res) { },
  })

}