(function(){
    X.pageLogic['savereport'] = {
        init : function(parms){
            var me = this;
            this.parms = parms;
            this.callback = parms.callback;
            var data = parms.extData;
            if(data._id){
                layui.form.val('savereportexample', {
                    "title": data['name']
                    ,"desc": data['desc']
                  });
            }
            $(document).off('click',".savereport-but-qd").on('click','.savereport-but-qd',function(){
                var tabval = layui.form.val('savereportexample');
                if(tabval['title'] == ""){
                    layer.msg("请填写报表名称");
                    return false;
                }
                if(tabval['desc'] == ""){
                    layer.msg("请填写报表备注");
                    return false;
                }

                if(data._id){
                    var arr = {
                        name: tabval['title'],
                        desc:tabval['desc'],
                        query:data['query'],
                        report_id:data['_id']
                        // project_id:X.DATA.projectid,
                        // cat: data['query']['eventView']['cksql']
                    }
                    X.api('report/edit','post',arr,function(d){
                        layer.msg(d);
                        layer.closeAll();
                    })
                }else {
                    var arr = {
                        name: tabval['title'],
                        desc:tabval['desc'],
                        query:data,
                        project_id:X.DATA.projectid,
                        cat: data['eventView']['cksql']
                    }
                    // console.log(arr);
                    X.api('report/create','post',arr,function(d){
                        layer.msg(d);
                        layer.closeAll();
                    })
                }
                

            })
            
            $(document).off('click',".savereport-but-qx").on('click','.savereport-but-qx',function(){
                layer.closeAll();
            })

        }
    };
})();