orderaction.js 2.8 KB
// src/components/order/orderaction.js
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 UFO_BUYER_DELETE_ORDER = 'ufo.buyer.delete';
const UFO_BUYER_CANCEL_ORDER = 'ufo.buyer.cancel';
const api = new OrderActionService();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    buttons: Array,
    //默认值:-1(不显示),0:订单列表,1:订单详情
    // fromPage: Number,
    timer: String,
    realPrice: String,
    orderCode:String,
    productId:String,
  },

  /**
   * 组件的初始数据
   */
  data: {
  },

  lifetimes: {
  },

  

  /**
   * 组件的方法列表
   */
  methods: {

    onButtonClick: function(e){
      let actionCode = e.currentTarget.dataset.buttonCode;
      let orderCode = e.currentTarget.dataset.orderCode;
      let productId = e.currentTarget.dataset.productId;
      
      if (actionCode == BUY_AGAIN) {
        wx.navigateTo({
          url: '/pages/productDetail/index?id=' + productId,
        })
      } else if (actionCode == NOW_BUY){
        console.log("== 去支付页面===")
        wx.navigateTo({
          //todo:
         
          //url: '/pages/productDetail/index?id=' + productId,
        })
      }else {
        this.showDialog(orderCode, actionCode);
      }
     
    },
    /**
   * 订单操作
   */
    actionOrder: function (orderCode, method) {
      let that = this;
      wx.showLoading({
        title: '加载中...',
      })
      let params = {
        uid: '500031132',
        method: method,
        orderCode: orderCode,
        debug: 'XYZ',
      }
      api.actionOrder(params, () => {
        wx.hideLoading();
      }).then(data => {
        event.emit('refresh-order');
      });
    },
    /**
     * 确认Dialog
     */
    showDialog: function (orderCode, actionType, ) {
      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;
       
      }
      wx.showModal({
        // title: title,
        content: content,
        showCancel: true,
        cancelText: "确定",
        cancelColor: '#000000',
        confirmText: "取消",
        confirmColor: '#E0E0E0',
        success: function (res) {
          if (res.cancel) {
            that.actionOrder(orderCode, method);
          } else {
            //点击取消,默认隐藏弹框
          }
        },
        fail: function (res) { },
        complete: function (res) { },
      })
    
    }
  }


})