jqMultipleShow("click", ".navList", ".tab", ".con");
var orderPage = new Vue({
    el: "#orderPage",
    data: {
        isRequset:true,
        orderId:0,              //订单ID
        userId: 0,              //用户ID
        orderInfo:{},           //订单信息
        shopOrderList:[],       //订单商品信息
        userInfo:{},            //订单用户信息
        orderInvoice:{},        //发票信息
        discernReceiptList:[],  //订单付款信息
        returnedPurchaseList:[],//订单退款信息
        orderIdentificationId:'',//订单标识
        modelType:0
    },
    filters: {
        NumFormat:function(text) {//处理金额
            return Number(text).toFixed(2);
        },
        NumBadge:function(n){//处理
            var num ='';
            if(n>100){num = 99}else{num = n;}
            return num;
        },
        stateExp:function (state){ //订单状态文字和颜色
            var stateText = '',
                stateTextObject={
                    0:'待确认',
                    4:'交易完成',
                    5:'订单完成',
                    6:'已关闭',
                    7:'交易全退',
                    77:'交易全退',
                    11:'待付款待发货',
                    12:'待付款部分发货',
                    13:'待付款已发货',
                    21:'部分付款待发货',
                    22:'部分付款部分发货',
                    23:'部分付款已发货',
                    31:'已付款待发货',
                    32:'已付款部分发货',
                    33:'已付款已发货',
                    111:'待付款待发货'
                };
            Object.keys(stateTextObject).forEach(function(key){
                if(key == state){
                    stateText = stateTextObject[key]
                }
            });
            return stateText;
        }
    },
    computed: {

    },
    methods: {
        GetQueryOrderDetailsInfo:function(){//查询订单详情
            var _self = this;
            OrderApi.QueryOrderDetailsInfo({orderID:_self.orderId},function (response) {
                if(response.code == 0){
                    var data = response.data;
                    _self.orderInfo = data.order;
                    _self.userInfo = data.userInfo;
                    _self.orderInvoice = data.orderInvoice;
                    _self.shopOrderList = data.shopOrderList;
                    _self.discernReceiptList = data.discernReceiptList;
                    _self.returnedPurchaseList = data.returnedPurchaseList;
                    _self.orderIdentificationId = '#'+ _self.orderInfo.orderID+'#';
                    _self.isRequset = false;
                }else{
                    CAIMEI.Alert(response.msg, '确定', false);
                }
            })
        },
        hanldConfirmOrderFn:function(){//确认订单
            var _self = this;
            CAIMEI.Modal('是否确认订单？','取消','确定',function () {
                OrderApi.AffirmOrderOrder({orderID:_self.orderId},function(response){
                    if(response.code == 0){
                        CAIMEI.dialog('确认成功',true,function () {
                            _self.GetQueryOrderListData();
                        });
                    }else{
                        CAIMEI.Alert(response.msg, '确定', false);
                    }
                })
            })
        },
        hanldCancelOrderFn:function(){//取消订单
            var _self = this;
            CAIMEI.Modal('确认取消该订单吗？','取消','确定',function () {
                OrderApi.GetCancelOrder({orderID:_self.orderId},function(response){
                    if(response.code == 0){
                        CAIMEI.dialog('取消成功',true,function () {
                            _self.GetQueryOrderDetailsInfo();
                        });
                    }else{
                        CAIMEI.Alert(response.msg, '确定', false);
                    }
                })
            })
        },
        hanldDeleteOrderFn:function(){//删除订单
            var _self = this;
            CAIMEI.Modal('确认删除该订单吗？','取消','确定',function () {
                OrderApi.GetDeleteOrder({orderID:_self.orderId},function(response){
                    if(response.code == 0){
                        CAIMEI.dialog('删除成功',true,function () {
                            window.location.href='/user/order/list.html?state=0';
                        });
                    }else{
                        CAIMEI.Alert(response.msg, '确定', false);
                    }
                })
            })
        },
        hanldReceivingOrderFn:function(){//确认收货
            var _self = this;
            CAIMEI.Modal('是否确认收货？','取消','确定',function () {
                OrderApi.GetAffirmOrder({orderID:_self.orderId},function(response){
                    if(response.code == 0){
                        CAIMEI.dialog('操作成功',true,function () {
                            _self.GetQueryOrderDetailsInfo();
                        });
                    }else{
                        CAIMEI.Alert(response.msg, '确定', false);
                    }
                })
            })
        },
        hanldPayOrderFn:function(){//支付订单
            var _self = this;
            OrderApi.OrderPaymentValidation({orderId:_self.orderId},function(response){
                if(response.code == 0){
                    var dataCode = response.data.code;
                    _self.payModelData = response.data;
                    switch(dataCode){
                        case 1:
                            _self.modelType = 1;
                            break;
                        case 2:
                            _self.modelType = 2;
                            break;
                        case -1:
                            CAIMEI.Alert('订单已申请全部退款，无需再付款！', '确定', false);
                            break;
                        default:
                            if(response.data.onlinePayFlag == '1'){
                                _self.modelType = 3;
                            }else{
                                window.location.href = '/pay/caimei-paycash.html?type=payfirm&orderID='+_self.orderId;
                            }
                    }
                }else{
                    CAIMEI.Alert(response.msg, '确定', false);
                }
            })
        },
        hanldPaymentConfirm:function() {//余额抵扣跳转
            var _self = this;
            OrderApi.OrderBalanceDeduction({orderId: _self.orderId}, function (response) {
                if (response.code == 0) {
                    if (_self.modelType === 2) {
                        window.location.href = '/pay/success.html?pageType=www&type=success&payAmount='+_self.payModelData.pendingPayments;
                    } else {
                        if (_self.orderInfo.onlinePayFlag === '1') {
                            _self.modelType = 3;
                        } else {
                            window.location.href = '/pay/caimei-paycash.html?type=payfirm&orderID='+_self.orderId;
                        }
                    }
                } else {
                    CAIMEI.Alert(response.msg, '确定', false);
                }
            });
        },
        hanldCancelConfirm:function(){//不使用余额抵扣直接跳转收银台
            var _self = this;
            if(_self.orderInfo.onlinePayFlag == '1'){
                _self.modelType = 3;
            }else{
                window.location.href = '/pay/caimei-paycash.html?type=payfirm&orderID='+_self.orderId;
            }
        },
        hidePaymentConfirm:function(){//隐藏弹窗
            var _self = this;
            _self.modelType = 0;
        },
        hanldQueryExpressFn:function(){//跳转查看物流

        },
        copyOrderBtnSubmitFn:function(){//复制订单标识
            var _self = this;
            var oInput = document.createElement("textarea");
            oInput.value = _self.orderIdentificationId;
            document.body.appendChild(oInput);
            oInput.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令
            document.body.removeChild(oInput);
            CAIMEI.dialog('复制成功');
        },
        showBadge:function(n){//处理标签
            var num ='';
            if(n>100){num = 99}else{num = n;}
            return num;
        },
        toFixedFn:function(text){//处理小数点后两位数
            return Number(text).toFixed(2);
        },
    },
    mounted: function () {
        if(globalUserData){
            this.userId = globalUserData.userId;
            this.orderId = CAIMEI.getUrlParam('orderId');
            this.GetQueryOrderDetailsInfo();
        }
        $('.navLayout').find('.navList').removeClass("on").find('.con').hide().find('a').removeClass("on");
        $('.navLayout').find('.navList').eq(0).addClass("on").find('.con').show().find('a').eq(0).addClass("on");

    }
});
