@model Angel.Models.MemberUsere
@{
    ViewBag.Title = "MemberRole";
    Layout = "~/Views/Shared/_LayoutForm.cshtml";
}

<style type="text/css">
    .fr {
        float: right;
    }

    .img-headshot {
        width: 90px;
        height: 90px;
        position: absolute;
        top: -30px;
        border: medium none;
        border-radius: 50%;
        cursor: pointer;
    }
  .layui-form-pane .layui-input-block {
        margin-left:0px;
    }
   .layui-input-block {
        margin-left:0px;
    }
</style>

<form class="layui-form layui-form-pane angel-form">

    <input data-val="true"  id="userid" name="userid" type="hidden" value="@Model.ID" />
    <input data-val="true"  id="Subject" name="Subject" type="hidden" value="@Model.Subject" />

    <div class="layui-form-item">
        <label class="layui-form-label">登陆名</label>
        <div class="layui-input-block" style="border:1px solid #e6e6e6;line-height:36px;margin-left:3px;padding-left:6px;">
           @Model.UserName
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" style="width:160px;">分配题库权限</label>
        <div class="layui-input-block" style="margin-left:163px;border:1px solid #e6e6e6;">
            <div id="userorletree"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-left:200px">
            <button type="button" class="layui-btn" lay-demo="getChecked">立即提交</button>
            <button type="reset" class="layui-btn">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    layui.use(["angelLayer", "angelUtils", "layer", "tree", "util"], function () {
        var angelLayer = layui.angelLayer;
        var angelUtils = layui.angelUtils;
        var layer = layui.layer;
        var tree = layui.tree;
        var util = layui.util;
        var $ = layui.$;

        angelUtils.ajax("api/amemberapi/listclasstree", "get", {subject:@Model.Subject}, true).done(function (data) {
           var treeData = data.data;
            //console.log(tagData);
            //渲染
            var inst1 = tree.render({
                elem: '#userorletree'  //绑定元素
              , showCheckbox: true  //是否显示复选框
              , data: treeData
              , id:'treeclassId'
            });

            tree.setChecked('treeclassId', [@Model.Selectedck]); //勾选指定节点

        }).fail(function (error) {
            console.log(error)
        });


        //按钮事件
        util.event('lay-demo', {
            getChecked: function (othis) {
                var checkedData = tree.getChecked('treeclassId'); //获取选中节点的数据
                var memberroledata = { userid: $("#userid").val(),Subject:$("#Subject").val(),data: checkedData };
                //layer.alert(JSON.stringify(checkedData), { shade: 0 });
               // console.log(checkedData);
                angelUtils.ajax("api/amemberapi/postaddrole", "post", memberroledata , true).done(function (data) {
                    //var treeData = data.msg;
                    angelLayer.greenTickMsg(data.msg, function () {
                        parent.location.reload(); // 父页面刷新
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引 再执行关闭
                    });

                }).fail(function (error) {
                    console.log(error)
                });

            }
          , setChecked: function () {
              tree.setChecked('treeclassId', [6, 9]); //勾选指定节点
          }
          , reload: function () {
              //重载实例
              //tree.reload('treeclassId', {

              //});

          }
        });








        //form.on("submit(add)", function (data) {
            
        //    angelUtils.ajax("api/amemberapi/postaddrole", "post", data.field, true).done(function (response) {
        //        angelLayer.greenTickMsg(response.message, function () {
        //            parent.location.reload(); // 父页面刷新
        //            parent.layer.close(parent.layer.getFrameIndex(window.name));//先得到当前iframe层的索引 再执行关闭
        //        });
        //    }).fail(function (error) {
        //        console.log(error)
        //    });
        //    return false;
        //});




    });
</script>

