/**
 * [OElove] (C)2010-2099 oelove.com biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2020/04/08 by CL $
*/
var _inst_oepage = null; //当前页面对象 通用分页列表
$(function(){
    //初始化
    function OEPage() {
        this.pull_box_id = "pull_box";
        this.pull_data_id = "pull_data";
        this.pull_cache = 0;
        this.scroll = null;
        this.params = "";
        this._this_dialog = null;
        this.slide_time = 200;

        this.pullUpLoad();
        
        //记录滚动cache
        $('#'+this.pull_box_id+' .scroll').scroll(function () {
            var height = $(this).scrollTop();
            oeui_cache.cacheScrollTop(height);
        });
    }
    
    OEPage.prototype = {
        
        //上拉分页
        pullUpLoad:function() {
            var _this = this;
        
            //获取cache list
            if (oeui_cache.getCacheTotalPage() > 1 && oeui_cache.isLoadCacheList()) {
                var cache_list_data = oeui_cache.getCacheList();
                if (typeof(cache_list_data) == "undefined") {
                    cache_list_data = "";
                }
                var cache_height = oeui_cache.getCacheScrollTop();
                var cache_next_page = oeui_cache.getCacheNextPage();
                if (cache_next_page != "") {
                    $("#page").val(cache_next_page);
                }
                $('#'+_this.pull_data_id).html($(cache_list_data));
                $('#'+_this.pull_box_id+' .scroll').scrollTop(cache_height);
                _this.pull_cache = 1;
                oeui_cache.preLoadImg(); //预载图片
            }
            var router_c = oeui_cache.getUrlparam('c');
            var arr = [];
            arr.push(router_c);
            sessionStorage.setItem('oeui_router', JSON.stringify(arr));

            setTimeout(function () {
                _this.scroll = OEUI.pullUpLoad({
                    el: document.getElementById(_this.pull_box_id),
                    pullUp: function (pullUp) {
                        var $page = $("#page").val();
                        pullUpLoad({
                            pullUp: pullUp,
                            page:$page,
                            pulldata:_this.pull_data_id,
                            pullcache:_this.pull_cache,
                            callback: function (data) {
                                //记录cache
                                if (data.nextpage == '2') {
                                    oeui_cache.clearScrollTop();
                                }
                                oeui_cache.cacheNextPage(data.nextpage);
                                oeui_cache.cacheTotalPage(data.pagecount);//pagecount
                                oeui_cache.cacheList(data.result);
                                //回滚高度
                                var cache_height = oeui_cache.getCacheScrollTop();
                                if (cache_height) {
                                    //$('#'+_this.pull_box_id+' .scroll').scrollTop(cache_height);
                                }
                                
                                
                                //回调，赋值total数量
                                var $total = data.total;
                                if (typeof($total) == 'undefined') {
                                    $total = '0';
                                }
                                if ($("#total_tips").length > 0) {
                                    $("#total_tips").html($total);
                                }
                                
                            }
                        });
                    }
                });
            });
        }
    }
    _inst_oepage = new OEPage();
});