{include "header.inc.html"}
<div class="content_box">
	<div class="toolbar_box">
		<div class="toolbar"> <span> <strong>{$lang.admin.finance.name}</strong><br />
		<span class="english">{$lang.admin.finance.name_en}</span> </span>
		<div class="toolbar_menu">
			<a href="{$adminUrl}finance/act/add">添加财务记录</a>
		</div>
		</div>
	</div>
	<div class="tool">
{if $smarty.get.act=="list" || $smarty.get.act==""}<a id="deleteChecked" class="ui-btn">删除所选</a>{/if}
		<form action="{$adminUrl}finance/" method="get" class="form" style="width:600px;display:inline;">
		会员ID：<input type="text" name="userId" class="checkUserId w80" value="{$smarty.get.userId}" /> 关键字：<input type="text" name="key" value="{$smarty.get.key}" /><input type="submit" class="btn_sub" value="{$lang.form.search}" /> {if $smarty.get.userId}用户 {$smarty.get.userId} 当前余额：{useramount id=$smarty.get.userId}{/if}
		</form>
		<div class="clr"></div>
	</div><!--.tool-->
<div class="brandForm">
<form class="form" action="{$adminUrl}finance" method="post" id="form-finance">
{if $smarty.get.act=="edit" || $smarty.get.act=="add"}
<input type="hidden" name="act" value="{$smarty.get.act}" />
{if $smarty.get.act=="edit"}
<input type="hidden" name="id" value="{$smarty.get.id}" />
{/if}
<input type="hidden" name="inajax" value="1" />
<div class="form-line">
<label class="label">用户ID：</label><div class="element"><input type="text" class="text w200 checkUserId notnull" name="userId" value="{$financeInfo.userId}" /></div></div>
<div class="form-line">
<label class="label">类型：</label><div class="element"><select name="typeId" class="transSelect"><option value="0">类型</option>
{financetype orderBy="id asc"}<option value="{$item.id}"{if $financeInfo.typeId==$item.id} selected{/if}>{$item.name}</option>{/financetype}
</select></div></div>
<div class="form-line">
<label class="label">状态：</label><div class="element"><select name="iStatus" class="transSelect"><option value="0">无效</option><option value="1"{if $financeInfo.iStatus==1} selected{/if}>有效</option>
</select></div></div>

<div class="form-line">
<label class="label">金额：</label><div class="element"><input type="text" class="text w200" name="amount" value="{$financeInfo.amount|string_format:'%.2f'}" /></div>
</div>
<div class="form-line">
<label class="label">关于：</label><div class="element"><input type="text" class="text w400" name="about" value="{$financeInfo.about}" /></div>
</div>
<div class="form-line">
<label class="label">在线交易号：</label><div class="element"><input type="text" class="text w200" name="outTradeNo" value="{$financeInfo.outTradeNo}" /></div>
</div>
<div class="form-line">
<label class="label">备注：</label><div class="element"><textarea type="text" class="text w400" name="remark">{$financeInfo.remark}</textarea></div>
</div>
<div class="form-line">
<label class="label">生效时间：</label><div class="element"><input type="text" class="text w130" name="effectiveTime" value="{if $smarty.get.act=='add'}{$smarty.now|date_format:'Y-m-d H:i:s'}{else}{$financeInfo.effectiveTime|date_format:'Y-m-d H:i:s'}{/if}" /></div></div>
{if $smarty.get.act=="edit"}<div class="form-line">
<label class="label">录入时间：</label><div class="element">{$financeInfo.posttime|date_format:'Y-m-d H:i:s'}</div></div>{/if}
<div class="form-line">
<label class="label"></label><div class="element"><input type="submit" class="btn_sub" value="提交" /></div>
</div>
</form>
</div>
 {else}
 <table class="table-ca table_1" id="tInfo">
 <tr>
<th class="w30"><input type="checkbox" value="1" name="allid" id="checkall" /></th><th class="w60">编号</th><th class="w120">在线交易号</th><th class="w80">用户ID</th><th class="w70">金额</th><th class="w40">类型</th><th class="">关于</th><th class="w40">状态</th><th class="w130">生效时间</th><th class="w130">录入时间</th><th class="w60">操作</th>
 </tr>
{finance limit=13 pager="true"}
<tr>
<td><input type="checkbox" name="id[]" value="{$item.id}" /></td><td>{$item.id}</td><td>{$item.outTradeNo}</td><td>{$item.userId}</td><td>{$item.amount}</td><td>{$item.type}</td><td>{$item.about}</td>
<td><img class="smodtoggle" name="iStatus" sid="{$item.id}" src="{$baseUrl}static/images/{if $item.iStatus==1 && $item.effectiveTime}yes{else}no{/if}.gif"></td>

<td>{if $item.effectiveTime}{$item.effectiveTime|date_format:"Y-m-d H:i:s"}{/if}</td><td>{$item.posttime|date_format:"Y-m-d H:i:s"}</td><td><a href="{$adminUrl}finance/act/edit/id/{$item.id}" class="modBtn">修改</a><a href="javascript:void(0)" class="delBtn" sid="{$item.id}">删除</a></td>
</tr>
{/finance}
</table>
<div class="page">
	<div class="pagin fr">{pager allCount=$allCount url='/qkadmin/finance/page/' type="finance" number="false"}</div>
</div>
{/if}
</div><!--.content_box-->
<script type="text/javascript">
$(function(){
	$("#form-finance").validate({
		rules:{ loginName:{ required:true } },messages:{ loginName:{ required:'请填写会员ID' } },submitHandler:function(){
			$("#form-finance").ajaxSubmit({	dataType:'json',success:function(json){ if(json.success){ qlib.tips({ icon:'success',msg:json.message }); if($("input[name='act']").val()=='add'){ $("#form-finance").find("input[name='loginName'],input[name='amount'],input[name='about'],input[name='outTradeNo']").val(''); } }else{ qlib.tips({ icon:'error',msg:json.message }); } },error:function(){ qlib.tips({ icon:'error',msg:'Ajax处理失败' }); } });
			return false;
		}
	})
	$("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}finance",
					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 id = $(this).attr("sid");
		var tr = $(this).parent("td").parent("tr");
		if(!id || !parseInt(id)){ return false; }
		$.ajax({
			type:"POST",
			url:"{$adminUrl}finance",
			data:"inajax=1&act=del&id="+id,
			dataType:"json",
			success:function(json){
				if(json.success){
					tr.slideUp().remove();
				}else{
					art.dialog(json.message);
				}
			}
		})
	});
	$("select[name='typeId']").change(function(){
		var val = $(this).val();
		var amount = $("input[name='amount']").val();
		amount = amount.replace('-','');
		if(val==2){
			$("input[name='amount']").val('-'+amount);
		}else{
			$("input[name='amount']").val(amount);
		}
	});
	$('.checkUserId').focus(function(){ $(this).select(); });
});
</script>
{include "footer.inc.html"}