(function(){
    X.pageLogic['setgrouping'] = {
        init : function(parms){
            var me = this;
            this.parms = parms;
            this.callback = parms.callback;
            var data = parms.extData;

            X.laytpldata("#judge-box-dot",data,".setgrouping-box .setgrouping-content-box");

            // 搜索
            $('.setgrouping-sousuo-txt-box input').bind('input propertychange', function() {
                var value = $(this).val();
                if(value != ""){
                    $(".setgrouping-sousuo-txt-box img").show();
                    var filteringdata = [];
                    for(let i in data){
                        var detailsdata = [];
                        for(let j in data[i]["category"]){
                            if(data[i]["category"][j]['event_desc'].indexOf(value) != -1){
                                detailsdata.push(data[i]["category"][j]);
                            }
                        }
                        if(detailsdata.length >0){
                            var arr = {
                                "title": data[i]['title'],
                                "id":data[i]['id'],
                                "category": detailsdata
                            };
                            filteringdata.push(arr);
                        }
                    }
                    X.laytpldata("#judge-box-dot",filteringdata,".setgrouping-box .setgrouping-content-box");
                }else {
                    $(".setgrouping-sousuo-txt-box img").hide();
                    X.laytpldata("#judge-box-dot",data,".setgrouping-box .setgrouping-content-box");
                }
            })

            //清空按钮
            $(".setgrouping-sousuo-txt-box img").click(function(){
                $(".setgrouping-sousuo-txt-box input").val("");
                $(".setgrouping-sousuo-txt-box img").hide();
                X.laytpldata("#judge-box-dot",data,".setgrouping-box .setgrouping-content-box");
            })
            
            $(document).off('click','.setgrouping-content-list').on('click','.setgrouping-content-list',function(){
                var index = $(this).attr('data-index');
                var indexs = $(this).attr('data-indexs');
                var valdata = {
                    'name':$(this).attr('data-name'),
                    'id':$(this).attr('data-id'),
                    'event_attr':data[index]['category'][indexs].event_attr,
                    'event_filter':data[index]['category'][indexs].event_filter
                }
                me.callback && me.callback(valdata);

                layer.close( me.parms.layIndex );//获取最新的弹窗关闭
            })
       
        }
    };
})();
