<%@ Page Title="" Language="C#" MasterPageFile="../BaseMaster.Master" CodeBehind="BorrowInfoDetail.aspx.cs" Inherits="WAP2P.Web.PC.Admin.Member.BorrowInfoDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <form class="auto" method="post" action="<% =Request.RawUrl %>"  onsuccess="parent.$.jPopupEdit.close(true);">
        <div class="m-editbar">
            <% =Request.QueryString["action"]  == "view" ? string.Empty : "<input type=\"submit\" class=\"btn-larger c-priority iconfont\" value=\"&#xe684; 保存\" />" %>
            <input type="button" class="btn-larger c-normal iconfont" value="&#xe634; 关闭" onclick="parent.$.jPopupEdit.close();" />
        </div>
        <div class="m-content m-editcontent">                        
            <ruson:Space runat="server" ID="edit" Visible="false">
                <table class="m-info" cellpadding="0" cellspacing="0" width="100%">                
                    <tr>
                        <th>会员账号</th>
                        <td>
                            <input type="text" id="userName" name="userName" placeholder="请选择资料所有者账号" class="w150 g-valign" maxlength="30" value="<% =Model.UserId == 0 ? string.Empty : WAP2P.Member.User.LoadOrNew(Model.UserId).Name.HtmlEncode() %>" data-vtype="must" data-vmsg="请输入会员账户" />
                            <input type="button" class="btn-base c-normal iconfont g-valign" value="&#xe60f;" onclick="$.jPopupEdit('选择会员账号', '../Common/UserSelect.aspx?radio=true&fn=selectUser');" />
                            <script>
                                function selectUser(obj) {
                                    if (obj && obj.users && obj.users.length)
                                        $('#userName').val(obj.users[0].name);
                                }
                            </script>
                        </td>
                    </tr>
                    <tr>
                        <th>资料名称</th>
                        <td><input type="text" name="name" class="w300" maxlength="100" placeholder="请输入资料名称" value="<% =Model.Name.HtmlEncode() %>" data-vtype="must" data-vmsg="资料名称不能为空" /></td>
                    </tr>              
                    <tr>
                        <th>借款资料类型</th>
                        <td><ruson:Select runat="server" ID="borrowInfoTypeId"></ruson:Select></td>
                    </tr>          
                </table>
            </ruson:Space>
            <ruson:Space runat="server" ID="view" Visible="false">
                <table class="m-info" cellpadding="0" cellspacing="0" width="100%">                
                    <tr>
                        <th>会员账号</th>
                        <td class="g-fbold"><% =GetUserDisplay(Model.UserId , Model.UserName) %></td>
                    </tr>
                    <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 class="info-listhead" colspan="2">审核/授额 信息</th>
                    </tr>
                    <tr>
                        <th>状态</th>
                        <td><% =Model.Status.GetDescription() %></td>
                    </tr>
                    <% if(Model.ValidAt.HasValue) { %>                                 
                    <tr>
                        <th>市场参考价格</th>
                        <td><% =Model.MarketPrice.ToMoneyString() %> 元</td>
                    </tr>
                    <tr>
                        <th>评估价值</th>
                        <td><% =Model.AssessmentPrice.ToMoneyString() %> 元</td>
                    </tr>
                    <tr>
                        <th>审核备注</th>
                        <td><% =Model.ValidRemark.BrEncode() %></td>
                    </tr>
                    <tr>
                        <th>审核信息</th>
                        <td><% =Model.ValidAt.HasValue ? string.Format("操作员 {0} 于 {1} 执行审核操作！", Model.ValidBy, Model.ValidAt.ToDateTimeString()) : string.Empty %></td>
                    </tr>
                    <tr>
                        <th>资料有效期</th>
                        <td><% =Model.Expires.ToDateString("长期") %></td>
                    </tr>
                    <tr>
                        <th>借款授信额度</th>
                        <td><% =Model.QuotaAt.HasValue ? Model.Quota.ToMoneyString() + " 元" : "待授额" %></td>
                    </tr>
                    <tr>
                        <th>授额信息</th>
                        <td><% =Model.QuotaAt.HasValue ? string.Format("操作员 {0} 于 {1} 执行授额操作！", Model.QuotaBy, Model.QuotaAt.ToDateTimeString()) : "待授额" %></td>
                    </tr>
                    <% } %>
                </table>
            </ruson:Space>
            <ruson:Space runat="server" ID="valid" Visible="false">
                <table class="m-info" cellpadding="0" cellspacing="0" width="100%">                
                    <tr>
                        <th>会员账户</th>
                        <td class="g-fbold"><% =GetUserDisplay(Model.UserId , Model.UserName) %></td>
                    </tr>
                    <tr>
                        <th>资料名称</th>
                        <td><% =Model.Name %></td>
                    </tr>              
                    <tr>
                        <th>借款资料类型</th>
                        <td><% =BorrowInfoType.LoadOrNew(Model.BorrowInfoTypeId).Name %></td>
                    </tr>
                    <asp:Repeater runat="server" ID="rptValidFormFields" ItemType="WAP2P.Sys.FormField">
                        <ItemTemplate>
                            <%# Item.BuildHtml("<tr><th>{%=Name%}</th><td>{%=Value%}</td></tr>", false) %>
                        </ItemTemplate>
                    </asp:Repeater>
                    <tr>
                        <th class="info-listhead" colspan="2">审核</th>
                    </tr>
                    <tr>
                        <th>审核状态</th>
                        <td>
                            <div class="ui-radio">
                                <label><input type="radio" name="status" checked="checked" value="<% =WAP2P.Member.BorrowInfo.ValidStatus.Quota %>" /> 通过</label>
                                <label><input type="radio" name="status" value="<% =WAP2P.Member.BorrowInfo.ValidStatus.ValidFail %>" /> 拒绝</label>                                
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>市场参考价格</th>
                        <td><input type="text" tabindex="1" name="marketPrice" class="w150 ui-float" value="" data-vtype="money" data-vmsg="请输入正确的金额" /> 元</td>
                    </tr>
                    <tr>
                        <th>评估价值</th>
                        <td><input type="text" tabindex="2"  name="assessmentPrice" class="w150 ui-float" value="" data-vtype="money" data-vmsg="请输入正确的金额" /> 元</td>
                    </tr>                    
                    <tr>
                        <th>资料有效期</th>
                        <td><input type="text" tabindex="4"  name="expires" class="w150 ui-date" value="<% =Model.Expires.ToDateString() %>" data-vtype="date" data-vmsg="请输入正确的日期" data-vmust="false" /></td>
                    </tr>
                    <tr>
                        <th>审核备注</th>
                        <td><textarea tabindex="5"  name="validRemark"><% =Model.ValidRemark.HtmlEncode() %></textarea></td>
                    </tr>
                </table>
            </ruson:Space>

            <ruson:Space runat="server" ID="quota" Visible="false">
                <table class="m-info" cellpadding="0" cellspacing="0" width="100%">                
                    <tr>
                        <th>会员账户</th>
                        <td class="g-fbold"><% =GetUserDisplay(Model.UserId , Model.UserName) %></td>
                    </tr>
                    <tr>
                        <th>资料名称</th>
                        <td><% =Model.Name %></td>
                    </tr>              
                    <tr>
                        <th>借款资料类型</th>
                        <td><% =BorrowInfoType.LoadOrNew(Model.BorrowInfoTypeId).Name %></td>
                    </tr>
                    <asp:Repeater runat="server" ID="rptQuotaFormFields" ItemType="WAP2P.Sys.FormField">
                        <ItemTemplate>
                            <%# Item.BuildHtml("<tr><th>{%=Name%}</th><td>{%=Value%}</td></tr>", false) %>
                        </ItemTemplate>
                    </asp:Repeater>
                    <tr>
                        <th class="info-listhead" colspan="2">审核信息</th>
                    </tr>
                    <tr>
                        <th>市场参考价格</th>
                        <td><% =Model.MarketPrice.ToMoneyString() %> 元</td>
                    </tr>
                    <tr>
                        <th>评估价值</th>
                        <td><% =Model.AssessmentPrice.ToMoneyString() %></td>
                    </tr>
                    <tr>
                        <th>审核备注</th>
                        <td><% =Model.ValidRemark.BrEncode() %></td>
                    </tr>
                    <tr>
                        <th>审核操作员</th>
                        <td><% =Model.ValidBy %> 于 <% =Model.ValidAt.ToDateTimeString() %> 审核。</td>
                    </tr>
                    <tr>
                        <th class="info-listhead" colspan="2">授额</th>
                    </tr>
                    <tr>
                        <th>借款授信额度</th>
                        <td><input type="text" tabindex="1"  name="quota" class="w150 ui-float" value="" data-vtype="money" data-vmsg="请输入正确的金额" /> 元</td>
                    </tr>
                    <tr>
                        <th>资料有效期</th>
                        <td><input type="text" tabindex="2"  name="expires" class="w150 ui-date" value="<% =Model.Expires.ToDateString() %>" data-vtype="date" data-vmsg="请输入正确的日期" data-vmust="false" /></td>
                    </tr>                    
                </table>
            </ruson:Space>
        </div>
    </form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script src="<% =this.ImportJsCss("../../res/core/scripts/areadata.js") %>"></script>
    <script type="text/javascript">
        var borrowTypeChange = function() {
            var sel = $('#borrowInfoTypeId'); tr = sel.closest('tr');
            $.get('?action=template&Id=<% =IsNew ? string.Empty : Model.Id.ToString() %>&borrowInfoTypeId=' + sel.val(), function(res) {
                //tr.nextAll('tr').remove();    //ie下有error
                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: 120,
                        height: 32,
                        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:'iconfont',
                        buttonText: '&#xe629; 上传' + (isfile ? '文件' : '图片'),
                        fileTypeExts: isfile ? '<% =WAP2P.Web.PC.Admin.Res.uploadify.SwfUpload.AllowFiles %>' : '<% =WAP2P.Web.PC.Admin.Res.uploadify.SwfUpload.AllowImages %>',
                        formData: {
                            <% =WAP2P.Web.Admin.Membership.CookieName %> : '<% =Request.Cookies[WAP2P.Web.Admin.Membership.CookieName].Value %>'
                        },
                        onUploadSuccess: function(res, data) {
                            eval('var d = ' + data);
                            if (d.Success) {
                                var showHtml = isfile ? '<a href="' + d.Message + '" target="_blank">点击下载查看</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 fs22 listvalue-delete" title="删除">&#xe65a;</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;
            };

            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-info').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>