{include "header.inc.html"}
{$linksLang = $lang.admin.links.form}
<div class="content_box">
	<div class="toolbar_box">
		<div class="toolbar"> <span> <strong>优惠券</strong><br />
		<span class="english">Coupon</span> </span> </div>
	</div>
<div class="tool">
{if $smarty.get.act=="list" || $smarty.get.act==""}
<a id="deleteChecked">删除所选</a>
{/if}
&nbsp;&nbsp;&nbsp;&nbsp;<a class="ui-btn" id="addCouponList">发放优惠券码</a>
</div>
<div class="none" id="dialogCouponList">
<form class="form" action="" method="post" id="couponForm">
<input type="hidden" name="act" value="add" /><input type="hidden" name="inajax" value="1" />
<div class="form-line"><label class="label">优惠券：</label><div class="element"><select name="couponId">{coupon limit="false" iStatus="1"}<option value="{$item.id}">{$item.name} 金额：{$item.money|string_format:"%.2f"}</option>{/coupon}</select></div></div>
<div class="form-line"><label class="label">发放个数：</label><div class="element"><input type="text" class="text w80" name="number" value="" maxlength="5" /> 发放个数(数字)</div></div>
<div class="form-line"><label class="label">绑定用户ID：</label><div class="element"><input type="text" class="text w100" name="userId" value="" maxlength="32" /> 可空，如发放给单独的用户，请填写用户ID</div></div>
<div class="form-line"><label class="label">过期日期：</label><div class="element"><input type="text" class="text w130" name="endtime" value="" maxlength="32" /> 过期日期时间，格式为 2013-10-01 12:30:00</div></div>
<div class="form-line"><label class="label"></label><div class="element"><input class="btn_sub" type="submit" value="{$lang.form.submit}"></div></div>
</form>
</div>

{if $smarty.get.act=="edit" || $smarty.get.act=="add"}

{else}
<table class="table-ca table_1" id="tInfo">
<tr>
<th class="w30"><input type="checkbox" value="1" name="allid" id="checkall" /></th><th>优惠券名称</th><th class="w140">优惠券号码</th><th class="w80">是否可用</th><th class="w80">价值金额</th><th class="w80">使用状态</th><th class="">用户</th><th class="w130">使用时间</th><th class="w130">使用IP</th><th class="w120">过期时间</th><th class="w40">{$lang.form.operate}</th>
</tr>
{usercoupon limit=15}
<tr sid="{$item.id}"><td><input type="checkbox" name="id[]" value="{$item.id}" /></td><td>{$item.name}</td><td>{$item.number}</td>
<td><img class="smodtoggle" name="iStatus" sid="{$item.id}" src="{$baseUrl}static/images/{if $item.iStatus==1 && ($item.endtime==0 || $item.endtime>$smarty.now) }yes{else}no{/if}.gif"></td>
<td>{$item.money}</td>
<td>{if $item.iStatus==0 || $item.useoftime}已使用{else}未使用{/if}</td>
<td{if $item.userId} class="J-user-anchor"{/if} sid="{$item.userId}">{if $item.userId}{$item.userId}{/if}</td><td>{if $item.useoftime}{$item.useoftime|date_format:'Y-m-d H:i:s'}{/if}</td><td>{$item.ip}</td><td>{if $item.endtime}{$item.endtime|date_format:"Y-m-d H:i:s"}{else}无限期{/if}</td><td><a href="javascript:void(0)" class="delBtn">{$lang.del}</a></td></tr>
{/usercoupon}
</table>
<div class="page"><div class="pagin fr">{pager allCount=$allCount url='/qkadmin/usercoupon/page/' number="false"}</div></div>

<script type="text/javascript">
$(function(){
	$("a#deleteChecked").button().click(function(){
		if(!confirm(lang[4])){ return false; }		
		var id = [];
		$("input[name='id[]']:checkbox:checked").each(function(index){
			id[index] = $(this).val();
			var sid = $(this).val();
			if(sid){
				var tr = $(this).parent("td").parent("tr");
				var sdata = "inajax=1&act=del&id="+sid;
				$.ajax({
					type:"POST",
					url:"{$adminUrl}usercoupon",
					data:sdata,
					dataType:"json",
					success:function(data){
						if(data.success){
							tr.fadeOut("slow").remove();
						}else{
							alert(data.message);
						}
					}
				});			
			}
		});
		
	});
	$(".delBtn").click(function(){
		if(!confirm(lang[4])){ return false; }
			var tr = $(this).parent("td").parent("tr");
			var id = tr.attr('sid');
			if(parseInt(id,10)){
				var sdata = "inajax=1&act=del&id="+id;
				$.ajax({
					type:"POST",
					url:"{$adminUrl}usercoupon",
					data:sdata,
					dataType:"json",
					success:function(data){
						if(data.success){
							tr.fadeOut("slow").remove();
						}else{
							alert(data.message);
						}
					}
				});
			}
		return false;
	});
	$("#addCouponList").click(function(){
		var dialogCardList = $('#dialogCouponList').dialog({ width:600,height:300,modal:true,resizable:false,title:'批量发放优惠券码' });
	});
	//$("#addCardList").trigger('click');
	$('#couponForm').ajaxForm({ dataType:'json',success:function(json){ if(json.success){ qlib.tips({ icon:'success',msg:json.message });$('#dialogCardList').dialog('destroy');location.reload(); }else{ qlib.tips({ icon:'error',msg:json.message }); } } });
})
</script>

{/if}

{include "footer.inc.html"}