{include "header.inc.html"}
{$goodsLang = $lang.admin.goods.form}
<div class="content_box">
	<div class="toolbar_box">
		<div class="toolbar"> <span> <strong>优惠券管理</strong><br />
		<span class="english">Coupon</span> </span> </div>
	</div>
{if $smarty.get.act=="add" || $smarty.get.act=="edit"}
<div class="adminForm">
<form class="form" id="form" action="" method="post">
<input type="hidden" name="inajax" value="1" />
<input type="hidden" name="act" value="{$smarty.get.act}" />
{if $smarty.get.act=="edit"}
<input type="hidden" name="id" value="{$smarty.get.id}" />
{/if}
<div class="panelDiv panel_0">
	<div class="form-line"><label class="label">优惠券名称：</label><div class="element"><input type="text" class="text w400" name="name" value="{$couponInfo.name}" /></div></div>
	<div class="form-line none"><label class="label">所属商家：</label><div class="element"><input type="text" class="text" name="comId" value="{$couponInfo.comId}" /></div></div>
	<div class="form-line"><label class="label">类型：</label><div class="element"><select name="typeId"><option value="0">优惠券类型</option>
	{coupontype}
	<option value="{$item.id}"{if $couponInfo.typeId==$item.id || ($smarty.get.act=="add" and $smarty.session.typeId==$item.id)} selected{/if}>{for $foo=1 to $item.grade*4}&nbsp;{/for}{$item.name}</option>
	{/coupontype}
	</select> <a href="javascript:void(0);" id="addCouponType">添加类型</a>
	</div></div>
	<div class="form-line"><label class="label">价值：</label><div class="element"><input type="text" class="text" name="money" value="{$couponInfo.money|string_format:'%.2f'}" /> 元 可抵消消费面额，数字，可保留两位小数</div></div>
	<div class="form-line none"><label class="label">折扣：</label><div class="element"><input type="text" class="text" name="discount" value="{$couponInfo.discount}" /> 数字，如8折请填写80，5.5折请填写55</div></div>
	<div class="form-line none"><label class="label">开始时间：</label><div class="element"><input type="text" class="text" name="starttime" value="{if $couponInfo.starttime!=0}{$couponInfo.starttime|date_format:'Y-m-d H:i:s'}{/if}" /> 格式如：2013-05-15 12:30:20</div></div>
	<div class="form-line none"><label class="label">结束时间：</label><div class="element"><input type="text" class="text" name="endtime" value="{if $couponInfo.endtime!=0}{$couponInfo.endtime|date_format:'Y-m-d H:i:s'}{/if}" />  格式如：2013-05-20 12:30:20</div></div>
	<div class="form-line none">
		<label class="label">图标：</label><div class="element"><input type="hidden" name="thumbId" id="thumbId" value="{$couponInfo.thumbId}" />
		{if  $couponInfo.thumbId}
		{attachment id=$couponInfo.thumbId limit=1}
		<img id="img-src" src="{$item.url}" />
		{/attachment}
		{else}
		<img id="img-src" src="{$baseUrl}static/images/default.png" />
		{/if}<br><span id="uploadBtn"></span>
		</div>
	</div>

	<div class="form-line"><label class="label">优惠券介绍：</label><div class="element">{editor content=$couponInfo.content}</div></div>
	<div class="form-line"><label class="label"></label><div class="element"><input type="submit" class="btn_sub" value="{$lang.form.submit}" /></div></div>
