(function(){
    X.pageLogic['apiadmin_add'] = {
        init : function(parms){
            var me = this;
            this.parms = parms;
            this.callback = parms.callback; //选择后执行的回调
            var data = parms.extData;//获取到上层弹窗传的数据


            X.api("authz/api_module","get",{},function(d){
                X.laytpldata("#apiadd-apitype-box-dot",d,".apiadd-apitype-box",function(){
                    $('#editable-select').editableSelect({ 
                       bg_iframe: true,
                       case_sensitive: false, 
                       items_then_scroll: 10 ,
                       isFilter:false
                    }); 
                    layui.form.render();
                    if(data != ""){
                        $("#editable-select_sele").val(data.name);
                        layui.form.val('addapifrom', {
                            "desc": data.desc
                            ,"path": data.path
                        });
                    }
                });
                
            });
            
            $(document).off('click','.newwenjian-qd').on('click','.newwenjian-qd',function(){
                var roleinfo = layui.form.val("addapifrom");
                for(let i in roleinfo){
                    if(roleinfo[i] == ""){
                        layer.msg('分类，名称，路径为必填项');
                        return;
                    }
                }
                if($("#editable-select_sele").val() == ""){
                    layer.msg('分类，名称，路径为必填项');
                    return;
                }
                var arr = {
                    "path": roleinfo.path,
                    "name": $("#editable-select_sele").val(),
                    "desc": roleinfo.desc
                }
                if(data == ""){
                    X.api('authz/add_api','post',arr,function(d){
                        X.pageLogic.apiadmin.updataapilist();
                        layer.closeAll();
                    });
                }else {
                    arr['id'] = data['_id'];
                    X.api('authz/edit_api','post',arr,function(d){
                        X.pageLogic.apiadmin.updataapilist();
                        layer.closeAll();
                    });
                }
                
            });

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

            $(document).off('click','.newwenjian-cha').on('click','.newwenjian-cha',function(){
                layer.closeAll();
               
            });
            
        
        }
    };
})();