<extend name="Public:base" />
<block name="content">


<div class="page-header">
	<a href="{:U('Lottery/index',array('state'=>1))}" class="btn btn-primary">活动中商品</a>
	&nbsp;&nbsp;
	<a href="{:U('Lottery/addGoods')}" style="display:none;" class="btn btn-primary">添加抽奖商品</a>
</div>	
<?php if($state == 1){
?>
<h1>活动中的商品</h1>
<?php }else { ?>
<h1>申请参加活动商品</h1>
<?php } ?>	

<div class="row">
	<div class="col-xs-12">	
		<div class="table-responsive">
			<table class="table table-striped table-bordered table-hover">
				<thead>
					<tr>											
						<th>ID</th>
						<th>商品ID</th>
						<th>图片</th>
						<th>商品名称</th> 
						<th>价格</th>
						<th>库存</th> 
						<th>中奖人数</th>  
						<th>所属店铺</th>
						<th>赠送券</th>	
						<?php if( $state == 1){ ?>
						<th>活动时间</th>	
						<?php }else{ ?>
						<th>申请时间</th>	
						<?php } ?>
						<th>操作</th>				
					</tr>
				</thead>
				<tbody>
						<volist name="list" id="data" empty="$empty">
						<tr>						
							<td>{$data.id}</td>
							<td>{$data.goods_id}</td>
							<td><img src="__ROOT__/{$data.image}" /></td>
							<td>{$data.name}</td>
							<td>
							<span class="green bold">拼团价：{$data.pinprice}</span>
							<br/>
							<span class="blue bold">单独价：{$data.danprice}</span>
							</td>
							<td>
							{$data.quantity}
							</td>
							<td>
							{$data.win_quantity}
							</td>
							<td>
							<?php $s = M('seller')->where(array('s_id'=>$data['store_id']))->field('s_true_name')->find();echo $s['s_true_name']; ?>
							</td>
							<td>
								{$data.voucher_title}
							</td>
							<td>
							<?php if( $state == 1){ ?>
								<?php echo date('Y-m-d H:i:s',$data['begin_time']); ?><br/>
							    <?php echo date('Y-m-d H:i:s',$data['end_time']); ?>
								<?php if($data['is_open_lottery'] == 1){ echo "<br/> <span class='green'>已开奖</span>"; } ?>
							<?php }else{ ?>
								<?php echo date('Y-m-d H:i:s',$data['addtime']); ?>
							<?php } ?>
						
							</td>
							<td>
							<?php if($data['state'] == 0) { ?>
								<a  class="btn btn-xs btn-info shenhe" href="javascript:;" rel-url='{:U("Lottery/shenhe",array("goods_id"=>$data["goods_id"],"id" => $data["id"]))}'>
									<i class="icon-check bigger-120"></i>
								</a> 
							<?php } ?>		
							</td>
						</tr>
						</volist>	
						
						<tr>
							<td colspan="20" class="page">{$page}</td>
						</tr>
				</tbody>
				
			</table>
		</div>
	</div>
</div>
<link rel="stylesheet" href="__CSS__/dialog.css" />	

<div class="ks-ext-mask" style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 999; display:none"></div>
	<div id="dialog" class="dialog" style="z-index: 9999; display:none">
    <div class="ks-contentbox">
      <div class="title">
      	<span>抽奖产品上线时间设置</span><a class="ks-ext-close" href="javascript:void(0)">X</a></div>
      
        <dl>
        	<dt>开始时间</dt>
    		<dd><input name="begin_time" id="begin_time" type="text" value="<?php echo date('Y-m-d H:i:s',time()); ?>" size="50"  /></dd>    		
    		<dt>结束时间</dt>
    		<dd><input name="end_time" id="end_time" type="text" value="<?php echo date('Y-m-d H:i:s',time()+86400); ?>" size="50"  /></dd>  
        </dl>
        
        <div class="J_DefaultMessage"></div>
        <div class="bottom">
        	<input type="hidden" id="sub_url" value="" />
        	 <a href="javascript:void(0);" class="J_SubmitPL ncsc-btn ncsc-btn-green">确认</a> 
        </div>
      
    </div>
  </div>  
  
</block>
<block name="javascript">
<script src="__PUBLIC__/js/moment/moment.js"></script>
<script src="__PUBLIC__/js/moment/locale/zh-cn.js"></script> 

<script src="__PUBLIC__/js/eonasdan-bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js"></script>
<link rel="stylesheet" href="__PUBLIC__/js/bootstrap-timepicker/css/bootstrap-timepicker.css" />
<script>

$(function(){
		$('#begin_time').datetimepicker({
		 format: 'YYYY/MM/DD H:mm:ss',//use this option to display seconds
		 icons: {
			time: 'btn btn-lg icon-time',
			date: 'btn btn-lg icon-calendar',
			up: 'fa icon-chevron-up',
			down: 'fa icon-chevron-down',
			previous: 'fa icon-chevron-left',
			next: 'fa icon-chevron-right',
			today: 'fa icon-arrows ',
			clear: 'fa icon-trash',
			close: 'fa icon-times'
		 }
		}).next().on(ace.click_event, function(){
			$(this).prev().focus();
		});
		
		$('#end_time').datetimepicker({
			 format: 'YYYY/MM/DD H:mm:ss',//use this option to display seconds
			 icons: {
				time: 'btn btn-lg icon-time',
				date: 'btn btn-lg icon-calendar',
				up: 'fa icon-chevron-up',
				down: 'fa icon-chevron-down',
				previous: 'fa icon-chevron-left',
				next: 'fa icon-chevron-right',
				today: 'fa icon-arrows ',
				clear: 'fa icon-trash',
				close: 'fa icon-times'
			 }
			}).next().on(ace.click_event, function(){
				$(this).prev().focus();
			});
		
		$('.J_SubmitPL').on('click',function(){
			var begin_time = $('#begin_time').val();
			var end_time = $('#end_time').val();
			
			var s_url = $('#sub_url').val();
			$.ajax({
				url:s_url,
				type:'post',
				data:{begin_time:begin_time,end_time:end_time},
				dataType:'json',
				success:function(result){
					if(result.code == 1) {
						alert('审核通过');
						location.href = location.href;
						return false;
					} else {
						alert(result.msg);
					}
				}
				
			})
		})
		
		$('.shenhe').click(function(){
			var s_url = $(this).attr('rel-url');
			$('#sub_url').val(s_url);
			$("#dialog").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
		})
		
		//关闭弹出层
		$('#dialog').on('click','.ks-ext-close',function(){	
		    $("#dialog").css('display','none');
		    $('.ks-ext-mask').css('display','none');
		    return false;
		});
		//关闭弹出层
		$('#dialog').on('click','.J_Cancel',function(){	
		    $("#dialog").css('display','none');
		    $('.ks-ext-mask').css('display','none');
		    return false;
		});
			
		
	
})
</script>						
</block>