jqMultipleShow("click", ".navList", ".tab", ".con");
var orderPage = new Vue({
    el: "#orderPage",
    data: {
        isRequset:true,
        userId: 0,
        orderTabBarIndex:0,
        orderTabBar: [
            {state: 0,text: '全部订单',bages:0},
            {state: 1,text: '待确认',bages:0},
            {state: 2,text: '待付款',bages:0},
            {state: 3,text: '待发货',bages:0},
            {state: 4,text: '已发货',bages:0},
            {state: 5,text: '退货/款',bages:0}
        ],
        listQuery:{
            searchNo:'',
            orderState:0,
            userId:0,
            beginTime:'',
            endTime:'',
            pageNum:1,
            pageSize:10
        },
        listRecord: 0,
        pageInput: '1',
        orderList:[],
        confirmedCount:'',//待確認數量
        paymentCount:'',//待付款
        waitShipmentsCount:'',//待发货
        shipmentsCount:'',//已发货
        salesReturnCount:'',//退货款
        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: {
        GetQueryOrderListData:function(){//查询订单列表
            var _self = this;
            OrderApi.GetQueryOrderListData(_self.listQuery,function (response) {
                if(response.code == 0){
                    var data = response.data;
                    if(data.results && data.results.length>0) {
                        _self.orderList = [];
                        _self.orderList = data.results;
                        _self.listRecord = data.totalRecord;
                    }else{
                        _self.orderList = [];
                        _self.orderList = data.results;
                    }
                    _self.isRequset = false;
                }else{
                    CAIMEI.Alert(response.msg, '确定', false);
                }
            })
        },
        hanldConfirmOrderFn:function(orderId){//确认订单
            var _self = this;
            CAIMEI.Modal('是否确认订单？','取消','确定',function () {
                OrderApi.AffirmOrderOrder({orderID:orderId},function(response){
                    if(response.code == 0){
                        CAIMEI.dialog('确认成功',true,function () {
                            _self.GetQueryOrderListData();
                        });
                    }else{
                        CAIMEI.Alert(response.msg, '确定', false);
                    }
                })
            })
        },
        hanldCancelOrderFn:function(orderId){//取消订单
            var _self = this;
            CAIMEI.Modal('确认取消该订单吗？','取消','确定',function () {
                OrderApi.GetCancelOrder({orderID:orderId},function(response){
                    if(response.code == 0){
                        CAIMEI.dialog('取消成功',true,function () {
                            _self.GetQueryOrderListData();
                        });
                    }else{
                        CAIMEI.Alert(response.msg, '确定', false);
                    }
                })
            })
        },
        hanldDeleteOrderFn:function(orderId){//删除订单
            var _self = this;
            CAIMEI.Modal('确认删除该订单吗？','取消','确定',function () {
                OrderApi.GetDeleteOrder({orderID:orderId},function(response){
                    if(response.code == 0){
                        CAIMEI.dialog('删除成功',true,function () {
                            _self.GetQueryOrderListData();
                        });
                    }else{
                        CAIMEI.Alert(response.msg, '确定', false);
                    }
                })
            })
        },
        hanldReceivingOrderFn:function(orderId){//确认收货
            var _self = this;
            CAIMEI.Modal('是否确认收货？','取消','确定',function () {
                OrderApi.GetAffirmOrder({orderID:orderId},function(response){
                    if(response.code == 0){
                        CAIMEI.dialog('操作成功',true,function () {
                            _self.GetQueryOrderListData();
                        });
                    }else{
                        CAIMEI.Alert(response.msg, '确定', false);
                    }
                })
            })
        },
        hanldDetilsOrderFn:function(orderId){//订单详情
            window.location.href='/user/order/detail.html?order='+orderId;
        },
        hanldPayOrderFn:function(orderId){//支付订单

        },
        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.listQuery.orderState = CAIMEI.getUrlParam('state');
            this.listQuery.userId = this.userId;
            this.GetQueryOrderListData();
        }
        console.log(this.listQuery.orderState)
        $('.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");

    }
});
