<style type="text/css">
input.checked_all{ margin-left:8px; }
input.checked_list{ margin-left:8px; }
table.ltable{ width:100%; float:left; }
.goods_box_json{ padding:0; margin:8px 0; float:left; }
</style> 
<table class="ltable">
	<thead>
		<tr> 
			<th width="35"><{if $smarty.get.input_type != 'radio'}><input type="checkbox" class="checked_all"/><{/if}></th>
			<th width="30">产品</th>
			<th></th>
			<th width="80">价格</th> 
			<th width="80">库存</th> 
		</tr>
	</thead>
	<tbody id="goods_list_con"></tbody> 
</table>
<div class="page goods_box_json"><div class="page"><{$data.page}></div></div>
<script type="text/javascript">
function ajax_submit(){
	var gid_arr = new Array();
	$(".ltablebox tr input").each(function(){ 
		gid_arr.push($(this).val());
	});
 	html = '';
	$("tbody#goods_list_con tr input").each(function(k, v){ 
		if($(this).attr("checked")){ 
			$this = $(this);
			gid = $this.val(); 
			if($.inArray(gid, gid_arr)<0){		//alert("数组里不包含！");
				images 	= $this.parent().parent().find('td:eq(1) img').attr('src');
				title 	= $this.parent().parent().find('td:eq(2)').html();
				price 	= $this.parent().parent().find('td:eq(3)').html();
				stock 	= $this.parent().parent().find('td:eq(4)').html(); 
				html += '<tr><input type="hidden" name="ckgid[]" value="'+gid+'">'+
						'	<td><img src="'+images+'"></td>'+
						'	<td>'+title+'</td>'+
						'	<td>'+price+'</td>'+
						'	<td>'+stock+'</td>'+
						'	<td><a href="javascript:;" class="gs_del" data-id="'+gid+'">删除</a></td> '+
						'</tr>'; 	 
			} 
		}
	}); 
	 
	if($(".ltablebox tr").length > 0){
		$(".ltablebox tr:last").after(html);
	}else{
		$(".ltablebox").html(html);
	}
	ajax_close();
}

$(function(){ 
	page = $(".ckgoods").attr('data-page');
	if(page == ''){
		page = '1';
	}
	$.get(SELLER+'promote/ajax_goods?page='+page+'&page_size=6&id=<{$smarty.get.id}>', function(result){ 
		data = jQuery.parseJSON(result);
		if(data.error == '0'){
			html_con(data); 
		}
	}); 
	function html_con(data){
		// 先检测那些被选中
		var ch_arr = new Array();
		$(".ltablebox tr input").each(function(){ 
			ch_arr.push($(this).val());
		});
		
		html = ''; 
		$.each(data.list, function(k,v){ 
			html += '<tr>';
			if(v.forbid == '1'){
				html += '<td><input type="checkbox" name="ckid[]" value="'+v.id+'" disabled="disabled" class="checked_list"/></td>';
			}else{
				if($.inArray(v.id, ch_arr)<0){		//alert("数组里不包含！");
					html += '<td><input type="checkbox" name="ckid[]" value="'+v.id+'" class="checked_list"/></td>';
				}else{
					html += '<td><input type="checkbox" name="ckid[]" value="'+v.id+'" checked="checked" class="checked_list"/></td>';
				}
			}
			html += '<td><img src="<{$__IMG__}>'+v.images+'"></td>'+
					'<td>'+v.title+'</td>'+
					'<td>'+v.price+'</td>'+
					'<td>'+v.stock+'</td>'+
				'</tr>'; 
		}); 
		$("#goods_list_con").html(html); 
		$(".goods_box_json").html(data.page);
	}
	
	$(document).on("click", ".page a", function(event){  
		var jump_url = $(this).attr('href');
		if(jump_url){
			$.get(jump_url, function(result){
				data = jQuery.parseJSON(result); 
				if(data.error == '0'){
					html_con(data); 
				} 
			});
			$(".ckgoods").attr('data-page', getPage(jump_url))
		} 
		if(window.event){
			window.event.returnValue = false;
		}else{  
			event.preventDefault();	 //for firefox
		}
	});
}); 
function getPage(url){  
	reg = new RegExp("(^|&)page=([^&]*)(&|$)");
	u = url.match(reg);
   	// var u = url.replace(/(\\?|^|&|\#)page=([^&|^#]*)(&|$|#)/, "$1"+key+"="+value+"$2");   
    return u[2];  
}  
</script>