/**
 * [OElove webapp] (C)2010-2099 oelove.com Inc.biz
 * Email: service@phpcoo.com，phpcoo@qq.com
 * This is not a freeware, use is subject to license terms
 * $ LastTime 2020.03.25 Update by OE/CL $
*/
var _inst_oepage = null; //当前页面对象
$(function(){
    
    //初始化
    function OEPage() {
        this.pull_box_id = "pull_box";
        this.pull_data_id = "pull_data";
        this.scroll = null;
        this.params = "";
        this._this_dialog = null;
        this.slide_time = 200;
        
        this.loadFirst();
    }
    
    //下拉加载分页
    OEPage.prototype.pullDownLoad = function () {
        var _this = this;
        
        _this.scroll = OEUI.PullDownLoad({
            el: document.getElementById(_this.pull_box_id),
            pullDown: function (pullDown) {
                var $page = $("#page").val();
                PullDownLoad({
                    pullDown: pullDown,
                    page:$page,
                    pulldata:_this.pull_data_id,
                    pullbox:_this.pull_box_id,
                    scroll_this_el:'.scroll_this_el',
                    scroll_page_top:'.scroll_page_top',
                    scroll_page_other:'.scroll_page_other'
                });
            }
        });
    }
    
    //加载第一页聊天数据
    OEPage.prototype.loadFirst = function () {
        var _this = this;
        var page = $("#page").val();
        var url = document.getElementById('reqs_url').value;
        $.ajax({
            type: 'POST',
            url: url,
            data: {
                page: page
            },
            success: function (json) {
                var res = JSON.parse(json);
                if (res.response == '1') {
                    $('#'+_this.pull_data_id).prepend($(res.result));
                    if (res.nextpage != '0') {
                        $('#page').val(res.nextpage);
                        _this.pullDownLoad();
                    }
                    $("#"+_this.pull_box_id+" .scroll").scrollTop($("#"+_this.pull_box_id+" .scroll").prop("scrollHeight"));
                    $("#"+_this.pull_box_id).css('opacity', '1');
                } 
                else {
                    if (res.result) {
                        OEUI.toast({
                            text: res.result
                        });
                    }
                    else {
                        OEUI.toast({
                            text: '网络繁忙，请稍后再试'
                        });
                    }
                }
            },
            error: function () {
                OEUI.toast({
                    text: '网络繁忙，请稍后再试'
                });
            }
        });
    }
    _inst_oepage = new OEPage();
});