<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">
<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.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>
<script src="<?php echo base_url();?>public/js/vendor/select2/select2.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 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>体力返比开关</header>
                    <section>
                        <div class="container-fluid">
                            <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger "  id="commitMinStage2">提交</button>
                        </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label m-b">开关:</label>
                                <div class="col-sm-4 input-group">
                                    <label class="checkbox-inline">
                                        <input type="radio" name="status" <?php if($status==0) echo "checked";?> value="0"> 关闭
                                    </label>
                                    <label class="checkbox-inline">
                                        <input type="radio" name="status" <?php if($status==1) echo "checked";?> value="1"> 开启
                                    </label>
                                </div>
                            </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>

<div class="content_wrapper">
    <div id="msg-tip"></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 $titleArr['configA'];?></header>
                    <section>
                        <?php if($configType == 'freezePoint'){?>
                            <div class="form-group row" style="display: flex;align-items: center">
                                <div class="col-sm-1" ><label >最小触发层级:</label></div>
                                <div class="col-sm-4">
                                    <input id="freezePointMinStage" class="form-control" value="<?=$minStage?>">
                                </div>
                                <div class="col-sm-3">
                                    <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger "  id="commitMinStage">提交</button>
                                </div>
                            </div>
                        <?php }?>
                        <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" style="padding-left: 15px;">
                                <span id="filespanpro1" class="btn btn-success fileinput-button filespanpro">
                                    <span>导入</span>
                                    <input type="file" id="upfilepro1" class="upfilepro">
                                </span>
                                <input type="button" style="display: none;margin-bottom: 10px;width: 80px;" class="btn btn-success btnpro" value="上传" id="btnpro1" ctype="configA"/>
                                <a type="button" href="<?=$exportUrlA?>" style="margin-bottom: 10px;width: 80px;" class="btn btn-success">导出</a>
                            </div>
                            <div style="color: red;">A = <?=$titleArr['A']?></div>
                            <div style="color: red;">B = <?=$titleArr['B']?></div>
                            <div class="row">

                                <div class="col-sm-12 form_boxs">
                                    <div class="table-responsive">
                                        <form action="">
                                            <div class="form-group row" style="display: none">
                                                <label class="col-sm-1">数数分组:</label>
                                                <div class="col-sm-11">
                                                    <select multiple name="groups[]" class="select2 form-control">
                                                        <?php foreach($ssGroups as $id => $group){ ?>
                                                            <option value="<?=$id?>"  <?php if(in_array($id, $configA['groups']))echo 'selected';?>  ><?=$group?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>

                                            </div>

                                         <input type="hidden" name="type" value="configA">
                                        <table id="roleTable_1" class="table table-bordered table-hover roleTable">
                                            <thead>
                                            <tr>
                                                <th>A\B</th>
                                                <?php foreach ($trArr as $key => $val) {
                                                    echo "<th>{$val}</th>";
                                                } ?>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody class="dataline">
                                            <?php
                                            if(is_array($configA['list'])  && !empty($configA['list'])){
                                                $b=0;
                                                foreach ($configA['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_1" dataType="spinsLost" lineNum="<?php echo count($configA['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 $titleArr['configB'];?></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="configB"/>
                                <a type="button" href="<?=$exportUrlB?>" 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="">
                                            <div class="form-group row">
                                                <label class="col-sm-1">数数分组:</label>
                                                <div class="col-sm-11">
                                                    <select multiple name="groups[]" class="select2 form-control">
                                                        <?php foreach($ssGroups as $id => $group){ ?>
                                                            <option value="<?=$id?>" <?php if(in_array($id, $configB['groups']))echo 'selected';?>  ><?=$group?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
                                         <input type="hidden" name="type" value="configB">
                                        <table id="roleTable_2" class="table table-bordered table-hover roleTable">
                                            <thead>
                                            <tr>
                                                <th>A\B</th>
                                                <?php foreach ($trArr as $key => $val) {
                                                    echo "<th>{$val}</th>";
                                                } ?>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody class="dataline">
                                            <?php
                                            if(is_array($configB['list'])  && !empty($configB['list'])){
                                                $b=0;
                                                foreach ($configB['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($configB['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>
    $('.select2').select2({})
    //新增一行
    $('.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<=11;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:'<?=$saveUrl?>',
            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: "<?=$importUrl?>/"+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
        }
    });

    $('#commitMinStage').click(function(){
        var minStage = $('#freezePointMinStage').val()
        console.log(minStage)
        showLoading()
        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:{minStage:minStage},
            url:'/config/saveSlotFreezePointMinStage',
            success: function(data){
                hideLoading()
                console.log(data);
                alert(data.msg)
            }
        });
    })

    $('#commitMinStage2').click(function(){
        var status = $('input[name="status"]:checked').val();
        // showLoading()
        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:{status:status},
            url:'/config/saveSlotSpinsReturnStatus',
            success: function(data){
                // hideLoading()
                console.log(data);
                alert(data.msg)
            }
        });
    })


</script>

