{echo:JS::import("form")}
<link type="text/css" rel="stylesheet" href="{url:#css/ucenter.css}" />
<div class="container list blank">
	<div class="row-5">
	<div class="col-1">
	{widget:name=sub_navs action=ucsidebar sidebar=$sidebar act=$actionId}
	</div>
	<div class="col-4">
		<h1 class="title"><span>账户金额管理：</span></h1>
		<div class="box">账户余额：<b class="">{$currency_symbol}{$customer['balance']|'0.00'}</b> <span class="fr"><a href="javascript:;" id="recharge-btn" class="btn btn-main btn-mini">充值</a> <a href="javascript:;" id="withdraw-btn" class="btn btn-main btn-mini">提现</a></span></div>
		<div class="mt10 tab">
			<ul class="tab-head">
			<li>交易记录<i></i></li>
				<li>提现申请记录<i></i></li>
			</ul>
			<div class="tab-body">
				<div>
					<table class="table table-list">
						<tr>
							<th width="160">时间</th> <th width="120">存入 / 取出</th><th width="120">余额</th> <th >备注</th>
						</tr>
						{query:name=balance_log where=user_id eq $user[id] order=id desc page=1 id=$obj}
						<tr class="{if:$key%2==1}odd{else:}even{/if}">
							<td>{$item['time']}</td> <td>{$item['amount']}</td><td>{$currency_symbol}{$item['amount_log']}</td><td>{$item['note']}</td>
						</tr>
						{/query}
					</table>
					<div class="page-nav">{echo:$obj->pagebar()}</div>
				</div>
				<div>
					<table class="table table-list">
						<tr>
							<th width="140">时间</th> <th width="120">提现金额</th><th width="120">名称</th> <th >账号</th> <th style="width:80px">状态</th>
						</tr>
						{query:name=withdraw where=user_id eq $user[id] page=1 id=$withdraw}
						<tr class="{if:$key%2==1}odd{else:}even{/if} {if:$item['status']==2}noborder{/if}">
							<td width="140">{$item['time']}</td> <td width="120">{$currency_symbol}{$item['amount']}</td><td width="120">{$item['type_name']}</td> <td >{$item['account']}</td> <td style="width:80px">{if:$item['status']==0}<span class="red">处理中</span>{elseif:$item['status']==1}<b class="green">提现成功</b>{else:}<span class="gray">失败</span>{/if}</td>
						</tr>
						{if:$item['status']==2}
						<tr>
							<td colspan="5" style="padding-left:20px;"><p>处理意见：{$item['re_note']} </p></td>
						</tr>
						{/if}
						{/query}
					</table>
					<div class="page-nav">{echo:$withdraw->pagebar()}</div>
				</div>
			</div>
		</div>
	</div>
	</div>
</div>
<div id="recharge-dialog" style="display:none"  >
	<form action="{url:/payment/dopay}"  method="post" formMsg="recharge-info" target="_blank" callback="close_dialog">
		<ul class="tiny-form hidden-msg" style="padding:20px 20px 0 20px;">
			<li class="line" style="height:20px;">
				<div id="recharge-info" class="alert alert-fail" style="display:none;"></div>
			</li>
			<li class="line caption">
				<label class="caption">充值金额：</label>
				<input class="field" type="text" name="recharge"  pattern="float" alt="最小金额不小于0.01"> <label></label>
			</li>
			<li class="line other">
				<label class="caption">支付方式：</label>
				<select class="field" name="payment_id">
					{query:name=payment as py fields=py.* join= left join pay_plugin as pp on py.plugin_id eq pp.id where=py.status eq 0 and pp.class_name ne 'balance' and pp.class_name ne 'received' order=sort desc}
					<option value="{$item['id']}">{$item['pay_name']}</option>
					{/query}
				</select>
			</li>
			<li class="line tc">
				<input type="submit" class="btn btn-main" value="立刻充值">
			</li>
		</ul>
	</form>
</div>
<div  id="withdraw-dialog" style="display:none" >
	<form id="withdraw_form" action="{url:/ucenter/withdraw}" method="post" target="_blank" callback="submit_withdraw" formMsg="withdraw-info">
		<ul class="tiny-form hidden-msg " style="padding:20px;">
		<li class="line" style="height:20px;">
				<div id="withdraw-info" class="alert alert-fail" style="display:none;"></div>
			</li>
			<li class="line caption">
				<label class="caption">账户金额：</label>
				<div class="field disabled">{$currency_symbol}{$customer['balance']}</div>
			</li>
			<li class="line caption ">
				<label class="caption">提现金额：</label>
				<input type="text" id="w_amount" name="amount" class="field"  pattern="float" min="1" max="{$customer['balance']}" alt="允许提现金额(1 - {$customer['balance']})"> <label></label>
			</li>
			<li class="line caption">
				<label class="caption">账户名/开户名：</label>
				<input type="text" class="field" id="w_name" name="name"  pattern="required" alt="开户对应的用户名"> <label></label>
			</li>
			<li class="line caption">
				<label class="caption">名称/开户行：</label>
				<input type="text" class="field" id="w_type_name" name="type_name"  pattern="required" alt="如（支付宝、中国银行）"> <label></label>
			</li>
			<li class="line caption">
				<label class="caption">账号/卡号：</label>
				<input type="text" class="field" id="w_account" name="account"  pattern="required" alt="如（支付宝账号、银行账号）"> <label></label>
			</li>
			<li class="line">
				<div class="tc"><input type="submit" class="btn btn-main" value="申请提现"></div>
			</li>
		</ul>
	</form>
</div>
<script type="text/javascript">
	$("#recharge-btn").on("click",function() {
		layer.open({
                  id:'rechargeDialog',
                  type: 1,
                  title: '充值',
                  move: false,
                  shade: 0.6,
                  area: ['460px', '300px'],
                  content: $('#recharge-dialog') //iframe的url
                });
	});
	$("#withdraw-btn").on("click",function() {
		layer.open({
                  id:'withdrawDialog',
                  type: 1,
                  title: '充值',
                  move: false,
                  shade: 0.6,
                  area: ['520px', '500px'],
                  content: $('#withdraw-dialog') //iframe的url
                });
	});
	function close_dialog(e){
		if(!e)layer.closeAll();
	}
	function submit_withdraw(e){
		if(!e){
			var name = $("#w_name").val();
			var type_name = $("#w_type_name").val();
			var account = $("#w_account").val();
			var amount = $("#w_amount").val();
			$.get("{url:/ucenter/withdraw}",{name:name,type_name:type_name,account:account,amount:amount},function(data){
				if(data['status']=='success'){
					layer.closeAll();
					window.location.href = "{url:/ucenter/account/rand/}"+Math.random()+"#tab-1";
				}else{
					layer.msg(data['msg']);
				}
			},'json');
		}
		return false;
	}
</script>
