var isPC = ($(window).width()>768);
var orderList = new Vue({
    el:'#orderList',
    data:{
        Status:[
            {name:'所有',value:'0'},
            {name:'待发货',value:'1'},
            {name:'部分发货',value:'2'},
            {name:'已发货',value:'3'},
        ],
        pay:[
            {name:'所有',value:'0'},
            {name:'待结算',value:'1'},
            {name:'部分结算',value:'2'},
            {name:'已结算',value:'3'},
        ],
        params:{
            ShopID:10100,
            pageNum: 1,
            pageSize: 10,
            sendOutStatus: '',//发货状态
            payStatus:'',//结算状态
            shopOrderNo:'',//订单编号
            name: '',//买家名称
        },
         pageInput: '1',
         listRecord: 0,
         isRequset:false,
         open:false,
         requestFlag: true,
         noMore: false,
         results:[],
    },
    computed: {
        pageTotal: function () {
            var total = Math.ceil(this.listRecord / this.params.pageSize);
            return total > 0 ? total : 1;
        },
        showPageBtn: function () {
            var total = Math.ceil(this.listRecord / this.params.pageSize);
            total = total > 0 ? total : 1;
            var index = this.params.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.params.pageNum = pageNum;
                this.MyOrderList(this.params);
            }
        },
     checkNum: function () {
        if (this.pageInput > this.pageTotal) {
            this.pageInput = this.pageTotal;
        } else if (this.pageInput < 1) {
            this.pageInput = 1;
        }
    },
    MyOrderList:function () {
       var _this = this;
        SupplierApi.MyOrderList(_this.params,function (res) {
            if(res.code==0){
                 console.log(res)
                 if(res.data.results.length > 0){
                     _this.isRequset = true;
                     _this.results = res.data.results;
                     _this.listRecord = res.data.totalRecord;
                 }else {
                     _this.results = res.data.results;
                     _this.listRecord = res.data.totalRecord;
                 }
            }
        })
    },
    opentittle:function(){
       this.open = !this.open;
    },
    getpayStatus:function () { //结算状态
        var _this = this;
        if(event.target.value==0){
            _this.params.payStatus = '';
        }else {
            _this.params.payStatus = event.target.value;
        }
    },
    getstatus:function () { //发货状态
      var _this = this;
        if(event.target.value==0){
         _this.params.sendOutStatus='';
        }else {
         _this.params.sendOutStatus=event.target.value;
        }
    },
    serchBtn:function () {
        var _this=this;
            _this.MyOrderList()
    },
    delivery:function (orderID) {//发货
        window.location.href='/supplier/order/delivery.html?shopOrderID='+orderID;
    },
    record:function (shopOrderID) {//发货记录
        window.location.href = '/supplier/order/delivery_record.html?shopOrderID='+shopOrderID;
    },
    Checklist:function (shopOrderID) {//售货清单
        window.location.href = '/supplier/order/delivery_record.html?shopOrderID='+shopOrderID;
    },
    seedetail:function (shopOrderID) {
        window.location.href = '/supplier/order/detail.html?shopOrderID='+shopOrderID;
    },
    },
    mounted:function () {
        var _self = this;
       _self.MyOrderList();
        if(globalUserData){
            _self.params.ShopID = globalUserData.shopId;
        }
        if(isPC){
            _self.open=true;
        }
         if(!isPC){
            //移动端上垃加载更多
            $(window).on('scroll', function(){
                var scrollTop = $(this).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = window.innerHeight;
                if (scrollTop + windowHeight >= scrollHeight) {
                    //此处是滚动条到底部时候触发的事件，在这里写要加载的数据，或者是拉动滚动条的操作
                    var totalPage = Math.ceil(_self.listRecord / _self.params.pageSize)?Math.ceil(_self.listRecord / _self.params.pageSize):1;
                    var next = _self.params.pageNum+1;
                    if(next <= totalPage){
                        if (_self.requestFlag){
                            _self.params.pageNum = next;
                            if (_self.isRequset) {
                                // 获取列表数据
                                _self.MyOrderList();
                            }
                        }
                        _self.requestFlag = false;
                    }else{
                        //到底了
                        _self.noMore = true;
                        $('footer').removeClass("noneImportant");
                    }
                }
            });
        }

    }
})
