<link rel="stylesheet" href="<?php echo base_url();?>public/js/date/datedropper.min.css">
<script src="<?php echo base_url();?>public/js/date/datedropper.min.js"></script>

<!-- Select2 -->
<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.min.css">
<script src="<?php echo base_url();?>public/js/vendor/select2/select2.full.min.js"></script>

<div class="content_wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>公会推荐配置</header>
                    <section>
                        <form id="dataForm">
                            <input name="id" type="hidden" value="<?php echo $config['id'] ?? 0;?>">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-sm-2 " style="text-align: right;vertical-align: center">
                                        <label class="form-control " style="border: none">置顶推荐位</label>
                                    </div>
                                    <div class="col-sm-2">
                                        <input class=" form-control" name='top_num' value='<?= $config['top_num']??0 ?>' />
                                    </div>
                                </div>

                                <?php foreach((array)$config['intervals'] as $item){?>
                                <div class="row intervals">
                                    <div class="col-sm-2 " style="text-align: right;vertical-align: center">
                                        <label class="form-control " style="border: none">区间配置</label>
                                    </div>
                                    <div class="col-sm-2">
                                        <input class=" form-control" name='start[]' value='<?= $item['start']??0 ?>' />
                                    </div>
                                    <div class="col-sm-2">
                                        <input class=" form-control" name='end[]' value='<?= $item['end']??0 ?>' />
                                    </div>
                                    <div class="col-sm-2 " style="text-align: right;vertical-align: center">
                                        <label class="form-control " style="border: none">区间对应抽取数量</label>
                                    </div>
                                    <div class="col-sm-2">
                                        <input class=" form-control" name='num[]' value='<?= $item['num']??0 ?>' />
                                    </div>
                                    <div class="col-sm-2 ">
                                        <button type="button" class="btn  btn-danger delLvGroup"  onclick="delLvGroup(this)">×</button>
                                    </div>
                                </div>
                                <?php }?>

                                <div class="row addLvGroup">
                                    <div class="col-sm-2">
                                        <button type="button" class="btn  btn-primary" style="float: right">+</button>
                                    </div>
                                </div>

                                <div class="row">
                                    <button type="button" class="btn btn-success btnSubmit">提交</button>
                                </div>
                            </div>
                        </form>
                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>
<script>
    $('.select2').select2({})
    $('.btnSubmit').click(function(){
        var datas = $('#dataForm').serializeArray();
        console.log(datas);
        $.post('/club/saveRecommendConfig', datas, function(res){
            if(typeof res == 'string')res = JSON.parse(res)
            alert(res.msg)
        })
    });

    function delLvGroup(obj){
        $(obj).parents('.intervals').remove()
    }

    $('.addLvGroup').click(function(){
        var html = `
        <div class="row intervals">
            <div class="col-sm-2 " style="text-align: right;vertical-align: center">
                <label class="form-control " style="border: none">等级区间</label>
            </div>
            <div class="col-sm-2">
                <input class=" form-control" name='start[]' value='0' />
            </div>
            <div class="col-sm-2">
                <input class=" form-control" name='end[]' value='0' />
            </div>
            <div class="col-sm-2 " style="text-align: right;vertical-align: center">
                <label class="form-control " style="border: none">区间对应抽取数量</label>
            </div>
            <div class="col-sm-2">
                <input class=" form-control" name='num[]' value='0' />
            </div>
            <div class="col-sm-2">
                <button type="button" class="btn  btn-danger" onclick="delLvGroup(this)">×</button>
            </div>
        </div>`
        $(this).before(html)
    })
</script>