<%@ Page Title="" Language="C#" MasterPageFile="~/Master/UserMaster.master" CodeBehind="BorrowDetail.aspx.cs" Inherits="WAP2P.Web.PC.User.Borrow.BorrowDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <div class="m-userbox m-buserbox pb20">
        <div class="m-operback">
            <a href="BorrowSelect<% =PageBase.PageExt %>"><< 返回发布选择页</a>
        </div>
        <ruson:Space runat="server" ID="empty" Visible="false">
            <div class="mt20 ml30">
                <% =errorMsg %>
            </div>
        </ruson:Space>
        <ruson:Space runat="server" ID="edit">
            <form class="js-auto js-vtip" method="post" action="<% =Request.RawUrl.UrlEncodeParam() %>" data-beforeSubmit="initInterestInput();" data-onsuccess="common.pageTip('<% =PageBase.TipType.Success %>', '发布成功，请耐心等待管理员审核。', '/User/Borrow/BorrowList' + gconfig.pageExt, '我的借款记录');">
                <table class="m-jsonfrom mt20" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <th>借款类型</th>
                        <td><% =borrowType.Name %></td>
                    </tr>
                    <tr runat="server" id="mortgage" visible="false">
                        <th>抵押物品</th>
                        <td>
                            <select name="mortgageId" id="mortgageId">
                                <asp:Repeater runat="server" ID="rptMortgage">
                                    <ItemTemplate>
                                        <option value="<%# Eval("Id") %>" <%# borrow.MortgageId == (long)Eval("Id") ? "selected=\"selected\"" : string.Empty %> data-expires="<%# Eval("Expires") %>" data-quota="<%# ((decimal)Eval("Quota")).ToMoneyString() %>"><%# Eval("Name") %></option>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </select>
                            <span class="ml20">可用额度：<span class="fcred-2"></span> 元，到期：<span class="fcred-2"></span></span>
                        </td>
                    </tr>
                    <tr>
                        <th>借款标题</th>
                        <td>
                            <div class="input-big js-tip">
                                <input type="text" name="name" class="w400" placeholder="请填写您的借款标题" maxlength="50" value="<% =borrow.Name.HtmlEncode() %>" data-vtype="must" data-vmsg="请输入借款标题" />
                                <span class="prompt">建议使用少于25个字的内容表述您的借款需求。</span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>借款用途</th>
                        <td>
                            <div class="input-big js-tip">
                                <select id="js-userToSel">                                    
                                    <asp:Repeater runat="server" ID="rptUserTo">
                                        <ItemTemplate>
                                            <option value="<%# Container.DataItem %>"<%# (string)Container.DataItem == borrow.UseTo ? " selected=\"selected\"" : string.Empty %>><%# Container.DataItem %></option>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                    <option value="">手动指定</option>
                                </select>
                                <input type="text" name="useTo" id="js-useTo" maxlength="100" value="<% =borrow.UseTo.HtmlEncode() %>" placeholder="请填写您的详细借款用途" class="w300" data-vtype="must" data-vmsg="请输入借款用途" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>还款来源</th>
                        <td><input type="text" name="repaySrc" maxlength="100" value="<% =borrow.RepaySrc.HtmlEncode() %>" placeholder="如工资" class="w300" data-vtype="must" data-vmsg="请输入您的还款来源" /></td>
                    </tr>
                    <tr>
                        <th>借款金额</th>
                        <td>
                            <div class="input-big js-tip">
                                <input type="text" class="text input-moneyicon js-slider" name="loanAmount" id="loanAmount" value="<% =isNew ? borrowType.MinAmount.ToMoneyString() : borrow.LoanAmount.ToMoneyString() %>"
                                    data-vtype="money" data-vmsg="请输入正确的借款金额"
                                    data-slider-min="<% =borrowType.MinAmount.ToJsString() %>"
                                    data-slider-max="<% =maxAmount.ToJsString() %>"
                                    data-slider-step="<% =borrowType.ByStep ? borrowType.StepAmount.ToJsString() : "1" %>" />
                                <span class="prompt">最少<% =borrowType.MinAmount.ToMoneyString() %>元，最大<span id="js-maxAmount"><% =maxAmount.ToMoneyString() %></span>元<% = borrowType.ByStep ? string.Format("，请输入{0}元的倍数", borrowType.StepAmount.ToMoneyString()) : string.Empty %>。
                                </span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>借款期限</th>
                        <td>
                            <div class="input-big js-tip">
                                <input type="text" name="loanDate" value="<% =isNew ? string.Empty : borrow.LoanDate.ToString() %>" class="w100 ui-int" data-vtype="number" data-vmsg="请输入正确的借款期限" /> 
                                <span class="ui-radio pl5" id="loanTimeType">
                                    <asp:Repeater runat="server" ID="loanTimeType" ItemType="WAP2P.Sys.BorrowType.LoanTimeInfo">
                                        <ItemTemplate>
                                            <label><input type="radio" name="loanDateUnit" value="<%# (int)Item.Unit %>" data-min="<%# Item.Min %>" data-max="<%# Item.Max %>"<%# (isNew && Container.ItemIndex == 0) || borrow.LoanDateUnit == Item.Unit ? " checked=\"checked\"" : string.Empty %> /><%# Item.Unit.GetDescription() %></label>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </span>
                                <span class="prompt">最少<span class="fcred-2" id="js-minLoanTime"></span>，最大<span class="fcred-2" id="js-maxLoanTime"></span>。</span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>还款方式</th>
                        <td>
                            <div class="input-big g-mb10 js-tip">
                                <select name="repayment" id="repayment" data-vtype="must" data-vmsg="请选择还款方式">
                                    <option value="" data-minInterest="<% =(borrowType.MinInterest * 100).ToInterestString() %>%" data-maxInterest="<% =(borrowType.MaxInterest * 100).ToInterestString() %>%">请选择还款方式</option>
                                    <asp:Repeater runat="server" ID="rptRepayment">
                                        <ItemTemplate>
                                            <option value="<%# Eval("Item1") %>" <%# borrow.Repayment == (string)Eval("Item1") ? " checked=\"checked\"" : string.Empty %> data-minInterest="<%# (borrowType.MinInterest * 100).ToInterestString() %>%" data-maxInterest="<%# (borrowType.MaxInterest * 100).ToInterestString() %>%"><%# Eval("Item2") %></option>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </select>                                
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>借款利率(年化率)</th>
                        <td id="interestArea">
                            <div class="input-big js-tip" id="interestArea">
                                <% if(borrowType.MinInterest == borrowType.MaxInterest) { %>
                                <span class="fcred-2 js-mininterest"><% =(borrowType.MinInterest * 100).ToInterestString() %> %</span>
                                <input type="hidden" id="ui-interest" class="js-mininterest" value="<% =isNew ? (borrowType.MinInterest * 100).ToInterestString() : (WAP2P.Sys.FinanceHelper.DayRateTo(borrow.LoanInterest.First().DayRate, BorrowType.LoanTimeUnit.Year, borrow.InterestType, borrow.CreateAt.Year) * 100).RoundX().ToInterestString() %>" />
                                <% } else if(borrowType.InterestPeriod > 1) { %> 
                                    <span>
                                        <input type="text" class="w100 ui-interest input-percentageicon" data-vtype="money|range" data-vmax="100" data-vmsg="请输入正确的利率|利率需在0%-100%之间" value="<% =isNew ? string.Empty : (WAP2P.Sys.FinanceHelper.DayRateTo(borrow.LoanInterest.First().DayRate, BorrowType.LoanTimeUnit.Year, borrow.InterestType, borrow.CreateAt.Year) * 100).RoundX().ToInterestString() %>" />
                                    </span>
                                    <span class="pl10">(执行月利率约为<span class="js-ratem fcred-3"></span>，执行日利率约为<span class="js-rated fcred-3"></span>)</span>
                                    <ul class="ui-listvalue pt10" id="js-interestUl">
                                        <asp:Repeater runat="server" ID="rptInterestArea" ItemType="WAP2P.BorrowLoan.Borrow.LoanInterestInfo">
                                            <ItemTemplate>
                                                <li>
                                                    <a href="javascript:void(0)" class="iconfont fs22 listvalue-delete js-areaOper" title="删除">&#xe634;</a>
                                                    <div class="pt10">
                                                        投标金额大于或等于 
                                                        <input type="text" class="w100 ui-float input-moneyicon" data-vtype="money" value="<%# Item.Amount.ToMoneyString() %>" data-vmsg="请输入正确的金额" /> 时，执行年化率 
                                                        <input type="text" class="w100 ui-interest input-percentageicon" value="<%# (WAP2P.Sys.FinanceHelper.DayRateTo(Item.DayRate, BorrowType.LoanTimeUnit.Year, borrow.InterestType, borrow.CreateAt.Year) * 100).RoundX().ToInterestString() %>" data-vtype="money|range" data-vmax="100" data-vmsg="请输入正确的利率|利率需在0%-100%之间" />  。                
                                                    </div>
                                                </li>
                                            </ItemTemplate>
                                        </asp:Repeater>                                    
                                    </ul>
                                    <input type="button" class="btn-base c-normal iconfont js-areaOper" id="js-btnInterestArea" value="&#xe628; 新增利率区间" onclick="$('#js-interestUl').append(document.getElementById('tmpInterest').innerHTML);" />
                                    <span class="prompt">最小年化率<span class="fcred-2 js-mininterest"><% =(borrowType.MinInterest * 100).ToInterestString() %>%</span>，最大年化率<span class="fcred-2 js-maxinterest"><% =(borrowType.MaxInterest * 100).ToInterestString() %>%</span>。</span>
                                    <input type="hidden" id="interestPeriod" value="<% =borrowType.InterestPeriod - 1 %>" />
                                <% } else { %>
                                    <span><input type="text" class="w100 ui-interest" data-vtype="money|range" data-vmax="100" data-vmsg="请输入正确的利率|利率需在0%-100%之间" value="<% =isNew ? string.Empty : (WAP2P.Sys.FinanceHelper.DayRateTo(borrow.LoanInterest.First().DayRate, BorrowType.LoanTimeUnit.Year, borrow.InterestType, borrow.CreateAt.Year) * 100).RoundX().ToInterestString() %>" /> %</span>
                                    <span class="pl10">(执行月利率约为<span class="js-ratem fcred-3"></span>，执行日利率约为<span class="js-rated fcred-3"></span>)</span>
                                    <span class="prompt">最小年化率<span class="fcred-2 js-mininterest"><% =(borrowType.MinInterest * 100).ToInterestString() %>%</span>，最大年化率<span class="fcred-2 js-maxinterest"><% =(borrowType.MaxInterest * 100).ToInterestString() %>%</span>。</span>
                                <% } %>
                                <input type="hidden" name="loanInterestJson" id="loanInterestJson" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>投标结束时间</th>
                        <td>
                            <div class="input-big js-tip">
                                <input type="text" class="text w136 ui-date ui-datetime" placeholder="请设置结束时间" name="bidEndAt" value="<% =borrow.BidEndAt.ToDateTimeString() %>" data-mindate="<%= DateTime.Now.AddDays(1).ToDateTimeString() %>" />
                                <span class="prompt">如设定了结束日期，该笔借款将在设定的日期到期时结束。您也可以不设置，由后台审核人员为您指定。</span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>单次至少投资</th>
                        <td>
                            <div class="input-big js-tip">
                                <input type="text" name="bidMinAmount" value="<% =isNew ? borrowType.StepAmount.ToMoneyString() :borrow.BidMinAmount.ToMoneyString() %>" class="w100 ui-float input-moneyicon" />
                                <% =borrowType.ByStep ? string.Format("<span class='prompt'>请输入{0}的整数倍。</span>", borrowType.StepAmount.ToMoneyString()) : string.Empty %>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>最多可投金额</th>
                        <td>
                            <div class="input-big js-tip">
                                <input type="text" name="bidMaxAmount" value="<% =borrow.BidMaxAmount.ToMoneyString() %>" class="w100 ui-float input-moneyicon" />
                                <% =borrowType.ByStep ? string.Format("<span class='prompt'>请输入{0}的整数倍，为空则不限制。</span>", borrowType.StepAmount.ToMoneyString()) : string.Empty %>
                            </div>
                        </td>
                    </tr>
                    <% if(borrowType.AdvanceRepay != BorrowType.AdvanceRepayEnum.NoSupport) { %>                  
                    <tr>
                        <th>满标立即还款</th>
                        <td>
                            <div class="input-big g-mb10 js-tip">
                                <% =HtmlHelper.CheckBox("bidFullAutoRepay", "满标立即还款", borrow.BidFullAutoRepay) %>
                            </div>
                        </td>
                    </tr>
                    <% } %>
                    <tr>
                        <th>投标奖励</th>
                        <td>
                            <div class="ui-radio" id="bidReward">
                                <label><input type="radio" name="bidRewardType" value="<% =(int)WAP2P.BorrowLoan.Borrow.BidReward.None %>"<% =borrow.BidRewardType == WAP2P.BorrowLoan.Borrow.BidReward.None ? " checked=\"checked\"" : string.Empty %> /> <% =WAP2P.BorrowLoan.Borrow.BidReward.None.GetDescription() %></label>                                
                                <label><input type="radio" name="bidRewardType" value="<% =(int)WAP2P.BorrowLoan.Borrow.BidReward.BidAmountRatio %>"<% =borrow.BidRewardType == WAP2P.BorrowLoan.Borrow.BidReward.BidAmountRatio ? " checked=\"checked\"" : string.Empty %> /> <% =WAP2P.BorrowLoan.Borrow.BidReward.BidAmountRatio.GetDescription() %></label>
                                <span class="g-hide"><input type="text" name="bidRewardRatio" class="ui-interest w100" value="<% =borrow.BidRewardRatio.HasValue ? (borrow.BidRewardRatio.Value * 100).ToInterestString() : string.Empty %>" data-vtype="money" data-vmsg="请输入正确的值" data-vmust="false" /> %</span>
                            </div>
                        </td>
                    </tr>
                    <asp:Repeater runat="server" ID="rptBorrowUserFilters">
                        <ItemTemplate>
                            <tr>
                                <th><%# Eval("Item2") %></th>
                                <td><%# ConfigService.GetConfig<WAP2P.BorrowLoan.IBorrowUserFilter>((string)Eval("Item1")).SettingHtml(borrow.UserFilterInterfaces == null ? null : (borrow.UserFilterInterfaces.FirstOrDefault(item => item.Id == (string)Eval("Item1")) ?? new ExtensionSetting()).Setting) %></td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                    <tr>
                        <th>定向密码</th>
                        <td>
                            <div class="input-big g-mb10 js-tip">
                                <input type="text" name="passwordCode" value="<% =borrow.PasswordCode.HtmlEncode() %>" class="text w218" maxlength="50" />
                                <span class="prompt">如设置了定向密码则投资人必须输入设置的密码方可成功投资。</span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>信息公开</th>
                        <td>
                            <div class="ui-checkbox">
                                <div class="mt5">
                                    <% =HtmlHelper.CheckBox("openMyInfo", "公开基本信息资料", borrow.OpenMyInfo) %>
                                    <span class="ml20"><% =HtmlHelper.CheckBox("openMyBorrowInfo", "公开我的借款资料", borrow.OpenMyBorrowInfo) %></span>
                                </div>
                                <div class="mt5">
                                    <% =HtmlHelper.CheckBox("openMyBid", "公开我的投资记录", borrow.OpenMyBid) %>
                                    <span class="ml20"><% =HtmlHelper.CheckBox("openMyBorrow", "公开我的借款记录", borrow.OpenMyBorrow) %></span>
                                </div>
                                <div class="mt5">
                                    <% =HtmlHelper.CheckBox("openMyQuota", "公开我的额度状况", borrow.OpenMyQuota) %>
                                    <span class="ml20"><% =HtmlHelper.CheckBox("openMyAccount", "公开我的资金账户", borrow.OpenMyAccount) %></span>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>补充说明</th>
                        <td>
                            <div style="width:500px; height:200px ; overflow:hidden;">
                                <script id="detail" name="detail" class="ui-editor" type="text/plain"><%= borrow.Detail %></script>
                            </div>
                        </td>
                    </tr>
                </table>
                <div class="btn-submits mt10 ml250">
                    <input type="submit" value="提 交" class="button btn-bbord c-normal fs16 w252" data-success-text="提交成功">
                    <div class="w252"><em class="m-sumtip js-vsum"></em></div>
                </div>
            </form>
        </ruson:Space>
    </div>
    <script type="text/template" id="tmpInterest">
        <li>
            <a href="javascript:void(0)" class="iconfont fs14 listvalue-delete js-areaOper" title="删除">&#xe634;</a>
            <div class="pt10">
                投标金额大于或等于<input type="text" class="w100 ui-float input-moneyicon" data-vtype="money" data-vmsg="请输入正确的金额" /> 时，执行年化率 <input type="text" class="w100 ui-interest input-percentageicon" data-vtype="money|range" data-vmax="100" data-vmsg="请输入正确的利率|利率需在0%-100%之间" />  。               
            </div>
        </li>
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script src="<% =this.ImportJsCss("/res/ueditor/ueditor.config.js") %>"></script>
    <script src="<% =this.ImportJsCss("/res/ueditor/ueditor.all.min.js") %>"></script>
    <script>
        //开关切换
        function toggleRadioNext(td) {
            $(td).find(':radio').each(function (i, n) {
                var next = $(n).parent().next();
                if (next.length && next[0].tagName == 'SPAN') {
                    if (n.checked) {
                        next.show();
                        next.find(':input').attr('data-vmust', 'true');
                    }
                    else {
                        next.hide();
                        next.find(':input').attr('data-vmust', 'false');
                    }
                }
            });
        };

        //还款方式
        var repaymentChange = function () {
            var op = $('#repayment :selected');
            $('.js-mininterest').val(op.attr('data-minInterest')).text(op.attr('data-minInterest'));
            $('.js-maxinterest').val(op.attr('data-maxInterest')).text(op.attr('data-maxInterest'));
        };
        repaymentChange();
        $('#repayment').change(repaymentChange);

        //抵押
        $(function () {
            var mortgageId = $('#mortgageId');
            var mortgageChange = function () {
                var sel = mortgageId.find(':selected');
                mortgageId.next().find('span:first').text(sel.attr('data-quota'));
                mortgageId.next().find('span:last').text(sel.attr('data-expires'));
                $('#js-maxAmount').text(sel.attr('data-quota'));
                $('#loanAmount').slider('revise', { max: parseFloat(sel.attr('data-quota').replace(/,/ig, '')) });

            };
            if (mortgageId.length) {
                mortgageId.change(mortgageChange);
                mortgageChange();
            }
        });        

        //用途
        $('#js-userToSel').change(function () {
            var val = $(this).val(), to = $('#js-useTo');
            if (val) {
                to.hide();
                to.val(val);
            } else {
                to.show();                
            }
        }).trigger('change');

        //时间
        $('#loanTimeType :radio').click(function () {
            var me = $(this), txt = me.parent().text();
            $('#js-minLoanTime').text(me.attr('data-min') + txt);
            $('#js-maxLoanTime').text(me.attr('data-max') + txt);
        }).filter(':checked').trigger('click');

        //利率
        var intersetReset = function (dom) {
            dom = $(dom);
            var val = parseFloat(dom.val()), ctr = dom.closest('span').next();
            ctr.find('.js-ratem').html(finance.yearRateTo(val, 'm'));
            ctr.find('.js-rated').html(finance.yearRateTo(val, 'd'));
        };
        $('#interestArea .ui-interest').each(function (i, n) {
            intersetReset(n);
        }).keyup(function () {
            intersetReset(this);
        });

        var interestAddbtn = $('#js-btnInterestArea');
        var interestBtnToggle = function () {
            if ($('#js-interestUl li').length >= parseInt($('#interestPeriod').val()))
                interestAddbtn.hide();
            else
                interestAddbtn.show();
        };
        $('#interestArea').on('click', '.js-areaOper', function () {
            var parent = $(this).parent();
            if (parent.is('li'))
                parent.remove();

            interestBtnToggle();
        });
        interestBtnToggle();

        function initInterestInput() {
            var obj = [];
            var interests = $('#interestArea .ui-interest'), amounts = $('#interestArea .ui-float');
            interests.each(function (i, n) {
                obj.push({
                    Amount: i == 0 ? 0 : parseFloat($(amounts.eq(i - 1)).val().replace(/,/g, '')),  //第一个为默认
                    DayRate: parseFloat($(n).val())  //注意这里是年化率，需在服务端重新算
                });
            });
            $('#loanInterestJson').val(utils.toJsonString(obj));
        }

        toggleRadioNext('#bidReward');
        $('#bidReward :radio').click(function () { toggleRadioNext('#bidReward') });

        toggleRadioNext('#vouchReward');
        $('#vouchReward :radio').click(function () { toggleRadioNext('#vouchReward') });

    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="list" runat="server">
</asp:Content>
