;
var settlement = new Vue({
    el:'#settlement',
    data:{
        params:{
            shopID:'',
            pageNum: 1,
            pageSize: 10,
            shopOrderNo:'',
            name: '',
            payStatus:'',
        },
        list:[],
        pageInput: '1',
        listRecord: 0,
        noMore: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.settlementList(this.params);
            }
        },
        checkNum: function () {
            if (this.pageInput > this.pageTotal) {
                this.pageInput = this.pageTotal;
            } else if (this.pageInput < 1) {
                this.pageInput = 1;
            }
        },
        settlementList:function () {
            var _this = this;
            SupplierApi.settlementList(_this.params,function (res) {
                if(res.code==0){
                    if(res.data.results!=''){
                        _this.list = res.data.results;
                        _this.listRecord = res.data.totalRecord;
                    }else {
                        _this.list = res.data.results;
                        _this.listRecord = res.data.totalRecord;
                    }
                    _this.requestFlag = true;
                }
            })
        },
        getstatus:function () { //状态
            var _this = this;
             _this.params.payStatus=event.target.value;
        },
        serchBtn:function () {
        console.log(this.params)
           this.settlementList()
        }
    },
    mounted:function () {
        var _self= this;
        if(globalUserData){
              _self.params.shopID = globalUserData.shopId;
            }
        _self.settlementList();
            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.settlementList();
                            }
                        }
                        _self.requestFlag = false;
                    }else{
                        //到底了
                        _self.noMore = true;
                        $('footer').removeClass("noneImportant");
                    }
                }
            });
        }
     $('.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");
    }
})
