<%@ Page Title="" Language="C#" MasterPageFile="../BaseMaster.Master" CodeBehind="OnlinePaymentDetail.aspx.cs" Inherits="WAP2P.Web.PC.Admin.Sys.OnlinePaymentDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <form action="" method="post" class="auto" beforeSubmit="setJson();" onsuccess="parent.$.jPopupEdit.close(true);">
        <div class="m-editbar">
            <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">
            <table class="m-info" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th>调用标识</th>
                    <td>
                        <input type="text" name="callCode" placeholder="请输入调用的代码" class="w250" maxlength="50" value="<%= Model.CallCode.HtmlEncode() %>" data-vtype="must"  data-vmsg="请输入调用代码" />
                        <em>推荐以支付平台的名称首字母大写命名，例如：通联支付命名“TL”</em>  
                    </td>
                </tr>
                <tr>
                    <th>平台名称</th>
                    <td>
                        <input type="text" name="name" class="w250" placeholder="请输入支付机构名称" maxlength="50" value="<%= Model.Name.HtmlEncode() %>" data-vtype="must" data-vmsg="请输入支付机构名称" />
                    </td>
                </tr>
                <tr>
                    <th>平台Logo</th>
                    <td>
                        <div id="platformLogoResult" class="mb10"><% = IsNew || string.IsNullOrEmpty(Model.PlatformLogo) ? string.Empty : string.Format("<img src=\"{0}\" alt=\"\">", Model.PlatformLogo) %></div>
                        <div class="pl136"><input type="hidden" name="platformLogo" id="platformLogo" value="<% =Model.PlatformLogo.HtmlEncode() %>" /></div>
                        <input type="file" id="platformLogoFile" />
                        <em>请上传尺寸为 <i class="fcred-3">126 X 40 像素</i> 的LOGO图片</em>
                    </td>
                </tr>
                <tr>
                    <th>排序值</th>
                    <td>
                        <input type="text" name="orderBy" class="w60 ui-int" value="<%=Model.OrderBy %>" data-vtype="number" data-vmsg="排序必须为数字" /><em>数值越大越靠前</em>
                    </td>
                </tr>
                <tr>
                    <th>是否启用</th>
                    <td><div class="ui-checkbox"><% =HtmlHelper.CheckBox("active", "启用", IsNew ? true : Model.Active) %></div></td>
                </tr>
                <tr>
                    <th>是否开启银行直连</th>
                    <td><div class="ui-checkbox"><% =HtmlHelper.CheckBox("direct", "启用", IsNew ? false : Model.Direct) %></div></td>
                </tr>
                <tr id="bankDirect" class="<%= Model.Direct ? string.Empty : "g-hide" %>">
                    <th>银行直连参数设置</th>
                    <td style="white-space:normal">
                        <em class="mb10">如指定了相应参数，则用户线上充值时可选择该银行作为直连充值接口。</em>
                        <div class="js-bankDirect">
                            <ul>
                                <asp:Repeater runat="server" ID="rptDirectList">
                                    <ItemTemplate>
                                        <li class="g-left w130 t-listbox" >
                                            <img src="<%# WAP2P.Web.Extensions.GetBankLogo(Eval("Value").ToString()) %>" id="<%# Eval("Value") %>" title="<%# Eval("Value") %>" />
                                            <span>参数：<input type="text" name="value" value="<%# Eval("Key") %>" class="w50" /></span>
                                        </li>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </ul>
                        </div>
                        <input type="hidden" id="directJson" name="directJson" />
                    </td>
                </tr>
                <tr>
                    <th>详细说明</th>
                    <td><textarea name="description"><%= Model.Description.HtmlEncode() %></textarea></td>
                </tr>
                <tr>
                    <th class="info-listhead" colspan="2">平台配置</th>
                </tr>
                <tr>
                    <td colspan="2">
                        <table class="m-info" cellpadding="0" cellspacing="0" width="100%" id="tbFields">
                            <tr>
                                <th class="g-fcenter">键</th>
                                <th class="g-fcenter">值</th>
                                <th class="g-fcenter">操作<span><input type="button" class="btn-base c-normal  iconfont g-right" id="btnAdd" value="&#xe67a; 新增" /></span></th>
                            </tr>
                            <asp:Repeater runat="server" ID="rptConfig">
                                <ItemTemplate>
                                    <tr>
                                        <td class="g-fcenter"><input type="text" class="w200" data-to="key" data-vtype="must" data-vmsg="请输入键" value="<%# Eval("Key") %>" /></td>
                                        <td class="g-fcenter"><input type="text" class="w200" data-to="value" data-vtype="must" data-vmsg="请输入值"  value="<%# Eval("Value") %>"/></td>
                                        <td class="g-fcenter" colspan="2"><a href="javascript:void(0);" class="mr10 iconfont" data-ref="up">&#xe622;上移</a><a href="javascript:void(0);" class="mr10 iconfont" data-ref="down">&#xe661;下移</a><a href="javascript:void(0);" class="iconfont" data-ref="del">&#xe611;删除</a></td>
                                    </tr> 
                                </ItemTemplate>
                            </asp:Repeater>                             
                        </table>
                        <input type="hidden" id="settingJson" name="settingJson" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
    <script type="text/template" id="tmpField">
        <tr>
            <td class="g-fcenter"><input type="text" class="w200" data-to="key" data-vtype="must" data-vmsg="请输入键" /></td>
            <td class="g-fcenter"><input type="text" class="w200" data-to="value" data-vtype="must" data-vmsg="请输入值" /></td>
            <td class="g-fcenter" colspan="2"><a href="javascript:void(0);" class="mr10 iconfont" data-ref="up">&#xe622;上移</a><a href="javascript:void(0);" class="mr10 iconfont" data-ref="down">&#xe661;下移</a><a href="javascript:void(0);" class="iconfont" data-ref="del">&#xe611;删除</a></td>
        </tr> 
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="script" runat="server">
    <script>
        $('#direct').on('click',function(){
            $("#bankDirect").toggle();
        });

        //添加
        $('#btnAdd').click(function () {
            var html = document.getElementById('tmpField').innerHTML;
            html = $(html);
            $(this).closest('tr').after(html);
        });

        //上移/下移/删除
        $('#tbFields').on('click', 'a', function () {
            var me = $(this);

            if (me.is('[data-ref=up]')) {

                var tr = me.closest('tr');
                if (tr.prevAll().length > 1)
                    tr.prev().before(tr);
                else
                    tr.closest('table').find('tr:last').before(tr);

            } else if (me.is('[data-ref=down]')) {

                var tr = me.closest('tr');
                if (tr.nextAll().length > 1)
                    tr.next().after(tr);
                else
                    tr.closest('table').find('tr:first').after(tr);

            } else if (me.is('[data-ref=del]')) {
                me.closest('tr').remove();
            }
        });

        //保存时获取设置Json
        function setJson()
        {
            var result = {};
            var trs = $('#tbFields tr'), len = trs.length;
            $.each(trs, function (i, n) {
                if (i == 0 || i + 1 > len)
                    return;

                n = $(n);
                var key = n.find('input[data-to=key]').val();
                if (key)
                    result[key] = n.find('input[data-to=value]').val();
            });

            var bankResult = {};
            var lis = $('.js-bankDirect li'), len = lis.length;
            $.each(lis,function(i,n){
                if(i + 1 > len)
                    return;
                n = $(n);
                var key = n.find('img').attr('id');
                var value = n.find('input[name=value]').val();
                if(value)
                    bankResult[key] = value;
            });

            $('#settingJson').val(utils.toJsonString(result));
            $('#directJson').val(utils.toJsonString(bankResult));
        }

        setTimeout(function () {
            $('#platformLogoFile').uploadify({
                width: 120,
                height: 32,
                multi: false,
                removeTimeout: 0,
                swf: '../res/uploadify/uploadify.swf?v=<% =CryptoHelper.Random(100000,999999) %>',
                uploader: '../res/uploadify/SwfUpload.aspx?type=image&width=126&height=40',
                buttonClass:'iconfont',
                buttonText: '&#xe629; 上传平台Logo',
                fileTypeExts: '<% =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) {
                        $('#platformLogo').val(d.Message).trigger('blur');
                        $('#platformLogoResult').html('<img src="' + d.Message + '" />');
                    } else {
                        $.jError(d.Message);
                    }
                }
            });
        }, 10);
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="list" runat="server">
</asp:Content>
