(function(){
    X.pageLogic['savedbaobiao'] = {
        init : function(parms){
             // 弹窗占满整平
            var me = this;
            this.parms = parms;
            this.callback = parms.callback;
            var type = parms.extData;
            layui.form.render();
            $(".saved-bg").css('height',window.innerHeight+'px');

            var data = []
            reportdata();

             function reportdata(){
                X.api("report/read_report",'post',{project_id:X.DATA.projectid},function(d){
                    data = d;
                    updatalist(type);
                    $(".saved-select-type").val(type);
                })
             }

             //关闭页面
             $(".saved-top img").click(function(){
                 layer.closeAll();
             })

            //  搜索报表选中事件
             $(".saved-sousuo-box .saved-txt").focus(function(){
                $(this).css("border","1px solid #3d90ff");
                $(this).css("box-shadow","0 0px 4px rgba(61, 144, 255, 0.45)");
             })
            //  失去光标事件
             $(".saved-sousuo-box .saved-txt").blur(function(){
                $(this).css("border","1px solid #eee");
                $(this).css("box-shadow","none");
             })

            //  下拉框
             $(".saved-select-type").change(function(){
                updatalist($(this).val())
             })

            function updatalist(title){
                var screendata=[];//筛选后的数据
                for(let i in data){
                   if(title == 0){
                       screendata = data;
                    }else {
                       if(data[i]['cat'] == title){
                           screendata.push(data[i]);
                       }
                    }
                }
                X.laytpldata("#saved-list-box-dot",screendata,".saved-list-box");
            }

            //  点击报表数据
             $(document).off('click','.saved-list').on('click','.saved-list',function(){
                var id = $(this).attr("data-id");
                var cat = $(this).attr("data-cat");
                if(type == cat){
                    for(let i in data){
                        if(id == data[i]['_id']){
                            me.callback && me.callback(data[i]);
                            layer.closeAll();
                        }
                    }
                }else {
                    layer.msg('选择报表不是当前分析报表');
                }
                
                
             })
             
            //  搜索
             $('.saved-sousuo-box .saved-txt').bind('input propertychange', function() {
                // console.log($(this).val());
                var screendata=[];//筛选后的数据
                for(let i in data){
                    if($(this).val() != ""){
                        if(data[i]['name'].indexOf($(this).val()) != -1){
                            screendata.push(data[i]);
                        }
                    }else {
                        screendata = data;
                    }
                }
                X.laytpldata("#saved-list-box-dot",screendata,".saved-list-box");
             })

            //  删除报表
            $(document).off('click','.saved-list-del').on("click",".saved-list-del",function(e){
                var id = $(this).attr("data-id");
                e.stopPropagation();
                X.api("report/delete","post",{"_id": id},function(d){
                    layer.msg('删除成功！！！');
                    reportdata();
                })
            })
            
            

        }
    };
})();
