jqMultipleShow("click", ".navList", ".tab", ".con");
var orderPage = new Vue({
    el: "#orderPage",
    data: {
        isRequset:true,
        userId: 0,
        StatusList:[
            {value:0,name:'所有'},
            {value:1,name:'已提交'},
            {value:2,name:'已对接'},
            {value:3,name:'已评价'},
            {value:4,name:'已取消'}
        ],
        listQuery:{
            keyword:'',
            status:0,
            userId:0,
            startTime:'',
            endTime:'',
            pageNum:1,
            pageSize:10
        },
        listRecord: 0,
        pageInput: '1',
        orderList:[],
        confirmedCount:'',//待確認數量
        paymentCount:'',//待付款
        waitShipmentsCount:'',//待发货
        shipmentsCount:'',//已发货
        salesReturnCount:'',//退货款
    },
    filters: {
        NumFormat:function(text) {//处理金额
            return Number(text).toFixed(2);
        },
        stateExp:function (state){ //订单状态文字和颜色
            var stateText = '',
                stateTextObject={
                    0:'已评价',
                    4:'已提交'
                };
                Object.keys(stateTextObject).forEach(function(key){
                    if(key == state){
                    stateText = stateTextObject[key]
                }
             });
            return stateText;
        }
    },
    computed: {
        pageTotal: function () {
            var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
            return total > 0 ? total : 1;
        },
        showPageBtn: function () {
            var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
            total = total > 0 ? total : 1;
            var index = this.listQuery.pageNum, arr = [];
            if (total <= 6) {
                for (var i = 1; i <= total; i++) {
                    arr.push(i);
                }
                return arr;
            }
            if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
            if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
            return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
        }
    },
    methods: {
        toPagination: function (pageNum) {//点击切换分页
            if (pageNum <= this.pageTotal) {
                this.listQuery.pageNum = pageNum;
                this.GetQueryOrderListData();
            }
        },
        checkNum: function () {//输入跳转分页
            if (this.pageInput > this.pageTotal) {
                this.pageInput = this.pageTotal;
            } else if (this.pageInput < 1) {
                this.pageInput = 1;
            }
        },
        GetQueryListData:function(){//查询订单列表
            var _self = this;
            RepairApi.GetFindMaintenance(_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);
                }
            })
        },
        hanldDetilsOrderFn:function(orderId){//订单详情
            window.location.href='/user/order/detail.html?order='+orderId;
        },
        selectStatusFn:function(event){
            this.listQuery.status = event.target.value;
        }
    },
    mounted: function () {
        if(globalUserData){
            this.userId = globalUserData.userId;
            this.listQuery.orderState = CAIMEI.getUrlParam('state');
            this.listQuery.userId = this.userId;
            this.GetQueryListData();
        }
        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(1).addClass("on");

    }
});
