<link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/bootstrap-table.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/table-fix-column.css">

<script src="<?php echo base_url();?>public/js/vendor/bootstrap/src/bootstrap-table.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap/src/table-fix-column.js"></script>

<style type="text/css">
    table {
        table-layout:fixed !important;
    }

    th{
        background: rgb(146, 208, 80);
    }

    td,th{
        max-width: 400px;
        word-wrap: break-word;
    }

    .table-hover > tbody > tr:hover {
        background-color: #c8bd6d;
    }

    input {
        width:60px;
    }

    #roleTable tr:nth-child(5n){
        background:rgb(198, 239, 206);
    } /**隔五行*/

    .fixed-table-toolbar {
        display: none;
    }

    .fileinput-button {
        position: relative;
        top: -5px;
    }

    .fileinput-button input{
        position:absolute;
        right: 0px;
        top: 0px;
        opacity: 0;
        -ms-filter: 'alpha(opacity=0)';
    }
</style>
<div class="content_wrapper">
    <div id="msg-tip"></div>
    <div class="container-fluid ">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>偷金币ratio配置</header>
                    <section>
                        <div class="container-fluid">
                            <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger commitBtn"  id="commitBtn_1">提交</button>

                            <div class="row">

                                <div class="col-sm-12 form_boxs">
                                    <div class="table-responsive">
                                        <form action="" >
                                            <table id="roleTable_1" class="table table-bordered table-hover roleTable">
                                                <thead>
                                                <tr>
                                                    <td>ID</td><td>基础倍率</td><td>好友权重</td><td>非好友权重</td><td>机器人限定</td><td>操作</td>
                                                </tr>
                                                </thead>
                                                <tbody class="dataline">
                                                <?php
                                                if(is_array($list)  && !empty($list)){
                                                    foreach ($list as $key => $val) {
                                                        echo '<tr>';
                                                        echo '<td><input type="text" class="form-control" name="conf['.$val['id'].'][id]" value="'.$val['id'].'" readonly></td>';
                                                        echo '<td><input type="text" class="form-control" name="conf['.$val['id'].'][bet]" value="'.$val['bet'].'"></td>';
                                                        echo '<td><input type="text" class="form-control" name="conf['.$val['id'].'][f_weight]" value="'.$val['f_weight'].'"></td>';
                                                        echo '<td><input type="text" class="form-control" name="conf['.$val['id'].'][weight]" value="'.$val['weight'].'"></td>';
                                                        echo '<td><input type="text" class="form-control" name="conf['.$val['id'].'][isRobot]" value="'.$val['isRobot'].'"></td>';
                                                        echo '<td><button type="button"  class="btn btn-danger delete-row" ><i class="fa fa-minus-square"></i>删除</button></td>';
                                                        echo '<tr>';
                                                    }
                                                }
                                                ?>
                                                </tbody>
                                            </table>
                                        </form>
                                    </div>
                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_1" dataType="betSpinsRule" pid="<?php echo intval(end($list)['id'])+1?>"><i class="fa fa-plus-square"></i>添加</button>

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




<script src="<?php echo base_url();?>public/js/common.js"></script>
<!--<script src="--><?php //echo base_url();?><!--public/js/imageChange.js"></script>-->

<script>
    //新增一行
    $('.addLine').on('click',function () {
        var dataType = $(this).attr("dataType");
        var pid = $(this).attr("pid");

        var html  ='<tr class="tr_line">';
        html +='<td><input class="form-control" type="text" name="conf['+pid+'][id]" value="'+pid+'"></td>';
        html +='<td><input class="form-control" type="text" name="conf['+pid+'][bet]" value="0"></td>';
        html +='<td><input class="form-control" type="text" name="conf['+pid+'][f_weight]" value="0"></td>';
        html +='<td><input class="form-control" type="text" name="conf['+pid+'][weight]" value="0"></td>';
        html +='<td><input class="form-control" type="text" name="conf['+pid+'][isRobot]" value="0"></td>';
        html +='<td><button type="button"  class="btn btn-danger delete-row" ><i class="fa fa-minus-square"></i>删除</button></td>';
        html +=" </tr>";
        $(this).parent().find('.dataline').append(html);
        pid = parseInt(pid)+1;
        $(this).attr("pid",pid);
        console.log(dataType,pid);
    });

    //删除一行
    $(document).on('click', '.delete-row', function() {
        if(confirm('是否确认删除该行')){
            // console.log($(this).attr('ctype'));
            // console.log($(this).parents('.form_boxs').find('.addLine').attr("lineNum"));
            $(this).parent().parent().remove();
            console.log($lineNum);
        }
    });





    //提交表格数据
    $('.commitBtn').click(function () {
        // var dataType = $(this).parent().find('form').attr('dataType');
        var datas = $(this).parent().find('form').serializeArray();
        // console.log(datas);
        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:datas,
            url:'config/actionStealRatio',
            success: function(data){
                console.log(data);
                if(data.ret == 0){
                    window.location.reload()
                }else{
                    // msgTip.messager().error(data.msg);
                }
            }
        });
    });



</script>

