{include file="templates/html_header.html"}
		<!-- /section:basics/navbar.layout -->
		<div class="main-container ace-save-state" id="main-container">
			<script type="text/javascript">
			{literal}
				try{ace.settings.loadState('main-container')}catch(e){}
			{/literal}
			</script>
			<!-- #section:basics/sidebar -->
			{include file="templates/html_sidebar.html"}
			<!-- /section:basics/sidebar -->
			<div class="main-content">
				<div class="main-content-inner">
					<!-- #section:basics/content.breadcrumbs -->
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="index.php">首页</a>
							</li>
							<li class="active">{$title}</li>
						</ul><!-- /.breadcrumb -->
						<!-- /section:basics/content.searchbox -->
					</div>

					<!-- /section:basics/content.breadcrumbs -->
					<div class="page-content">
					<h3 class="header smaller lighter blue">
						{$title}
						<small>红包配置列表</small>
					</h3>
						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
									<div class="widget-box widget-color-blue" id="widget-box-2">
										<div class="widget-header">
											<h5 class="widget-title bigger lighter">
												<i class="ace-icon fa fa-users"></i>
												红包雨轮次信息设置
											</h5>
											<div class="widget-toolbar no-border">
												<button class="btn btn-xs btn-yellow btn-add-item"><i class="fa fa-plus"></i>添加轮次</button>
											</div>
										</div>
										<div class="widget-body">
													<div class="widget-main no-padding">
														<table class="table table-striped table-bordered table-hover">
															<thead class="thin-border-bottom">
																<tr>
																	<th>id</th>
																	<th>状态</th>
																	<th>类型</th>
																	<th>金额</th>
																	<th>数量</th>
																	<th>每个人可中的次数</th>
																	<th>中奖概率</th>
																	<th>游戏时长</th>
																	<th>操作</th>
																</tr>
															</thead>
															<tbody>
															{foreach $redpacket_round $item}
																<tr id="item{$item['id']}">
																	<td class="">{$item['id']}</td>
																	<td class="">{if $item['status']==1}未开始{else if $item['status']==2}进行中{else if $item['status']==3}结束{/if}</td>
																	<td class="">{if $item['type']==1}普通红包{else  if $item['type']==2}随机红包{/if}</td>
																	<td class="">{$item['amount']}</td>
																	<td>{$item['num']}</td>
																	<td>{$item['numperperson']}</td>
																	<td>{$item['chance']}</td>
																	<td>{$item['lefttime']}</td>
																	<td>
																		<span class="label label-info btn-edit" data="{$item['id']}">修改</span>
																		<a href="redpacketusers.php?roundid={$item['id']}"><span class="label label-info" >中奖纪录</span></a>
																		
																		<a href="###" onclick="del('{$item['id']}')"><span class="label label-danger">删除</span></a>
																	</td>
																</tr>
															{/foreach}
															</tbody>
														</table>
													</div>
											{$pagerhtml}
												</div>
										
									</div>
									<div id="save-form" class="modal" tabindex="-1">
									<div class="modal-dialog">
										<div class="modal-content">
										
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal">&times;</button>
												<h4 class="blue bigger">红包活动</h4>
											</div>
											<div class="modal-body">
											<div class="row">
											<div class=" col-sm-12">
											<!-- #section:elements.tab -->
											<form class="form-horizontal" >
												<div class="form-group">
													<label  class="col-sm-2 control-label">状态：</label>
													<div class="col-sm-8">
														<div class="radio-inline">
															<label>
																<input name="status" type="radio" class="ace" value="1" />
																<span class="lbl">未开始</span>
															</label>
														</div>
														<div class="radio-inline">
															<label>
																<input name="status" type="radio" class="ace" value="2"/>
																<span class="lbl">进行中</span>
															</label>
														</div>
														<div class="radio-inline">
															<label>
																<input name="status" type="radio" class="ace" value="3"/>
																<span class="lbl">结束</span>
															</label>
														</div>
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-2 control-label">红包类型：</label>
													<div class="col-sm-8">
														<div class="radio-inline">
															<label>
																<input name="type" type="radio" class="ace" value="1"/>
																<span class="lbl">普通红包</span>
															</label>
														</div>
														<div class="radio-inline">
															<label>
																<input name="type" type="radio" class="ace" value="2"/>
																<span class="lbl">随机红包</span>
															</label>
														</div>
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-2 control-label">金额：</label>
													<div class="col-sm-8">
														<input class="form-control" type="text" name="amount" placeholder="请输入红包金额，单位元" value="" />
													</div>
												</div>
												
												<div class="form-group minmaxamount">
												<label class="col-sm-2 control-label">金额范围：</label>
													<div class="col-sm-4">
														<input class="form-control" type="text" name="minamount" placeholder="请输入最小红包金额，单位元" value="" />
													</div>
													<label class="col-sm-1 control-label">到</label>
													<div class="col-sm-4">
														<input class="form-control" type="text" name="maxamount" placeholder="请输入最大红包金额，单位元" value="" />
													</div>
													
												</div>
												<div class="form-group">
													<label class="col-sm-2 control-label">红包数：</label>
													<div class="col-sm-8">
														<input class="form-control" type="text" name="num" placeholder="请输入红包数，单位个" value="" />
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-2 control-label">每人可得的红包数：</label>
													<div class="col-sm-8">
														<input class="form-control" type="text" name="numperperson" placeholder="请输入每人可得的红包数，单位个" value="" />
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-2 control-label">概率：</label>
													<div class="col-sm-8">
														<input class="form-control" type="text" name="chance" placeholder="请输入获得红包的概率，单位千分之一" value="" />
													</div>
												</div>
												<div class="form-group">
													<label class="col-sm-2 control-label">活动时长：</label>
													<div class="col-sm-8">
														<input class="form-control" type="text" name="lefttime" placeholder="请输入活动时长，单位秒" value="" />
													</div>
												</div>
												
											</form>
											</div>
										<!-- /section:elements.tab -->
											</div>
											</div>
											<div class="modal-footer">
												<input type="hidden" name="id" value="0" />
												<button class="btn btn-sm" data-dismiss="modal">
													<i class="ace-icon fa fa-times"></i>
													取消
												</button>

												<button class="btn btn-sm btn-primary btn-save-item">
													<i class="ace-icon fa fa-check"></i>
													保存
												</button>
											</div>
										</div>
									</div>
								</div>
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->
{include file="templates/html_footercontent.html"}
<!-- 写每个页面自定的js -->
<script type="text/javascript">
{literal}
function setradio(name,val){
	var radios=$('input[name='+name+']');
	for(var i=0,l=radios.length;i<l;i++){
		if(val==$(radios[i]).val()){
			$(radios[i]).attr('checked',true);
		}
	}
}
function del(id){
	if(!confirm('确认要删除这条红包轮次记录吗？'))return false;
	$.ajax({
		'url':'doredpacket.php?action=delredpacketround',
		'type':'post',
		'data':{'id':id},
		'dataType':'json',
		'success':function(json){
			if(json.code>0){
				$('#item'+id).remove();
			}else{
				alert(json.message);
			}
		}
	});
}
jQuery(function($){
	$('.btn-add-item').bind('click',function(){
		$('input[name=id]').val(0);
		
		setradio('status',1);
		//$('input[name=type]').val(json.data.type);
		setradio('type',1);
		//if(json.data.type==1){
		$('.minmaxamount').css({"display":'none'});
		//}
		$('input[name=amount]').val(0);
		$('input[name=minamount]').val(0);
		$('input[name=maxamount]').val(0);
		$('input[name=num]').val(1);
		$('input[name=numperperson]').val(1);
		$('input[name=chance]').val(1);
		$('input[name=lefttime]').val(30);
		
		$('#save-form').modal('show');
	});
	$('input[name=type]').bind('click',function(){
		var type=$('input[name=type]:checked').val();
		if(type==1){
			$('.minmaxamount').slideUp();
		}else{
			$('.minmaxamount').slideDown();
		}
	});
	$('.btn-edit').bind('click',function(){
		var id=$(this).attr('data');
		$('input[name=id]').val(id);
		//设置表单初始值
		$.ajax({
			'url':'doredpacket.php?action=getredpacketround',
			'type':'post',
			'data':{'id':id},
			'dataType':'json',
			'success':function(json){
				if(json.code<0){
					alert('json.message');
				}
				setradio('status',json.data.status);
				setradio('type',json.data.type);
				if(json.data.type==1){
					$('.minmaxamount').css({"display":'none'});
				}
				$('input[name=amount]').val(json.data.amount);
				$('input[name=minamount]').val(json.data.minamount);
				$('input[name=maxamount]').val(json.data.maxamount);
				$('input[name=num]').val(json.data.num);
				$('input[name=numperperson]').val(json.data.numperperson);
				$('input[name=chance]').val(json.data.chance);
				$('input[name=lefttime]').val(json.data.lefttime);
			}
		})
		$('#save-form').modal('show');
	});
	
	$('.btn-save-item').bind('click',function(){
		var id=$('input[name=id]').val();
		var status=$('input[name=status]:checked').val();
		var type=$('input[name=type]:checked').val();
		var amount=$('input[name=amount]').val();
		var minamount=type==2?$('input[name=minamount]').val():0;
		var maxamount=type==2?$('input[name=maxamount]').val():0;
		var num=$('input[name=num]').val();
		var numperperson=$('input[name=numperperson]').val();
		var chance=$('input[name=chance]').val();
		var lefttime=$('input[name=lefttime]').val();
		$.ajax({
			"url":"doredpacket.php?action=saveredpacketround",
			"type":"post",
			"dataType":'json',
			'data':{'id':id,'status':status,'type':type,'amount':amount,
				'minamount':minamount,'maxamount':maxamount,'num':num,
				'numperperson':numperperson,'chance':chance,'lefttime':lefttime
				},
			'success':function(json){
				if(json.code<0){
					alert(json.message)
				}else{
					window.location.reload();
				}
			}
		});
		
	});
});
{/literal}
</script>
{include file="templates/html_footer.html"}