<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><?php echo $betSpinsRule['title'];?></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="" >
                                        <input type="hidden" name="type" value="betSpinsRule">
                                        <table id="roleTable_1" class="table table-bordered table-hover roleTable">
                                            <thead>
                                            <tr>
                                                <td>倍率</td><td>修正需消耗总体力</td><td>操作</td>
                                            </tr>
                                            </thead>
                                            <tbody class="dataline">
                                            <?php
                                                if(is_array($betSpinsRule['list'])  && !empty($betSpinsRule['list'])){
                                                    $a=0;
                                                    foreach ($betSpinsRule['list'] as $key => $val) {
                                                        echo '<tr>';
                                                        echo '<td><input type="text" class="form-control" name="k['.$a.']" value="'.$key.'"></td>';
                                                        echo '<td><input type="text" class="form-control" name="v['.$a.']" value="'.$val.'"></td>';
                                                        echo '<td><button type="button"  class="btn btn-danger delete-row" ><i class="fa fa-minus-square"></i>删除</button></td>';
                                                        echo '<tr>';
                                                        $a++;
                                                    }
                                                 }
                                            ?>
                                            </tbody>
                                        </table>
                                        </form>
                                    </div>
                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_1" dataType="betSpinsRule" lineNum="<?php echo count($betSpinsRule['list'])?>"><i class="fa fa-plus-square"></i>添加</button>

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

    <div id="msg-tip2"></div>
    <div class="container-fluid ">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i><?php echo $spinsLost['title'];?></header>
                    <section>
                        <div class="container-fluid">
                            <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger commitBtn"  id="commitBtn_2">提交</button>
                            <div class="row" style="padding-left: 15px;">
                                <span id="filespanpro2" class="btn btn-success fileinput-button filespanpro">
                                    <span>导入</span>
                                    <input type="file" id="upfilepro2" class="upfilepro">
                                </span>
                                <input type="button" style="display: none;margin-bottom: 10px;width: 80px;" class="btn btn-success btnpro" value="上传" id="btnpro2" ctype="spinsLost"/>
                                <a type="button" href="/Export/slotWeightChange/spinsLost" style="margin-bottom: 10px;width: 80px;" class="btn btn-success">导出</a>
                            </div>
                            <div class="row">

                                <div class="col-sm-12 form_boxs">
                                    <div class="table-responsive">
                                        <form action="">
                                         <input type="hidden" name="type" value="spinsLost">
                                        <table id="roleTable_2" class="table table-bordered table-hover roleTable">
                                            <thead>
                                            <tr>
                                                <td>体力/倍率</td>
                                                <?php foreach ($trArr as $key => $val) {
                                                    echo "<td>{$val}</td>";
                                                } ?>
                                                <td>操作</td>
                                            </tr>
                                            </thead>
                                            <tbody class="dataline">
                                            <?php
                                            if(is_array($spinsLost['list'])  && !empty($spinsLost['list'])){
                                                $b=0;
                                                foreach ($spinsLost['list'] as $key => $val) {
                                                    echo '<tr class="tr_line">';
                                                        echo '<td><input type="text" class="form-control" name="k['.$b.']" value="'.$key.'"></td>';
                                                        foreach($trArr as $k=>$v){
                                                            echo '<td><input type="text" class="form-control" name="v['.$b.']['.$k.']" value="'.$val[$k].'"></td>';
//                                                            echo '<td><input type="text" class="form-control" name="v['.$b.']['.$k.']" value="'.$v.'"></td>';
                                                        }
                                                        echo '<td><button type="button"  class="btn btn-danger delete-row" ><i class="fa fa-minus-square"></i>删除</button></td>';
                                                    echo "</tr>";
                                                    $b++;
                                               } }?>
                                            </tbody>
                                        </table>
                                        </form>
                                    </div>
                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_2" dataType="spinsLost" lineNum="<?php echo count($spinsLost['list'])?>"><i class="fa fa-plus-square"></i>添加</button>

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

    <div id="msg-tip3"></div>
    <div class="container-fluid ">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i><?php echo $spinsLostDay['title'];?></header>
                    <section>
                        <div class="container-fluid">
                            <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger commitBtn"  id="commitBtn_3">提交</button>
                            <div class="row" style="padding-left: 15px;">
                                <span id="filespanpro3" class="btn btn-success fileinput-button filespanpro">
                                    <span>导入</span>
                                    <input type="file" id="upfilepro3" class="upfilepro">
                                </span>
                                <input type="button" style="display: none;margin-bottom: 10px;width: 80px;" class="btn btn-success btnpro" value="上传" id="btnpro3" ctype="spinsLostDay"/>
                                <a type="button" href="/Export/slotWeightChange/spinsLostDay" style="margin-bottom: 10px;width: 80px;" class="btn btn-success">导出</a>
                            </div>
                            <div class="row">

                                <div class="col-sm-12 form_boxs">
                                    <div class="table-responsive">
                                        <form action="" >
                                        <input type="hidden" name="type" value="spinsLostDay">
                                        <table id="roleTable_3" class="table table-bordered table-hover roleTable">
                                            <thead>
                                            <tr>
                                                <td>体力总消耗</td>
                                                <?php foreach ($trArr as $key => $val) {
                                                    echo "<td>{$val}</td>";
                                                } ?>
                                                <td>操作</td>
                                            </tr>
                                            </thead>
                                            <tbody class="dataline">
                                            <?php
                                            if(is_array($spinsLostDay['list'])  && !empty($spinsLostDay['list'])){
                                                $c=0;
                                                foreach ($spinsLostDay['list'] as $key => $val) {
                                                    echo "<tr>";
                                                    echo '<td><input type="text" class="form-control" name="k['.$c.']" value="'.$key.'"></td>';
                                                    foreach($trArr as $k=>$v){
                                                        echo '<td><input type="text" class="form-control" name="v['.$c.']['.$k.']" value="'.$val[$k].'"></td>';
                                                    }
                                                    echo '<td><button type="button"  class="btn btn-danger delete-row" ><i class="fa fa-minus-square"></i>删除</button></td>';
                                                    echo "</tr>";
                                                    $c++;
                                                } }?>
                                            </tbody>
                                        </table>
                                        </form>
                                    </div>
                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_3" dataType="spinsLostDay" lineNum="<?php echo count($spinsLostDay['list'])?>"><i class="fa fa-plus-square"></i>添加</button>

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

    <div id="msg-tip4"></div>
    <div class="container-fluid ">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i><?php echo $slotLimitDay['title'];?></header>
                    <section>
                        <div class="container-fluid">
                            <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger commitBtn"  id="commitBtn_4">提交</button>
                            <div class="row" style="padding-left: 15px;">
                                <span id="filespanpro4" class="btn btn-success fileinput-button filespanpro">
                                    <span>导入</span>
                                    <input type="file" id="upfilepro4" class="upfilepro">
                                </span>
                                <input type="button" style="display: none;margin-bottom: 10px;width: 80px;" class="btn btn-success btnpro" value="上传" id="btnpro4" ctype="slotLimitDay"/>
                                <a type="button" href="/Export/slotWeightChange/slotLimitDay" style="margin-bottom: 10px;width: 80px;" class="btn btn-success">导出</a>
                            </div>
                            <div class="row">

                                <div class="col-sm-12 form_boxs">
                                    <div class="table-responsive">
                                        <form action="" >
                                            <input type="hidden" name="type" value="slotLimitDay">
                                        <table id="roleTable_4" class="table table-bordered table-hover roleTable">
                                            <thead>
                                            <tr>
                                                <td>次数</td>
                                                <?php foreach ($trArr as $key => $val) {
                                                    echo "<td>{$val}</td>";
                                                } ?>
                                                <td>操作</td>
                                            </tr>
                                            </thead>
                                            <tbody class="dataline">
                                            <?php
                                            if(is_array($slotLimitDay['list'])  && !empty($slotLimitDay['list'])){
                                                $d=0;
                                                foreach ($slotLimitDay['list'] as $key => $val) {

                                                    echo "<tr>";
                                                    echo '<td><input type="text" class="form-control" name="k['.$d.']" value="'.$key.'"></td>';
                                                    foreach($trArr as $k=>$v){
                                                        echo '<td><input type="text" class="form-control" name="v['.$d.']['.$k.']" value="'.$val[$k].'"></td>';
                                                    }
                                                    echo '<td><button type="button"  class="btn btn-danger delete-row" ><i class="fa fa-minus-square"></i>删除</button></td>';
                                                    echo "</tr>";
                                                    $d++;
                                                } }?>
                                            </tbody>
                                        </table>
                                        </form>
                                    </div>
                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_4" dataType="slotLimitDay" lineNum="<?php echo count($slotLimitDay['list'])?>"><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 lineNum = $(this).attr("lineNum");

        var html  ='<tr class="tr_line">';
            if(dataType=='betSpinsRule'){
                html +='<td><input class="form-control" type="text" name="k['+lineNum+']" value=""></td>';
                html +='<td><input class="form-control" type="text" name="v['+lineNum+']" value=""></td>';
            }else{
                html +='<td><input class="form-control" type="text" name="k['+lineNum+']" value=""></td>';
                for (i=1;i<22;i++){
                    html +='<td><input class="form-control" type="text" name="v['+lineNum+']['+i+']" value=""></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);
        lineNum = parseInt(lineNum)+1;
        $(this).attr("lineNum",lineNum);
        console.log(dataType,lineNum);
    });

    //删除一行
    $(document).on('click', '.delete-row', function() {
        if(confirm('是否确认删除该行')){
            // console.log($(this).attr('ctype'));
            // console.log($(this).parents('.form_boxs').find('.addLine').attr("lineNum"));
            $lineNum = $(this).parents('.form_boxs').find('.addLine').attr("lineNum");
            $lineNum--;
            $(this).parents('.form_boxs').find('.addLine').attr("lineNum",$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/saveSlotWeightChangeCfg',
            success: function(data){
                // console.log(data);
                if(data.ret == 0){
                    window.location.reload()
                }else{
                    msgTip.messager().error(data.msg);
                }
            }
        });
    });

    $(".btnpro").click(function(){
        var formData = new FormData();
        var file = $(this).parent().find("input[type='file']")[0].files[0];
        var ctype=$(this).attr('ctype');
        formData.append("file",file);
        // console.log(formData);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Import/slotWeightChange/"+ctype, // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调
                data = JSON.parse(data);
                if(data.ret == 0){
                    window.location.reload();
                }else {
                    msgTip = $('#msg-tip');
                    msgTip.messager().warn('上传失败');
                }
            }
        });
    });

    $(".filespanpro").on("change", "input[type='file']", function() {
        var filePath = $(this).val();
        console.log(filePath);
        //如果仅上传图片 if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1) {
        if (filePath) {
            $(this).parent().hide();
            $(this).parent().next().show();
            // $('#filespanpro').hide();
            // $('#btnpro').show();
        } else {
            return false
        }
    });

</script>

