@page
@model Waste.Web.Entry.Pages.Result.GlobalConfigModel
@{
    ViewData["Title"] = "字段配置";
}
<div class="layui-card">

    <div class="layui-card-body">
        <form class="layui-form" action="" style="text-align:center">
            @foreach (var item in Model.Column)
            {
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">@item.SystemTitle</label>
                        <div class="layui-input-block">
                            <input type="text" name="@item.Name" lay-verify="required" value="@item.Title" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <input type="checkbox" name="show-@item.Name" title="" checked="@item.IsShow">
                    </div>
                </div>
            }
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">更新</button>
                </div>
            </div>
        </form>
    </div>
</div>

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




            // 提交事件
            form.on('submit(demo1)', function (data) {
                var field = data.field; // 获取表单字段值
                // 显示填写结果，仅作演示用
                // layer.alert(JSON.stringify(field), {
                //     title: '当前填写的字段值'
                // });

                const arr = [];
                for (const property in field) {
                    if (!property.startsWith('show-')) {
                        arr.push({ Name: property, Title: field[property], IsShow: field['show-' + property] == 'on' })
                    }
                }
                $.ajax({
                    url: "?handler=UpdateConfig",
                    type: "post",
                    dataType: "json",
                    data: JSON.stringify(arr),
                    contentType: "application/json;charset=utf-8",
                    success: function (res) {
                        
                        
                    },
                    complete: function () {
                        layer.msg('更新成功');
                    },
                    fail: function (res) {

                    }
                });


                return false; // 阻止默认 form 跳转
            });



        });
    </script>
    <style>
        .layui-form-label {
            width: 100px !important;
        }

        .layui-form-checkbox i {
            border-left: 1px solid #d2d2d2;
        }

        .layui-form-item{
            margin-bottom: 0px !important;
        }
    </style>
}
