<!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="goodForm" 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="goodsubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php foreach ($list as $key => $vl) { ?>
                            <div class="row AllTypeControl" 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="good[<?php echo $vl['propsId'];?>][propsId]" value="<?php echo $vl['propsId'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">宝箱名称*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="good[<?php echo $vl['propsId'];?>][name]" value="<?php echo $vl['name'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">卡片数量*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="good[<?php echo $vl['propsId'];?>][card]" value="<?php echo $vl['reward'][17]['num'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">小丑卡兑换数量: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="good[<?php echo $vl['propsId'];?>][joker]" value="<?php echo $vl['reward'][18]['num'];?>">
                                    </div>
                                </div>
                                <div class="form-group" >

                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label"><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['reward'][14]['pro'] 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="good[<?php echo $vl['propsId'];?>][coins][num][]" value="<?php echo $reward['num'];?>">
                                                    </div>
                                                    <label class="col-sm-2 control-label">概率*: </label>
                                                    <div class="col-sm-2">
                                                        <input type="text" class="form-control"  name="good[<?php echo $vl['propsId'];?>][coins][v][]" value="<?php echo $reward['v'];?>">
                                                    </div>
                                                    <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                                </div>
                                            <?php } ?>
                                            <button type="button" class="btn btn-success addParent" propsId="<?php echo $vl['propsId'];?>" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                        </div>
                                    </div>
                                    <label class="col-sm-1 control-label"><a href="/#config/chestWeight/3/spinsNum/<?php echo $vl['propsId'];?>" target="_blank" type="button" class="btn btn-success">体力奖励配置</a></label>
                                    <label class="col-sm-1 control-label"><a href="/#config/chestWeight/3/petExp/<?php echo $vl['propsId'];?>" target="_blank" type="button" class="btn btn-success">宠物经验配置</a></label>
                                </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 propsId = $(this).attr('propsId');
            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="good['+propsId+'][coins][num][]" value="1">'
            str += '</div><label class="col-sm-2 control-label">概率*: </label><div class="col-sm-2"><input type="text" class="form-control" name="good['+propsId+'][coins][v][]" value="1"></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);
            }
        });

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