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

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <div class="m-userbox m-buserbox">
        <div class="m-prompt pl10 pr10 mt20">
            <div class="prompt-left g-left mt10">
                联系专属客服：<div class="mt10 fs14 g-fcenter"><% =CurrentUser.GetService() %></div>
            </div>
            <div class="prompt-small g-right">
                <p>提供正确的借款相关资料将有助于您提升信用等级、获得更高的授信额度以及更快的获得投资人的青睐。</p>
                <p>详细情况具体请查看 <a href="/Help/" target="_blank">帮助中心</a>。</p>
            </div>
        </div>
        <div class="pt5 pb50">
            <div class="form-big">
                <a href="BorrowInfoList<% =PageExt %>" class="g-right mb10 mr10"> << 返回列表页</a>
                <form class="js-auto js-vtip" method="post" action="<% =Request.RawUrl.UrlEncodeParam() %>" data-onsuccess="location.href='BorrowInfoList<%= PageExt %>';">
                    <ruson:Space runat="server" ID="edit" Visible="true">
                        <table width="100%" class="m-jsonfrom mt20">
                            <tbody>
                                <tr>
                                    <th>资料名称</th>
                                    <td class="js-tip">
                                        <input type="text" name="name" maxlength="100" placeholder="请输入资料名称" value="<% =Model == null ? string.Empty : Model.Name.HtmlEncode() %>" data-vtype="must" data-vmsg="资料名称不能为空"></td>
                                </tr>
                                <tr>
                                    <th>借款资料类型</th>
                                    <td><ruson:Select runat="server" ID="borrowInfoTypeId"></ruson:Select></td>
                                </tr>
                            </tbody>
                        </table>
                        <div class="btn-submits mt10 ml152">
                            <input type="submit" value="保 存" class="btn-bbord c-normal fs16 w252" data-success-text="保存成功">
                            <div class="w252"><em class="m-sumtip js-vsum"></em></div>
                        </div>

                    </ruson:Space>
                    <ruson:Space runat="server" ID="view" Visible="false">
                        <table width="100%" class="m-jsonfrom mt20">
                            <tr>
                                <th>资料名称</th>
                                <td><% =Model.Name %></td>
                            </tr>
                            <tr>
                                <th>借款资料类型</th>
                                <td><% =BorrowInfoType.LoadOrNew(Model.BorrowInfoTypeId).Name %></td>
                            </tr>
                            <asp:Repeater runat="server" ID="rptViewFormFields" ItemType="WAP2P.Sys.FormField">
                                <ItemTemplate>
                                    <%# Item.BuildHtml("<tr><th>{%=Name%}</th><td>{%=Value%}</td></tr>", false) %>
                                </ItemTemplate>
                            </asp:Repeater>
                            <tr>
                                <th>审核状态</th>
                                <td><% =Model.Status.GetDescription() %></td>
                            </tr>
                            <% if (Model.Status == WAP2P.Member.BorrowInfo.ValidStatus.ValidSuccess)
                               { %>
                            <tr>
                                <th>市场参考价格</th>
                                <td><% =Model.MarketPrice.ToMoneyString() %> 元</td>
                            </tr>
                            <tr>
                                <th>评估价值</th>
                                <td><% =Model.AssessmentPrice.ToMoneyString() %> 元</td>
                            </tr>
                            <tr>
                                <th>借款授信额度</th>
                                <td><% =Model.Quota.ToMoneyString() %> 元</td>
                            </tr>
                            <tr>
                                <th>资料有效期</th>
                                <td><% =Model.Expires.ToDateString("长期") %></td>
                            </tr>
                            <%} %>
                        </table>
                    </ruson:Space>
                </form>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script src="<% =this.ImportJsCss("~/res/uploadify/jquery.uploadify.min.js") %>"></script>
    <script src="<% =this.ImportJsCss("/res/core/scripts/areadata.js") %>"></script>

    <script>
        var borrowTypeChange = function() {
            var sel = $('#borrowInfoTypeId'); tr = sel.closest('tr');
            $.get('?action=template&Id=<% =Model == null ? string.Empty : Model.Id.ToString() %>&borrowInfoTypeId=' + sel.val(), function(res) {
                tr.nextAll('tr').each(function(i, n) {
                    n.parentNode.removeChild(n);
                })
                tr.after(res);
                formService.init();
            });
        };
        $('#borrowInfoTypeId').change(borrowTypeChange);
        borrowTypeChange();

        //配合后端的表单编辑的js
        var formService = {
            initJs: function() {
                $('script.js-script').each(function (i, n) {
                    eval(n.innerHTML);
                });
            },
            initUpload: function(id, multi, isfile) {
                setTimeout(function () {
                    $('#' + id + 'File').uploadify({
                        width: 96,
                        height: 34,
                        multi: multi ? true : false,
                        removeTimeout: 0,
                        swf: '/res/uploadify/uploadify.swf?v=<% =CryptoHelper.Random(100000,999999) %>',
                        uploader: '/res/uploadify/SwfUpload.aspx?type=' + (isfile ? 'file' : 'image'),
                        buttonClass:'btn-nobordbig c-normal',
                        buttonText: '上传' + (isfile ? '文件' : '图片'),
                        fileTypeExts: isfile ? '<% =WAP2P.Web.PC.Admin.Res.uploadify.SwfUpload.AllowFiles %>' : '<% =WAP2P.Web.PC.Admin.Res.uploadify.SwfUpload.AllowImages %>',
                        formData: {
                            <% =WAP2P.Web.User.Membership.CookieName %> : '<% =Request.Cookies[WAP2P.Web.User.Membership.CookieName].Value %>'
                        },
                        onUploadSuccess: function(res, data) {
                            eval('var d = ' + data);
                            if (d.Success) {
                                var showHtml = isfile ? '<a href="' + d.Message + '" target="_blank"><span class="iconfont fs24">&#xe631;</span> 下载查看</a>' : '<a href="' + d.Message + '" target="_blank"><img width="150" src="' + d.Message + '" alt="" /></a>';
                                if (multi) {
                                    var vals = $('#' + id + 'Input');
                                    vals.append('<input type="hidden" name="' + id + '" value="' + d.Message + '" />');
                                    vals.find('.js-uploadMustInput').val(d.Message).trigger('blur');
                                    $('#' + id + 'Result').append(showHtml);
                                } else {
                                    $('#' + id).val(d.Message).trigger('blur');
                                    $('#' + id + 'Result').html(showHtml);
                                }
                            } else {
                                $.jError(d.Message);
                            }
                        }
                    });
                }, 10);
            },
            init: function() {
                formService.initJs();
                $('input.js-imageUpload').each(function(i, n) {
                    n = $(n);
                    formService.initUpload(n.attr('data-id'), false, false);
                });
                $('input.js-imageMultiUpload').each(function(i, n) {
                    n = $(n);
                    formService.initUpload(n.attr('data-id'), true, false);
                });
                $('input.js-fileUpload').each(function(i, n) {
                    n = $(n);
                    formService.initUpload(n.attr('data-id'), false, true);
                });
                $('input.js-fileMultiUpload').each(function(i, n) {
                    n = $(n);
                    formService.initUpload(n.attr('data-id'), true, true);
                });

                //自定义表单多图片或文件上传处理
                $('.ui-imageuploadmulti, .ui-fileuploadmulti').on('mouseenter', 'a', function () {                    
                    $(this).append($('<i class="iconfont fs16 iconsDelete" title="删除">&#xe605;</i>').click(function() {
                        var a = $(this).closest('a'), src = a.attr('href');
                        var inputs = a.closest('div').next();
                        inputs.find('[value="' + src + '"]').not('.js-uploadMustInput').remove();
                        if (inputs.find('input').length == 1) inputs.find('.js-uploadMustInput').val('');
                        a.remove();
                        return false;
                    }));
                }).on('mouseleave', 'a', function () {
                    $(this).find('i').remove();
                });
            }
        };

        var imgObj=$('.ui-customuploads').before('<div class="customuploads-new"><div class="customuploads-col"></div><div class="customuploads-col"></div><div class="customuploads-col"></div></div>').find('img').each(function(){
            var me=$(this),
                myparent=me.parent(),
                newImgList=myparent.prev(),
                imgUrl=me.attr('src'),
                indexNum=me.index()+1;           
            if(indexNum%3==0){
                indexNum=2;
            }else if(indexNum%3==1){
                indexNum=0;
            }else{
                indexNum=1;
            };
            var tempH=0;
            newImgList.find('.customuploads-col').each(function(i,n){
                if(tempH>=$(this).outerHeight()){
                    tempH=$(this).outerHeight();
                    indexNum=i;
                }
            })
            newImgList.find('.customuploads-col').eq(indexNum).append('<a target="_blank" href="'+ imgUrl +'"><img src="'+ imgUrl +'" width="'+newImgList.find('.customuploads-col').width()+'" /></a>');
            if(myparent.find('img').length==newImgList.find('img').length){
                myparent.remove();
            }
        });
        $('.m-jsonfrom').imageWidthReset({ 'pWidth': 210 });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="list" runat="server">
    <asp:Repeater runat="server" ID="rptTemplateFormFields" ItemType="WAP2P.Sys.FormField">
        <ItemTemplate>
            <%# Item.BuildHtml("<tr><th>{%=Name%}</th><td>{%=Value%}</td></tr>", true , "field_") %>
        </ItemTemplate>
    </asp:Repeater>
</asp:Content>