</form>
</div>
<div id="addCouponTypeDialog" class="none">
<input type="text" name="couponTypeName" id="couponTypeName" class="w200" style="height:24px;line-height:24px;" value="" />
</div>
<script type="text/javascript">
$(function(){
	$("#addCouponType").click(function(){
		$('#addCouponTypeDialog').dialog({ title:'添加购物券类型',width:350,height:130,resizable:false,modal:true,buttons:{ "确定":function(){
					var couponTypeName = $('#couponTypeName').val();
					if(couponTypeName){
						var sdata={ act:'addType',inajax:1,name:couponTypeName };
						$.ajax({ type:'POST',url:'{$adminUrl}coupon',data:sdata,dataType:'json',success:function(json){ icon='error';if(json.success){ icon='success';
							$("select[name='typeId']").prepend("<option value='"+json.data.id+"'>"+couponTypeName+"</option>");$("select[name='typeId']").val(json.data.id);
							$('#addCouponTypeDialog').dialog("destroy");
						};qlib.tips({ icon:icon,msg:json.message }); }});
					}
				}
			}
		});
	});
});
</script>
{else}
<div class="tool">
<div class="left">
</div>
<div class="right">
<a class="ui-btn" href="{$adminUrl}coupon?act=add">添加优惠券</a>
</div>
<div class="clr"></div>
</div><!--.tool-->
 <table class="table-ca table-list">
 <tr sid="{$item.id}">
<th class="w70">{$lang.form.id}</th><th>优惠券名称</th><th class="w150">类型</th><th class="w60">价值</th>
<th class="w60">是否有效</th><th class="w120">{$lang.form.posttime}</th><th class="w70">{$lang.form.operate}</th>
 </tr>
{coupon limit=15 pager="true" key=$key catId=$smarty.request.catId iStatus=''}
<tr sid="{$item.id}">
<td>{$item.id}</td><td><div class="tleft">{$item.name}</div></td><td>{$item.typeInfo.name}</td>
<td><span name="money" class="smodedit" width="40">{$item.money|string_format:"%.2f"}</span></td>
<td><img class="smodtoggle" name="iStatus" src="{$baseUrl}static/images/{if $item.iStatus==1}yes{else}no{/if}.gif"></td>
<td title="{$item.posttime|date_format:'Y-m-d H:i:s'}">{$item.posttime|date_format:"Y-m-d H:i:s"}</td>
<td><a href="{$item.url}" target="_blank" class="viewBtn" style="display:none !important" title="{$lang.view}">{$lang.view}</a> <a href="{$adminUrl}coupon/act/edit/id/{$item.id}" class="modBtn" title="{$lang.edit}">{$lang.edit}</a> <a href="javascript:void(0)" class="delBtn" title="{$lang.del}" sid="{$item.id}">{$lang.del}</a></td>
</tr>
{/coupon}
</table>
<div class="page">
{$key=$key|escape:"url"}
{if $key}
{$key = "/key/$key"}
{/if}
	<div class="pagin fr">{if $cfg_lang=="zh-ch"}共 {$allCount} 条记录{else} {$allCount} Records{/if}&nbsp;&nbsp;&nbsp;&nbsp; {pager allCount=$allCount type="goods"  number="false"}</div>
</div>
{/if}
{if $smarty.get.act=="edit" || $smarty.get.act=="add"}
<script type="text/javascript" src="/plugins/swfupload/swfupload.js"></script>
<script type="text/javascript">
var swfu;
$(function(){
	$("#form").validate({
		rules:{
			"name":{ required:true }
		},
		messages:{
			"name":{ required:'请填写优惠券名称' }
		},
		submitHandler:function(form){
			qlib.tips({ timer:false });
			$("#form").ajaxSubmit({ dataType:'json',success:showResponse,error:function(){ qlib.tips('ajax处理错误'); } });
		}
	});
	function showResponse(rt,st,xhr,form){
		if(rt.success){
			var act = $("input[name='act']").val();
			if(act=='add'){
			$("#form input[type='text'],#form textarea").val('');
			}
			qlib.tips({ msg:rt.message,icon:'success' });
		}else{
			qlib.tips(rt.message);
		}
	}
});
</script>
{/if}
<script type="text/javascript">
$(function(){
	$(".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}coupon",
					data:sdata,
					dataType:"json",
					success:function(data){
						if(data.success){
							tr.fadeOut("slow").remove();
						}else{
							qlib.tips(data.message);
						}
					}
				});
			}
		return false;
	});

});
</script>
</div>
{include "footer.inc.html"}