var isPC = ($(window).width()>768);
var deliveryRecode = new Vue({
    el:'#deliveryRecode',
    data:{
    userInfo:{},
    logisticsList:[],
    isShow:false,
    open:false,
     pageInput: '1',
     listRecord: 0,
     params:{
         shopOrderId:'',
         pageNum: 1,
         pageSize: 10,
     },
     noMore: false,
      isRequset:false,
    },
     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.shipmentsRecord(this.params);
            }
        },
     checkNum: function () {
        if (this.pageInput > this.pageTotal) {
            this.pageInput = this.pageTotal;
        } else if (this.pageInput < 1) {
            this.pageInput = 1;
        }
    },
        shipmentsRecord:function () {
        var _this = this
            SupplierApi.shipmentsRecord(_this.params, function (res) {
            if(res.code==0){
                _this.userInfo = res.data.userInfo;
                _this.listRecord = res.data.logisticsBatchPage.totalRecord;
                var logisticsBatchPage = res.data.logisticsBatchPage;
                if(logisticsBatchPage.results==''){
                     _this.logisticsList = [];
                     _this.isShow = true
                }else {
                    _this.logisticsList = logisticsBatchPage.results;
                    _this.isShow = false
                }
            }
         })
        }
    },
    mounted:function () {
        var _self = this;
        if (globalUserData) {
            _self.params.shopOrderId = globalUserData.shopId;
        }
         _self.shipmentsRecord();
          if(isPC){
            _self.open=true;
        }
              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.shipmentsRecord();
                            }
                        }
                        _self.requestFlag = false;
                    }else{
                        //到底了
                        _self.noMore = true;
                        $('footer').removeClass("noneImportant");
                    }
                }
            });
        }
    }
})
