<%@ Page Title="" Language="C#" MasterPageFile="../BaseMaster.Master" CodeBehind="BorrowInfoTypeDetail.aspx.cs" Inherits="WAP2P.Web.PC.Admin.Sys.BorrowInfoTypeDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <form class="auto" method="post" action="" beforeSubmit="setFormJson();"  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="name" placeholder="请输入合适的借款资料名称" class="w250" maxlength="50" value="<% =Model.Name.HtmlEncode() %>" data-vtype="must" data-vmsg="请输入资料名称"/></td>
                </tr>
                <tr>
                    <th>启用状态</th>
                    <td><div class="ui-checkbox"><% =HtmlHelper.CheckBox("active", "启用资料", IsNew ? true : Model.Active) %></div></td>
                </tr>
                <tr>
                    <th>备注</th>
                    <td><textarea name="remark"><% =Model.Remark.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">字段数据(来源数据全局设置)/说明</th>
                                <th class="g-fcenter">是否必填</th>
                                <th class="g-fcenter">操作</th>
                            </tr>                              
                            <tr>
                                <td colspan="5">
                                    完成该模块审核获得：
                                    <span class="pl50">现金奖励：<input type="text" name="rewardAmount" class="w100 ui-float" value="<% =formSetting.Reward.Amount.ToMoneyString() %>" data-vtype="must|money" data-vmsg="请输入现金奖励|金额值输入错误" /></span>
                                    <span class="pl50">信用评分：<input type="text" name="rewardCredit" class="w60 ui-int" value="<% =formSetting.Reward.Credit %>" data-vtype="must|number" data-vmsg="请输入信用奖励|评分值输入错误"  /></span>
                                    <span class="pl50">会员积分：<input type="text" name="rewardScore" class="w60 ui-int" value="<% =formSetting.Reward.Score %>" data-vtype="must|number" data-vmsg="请输入积分奖励|积分值输入错误"  /></span>
                                    <span class="pl50"><input type="button" class="btn-base c-normal  iconfont g-right" id="btnAdd" value="&#xe67a; 新增" /></span>
                                </td>
                            </tr>
                        </table>
                        <input type="hidden" id="formJson" name="formJson" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
    <script type="text/template" id="tmpField">
        <tr>
            <td class="g-fcenter"><input type="text" class="w200" data-to="Name" /><input type="hidden" data-to="CallCode" /></td>
            <td class="g-fcenter"><ruson:EnumSelect runat="server" ID="fieldType" TypeName="WAP2P.Sys.FormFieldType,WAP2P.Sys" data-to="Type"></ruson:EnumSelect></td>
            <td class="g-fleft">
                <input type="text" class="w200" data-to="Description" />
                <ruson:Select runat="server" id="baseForm" data-to="BaseFormCallCode" TipsText="请选择.." style="display:none;"></ruson:Select>
            </td>
            <td class="g-fcenter"><div class="ui-checkbox"><label><input type="checkbox" data-to="IsMust" /> 必填</label></div></td>
            <td class="g-fcenter"><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>
        function typeChange() {
            var val = parseInt($(this).val());
            var td = $(this).closest('td').next();

            if (val > 100) {
                td.find('select').show();
                td.find('input').hide();
            } else {
                td.find('input').show();
                td.find('select').val('').hide();
            }
        };

        //添加
        $('#btnAdd').click(function () {
            var html = document.getElementById('tmpField').innerHTML;
            html = $(html);
            html.find('select[data-to=Type]').change(typeChange);
            $(this).closest('tr').before(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 setFormJson()
        {
            var result = [];
            var trs = $('#tbFields tr'), len = trs.length;            

            $.each(trs, function (i, n) {
                if (i == 0 || i + 1 >= len)
                    return;

                n = $(n);
                var obj = {
                    CallCode: n.find('input[data-to=CallCode]').val(),
                    Name: n.find('input[data-to=Name]').val(),
                    Type: n.find('select[data-to=Type]').val(),
                    Description: n.find('input[data-to=Description]').val(),
                    BaseFormCallCode: n.find('select[data-to=BaseFormCallCode]').val(),
                    IsMust: n.find('input[data-to=IsMust]')[0].checked
                };

                if (obj.Name)
                    result.push(obj);
            });

            $('#formJson').val(utils.toJsonString(result));
        }

        //编辑时初始化数据
        (function initForm() {
            var data = <% =IsNew ? "null" : formSetting.ToJson() %>;

            if (data) {
                var tr = $('#tbFields tr:last');

                $.each(data.Fields, function(i, n) {

                    var html = document.getElementById('tmpField').innerHTML;
                    html = $(html);
                    html.find('select[data-to=Type]').change(typeChange);
                    html.find('input[data-to=CallCode]').val(n.CallCode);
                    html.find('input[data-to=Name]').val(n.Name);
                    html.find('select[data-to=Type]').val(n.Type);

                    var desc = html.find('input[data-to=Description]');
                    desc.val(n.Description);
                    var formCode = html.find('select[data-to=BaseFormCallCode]');
                    formCode.val(n.BaseFormCallCode);
                    if (n.Type > 100) {
                        formCode.show();
                        desc.hide();
                    }
                    if (n.IsMust) html.find('input[data-to=IsMust]')[0].checked = true;

                    tr.before(html);
                });
            }
        })();
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="list" runat="server">
</asp:Content>
