(function(){
    X.pageLogic['participate'] = {
        init : function(parms){
            var me = this;
            this.parms = parms;
            this.callback = parms.callback;
            var data = parms.extData;
            
            console.log(data);
            X.laytpldata("#judge-box-dot",data.list,".setgrouping-box2 .setgrouping-content-box2");
            layui.form.render();

            if( data.select &&  data.select.length > 0){
                var select = data['select'];
                var selectdata = {};
                for(let i in select){
                    selectdata["like["+select[i]+"]"] = true; 
                }
                console.log(selectdata);
                layui.form.val('participateexample', selectdata);
            }

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

            //清空按钮
            $(".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.list,".setgrouping-box2 .setgrouping-content-box2");
            })

            layui.form.on('checkbox(checkboxexample)', function(){
                var data = layui.form.val('participateexample');
                console.log(data);
                if(Object.keys(data).length >= 30){
                    $(this).prop("checked", false);
                }
              });
            
            $(document).off('click','.participate-but').on('click','.participate-but',function(){
                var dataarr = layui.form.val('participateexample');
                console.log(data);
                var idarr = [];
                for(let i in dataarr){
                    var arr = i.substring(5);
                    arr = arr.substring(0,arr.length - 1);
                    idarr.push(arr);
                }
                var callbackdata = [];
                for(let i in data['list']){
                    for(let j in data['list'][i]['category']){
                        for(let z in idarr){
                            if(data['list'][i]['category'][j]['event_name'] == idarr[z]){
                                var arr = {
                                    'event_desc': data['list'][i]['category'][j]['event_desc'],
                                    'event_name': data['list'][i]['category'][j]['event_name']
                                }
                                callbackdata.push(arr);
                            }
                        }
                        
                    }
                }
                // console.log(callbackdata);
                me.callback && me.callback(callbackdata);
                layer.close( me.parms.layIndex );//获取最新的弹窗关闭
            })
       
        }
    };
})();
