<!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="configForm" 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-success" id="configsubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <div class="row addOrDelControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                            <div class="form-group">
                                <div class="col-sm-6">
                                    <?php foreach ($list as $k => $reward) { ?>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">等级*: </label>
                                            <div class="col-sm-2">
                                                <input type="text" class="form-control"  name="config[levelId][]" value="<?php echo $reward['levelId'];?>">
                                            </div>
                                            <label class="col-sm-2 control-label">数量*: </label>
                                            <div class="col-sm-2">
                                                <input type="text" class="form-control"  name="config[coins][]" value="<?php echo $reward['coins'];?>">
                                            </div>
                                            <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                        </div>
                                    <?php } ?>
                                    <button type="button" class="btn btn-success configAdd" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

<script>
    $(function () {
        $('.addOrDelControl').on("click",'.deleteParent',function(){
            $(this).parent().remove();
        });


        $('.configAdd').on("click",function(){
            var str = "";
            str += '<div class="form-group"><label class="col-sm-2 control-label">等级*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="config[levelId][]" value="1">'
            str += '</div><label class="col-sm-2 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control" name="config[coins][]" value="1"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });


        $('#configsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("configForm"));
            $.ajax({
                url: rootPath + 'config/actionFriendGiftCoins',
                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);
                }
            });
        });
    });

</script>
</html>
