@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'laydate', 'common', 'optimizeSelectOption'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common,
            laydate = layui.laydate;
        // 自定义验证规则
        form.verify({
            pass: function (value, elem) {
                var EXP = /^[\S]{6,12}$/;
                if (value && !EXP.test(value)) {
                    return '密码必须6到12位，且不能出现空格';
                }
            }
        });
        var keyValue = $.request("keyValue");
        //权限字段
        common.authorizeFields('adminform');
        //执行一个laydate实例
        laydate.render({
            elem: '#F_Birthday'
            , btns: ['clear', 'now']
            , trigger: 'click',
            format: 'yyyy-MM-dd',
        });
        function initControl() {
            $("#F_CompanyId").bindSelect({
                url: "/SystemOrganize/SystemSet/GetListJson",
                id: "F_Id",
                text: "F_CompanyName"
            });
            $("#F_DutyId").bindSelect({
                url: "/SystemOrganize/Duty/GetListJson",
                id: "F_Id",
                text: "F_FullName"
            });
        }
        $(function () {
            initControl();
            if (!!keyValue) {
                common.ajax({
                    url: "/SystemOrganize/User/GetFormJson",
                    data: { keyValue: keyValue },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        common.val('adminform', data);
                        $("#F_UserPassword").val("******").attr('disabled', 'disabled');
                    }
                });
            }
            form.render();
        });
        wcLoading.close();
        //select验证
        form.verify({
            required: function (value, item) {
                var msg = "必填项不能为空";
                value = $.trim(value);
                var isEmpty = !value || value.length < 1;
                // 当前验证元素是select且为空时,将页面定位至layui渲染的select处，或自定义想定位的位置
                if (item.tagName == 'SELECT' && isEmpty) {
                    $("html").animate({
                        scrollTop: $(item).siblings(".layui-form-select").offset().top - 74
                    }, 50);
                }
                if (isEmpty) {
                    return msg;
                }
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
                var postData = data.field;
                common.submitForm({
                    url: "/SystemOrganize/User/SubmitForm?keyValue=" + keyValue,
                    param: postData,
                    success: function () {
                        common.parentreload("data-search-btn");
                    }
                })
            return false;
        });
    });
    function search(fileds) {
        layui.use(['jquery', 'form', 'common'], function () {
            var form = layui.form,
                $ = layui.$,
                common = layui.common;
            //不同弹窗
            if (fileds == '角色') {
                common.modalOpen({
                    title: "选择角色",
                    url: "/SystemOrganize/Role/AddForm?name=" + "F_RoleName" + "&value=" + "F_RoleId" + "&ids=" + $('#F_RoleId').val(),
                    width: "650px",
                    height: "600px",
                });
            }
            else if (fileds == '部门') {
                common.modalOpen({
                    title: "选择组织",
                    url: "/SystemOrganize/Organize/AddForm?name=" + "F_OrganizeName" + "&value=" + "F_OrganizeId" + "&ids=" + $('#F_OrganizeId').val() + "&managerkey=" + $('#F_ManagerId').val() + "&managername=" + $('#F_ManagerName').val(),
                    width: "650px",
                    height: "600px",
                });
            }
            else if (fileds == '用户') {
                common.modalOpen({
                    title: "选择用户",
                    url: "/SystemOrganize/User/AddForm?name=" + "F_ManagerName" + "&value=" + "F_ManagerId" + "&ids=" + $('#F_ManagerId').val(),
                    width: "650px",
                    height: "600px",
                });
            }
            else {
                return false;
            }
        });
    }
</script>
<body>
    <div class="layuimini-container ">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">账号</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_Account" name="F_Account" maxlength="50" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">密码</label>
                        <div class="layui-input-block">
                            <input type="password" id="F_UserPassword" name="F_UserPassword" lay-verify="required|pass" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">公司</label>
                        <div class="layui-input-block">
                            <select id="F_CompanyId" name="F_CompanyId" lay-verify="required" lay-search="" >
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">部门</label>
                        <div class="layui-input-block">
                            <input id="F_OrganizeName" name="F_OrganizeName" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" onclick="search('部门')" />
                            <input id="F_OrganizeId" name="F_OrganizeId" type="text" hidden />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">角色</label>
                        <div class="layui-input-block">
                            <input id="F_RoleName" name="F_RoleName" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" onclick="search('角色')" />
                            <input id="F_RoleId" name="F_RoleId" type="text" hidden />
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">职位</label>
                        <div class="layui-input-block">
                            <select id="F_DutyId" name="F_DutyId" lay-verify="required" lay-search="">
                                <option value="">==请选择==</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">姓名</label>
                        <div class="layui-input-block">
                            <input id="F_RealName" name="F_RealName" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label required">性别</label>
                        <div class="layui-input-block">
                            <select id="F_Gender" name="F_Gender">
                                <option value="true">男</option>
                                <option value="false">女</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">手机</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_MobilePhone" name="F_MobilePhone" autocomplete="off" lay-verify="phone" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">生日</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_Birthday" name="F_Birthday" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_Email" name="F_Email" autocomplete="off" lay-verify="email" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">微信</label>
                        <div class="layui-input-block">
                            <input type="text" id="F_WeChat" name="F_WeChat" autocomplete="off" maxlength="50" class="layui-input">
                        </div>
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">高管</label>
                        <div class="layui-input-block">
                            <select id="F_IsSenior" name="F_IsSenior">
                                <option value="false">否</option>
                                <option value="true">是</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">直属上级</label>
                        <div class="layui-input-block">
                            <input id="F_ManagerName" name="F_ManagerName" type="text" maxlength="50" autocomplete="off" class="layui-input" onclick="search('用户')" />
                            <input id="F_ManagerId" name="F_ManagerId" type="text" hidden />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">类型</label>
                        <div class="layui-input-block">
                            <select id="F_IsAdmin" disabled name="F_IsAdmin">
                                <option value="false" selected>普通用户</option>
                                <option value="true">系统管理员</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6 layui-hide">
                        <label class="layui-form-label">允许登录</label>
                        <div class="layui-input-block">
                            <select id="F_EnabledMark" name="F_EnabledMark" lay-verify="required">
                                <option value="true">是</option>
                                <option value="false">否</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <div class="layui-row layui-hide">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入备注" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>
