<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MainMaster.master" CodeBehind="Calculator.aspx.cs" Inherits="WAP2P.Web.PC.Tool.Calculator" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">.m-bg{min-width:initial;}</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">    
    <div class="m-page m-calculator">
        <div class="m-container g-zindexmin g-ohide mt20 mb20">
            <dl class="ui-tab">                
                <dt><a href="Calculator<% =PageBase.PageExt %>" class="on">理财计算器</a></dt>
                <dt><a href="Risk<% =PageBase.PageExt %>">抗风险评测</a></dt>
                <dd>
                    <div class="form-normal mt40 pl30 pr30 g-left calculator-form">
                        <h4 class="fcblack-3 fs16 mb30">输入参数</h4>
                        <form class="js-auto js-vtip" method="post" action="<% =Request.RawUrl.UrlEncodeParam() %>" data-onsuccess="calculate();" >
                            <div class="input-big">
                                <label class="topfont">投资金额：</label>
                                <input type="text" class="text w290 ui-int input-moneyicon" id="amount" name="amount" value="<% =Request.QueryString["amount"].HtmlEncode() %>" placeholder="请输入您要投资的金额" data-vtype="range" data-vmin="1" data-vmax="99999999" data-vmsg="请输入正确的投资金额" onblur="if($(this).val() > 99999999) $(this).val(99999999);" />
                            </div>
                            <div class="input-big">
                                <label class="topfont">年化率：</label>
                                <input type="text" class="text w290 ui-float input-percentageicon" name="interest" value="<% =Request.QueryString["interest"].HtmlEncode() %>" placeholder="请输入年化率" data-vtype="range" data-vmin="1" data-vmax="99" data-vmsg="请输入正确的年化率" onblur="if($(this).val() > 99) $(this).val(99);" />
                            </div>
                            <div class="input-big">
                                <label class="topfont">借款期限：</label>
                                <input type="text" class="text w290 ui-int input-monthicon" name="repayAt" value="<% =Request.QueryString["month"].HtmlEncode() %>" placeholder="请输入借款期限" data-vtype="range" data-vmin="1" data-vmax="36" data-vmsg="请输入1-36之间的借款期限" onblur="if($(this).val() > 36) $(this).val(36);" />
                            </div>
                            <div class="ui-radio js-tip">
                                <span class="g-block">还款类型：</span>
                                <asp:Repeater runat="server" ID="rptRepayment">
                                    <ItemTemplate>
                                        <label><input type="radio" name="type" value="<%# Eval("Item1") %>"<%# (string.IsNullOrEmpty(Request.QueryString["repayType"]) ? Container.ItemIndex == 0 : Request.QueryString["repayType"] == (string)Eval("Item1")) ? " checked=\"checked\"" : string.Empty %> /><%# Eval("Item2") %></label>
                                    </ItemTemplate>
                                </asp:Repeater>                                
                            </div>
                            <div class="btn-submits">       
                                <input type="submit" class="btn-bbord c-normal fs18 mt10 w324" value="确 定" />
                                <div class="w324"><em class="m-sumtip js-vsum"></em></div>
                            </div>
                        </form>
                    </div>
                    <div class="g-right calculator-infor">
                        <h4 class="fcblack-3 fs16 mt40 mb30">统计</h4>
                        <ul>
                            <li>本息合计：￥<span class="js-total fcred-3 fs20">0</span></li>
                            <li>利息收入共：￥<span class="js-interest fcred-3 fs20">0</span></li>
                        </ul>
                        <h4 class="fcblack-3 fs16 mt30">本息收款时间表</h4>
                        <table class="table-normal mt10 m-boborder js-ajaxlist">
                            <tr>
                                <th style="width: 25%;">期数</th>
                                <th style="width: 25%;">回款总额（元）</th>
                                <th style="width: 25%;">回款本金（元）</th>
                                <th style="width: 25%;">回款利息（元）</th>
                            </tr>
                        </table>
                    </div>
                </dd>
            </dl>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script>
        function calculate() {
            var res = window['ajaxResponseData'];
            if (res && res.Success) {
                var jsonData = eval(res.Message);
                var html = '';
                var content = $('.js-ajaxlist').find('tr:first');
                var total = 0;
                var interest = 0;
                content.nextAll().remove();

                $.each(jsonData, function (i, item) {
                    html += '<tr><td>' + item.Period + '</td>';
                    html += '<td>' + finance.toMoneyString(item.ShouldRepayPrincipal + item.ShouldRepayInterest) + ' 元</td><td>' + finance.toMoneyString(item.ShouldRepayPrincipal) + ' 元</td><td>' + finance.toMoneyString(item.ShouldRepayInterest) + ' 元</td></tr>'
                    total += (item.ShouldRepayPrincipal + item.ShouldRepayInterest);
                    interest += item.ShouldRepayInterest;
                });
                $('.js-total').html(finance.toMoneyString(total));
                $('.js-interest').html(finance.toMoneyString(interest.toFixed(2)));
                content.after(html);
            }
        }

        $(function () {
            if ($('#amount').val()) {
                $('form.js-auto').trigger('submit');
            }
        });        
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="list" runat="server">
</asp:Content>
