<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页背景配置</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="<?php echo base_url(); ?>public/js/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" href="<?php echo base_url(); ?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
    <link rel="stylesheet" href="<?php echo base_url(); ?>public/css/jquery.timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="<?php echo base_url(); ?>public/js/vendor/select2/select2.min.css">

    <style type="text/css">
        .thumbnail {
            margin: 10px;
        }

        .lang-name {
            margin-left: 42px;
        }

        .upimg {
            cursor: pointer;
        }

    </style>
</head>
<body>
<div id="msg-tip">

</div>
<div class="content_wrapper">
    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="form" action="#" style="margin-top: 20px">
                <header><i class="fa fa-fw fa-file"></i>登录弹框配置</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <button type="button" class="btn btn-primary" id="submitBtn">提交</button>
                                <button style="margin-left: 10px" type="button" class="btn btn-success" data-toggle="modal" data-target="#triggerEditBtn">新增</button>
                                <span style="float: right;color: red">排序值越大越靠前</span>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php foreach ($list as $key => $vl) { ?>
                            <div class="row" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">弹框ID</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" readonly name="config[<?php echo $vl['id']; ?>][id]" value="<?php echo $vl['id']; ?>">
                                    </div>
                                    <label class="col-sm-1 control-label">名称</label>
                                    <div class="col-sm-2">
                                        <input type="text" class="form-control" readonly name="config[<?php echo $vl['id']; ?>][name]" value="<?php echo $vl['name']; ?>">
                                    </div>
                                    <label class="col-sm-1 control-label">说明</label>
                                    <div class="col-sm-4">
                                        <input type="text" class="form-control" name="config[<?php echo $vl['id']; ?>][desc]" value="<?php echo $vl['desc']; ?>">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">等级区间</label>
                                    <div class="col-sm-2 ">
                                        <div class="input-group">
                                            <input type="text" style="text-align: center" class="form-control" name="config[<?php echo $vl['id']; ?>][s_lv]" value="<?php echo $vl['s_lv'] ?>">
                                            <span class="input-group-addon">-</span>
                                            <input type="text" style="text-align: center" class="form-control" name="config[<?php echo $vl['id']; ?>][e_lv]" value="<?php echo $vl['e_lv'] ?>">
                                        </div>
                                    </div>
                                    <label class="col-sm-1 control-label">排序</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" name="config[<?php echo $vl['id']; ?>][sort]" value="<?php echo $vl['sort']; ?>">
                                    </div>
                                    <label class="col-sm-1 control-label">状态</label>
                                    <div class="col-sm-1">
                                        <select class="form-control" name="config[<?php echo $vl['id']; ?>][status]"">
                                        <option value="0" <?php if ($vl['status'] == 0) echo 'selected'; ?>>关</option>
                                        <option value="1" <?php if ($vl['status'] == 1) echo 'selected'; ?>>开</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

<!--活动编辑弹窗-->
<div class="modal" id="triggerEditBtn" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 60%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">新增一项登录弹窗配置</h4>
            </div>
            <form class="form-horizontal" method="post" id="triggerForm" action="">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">弹框ID:</label>
                        <div class="col-sm-2">
                            <input placeholder="新增时自动递增" type="number" readonly class="form-control" name="id">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">名称:</label>
                        <div class="col-sm-3">
                            <input placeholder="输入名称(英文,不可重复)" type="text" class="form-control" name="name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">说明:</label>
                        <div class="col-sm-3">
                            <input placeholder="输入说明,用做备注" type="text" class="form-control" name="desc">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">等级区间</label>
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input placeholder="最小等级" type="text" style="text-align: center" class="form-control" name="s_lv" >
                                <span class="input-group-addon">-</span>
                                <input placeholder="最大等级" type="text" style="text-align: center" class="form-control" name="e_lv" >
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">排序:</label>
                        <div class="col-sm-2">
                            <input placeholder="" type="number" class="form-control" name="sort">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">状态:</label>
                        <div class="col-sm-3">
                            <label class="select-inline">
                                <select class="form-control" name="status">
                                    <option value="0">关</option>
                                    <option value="1">开</option>
                                </select>
                            </label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="confSubmitBtn">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('#submitBtn').click(function () {
            var data = new FormData(document.getElementById("form"));
            $.ajax({
                url: rootPath + 'Config/actionLoginBulletBox',
                type: 'POST',
                data: data,
                dataType: 'json',
                contentType: false, //必须
                processData: false, //必须
                success: function (data) {
                    alert(data.msg);
                    window.location.reload();
                },
                error: function (msg) {
                    alert(data.msg);
                }
            });
        });

        $('#confSubmitBtn').click(() => {
            const data = $('#triggerForm').toObject()
            console.log(data)
            $.ajax({
                url: 'Config/addLoginBulletBox',
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (data) {
                    alert(data.msg);
                    if (data.ret === 0) {
                        window.location.reload();
                    }
                },
                error: function (data) {
                    alert(data.msg);
                }
            });
        });
    });
</script>
</html>
