/**
 * [OElove] (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
 * $ Last update 2020/03/13 by CL $
*/
$(function(){
    //记录来源缓存
    var $frompre = $("#frompre").val();
    if (typeof($frompre) == 'undefined') {
        $frompre = '';
    }
    oeui_cache.jumpSetCacheRouter($frompre);
    
    function OEDetail() {
        this.data_id = "bmuser_data"; //报名列表框
        this.page = 1;
        this._this_dialog = null;
        this.slide_time = 300;
        this.api_url = WAP_APPFILE +'&c=party';
        
        this.id = ''; //ID
        this.obj_id = ''; //按钮ID
        this.need_dialog = '';//是否侧滑 
        
        this.wake();
        
    }
    
    OEDetail.prototype = {
        
        //唤醒
        wake:function() {
            var _this = this;
            
            //切换内容
            $(document).on("click", "[f='but_sel_content']", function(){
                var $box = $(this).attr("data-box");
                $("[f='but_sel_content']").removeClass("current");
                $(this).addClass("current");
                $(".box_list").hide();
                $("#"+$box+"_box").show();
            });
            
            //点击查看报名会员
            $(document).on("click", "[f='but_view_bmuser']", function(){
                _this.id = $(this).attr("data-id");
                _this.obj_id = $(this).attr("id");
                _this.need_dialog = $(this).attr("data-dialog");
                if (typeof(_this.need_dialog) == 'undefined') {
                    _this.need_dialog = '0';
                }
                if (typeof(_this.obj_id) == 'undefined') {
                    _this.obj_id = '';
                }
                if (_LOGIN_STATUS == '0') {
                    _this.login();
                    return;
                }
                $("#page").val("1");
                _this.getBmList();
            }); 
            //关闭会员列表
            $(document).on("click", "[f='but_close_bmuser']", function(){
               if (_this._this_dialog) {
                   _this._this_dialog.hide();
               }
            });
            //加载更多报名
            $(document).on("click", "[f='but_more_comment']", function(){
                _this.need_dialog = $(this).attr("data-dialog");
                if (typeof(_this.need_dialog) == 'undefined') {
                    _this.need_dialog = '0';
                }
                $("#more_comment_wrap").find("img").show();
                _this.getBmList();
            });
            //筛选性别
            $(document).on("click", "[f='but_sel_user']", function(){
                _this.need_dialog = $(this).attr("data-dialog");
                if (typeof(_this.need_dialog) == 'undefined') {
                    _this.need_dialog = '0';
                }
                $("[f='but_sel_user']").removeClass("current");
                $(this).addClass('current');
                var $gender = $(this).attr("data-gender");
                $("#s_gender").val($gender);
                $("#page").val("1");
                _this.getBmList();
            });
        },
        
        //跳到登录页
        login:function() {
            var _this = this;
            var $back_url = _this.api_url+'&a=detail&id='+_this.id+'&nofollow=1';
            window.location.href = WAP_APPFILE+'&c=passport&a=login&forward='+encodeURIComponent($back_url);
        },
        
        
        //获取报名列表
        getBmList:function($page) {
            var _this = this;
            
            if (typeof($page) == 'undefined') {
                $page = '';
            }
            if ($page == '') {
                $page = $("#page").val();
            }
            var $reqs_url = $("#reqs_url").val();
            var $s_gender = $("#s_gender").val();
            if (typeof($s_gender) == 'undefined') {
                $s_gender = '0';
            }
            $reqs_url += "&id="+_this.id+"&s_gender="+$s_gender;
            
            var loading = null;
            var timer = setTimeout(function () {
                loading = OEUI.showLoading({
                    type:2
                });
            }, 200);
                
            $.ajax({
                type: "POST",
                url: $reqs_url,
                cache: false,
                data: {
                    page:$page
                },
                dataType: "json",
                success: function($data) {
                    
                    var $json = eval($data);
                    var $response = $json.response;
                    var $result = $json.result;
                    var $nextpage = $json.nextpage; //下一页
                    if (typeof($nextpage) == 'undefined') {
                        $nextpage = '';
                    }
                    var $total = $json.total;
                    if (typeof($total) == 'undefined') {
                        $total = '';
                    }
                    
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;
                        
                    if ($response == '1') {
                        $("#page").val($nextpage); //重新赋值
                        
                        if ($result.length > 0) {
                            //载入数据
                            if ($page == 1) {
                                $("#"+_this.data_id).html($result);
                            }
                            else {
                                $("#"+_this.data_id).append($result);
                            }

                            if ($nextpage > 0) { //还有下一页
                                $("#more_comment_wrap").show();
                                $("#more_comment_wrap").find("img").hide();
                            }
                            else { //没有下一页
                                $("#more_comment_wrap").hide();
                                $("#more_comment_wrap").find("img").hide();
                            }
                            
                        }
                        else {
                            $("#"+_this.data_id).html($result);
                        }
                        
                        //弹出窗口
                        if (_this.need_dialog == '1') {
                            _this._this_dialog = OEUI.Dialog({
                                el: '#bmuser_wrap',
                                animated: 'slideRightIn',
                                time:_this.slide_time
                            });
                        }
                    }
                    else {
                        if ($result != '') {
                            OEUI.toast({
                                type: 'bottom', 
                                text: $result
                            });
                            return;
                        }
                    }
                },
                error: function() {
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;
                }
            });
        }
    }
    
    new OEDetail();

});