(function(){
    X.pageLogic['datarightsedit'] = {
        init : function(parms){
            var me = this;
            this.parms = parms;
            this.callback = parms.callback; //选择后执行的回调
            var data = parms.extData;//获取到上层弹窗传的数据
            X.api("data_auth/all_event","get",{},function(d){
                X.laytpldata("#datarightsedit-check-box-dot",d,".datarightsedit-check-box");
                layui.form.render();
            })
            
            if(data){
                var dataArr ={};
                for(let i in data.data){
                    dataArr[data.data[i]] = true;
                }
                layui.form.val('datarightseditexample',dataArr);
                $(".datarightsedit-txt-input").val(data.title);
            }


            $(".datarightsedit-qx").click(function(){
                layer.closeAll();
            })

            $(".datarightsedit-top-box img").click(function(){
                layer.closeAll();
            })

            $(".datarightsedit-qd").click(function(){
                var tit = $(".datarightsedit-txt-box input").val();
                var fromdata = layui.form.val('datarightseditexample');//选中的权限
                var dataArr=[];
                for(let i in fromdata){
                    dataArr.push(i);
                }
                if(data){
                    X.api("data_auth/edit_data_auth","post",{title:tit,data:dataArr,data_auth_id:data.id},function(d){
                        layer.msg("修改成功");
                        layer.closeAll();
                        X.pageLogic.datarights.dataauthlist();
                    })
                }else {
                    X.api("data_auth/add_data_auth","post",{title:tit,data:dataArr},function(d){
                        layer.msg("创建成功");
                        layer.closeAll();
                        X.pageLogic.datarights.dataauthlist();
                    })
                }
                
            })

        }
    };
})();
