<!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">
    <script src="<?php echo base_url();?>public/js/vendor/select2/select2.full.min.js"></script>
    <style type="text/css">
        .thumbnail {
            margin:10px;
        }

        .lang-name {
            margin-left:42px;
        }

        .upimg {
            cursor: pointer;
        }

    </style>
</head>
<body>
<div class="content_wrapper">
    <style>
        .btn-name {
            white-space: nowrap;
        }
    </style>
    <div class="container-fluid">
        <div id="msg-tip"></div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>体力不足广告转盘配置</header>
                    <section>
                        <div class="container-fluid">
                            <button class="btn btn-primary" id="subForm" type="button">提交</button>
                        </div>
                        <hr>
                        <form action="" id="formData">
                        <div class="form-group">
                            <div class="col-sm-6  input-group">
                                <label class="col-sm-8 control-label">奖励刷新时间（单位分钟）*:</label>
                                <input type="text"   name="resetTs" value="<?php echo $resetTs?>">
                            </div>
                            <div class="col-sm-6  input-group">
                                <label class="col-sm-8 control-label">最终大奖需满足最小次数*:</label>
                                <input type="text"   name="mrLimit" value="<?php echo $mrLimit?>">
                            </div>
                        </div>
                        <hr>




                        </form>
                        <div class="container-fluid">
                            <button class="btn btn-primary" id="addConf" type="button">添加</button>
                        </div>

                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>

</body>
<script src="<?php echo base_url();?>public/js/common.js"></script>
<script>
var group_k = 0;
// var data =[{"star_lv":1,"end_lv":100,"conf":[{"id":1,"pro":100,"spins":10},{"id":2,"pro":100,"spins":10},{"id":3,"pro":100,"spins":10}]},{"star_lv":101,"end_lv":1000,"conf":[{"id":1,"pro":100,"spins":10},{"id":2,"pro":100,"spins":10},{"id":3,"pro":100,"spins":10}]}]
// initHtml(data)
var info = '<?php echo json_encode($list,32)?>';
if(info.length>0){
    initHtml(JSON.parse(info))
}

function addHtml(k,ones){
   var html =
       `<div class="container-fluid lv_conf_one">
        <div class="row">
            <div class="col-sm-12">
                <div class="table-responsive">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">等级区间</label>
                        <div class="col-sm-2 input-group">
                            <input type="text" class="form-control"  name="list[`+k+`][star_lv]" value="`+ones.star_lv+`">
                            <span class="input-group-addon">-</span>
                            <input type="text" class="form-control"  name="list[`+k+`][end_lv]" value="`+ones.end_lv+`">
                        </div>
                    </div>
                    <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>权重</th>
                            <th>体力</th>
                        </tr>
                        </thead>
                        <tbody>`
    var tip = ""
    $.each(ones.conf, function (i, o){
        if(o.id==10){
            tip = "(*最终大奖)"
        }
        html +='<tr><td><input type="text" class="form-control"  name="list['+k+'][conf]['+i+'][id]" value="'+o.id+'" readonly></td><td><input class="form-control" type="text" name="list['+k+'][conf]['+i+'][pro]" value="'+o.pro+'"></td><td><input class="form-control" type="text" name="list['+k+'][conf]['+i+'][spins]" value="'+o.spins+'">'+tip+'</td></tr>'
    });
    html+=                 `</tbody>
                    </table>
                </div>
            </div>
        </div>
        </div>`

    return html
}
function initHtml(data){
    var html =""
    $.each(data, function (i, o){
        html +=addHtml(i,o)
        group_k++
    });
    // console.log(html)
    $("#formData").append(html)
    return html
}
$("#subForm").click(function (){
    var data = $('#formData').toObject()
    console.log(data)
    $.ajax({
        url: rootPath + 'Ad/actionSpinSlot',
        type: 'POST',
        data: data,
        dataType: 'json',
        success: function (data2) {
            // console.log('----------',data2)
            alert(data2.msg);
            // confirm(data.msg);
            window.location.reload();
        },
        error: function (data2) {
            console.log(data2)
            alert(data2.msg);
        }
    });
});
$("#addConf").click(function (){
    var ones = {"star_lv":1,"end_lv":100,"conf":[]}
    for (var i=0;i<10;i++){
        ones.conf.push({"id":i+1,"pro":0,"spins":0})
    }
    var html =addHtml(group_k,ones)
    group_k++;
    $("#formData").append(html)
});
</script>
</html>

