<?
$menu=new menu($_SESSION['ddadmin'],$duoduo);
$data=$menu->qzmenu($_GET['id']);
$row=$duoduo->select("role","*","id=".$_GET['id']);
?>
<br>
<div class="layui-form layuimini-main">

        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" lay-reqtext="" placeholder="请输入管理员组姓名" value="<?=$row['title']?>" class="layui-input">
              
            </div>
        </div>
     
      <div class="layui-form-item">
           <label class="layui-form-label required">权限</label>
           <div class="layui-input-block">
            <input type="hidden" name="ids" id="ids" value="">
          <div id="test1" class="demo-tree demo-tree-box"></div>
          </div>
      </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" value="<?=$row['id']?>" name="id">
                <button class="layui-btn layui-btn-normal jian_save" lay-submit lay-filter="saveBtn" >确认保存</button>
            </div>
        </div>
   
</div>
<script>
    layui.use(['form', 'table',"tree"], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            tree=layui.tree,
            $ = layui.jquery;
    
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
      
        //常规用法
      tree.render({
        elem: '#test1' //默认是点击节点可进行收缩
        ,data: <?=json_encode($data)?>
         ,showCheckbox:true
        ,id: 'demoId1'
      });
    
    $(".jian_save").click(function(){
   
      var checkData = tree.getChecked('demoId1');
       var ids=[];
       
        for (var i=0;i<checkData.length;i++)
            { 
                ids.push(checkData[i].id)
                if (checkData[i]['children']){
                 children=checkData[i]['children'];
                  for (var j=0;j<children.length;j++){

                     ids.push(children[j].id)
                 }
                }
               
            }
         var ids_str=(ids.toString());
         $("#ids").val(ids_str);
   
     
  })

    });
</script>