layui.use(['form', 'layer'], function () {
    var form = layui.form
    layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    form.on("submit(save)", function (data) {
        //弹出loading
        var index = layer.msg('数据提交中，请稍候...', {
            icon: 16,
            shade: 0.8,
            time:false //取消自动关闭
        });
        var ids = $("#ids").val();
        var userName = $("#userName").val();
        var zTreeOjb = $.fn.zTree.getZTreeObj("roleTree");
        var checkedNodes = zTreeObj.getCheckedNodes();
        //alert(ids+"=="+ JSON.stringify(checkedNodes))
        var json = [];
        for(var i=0;i<checkedNodes.length;i++){
            var obj = new Object();
            obj.roleId = checkedNodes[i].id;
            obj.roleName = checkedNodes[i].name;
            obj.userId = ids;
            obj.userName = userName;
            json.push(obj);
        }

        //alert(JSON.stringify(json))
        //实际使用时的提交信息
        $.ajax( {
            url : "/sysUserRole/save",
            type : "POST",
            dataType:"json",
            contentType:'application/json;charset=UTF-8',
            data:JSON.stringify(json),
            success : function(res) {
                layer.close(index);//手动关闭
                layer.msg(res.message);
                layer.closeAll("iframe");
                //刷新父页面
                parent.location.reload();
            },
            error:function(e){
                layer.close(index);//手动关闭
                layer.msg("操作失败,请重试!");
                layer.closeAll("iframe");
                //刷新父页面
                parent.location.reload();
            }
        })
    })
})