<#assign base=request.contextPath />
<#import "../common/defaultLayout.ftl" as defaultLayout>
<@defaultLayout.layout>
    <link rel="stylesheet" href="${base}/assets/css/amazeui.switch.css"/>
    <script type="text/javascript">
        var base = '${base}';
    </script>
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">系统管理</strong> /
                    <small>前端账号管理</small>
                </div>
            </div>

            <form method="post" class="am-form" id="tmpForm" action="${base}/manager/save">
                <input name="managerId" id="managerId" type="hidden" value="${managerId!}"/>
                <div class="am-tabs am-margin" data-am-tabs>
                    <ul class="am-tabs-nav am-nav am-nav-tabs">
                        <li class="am-active"><a href="#tab1">新增/编辑</a></li>
                    </ul>
                    <div class="am-tabs-bd">
                        <div class="am-tab-panel am-fade am-in am-active" id="tab1">
                            <#--<div class="am-g am-form-group am-margin-top" style="display: flex;">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>登录名</div>
                                <div class="am-u-sm-6 am-u-md-6">
                                    <input class="js-ajax-validate" name="userName" value="${manager.userName!}"
                                           type="text"/>
                                </div>
                            </div>-->
                            <div class="am-g am-form-group am-margin-top" style="display: flex;">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>姓名</div>
                                <div class="am-u-sm-6 am-u-md-6">
                                    <input class="js-ajax-validate" name="name" value="${manager.name!}"
                                           type="text" required/>
                                </div>
                                <div class="am-u-sm-2 am-u-md-4 input-msg"></div>
                            </div>
                            <div class="am-g am-form-group am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>
                                    角色
                                </div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <select id="roleId" name="roleId"
                                            data-am-selected="{btnSize: 'sm',maxHeight: 200,searchBox: 1}" required>
                                        <option value="-1">请选择</option>
                                        <#if managerRoleList?exists>
                                            <#list managerRoleList as node>
                                                <option value="${node.id!}" <#if manager.roleId! == node.id >
                                                selected </#if>>${node.roleName}</option>
                                            </#list>
                                        </#if>
                                    </select>
                                </div>
                                <div class="am-u-sm-2 am-u-md-4 input-msg"></div>
                            </div>
                            <div class="am-g am-form-group am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>
                                    手机号
                                </div>
                                <div class="am-u-sm-6 am-u-md-6">
                                    <input name="phone" class="am-form-field am-input-sm"
                                           data-validate-async data-validation-message="请输入正确格式手机号码！"
                                           onkeyup="value=value.replace(/[^\d]/g,'')"
                                           type="text" id="phone" value="${manager.phone!}" minlength="11"
                                           maxlength="11"
                                           required
                                           placeholder="请输入正确格式手机号码！"
                                           onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
                                           <#if managerId != -1 >readonly</#if>
                                    />
                                </div>
                                <div class="am-u-sm-2 am-u-md-4 input-msg"></div>
                            </div>
                            <div class="am-g am-form-group am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>
                                    所属区域
                                </div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <select id="regionId" name="regionId"
                                            data-am-selected="{btnSize: 'sm',maxHeight: 200,searchBox: 1}" required>
                                        <option value="-1">请选择</option>
                                        <#if regionList?exists>
                                            <#list regionList as node>
                                                <option value="${node.id!}" <#if manager.regionId! == node.id >
                                                selected </#if>>${node.name}</option>
                                            </#list>
                                        </#if>
                                    </select>
                                </div>
                                <div class="am-u-sm-2 am-u-md-4 input-msg"></div>
                            </div>
                            <div class="am-g am-form-group am-margin-top" style="display: flex;">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>归属单位</div>
                                <div class="am-u-sm-6 am-u-md-6">
                                    <input class="js-ajax-validate" name="company" value="${manager.company!}"
                                           type="text" required/>
                                </div>
                                <div class="am-u-sm-2 am-u-md-4 input-msg"></div>
                            </div>
                            <div class="am-g am-form-group am-margin-top" style="display: flex;">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">备注</div>
                                <div class="am-u-sm-6 am-u-md-6">
                                    <input class="js-ajax-validate" name="remark" value="${manager.remark!}"
                                           type="text"/>
                                </div>
                            </div>
                            <div class="am-g am-form-group am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                    <span style="color: red;">*</span>
                                    初始密码
                                </div>
                                <div class="am-u-sm-6 am-u-md-6">
                                    初始密码为手机号后6位,请登录后尽快修改
                                </div>
                                <div class="am-u-sm-2 am-u-md-4 input-msg"></div>
                            </div>
                        </div>
                    </div>
                </div>

                <!--选项卡（tabs）end-->
                <div class="am-margin">
                    <button type="submit" id="submitBtn" class="am-btn am-btn-primary am-btn-xs">提交保存</button>
                    <button type="button" class="am-btn am-btn-warning am-btn-xs"
                            onclick="javascript:history.go(-1);">返回上一级
                    </button>
                </div>
            </form>
        </div>
    </div>

</@defaultLayout.layout>
<script src="${base}/common/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="${base}/common/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="${base}/common/jQuery-File-Upload/js/jquery.fileupload.js"></script>
<script src="${base}/common/jQuery-File-Upload/js/jquery.fileupload-process.js"></script>
<script src="${base}/common/jQuery-File-Upload/js/jquery.fileupload-validate.js"></script>
<script src="${base}/assets/js/amazeui.switch.js"></script>

<script>

    $(function () {
        /*表单验证：begin*/
        //自定义规则，用法：验证元素上加class="js-pattern-sort"
        if ($.AMUI && $.AMUI.validator) {
            $.AMUI.validator.patterns.sort = /^([0-9]+)$/;
        }
        $("#tmpForm").validator({
            // 域通过验证时回调
            onValid: function (validity) {
                $(validity.field).closest('.am-form-group').find('.am-alert').hide();
            },
            // 域验证通过时添加的操作，通过该接口可定义各种验证提示
            markValid: function (validity) {
                // this is Validator instance
                var $field = $(validity.field);
                //add by zxl，只对有required属性的字段进行验证
                if (typeof ($field.attr("required")) != "undefined") {
                    var options = this.options;
                    var $parent = $field.closest('.am-form-group');
                    $field.addClass(options.validClass).removeClass(options.inValidClass);

                    $parent.addClass('am-form-success').removeClass('am-form-error');

                    options.onValid.call(this, validity);
                }
            },
            // 验证出错时的回调， validity 对象包含相关信息，格式通 H5 表单元素的 validity 属性
            onInValid: function (validity) {
                var $field = $(validity.field);
                var $group = $field.closest('.am-form-group');
                var $alert = $group.find('.am-alert');
                // 使用自定义的提示信息 或 插件内置的提示信息
                var msg = $field.data('validationMessage') || this.getValidationMessage(validity);

                if (!$alert.length) {
                    $alert = $("<div class='am-alert am-alert-danger'></div>").hide().appendTo($group.find(".input-msg"));
                }
                console.log("onInValid : " + $field.val());
                $alert.html(msg).show();
            }
        });
        /*表单验证：end*/

    })

</script>