<!DOCTYPE html>
<html>
	<?php echo $this->fetch('head.html'); ?>
	<body>
		<div class="pdl-10 f16 mgb-10">
			 款式管理:: <?php echo $this->_var['product']['title']; ?>
		</div>
		<div class="main-body">
			<table class="tbs">
				<thead>
            	<tr class="info">
                	<td width="200">款式名称</td>
                	 
                    <td width="80">价格</td>
                    
                    <td width="80">销量</td>
                    <td  >操作</td>
                </tr>
				</thead>
                <tbody id="kslist">
                
                 
                </tbody>
                <tr class="ksitem" did="0">
                	<td><input type="text" class="ks-title w98" placeholder="款式名称"  > </td>
                	 
                    <td> <input type="text" class="ks-price w98" placeholder="价格"  ></td>
                    
                    <td><input type="text" class="ks-buy-num w98" placeholder="销量" value="0"  ></td>
                    <td> <button type="button" class="ks-add btn btn-success"  >添加</button></td>
                </tr>
            </table>
		</div>
		<?php echo $this->fetch('footer.html'); ?>
		<script>
			 function kslist(){
				 $.get("/moduleadmin.php?m=household_product_ks&a=jlist&productid=<?php echo $this->_var['product']['id']; ?>",function(data){
					 var html='';
					 for(var i=0;i<data.length;i++){
						html=html+'<tr class="ksitem" did="'+data[i].id+'"><td><input type="hidden" class="ks-id" value="'+data[i].id+'"><input type="text" class="ks-title w98" value="'+data[i].title+'" placeholder="款式名称" > </td>   <td> <input type="text" class="ks-price w98" value="'+data[i].price+'" placeholder="价格"  ></td> <td><input type="text" class="ks-buy-num w98" value="'+data[i].buy_num+'" placeholder="销量"  readonly ></td> <td> <button type="button" class="ks-add btn btn-success"  >编辑</button> <button type="button" class="ks-del btn btn-success"  >删除</button> </td> </tr>'; 
					 }
					 $("#kslist").html(html);
				 },"json");
			 }
             $(function(){
				 kslist();
				$(document).on("click",".ks-add",function(){
					var $obj=$(this).parents(".ksitem");
					if($obj.find(".ks-title").val()=='' || $obj.find(".ks-price").val()=='' ){
						skyToast('请完善信息');
						return false;
					}
					$.post("/moduleadmin.php?m=household_product_ks&a=save&ajax=1",{
						productid:"<?php echo $this->_var['product']['id']; ?>",
						id:$obj.find(".ks-id").val(),
						size:$obj.find(".ks-size").val(),
						title:$obj.find(".ks-title").val(),
						price:$obj.find(".ks-price").val(),
						total_num:$obj.find(".ks-total-num").val(),
						buy_num:$obj.find(".ks-buy-num").val()
					},function(data){
							skyToast('保存成功');
							if($obj.attr("did")=="0"){
								kslist();
								$obj.find(".ks-title").val('')
							}
					},"json")
				});
				
				$(document).on("click",".ks-del",function(){
					if(confirm('确认删除吗？')){
						var $obj=$(this).parents(".ksitem");
						$.get("/moduleadmin.php?m=household_product_ks&a=delete&ajax=1&id="+$obj.find(".ks-id").val(),function(data){
							kslist();
						})
					}
				});
			 });
             </script>
	</body>
</html>
