var documentList = new Vue({
    el: "#documentList",
    data: {
        requestFlag: true,
        userId: 0,
        supplierInfo:{},
        supplierBanner: [],
        mainProducts:[],
        listQuery: {
            name: '',
            pageNum: 1,
            pageSize: 20
        },
        hasNextPage:false,
        pdfDataList:[],
    },
    computed: {

    },
    methods: {
        GetDocumentDataListInfo:function(more){
            var _self = this;
            DocumentApi.GetDocumentDataList(_self.listQuery,function(response){
                if(response.code == 0){
                    var data = response.data;
                    _self.hasNextPage = data.hasNextPage;
                    if(more){
                        _self.pdfDataList = _self.pdfDataList.concat(data.list);
                    }else{
                        _self.pdfDataList = data.list
                    }
                }else{
                    CAIMEI.Alert(response.msg, '确定', false);
                }
            })
        },
        searchKeyWord:function(){//搜索
            var _self = this;
            if (_self.listQuery.name ==''){
                CAIMEI.dialog('请输入搜索关键字',false,function () {});
                return;
            }
            this.GetDocumentDataListInfo();
        },
        PdfDetails:function(id){//跳转
            location.href = '/document/details.html?id='+id;
        },
        keyupSearch: function(event) {
            // 搜索输入框 按回车键搜索
            var keyCode = event.keyCode || event.which;
            console.log(keyCode)
            if(keyCode === 13){
                this.GetDocumentDataListInfo();
            }
        },
        showPdfList:function(item){
            item.isShowDowns = !item.isShowDowns;
        }
    },
    created: function () {

    },
    mounted: function () {
        var _self = this;
        if(CAIMEI.getUrlParam('keyWord')){
            _self.listQuery.name = decodeURI(CAIMEI.getUrlParam('keyWord'));
        }
        _self.GetDocumentDataListInfo();
        //上垃加载更多
        $(window).on('scroll', function(){
            var scrollTop = $(this).scrollTop();
            var scrollHeight = $(document).height();
            var windowHeight = window.innerHeight;
            if (scrollTop + windowHeight >= scrollHeight) {
                //此处是滚动条到底部时候触发的事件，在这里写要加载的数据，或者是拉动滚动条的操作
                var next = _self.listQuery.pageNum+1;
                if(_self.hasNextPage){
                    if (_self.requestFlag){
                        _self.listQuery.pageNum = next;
                        // 获取列表数据
                        _self.GetDocumentDataListInfo(true);
                    }
                    _self.requestFlag = false;
                }
            }
        });
    }
});
