<%@ Page Title="" Language="C#" MasterPageFile="~/Master/UserMaster.master" CodeBehind="RepayList.aspx.cs" Inherits="WAP2P.Web.PC.User.Borrow.RepayList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <div class="m-userbox">
        <dl class="ui-tab">
            <dt><a href="javascript:void(0);" class="on">还款操作</a></dt>
            <dt><a href="RepayRecordList<% =PageBase.PageExt %>">还款记录</a></dt>
            <dd>
                <div class="m-prompt pl10 pr10 mt20">
                    <div class="prompt-left g-left mt10">
                        开启自动还款：
                        <div class="ui-toggle mt10 ml40 js-toggle">
                            <label class="<% =isAutoRepay ? "on" : string.Empty %>">
                                <input type="checkbox" name="autoRepay" <% =isAutoRepay ? "checked=\"checked\"" : string.Empty %> />
                            </label>
                        </div>
                    </div>
                    <div class="prompt-small g-right">
                        <p>开启自动还款后，需保证您的账户中有足够的可用余额，系统将在借款到期前半小时内自动进行还款操作，避免您因遗忘还款时间而造成不必要的损失。</p>
                        <p>详细情况具体请查看 <a href="/Help/" target="_blank">帮助中心</a>。</p>
                    </div>
                </div>
                <form action="?action=search" method="get" class="search"></form>
                <table class="table-normal mt20 js-ajaxlist">
                    <tr>
                        <th style="width: 18%;">借款名称</th>
                        <th style="width: 8%;">期数</th>
                        <th style="width: 15%;">应还本金</th>
                        <th style="width: 12%;">应还利息</th>
                        <th style="width: 12%;">费用</th>
                        <th style="width: 12%;">逾期罚息</th>
                        <th style="width: 17%;">应还时间</th>
                        <th style="width: 12%;">操作</th>
                    </tr>
                </table>
            </dd>
        </dl>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script>
        $('input[name=autoRepay]').change(function(){
            setAutoPayments($(this).is(":checked") ? "1" : "0");
        });

        function setAutoPayments(type) {
            $.ajax({
                type: 'get',
                url: location.href,
                cache: false,
                data: { action: 'setAuto', t: type },
                dataType: 'json',
                success: function (res) {
                     $('.js-toggle :checkbox').toggle('changeClick', res.Success);                    
                }
           });
        }

        $('.js-ajaxlist').on('click', '.js-repay', function () {            
            var me = $(this);
            $.ajax({
                type: 'get',
                url: location.href,
                cache: false,
                data: { action: 'advanceRepayCheck', id: me.attr('data-id') },
                dataType: 'json',
                success: function (res) {
                    if (res.Success) {
                        if (res.Message) {
                            $.jConfirm(res.Message, function () {
                                member.pay('<% =(int)WAP2P.Account.AccountActionType.本金还款 %>', 'repayId=' + me.attr('data-id'), function () {
                                    $('form.search').trigger('submit');
                                });
                            });
                        } else {
                            member.pay('<% =(int)WAP2P.Account.AccountActionType.本金还款 %>', 'amount=' + me.attr('data-money') + '&repayId=' + me.attr('data-id'), function () {
                                $('form.search').trigger('submit');
                            });
                        }
                    } else
                        $.jError(res.Message);
                }
            });            
        });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="list" runat="server">
    <ruson:Repater runat="server" ID="rptRepayList" ItemType="WAP2P.BorrowLoan.Repay">
        <ItemTemplate>
            <tr>
                <td class="g-fleft"><a href="<%# WAP2P.Web.Extensions.GetBorrowUrl(Item.BorrowId) %>"><%# Item.BorrowName.LeftX(20) %></a></td>
                <td>第<%# Item.Period %>期</td>
                <td class="fcred-3"><%# Item.ShouldRepayPrincipal.ToMoneyString() %> 元</td>
                <td class="fcred-3"><%# Item.ShouldRepayInterest.ToMoneyString() %> 元</td>                
                <td class="fcred-3"><%# Item.ShouldRepayFee.ToMoneyString() %> 元</td>                
                <td class="fcred-3"><%# Item.ShouldRepayOverdue.ToMoneyString() %> 元</td>
                <td><%# Item.ShouldRepayAt.ToDateTimeString() %></td>
                <td><%# Item.Status != WAP2P.BorrowLoan.Repay.RepayStatus.UserRepayment ? string.Format("<input type='button' data-id='{0}' data-money='{1}' class='btn-bordmini c-minibtn js-repay' value='还款' />", Item.Id, Item.ShouldRepayPrincipal + advanceRepayInterest + advanceRepayViolate + Item.ShouldRepayOverdue + Item.ShouldRepayFee) : Item.Status.GetDescription() %></td>
            </tr>
        </ItemTemplate>
        <EmptyTemplate>
            <tr>
                <td colspan="8" class="g-fleft">暂无数据。</td>
            </tr>
        </EmptyTemplate>
    </ruson:Repater>
    <tr class="pager">
        <td colspan="8">
            <div class="ui-pages g-fright">
                <ruson:Pager runat="server" ID="pages" CssClass="pages" />
                <a href="<% =Request.RawUrl.UrlEncodeParam() %>" class="g-hide"></a>
            </div>
        </td>
    </tr>
</asp:Content>
