<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vip配置</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>
            <header><i class="fa fa-fw fa-file"></i>超级Bet触发体力配置</header>
            <section>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-2">
                            <input type="text" class="form-control" id="actSpinsLimit" name="actSpinsLimit" value="<?php echo $actSpinsLimit;?>">
                        </div>
                        <div class="col-sm-1">
                            <button type="button" class="btn btn-success" onclick="setActSpinsLimit()">提交</button>
                        </div>
                    </div>
                </div>
            </section>
        </aside>
    </div>
    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="configForm" action="#" style="margin-top: 20px">
                <input type="hidden" value="<?php echo $id;?>" name="id"/>
                <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 containerWrap">
                        <?php foreach ($crazyBetConfig as $key => $vl) { ?>
                            <div class="row itemRow" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <div class="form-group" >
                                    <input type="hidden" class="form-control" readonly name="config[<?php echo $vl['id'];?>][id]" value="<?php echo $vl['id'];?>">
                                    <input type="hidden" class="form-control" readonly name="config[<?php echo $vl['id'];?>][actData]" value="<?php echo $vl['actData'];?>">
                                    <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'];?>][bet]" value="<?php echo $vl['bet'];?>">
                                    </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'];?>][levelId]" value="<?php echo $vl['levelId'];?>">
                                    </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'];?>][spins]" value="<?php echo $vl['spins'];?>">
                                    </div>
                                    <label class="col-sm-2 control-label">倍率关闭的体力上限</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="config[<?php echo $vl['id'];?>][spinsLimit]" value="<?php echo $vl['spinsLimit'];?>">
                                    </div>
                                    <div class="col-sm-1">
                                        <button class="  delItem form-control btn btn-danger" data-id="<?=$vl['id']?>" type="button">删除</button>
                                    </div>

                                </div>
                            </div>
                        <?php } ?>
                    </div>
                    <div class="row" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                        <div class="col-sm-1">
                            <button class="  addItem form-control btn btn-info" type="button">添加</button>
                        </div>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

<script>
    function setActSpinsLimit() {
        $.ajax({
            url: rootPath + 'activity/setActSpinsLimit',
            type: 'POST',
            data: {
                'actSpinsLimit':$('#actSpinsLimit').val(),
            },
            dataType: 'json',
            success: function (data) {
                alert(data.msg);
            },
            error: function (data) {
                alert(data.msg);
            }
        }) ;
    }
    $(function () {
        $('#configsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("configForm"));
            $.ajax({
                url: rootPath + 'activity/actionConfig',
                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);
                }
            });
        });
    });

    $('#configForm').on('click', '.delItem', function(){
        var _this = $(this)
        var id = parseInt(_this.data('id'))
        if(id > 0 && confirm('删除之后无法恢复，是否确定要删除该记录？')){
            $.post('/activity/delCrazyBetCfg/9',{id:id},function(data){
                console.log(data)
                if(typeof data == 'string')data = JSON.parse(data)
                alert(data.msg)
                if(data.ret < 1){
                    _this.parents('.itemRow').remove();
                }
            })
        }
        else{
            _this.parents('.itemRow').remove();
        }
    })
    var addCnt = 0;
    $('.addItem').click(function(){
        addCnt++;
        var idx = 'add'+addCnt
        var html = '<div class="row itemRow" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">\n'+
'                                <div class="form-group" >\n'+
'                                    <input type="hidden" class="form-control" readonly name="config['+idx+'][id]" value="0">\n'+
'                                    <input type="hidden" class="form-control" readonly name="config['+idx+'][actData]" value="1">\n'+
'                                    <label class="col-sm-1 control-label">倍率</label>\n'+
'                                    <div class="col-sm-1">\n'+
'                                        <input type="text" class="form-control"  name="config['+idx+'][bet]" value="">\n'+
'                                    </div>\n'+
'                                    <label class="col-sm-1 control-label">等级</label>\n'+
'                                    <div class="col-sm-1">\n'+
'                                        <input type="text" class="form-control"  name="config['+idx+'][levelId]" value="">\n'+
'                                    </div>\n'+
'                                    <label class="col-sm-1 control-label">体力</label>\n'+
'                                    <div class="col-sm-1">\n'+
'                                        <input type="text" class="form-control"  name="config['+idx+'][spins]" value="">\n'+
'                                    </div>\n'+
'                                    <label class="col-sm-2 control-label">倍率关闭的体力上限</label>\n'+
'                                    <div class="col-sm-1">\n'+
'                                        <input type="text" class="form-control"  name="config['+idx+'][spinsLimit]" value="">\n'+
'                                    </div>\n'+
'                                    <div class="col-sm-1">\n'+
'                                        <button class="  delItem form-control btn btn-danger" data-id="0" type="button">删除</button>\n'+
'                                    </div>\n'+
'\n'+
'                                </div>\n'+
'                      </div>';
        $('.containerWrap').append(html)
    })
</script>
</html>
