/**
 * [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/03/10 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();
        this.pullDownRefresh();
        //记录滚动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);
                                }
                            }
                        });
                    }
                });
            });
        },
        
        //下拉刷新
        pullDownRefresh:function() {
            var _this = this;
            OEUI.pullDownRefresh({
                el: document.getElementById(_this.pull_box_id),
                refresh: function (pullDown) {
                    pullDownRefresh({
                        scroll: _this.scroll,
                        pullDown: pullDown,
                        pulldata:_this.pull_data_id,
                        pullcache:_this.pull_cache,
                        page:"1",
                        //记录cache
                        callback: function (data) {
                            oeui_cache.cacheNextPage(data.nextpage);
                            oeui_cache.cacheTotalPage(data.pagecount);//pagecount
                            oeui_cache.cacheList(data.result);
                        }
                    });
                }
            });
        }
    }
    _inst_oepage = new OEPage();
});