//cc
(function(){
    X.pageLogic['search'] = {
        init : function(){

            var data = {
                'user_arrt_title':'',//用户属性
                'user_arrt_id':'',  //用户属性id
                'user_arrt_type':'', //用户属性type
                'comparator_title':'',//筛选条件
                'comparator_id':'', //筛选条件id
                'condition':'', //手动输入条件，区间用~符号隔开如0~10
                'start_time':'', //开始时间
                'end_time':'', //结束时间
                'pages': 1
            }

            var filter_props,filter_maparr;
                
            X.api("data_mana/game_user_event_list","post",{cat:'user'},function(d){
                filter_props = d;
                X.api("data_auth/filter_map","get",{},function(d){
                    filter_maparr = d;
                    
                    $(".search_top .zhanghu_box span").html(filter_props[0]['category'][0]['title']);
                    data['user_arrt_title'] = filter_props[0]['category'][0]['title'];
                    data['user_arrt_id'] = filter_props[0]['category'][0]['id'];
                    data['user_arrt_type'] = filter_props[0]['category'][0]['data_type'];

                    var comparatorarr = filter_maparr[filter_props[0]['category'][0]['data_type']]

                    data['comparator_title'] = comparatorarr[0]['title'];
                    data['comparator_id'] = comparatorarr[0]['id'];
                    istimeboxtype(filter_props[0]['category'][0]['data_type']);

                    var start = moment().subtract(6, 'days');
                    var end = moment();
                    var startTime = start.format('YYYY-MM-DD')+ " "+ "00:00:00";
                    var endTime = end.format('YYYY-MM-DD')+ " "+ "23:59:59";
                    data['start_time'] = startTime;
                    data['end_time'] = endTime

                    X.laytpldata("#judge-box-dot",filter_maparr[filter_props[0]['category'][0]['data_type']],'.judge_box');

                });
            });

            function istimeboxtype(type){
                if(type == "datetime"){
                    $(".search_left .judge_box").hide();
                    $(".search_left .search_txt").hide();
                    $(".search_left .time-box").show();
                }else {
                    $(".search_left .judge_box").show();
                    $(".search_left .search_txt").show();
                    $(".search_left .time-box").hide();
                }
            };

            $(document).off("click",'.search_pop .zhanghu_box').on('click','.search_pop .zhanghu_box',function(){
                var obj = $(".search_pop .zhanghu_box"); 
                var offset = obj.offset();

                //点击按钮，数据，向左偏移，向右偏移
                X.querycriteriapop(filter_props,'category',offset.left,offset.top+obj.height(),function(val){
                    $(".search_top .zhanghu_box span").html(val.title);
                    data['user_arrt_title'] = val.title;
                    data['user_arrt_id'] = val.id;
                    data['user_arrt_type'] = val.type;

                    var comparatorarr = filter_maparr[val.type];
                    data['comparator_title'] = comparatorarr[0]['title'];
                    data['comparator_id'] = comparatorarr[0]['id'];
                    // 渲染条件框数据
                    X.laytpldata("#judge-box-dot",filter_maparr[val.type],'.judge_box'); 
                    istimeboxtype(val.type)

                });
            });

            $(document).off("click",'.user-id').on('click','.user-id',function(){
                X['DATA']['search-user-id'] = $(this).attr("data-id");
                X.gourl('userinfo','conetnt');
            });

            
            $(document).off("click",'.more_data p').on('click','.more_data p',function(){
                // X['DATA']['search-user-id'] = $(this).attr("data-id");
                X.gourl('userinfolist','conetnt');
            });
            
            //渲染日期选择器
            X.daterender(".timechoice",function(start,end,label){
                var startTime = start.format('YYYY-MM-DD')+ " "+ "00:00:00";
                var endTime = end.format('YYYY-MM-DD')+ " "+ "23:59:59";
                data['start_time'] = startTime;
                data['end_time'] = endTime;
            });

            // 下拉选项改变事件
            $(".search_left .judge_box").change(function(){
                var judgeid = $(this).val();
                var judgetitle = $('.judge_box option:selected').text();
                data['comparator_title'] = judgetitle;
                data['comparator_id'] = judgeid;
            });

            // 搜索按钮单击事件
            $(".search_top .searcg_but").click(function(){
                data['condition'] = $(".search_txt").val();

                X.api('ck/seek_user','post', data ,function (val){

                    X.api('ck/seek_user_count','post', data ,function (d){
                        $(".more_data span").html(d);
                        if(d > 10){
                            $(".search_pop .more_data-box").show();
                            X['ueser_search_data'] = data;
                        }else {
                            $(".search_pop .more_data-box").hide();
                            X['ueser_search_data'] = [];
                        }
                    })

                    X.laytpldata("#search-data-dot",val.refer.values,".search_pop .search_data",function(){

                    });
                    // $(".more_data span").html(d.totalNum);
                });
            });



        },
    };
})();
