<{import file="index/header_shop.html" title="促销活动"}>
<!--datapiker--> 
<link rel="stylesheet" type="text/css" href="<{$__PUBLIC__}>plug/laydate/need/laydate.css"> 
<link rel="stylesheet" type="text/css" href="<{$__PUBLIC__}>plug/laydate/skins/default/laydate.css"> 
<!--data end---> 
<style type="text/css">
/*图片头像*/
.gs_img{ width:100%; padding:0 0 0 10px; float:left; }
.gs_img img{ max-width:35px; max-height:35px; float:left; }
.gs_img a{ padding:6px 0 0 10px; float:left; }

/*分页*/
.spage{ width:100%; padding:10px 0; text-align:right; float:left; }
.spage a{ padding:5px; background:#f8f8f8; border-radius:1px; margin:0 10px 0 0; }
.spage span a{ background:#3399FF; padding:2px 3px; line-height:12px; color:#FFFFFF; }

/*产品规格*/
table tbody tr td{ padding:0; }
table tbody.sku_box input{ padding:2px; border-radius:0; }
</style> 
<div class="tab_name"><a class="back" href="?m=goods_act&a=seckill">添加优惠</a></div> 
<div class="baseBox">
	<form id="form" method="post"> 
		<{if $row.id}><input type="hidden" name="id" id="id" value="<{$row.id}>"/><{/if}>
		<input type="hidden" name="gid" id="gid" value="<{$row.gid}>"/>
		<table class="etable" width="100%">
			<tr>
				<td width="120">活动名称：</td>
				<td><input type="text" name="name" id="name" value="<{$row.name}>" size="30"/></td>
			</tr>
			<tr>
				<td>开始时间：</td>
				<td>
					<span class="time">
						<input type="text" name="start_time" id="start_time" size="20" id="text" value="<{$row.start_time}>"/>
					</span> 
					<span class="time">
						<i style="color:#666666;">结束时间：</i>
						<input type="text" name="end_time" id="end_time" size="20" id="text" value="<{$row.end_time}>"/>
					</span> 
				</td>
			</tr>  
			<tr>
				<td valign="top" style="padding-top:15px;">选择产品：</td>
				<td>
					<!--产品列表-->
					<table class="ltable" style="width:650px">
						<thead>
							<tr>
								<th>标题</th>
								<th width="60">库存</th>
								<th width="66">操作</th>
							</tr>
						</thead>
						<tbody>
							<{if $goods.list}>
								<{foreach item=i from=$goods.list}>
									<tr>
										<td style="text-align:left;">
											<div class="gs_img">
												<img src="<{$__IMG__}><{$i.images|img_size:30x30}>">
												<a href="index.php?m=goods&a=detail&id=<{$i.id}>" target="_blank"><{$i.title}></a>	
											</div>
										</td>
										<td><{$i.stock}></td>
										<td>
											<a href="javascript:;" class="chose_goods" data-id="<{$i.id}>">选择</a>
										</td>
									</tr>
								<{/foreach}>
								<{if $goods.page}><tr><td colspan="3"><div class="spage"><{$goods.page}></div></td></tr><{/if}>
							<{else}>
								<tr><td colspan="3">暂无产品</td></tr>	
							<{/if}>
						</tbody>
					</table>
					<!---产品结束--->
				</td>
			</tr>
			<tr>
				<td valign="top" style="padding-top:21px;">产品规格：</td>
				<td>
					<!--规格编辑价格-->
					<table class="ltable" style="width:650px">
						<thead>
							<tr>
								<th>规格</th>
								<th width="60">价格</th>
								<th width="50">库存</th>
								<th width="70">优惠价格</th>
							</tr>
						</thead>
						<tbody class="sku_box">
							<tr>
								<td colspan="4" style="border-bottom:1px solid #efefef;"><div style="width:100%; text-align:center; font-weight:100; padding:10px 0;">请选择产品</div></td>
							</tr>
						</tbody>
						
					</table>
					<!--规格编辑价格-->		
				</td>
			</tr> 
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" name="submit" class="submit" value="保存"/></td>
			</tr>
		</table>
	</form> 
</div>
<{include file="index/footer.html"}>  
<script type="text/javascript" src="<{$__PUBLIC__}>plug/laydate/laydate.js"></script>
<script type="text/javascript"> 
var start = {
	elem:'#start_time', 
	format:'YYYY-MM-DD hh:mm:ss', 
	min:laydate.now(), 
	max:'2099-06-16 23:59:59',  
	istime:true, 
	istoday:false, 
	choose:function(datas){
		end.min = datas; 
		end.start = datas 
	}
};
var end = { 
	elem:'#end_time', 
	format:'YYYY-MM-DD hh:mm:ss', 
	min:laydate.now(), 
	max:'2099-06-16 23:59:59', 
	istime:true, 
	istoday:false, 
	choose:function(datas){
		start.max = datas; 
	}
};
laydate(start);
laydate(end);  
$(function(){
	// 保存
	$("form").submit(function(){ 
		var name = $("#name").val();
		if(name == ''){ $.alert('活动名称不能为空');	return false; }
	 	$.ajax({
			type:'POST',
			url:'member.php?m=goods_act&a=seckill_save',
			data:$("#form").serialize(),
			success:function(result){ 
				var data = jQuery.parseJSON(result); 
				if(data.error == 0){
					$.alert('保存成功');
					location.href="?m=goods_act&a=seckill";
				}else{ 
					$.alert(data.msg); 
				}
			},error:function(){
				$.alert('错误');
			}
		}); 
		return false;
 	});
	
	// 选择产品
	$(".chose_goods").click(function(){ 
		gid = $(this).attr('data-id'); 
		$('#gid').val(gid);
		sku_goods(gid); 
	});
	<{if $row.id}>
		sku_goods('<{$row.gid}>', '<{$row.id}>');
	<{/if}> 
	
	// 双击覆盖
	$(document).on('dblclick', 'table tbody.sku_box tr td input', function(){ 
		price = $(this).val();
		$("table tbody.sku_box tr td input").val(price);
	});
});
function sku_goods(gid, id){
	gid = gid?gid:0;
	id = id?id:0;
	$.ajax({
		type:'GET',
		url:'?m=goods_act&a=seckill_goods_sku&gid='+gid+'&type=0', 
		success:function(result){
			var data = jQuery.parseJSON(result); 
			if(data.error == 0){
				html = '';
				$.each(data.sku_list, function(k, v){
					html += '<tr>'+
								'<td style="text-align:left; padding-left:10px;">'+v.sku_name+'</td>'+
								'<td>'+v.price+'</td>'+
								'<td>'+v.stock+'</td>'+ 
								'<td><input type="text" size="5" name="seckill_price['+v.id+']" value="'+v.act_price+'"/></td>'+
							'</tr>'; 
				});
				$("tbody.sku_box").html(html);
			}else{
				$.alert(data.msg);
				$(".submit_reg").attr("disabled",false);  
			}
		},error:function(){
			alert('错误');
		}
	});  
}
</script>