<!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="starExForm" 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="starExSubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php foreach ($starList as $key => $vl) { ?>
                            <div class="AllTypeControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <div class="row form-group">
                                    <label class="col-sm-1 control-label">ID*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control" readonly name="good[<?php echo $vl['id']; ?>][id]"
                                               value="<?php echo $vl['id']; ?>">
                                    </div>

                                    <label class="col-sm-1 control-label">解锁等级*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control" name="good[<?php echo $vl['id']; ?>][unlock_level]"
                                               value="<?php echo $vl['unlock_level']; ?>">
                                    </div>

                                    <label class="col-sm-1 control-label">刷新时间(秒)*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control" name="good[<?php echo $vl['id']; ?>][refresh_time]"
                                               value="<?php echo $vl['refresh_time']; ?>">
                                    </div>

                                    <label class="col-sm-1 control-label">星星数量*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control" name="good[<?php echo $vl['id']; ?>][star_num]"
                                               value="<?php echo $vl['star_num']; ?>">
                                    </div>

                                    <label class="col-sm-1 control-label">皮肤宝箱ID*: </label>
                                    <div class="col-sm-2">
                                        <label class="select-inline">
                                            <select class="form-control" name="good[<?php echo $vl['id']; ?>][skin]">
                                                <?php foreach ($skinList as $item) { ?>
                                                    <option value="<?php echo $item['id']; ?>" <?php if ($vl['skin'] == $item['id']) echo 'selected'; ?> ><?php echo $item['name']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </label>
                                    </div>

                                </div>
                                <div class="row form-group">
                                    <label class="col-sm-1 control-label" style="margin-left: 1rem;">
                                        <button type="button" class="btn btn-success showHide">兑换价格配置</button>
                                    </label>
                                    <div class="col-sm-5" style="display: none">
                                        <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                            <?php foreach ($vl['clear_refresh'] as $rateV) { ?>
                                                <div class="form-group">
                                                    <label class="col-sm-3 control-label">金币倍率*: </label>
                                                    <div class="col-sm-6">
                                                        <input type="number" class="form-control" name="good[<?php echo $vl['id']; ?>][clear_refresh][]"
                                                               value="<?php echo $rateV; ?>">
                                                    </div>
                                                    <button type="button" class="btn btn-danger deleteParent">删除</button>
                                                </div>
                                            <?php } ?>
                                            <button type="button" class="btn btn-success addParent" id="<?php echo $vl['id']; ?>"
                                                    style="margin-left: 12px;margin-bottom: 10px;">增加
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="superStarExForm" 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="superStarExSubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php foreach ($superStarList as $key => $vl) { ?>
                            <div class="AllTypeControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <div class="row form-group">
                                    <label class="col-sm-1 control-label">ID*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control" readonly name="good[<?php echo $vl['id']; ?>][id]"
                                               value="<?php echo $vl['id']; ?>">
                                    </div>

                                    <label class="col-sm-1 control-label">解锁等级*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control" name="good[<?php echo $vl['id']; ?>][unlock_level]"
                                               value="<?php echo $vl['unlock_level']; ?>">
                                    </div>

                                    <label class="col-sm-1 control-label">刷新时间(秒)*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control" name="good[<?php echo $vl['id']; ?>][refresh_time]"
                                               value="<?php echo $vl['refresh_time']; ?>">
                                    </div>

                                    <label class="col-sm-1 control-label">星星数量*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control" name="good[<?php echo $vl['id']; ?>][star_num]"
                                               value="<?php echo $vl['star_num']; ?>">
                                    </div>

                                    <label class="col-sm-1 control-label">皮肤宝箱ID*: </label>
                                    <div class="col-sm-2">
                                        <label class="select-inline">
                                            <select class="form-control" name="good[<?php echo $vl['id']; ?>][skin]">
                                                <?php foreach ($skinList as $item) { ?>
                                                    <option value="<?php echo $item['id']; ?>" <?php if ($vl['skin'] == $item['id']) echo 'selected'; ?> ><?php echo $item['name']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </label>
                                    </div>

                                </div>
                                <div class="row form-group">
                                    <label class="col-sm-1 control-label" style="margin-left: 1rem;">
                                        <button type="button" class="btn btn-success showHide">兑换价格配置</button>
                                    </label>
                                    <div class="col-sm-5" style="display: none">
                                        <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                            <?php foreach ($vl['clear_refresh'] as $rateV) { ?>
                                                <div class="form-group">
                                                    <label class="col-sm-3 control-label">金币倍率*: </label>
                                                    <div class="col-sm-6">
                                                        <input type="number" class="form-control" name="good[<?php echo $vl['id']; ?>][clear_refresh][]"
                                                               value="<?php echo $rateV; ?>">
                                                    </div>
                                                    <button type="button" class="btn btn-danger deleteParent">删除</button>
                                                </div>
                                            <?php } ?>
                                            <button type="button" class="btn btn-success addParent" id="<?php echo $vl['id']; ?>"
                                                    style="margin-left: 12px;margin-bottom: 10px;">增加
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

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

        $('.addParent').on("click", function () {
            var id = $(this).attr('id');
            var str = "";
            str += '<div class="form-group"><label class="col-sm-3 control-label">金币倍率*: </label><div class="col-sm-6"><input type="text" class="form-control"  name="good[' + id + '][clear_refresh][]" value="1">';
            str += '</div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });

        $('.showHide').on("click", function () {
            if ($(this).parent().next().css("display") == "block") {
                $(this).parent().next().hide(300);
            } else {
                $(this).parent().next().show(300);
            }
        });

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

        $('#superStarExSubmitBtn').click(function () {
            var data = new FormData(document.getElementById("superStarExForm"));
            $.ajax({
                url: rootPath + 'StarExchange/configUpdate',
                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>
