<!DOCTYPE html>

<html>

	<head>
		<meta charset="utf-8">
		<title>规格管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="<?= RESOURCES ?>/layuiadmin/layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="<?= RESOURCES ?>/layuiadmin/layuiadmin/style/admin.css" media="all">
	</head>

	<body>
	
	<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body"  >
        <form class="layui-form" action="" lay-filter="goodsparameter-form">
          
          <div class="layui-form-item">
             
            <table class="layui-table">
								 <colgroup>
								    <col>
								 </colgroup>
								 
								 <thead>
								    <tr>
								      <th>规格分类</th>
								    </tr> 
								 </thead>
								 
								<tbody id="content">
										<?=$html?>
								</tbody>
			 </table>
             
          </div>
                 
          <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
              <div class="layui-footer" style="left: 0;">
                <button class="layui-btn" lay-submit="" lay-filter="goodsparameter-save">确认规格</button>
              </div>
            </div>
          </div>
          
          
        </form>
      </div>
    </div>
  </div>
	

		 

		<script src="<?= RESOURCES ?>/layuiadmin/layuiadmin/layui/layui.js"></script>
		<script>
			layui.config({
				base: '<?= RESOURCES ?>/layuiadmin/layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laydate'], function() {
				var $ = layui.$,
					admin = layui.admin,
					element = layui.element,
					layer = layui.layer,
					laydate = layui.laydate,
					form = layui.form;

				form.render(null, 'goodsparameter-form');
				
				/* 监听提交 */
				form.on('submit(goodsparameter-save)', function(data) {
					//请求接口
					admin.req({
						url: '/<?= ADMIN_NAME ?>/inc/goodsparameteritemupdate?goodnumber=<?=$goodnumber?>' //实际使用请改成服务端真实接口
							,
						data: data.field,
						type: 'post',
						done: function(res) {
							//alert(res.msg);
							//登入成功的提示与跳转
							layer.msg(res.msg, {
								offset: '150px',
								icon: 1,
								time: 1000
							} );

						}
					});

					return false;
				});
				
				//监听checkbox复选 
			    form.on('checkbox(checkboxchange)', function(data){
//				  console.log(data.elem); //得到checkbox原始DOM对象
//				  console.log(data.elem.checked); //是否被选中，true或者false
//				  console.log(data.value); //复选框value值，也可以通过data.elem.value得到
//				  console.log(data.othis); //得到美化后的DOM对象
				  var id = $("#"+data.elem.id).data('id');
				  var classid = $("#"+data.elem.id).data('classid');
				  console.log(data.elem.checked);
				  
				  var temp_val="";
				  
			      
				//子类选中选中状态应该和父类保持一致
				 /*  $(".goodsparameter").each(function(){
					  console.log($(this).data('classid') +" "+id );
					  
	                    if ($(this).data('classid')==id) {
	                    	if(data.elem.checked)
                    		{
	                    		//选中子类
	                    		$(this).attr("checked", true);
                    		}else{
                    			//取消选中子类
                    			$(this).attr("checked", false);
                    		}
	                    	
	                    }
	              }); */
	              
	              var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
	  		      child.each(function(index, item){
	  		    	if ($("#"+item.id).data('classid')==id) {
	  		    		item.checked = data.elem.checked;
	  		    	}
	  		        
	  		     });
 
				
				  //重现渲染控件
				  form.render('checkbox');
				  
				  
				}); 

			});
		</script>
	</body>

</html>