@using Abp.Json
@using MineTec.ProManager.Organizations.Dto
@model OrganizationUnitDto

<form class="layui-form" lay-filter="organization-form" style="padding: 15px 0 0 0;">
    <input type="hidden" name="id" />
    <input type="hidden" name="parentId" />
    <div class="layui-form-item">
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-block">
            <input type="text" name="displayName" lay-verify="required" placeholder="请输入部门名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-hide" lay-submit lay-filter="organization-submit" id="organization-submit">提交</button>
        </div>
    </div>
</form>

@section scripts{
    <script type="text/javascript">
        layui.use(['abp', 'form'], function () {
            var $ = layui.$;
            var abp = layui.abp;
            var form = layui.form;

            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.iframeAuto(index);

            form.val("organization-form", @Html.Raw(JsonExtensions.ToJsonString(Model,true,false)));
            form.render();

            window.submitForm = function () {
                $("#organization-submit").click();
            }

            form.on('submit(organization-submit)', function (data) {
                var field = data.field;

                var waitIndex = parent.layer.load(2);
                abp.ajax({
                    url: "@Url.Action(Model.Id > 0 ?"UpdateOrganizationUnit":"CreateOrganizationUnit","OrganizationUnits")",
                    data: JSON.stringify(field),
                    abpHandleError: false
                }).done(function (data) {
                    if (data.code == 200) {
                        data.index = index;
                        let parentWindow = parent.selectedWindow().window;
                        parentWindow.saveCallback(data);
                    }
                }).fail(function (jqXHR) {
                    parent.layer.msg(jqXHR.message, { icon: 5 });
                }).always(function () {
                    parent.layer.close(waitIndex);
                });

                return false;
            });
        });
    </script>
}
