/**
 * [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_oeindex2 = null;
$(function(){
    
    function OEIndex2() {
        this.wake();
        this.user();
    }
    
    OEIndex2.prototype = {
        
        wake:function(){
            var _this = this;
            
            //载入访问记录
            /*
            setTimeout(function(){
                _this.getVisitme();
            }, 50);
            */
            
            //切换文章分类
            $(document).on("click", "[f='but_sel_article']", function(){
                $("[f='but_sel_article']").removeClass('bg_main color_f bg_body');
                $(this).addClass('bg_main color_f').siblings().addClass('bg_body');
                var $id = $(this).attr("data-id");
                $(".art_list").hide();
                $("#art_box_"+$id).show();
            });
            
            
        },
        
        user:function() {
            var _this = this;
            //切换会员
            $(document).on("click", "[f='but_grid_user']", function(){
                var $type = $(this).attr("data-type");
                $("[f='but_grid_user']").removeClass("bg_main color_f bg_body");
                $(this).addClass('bg_main color_f').siblings().addClass('bg_body');
                $(".grid_list").hide();
                $("#grid_data_"+$type).show();
                if ($("#grid_data_"+$type).html().length == 0) {
                    _this.getUserData($type);
                }
            });
            
        },
        
        getUserData:function($type) {
            var _this = this;
            
            /*
            var loading = null;
            var timer = setTimeout(function () {
                loading = OEUI.showLoading({
                    type:2
                });
            }, 200);
            */
            
            
            $.ajax({
                type: "POST",
                url: WAP_APPFILE,
                cache: false,
                data: {
                    c:'index', a:'randuser', type:$type
                },
                dataType: "json",
                success: function($data) {
                    var $json = eval($data);
                    var $response = $json.response;
                    var $result = $json.result;
                    
                    /*
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;
                    */
                    
                    if ($response == "1") { 
                        $("#grid_data_"+$type).html($result);
                        preload_img();
                        
                        
                        var $more_url = WAP_APPFILE+"&c=user";
                        if ($type == '1') {
                            $more_url += "&s_gender=1";
                        }
                        else if ($type == '2') {
                            $more_url += "&s_gender=2";
                        }
                        $("#grid_more").find("a").attr("href", $more_url);
                        $("#grid_more").show();
                    }
                    else {
                        $("#grid_more").hide();
                    }
                },
                error: function() {
                    /*
                    clearTimeout(timer);
                    loading && loading.hideLoading();
                    timer = null;
                    */
                    OEUI.toast({
                        type: 'bottom',
                        text: '网络繁忙，请稍后再试！'
                    });
                }
            });
            
        }, 
        
        getVisitme:function() {
            var _this = this;
            $.ajax({
                type: "POST",
                url: WAP_APPFILE,
                cache: false,
                data: {
                    c:'ajax', a:'visitme'
                },
                dataType: "json",
                success: function($data) {
                    var $json = eval($data);
                    var $response = $json.response;
                    var $result = $json.result;
                    if ($response == "1") { 
                        $("#visitme_data").html($result);
                        $("#visitme_box").show();
                        preload_img();
                    }
                },
                error: function() {
                }
            });
        }
        
    }
    inst_oeindex2 = new OEIndex2();
    inst_oeindex2.getUserData(0);
});
