<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 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">
                            <div style="margin-bottom: 10px;">
                                <button type="button" style="width: 80px;" class="btn btn-danger commitBtn" id="commitBtn_1">提交</button>

                                <span id="filespan" class="btn btn-success fileinput-button" style="margin-left: 50px;top: 0;">
                                    <label style="margin-bottom: 0" for="upfile1">导入</label>
                                    <input type="file" id="upfile1">
                                </span>
                                <input type="button" style="display: none;margin: 5px;top: 0;width: 80px;" class="btn btn-success" value="上传" id="btn1"
                                       onclick="importStealLuckConf()"/>
                                <a type="button" href="/Export/stealLuckConf" style="margin: 5px;" 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="1">
                                            <table id="roleTable_1" class="table table-bordered table-hover roleTable">
                                                <thead>
                                                <tr>
                                                    <th width="20%">Index</th>
                                                    <th>倍率</th>
                                                    <th>消耗值</th>
                                                </tr>
                                                </thead>
                                                <tbody id="stealBottleConf">
                                                <?php
                                                if (is_array($list2['mulSpend']) && !empty($list2['mulSpend'])) {
                                                    foreach ($list2['mulSpend'] as $key => $val) {
                                                        echo '<tr id="stealBottleTr_' . $key . '" data-idx="' . $key . '">';
                                                        $index = $key + 1;
                                                        echo '<td width="120"><input type="number" class="form-control" name="" value="' . $index . '" readonly></td>';
                                                        echo '<td><input type="number" class="form-control" name="conf[mulSpend][' . $key . '][mul]" value="' . $val['mul'] . '"></td>';
                                                        echo '<td><input type="number" class="form-control" name="conf[mulSpend][' . $key . '][spend]" value="' . $val['spend'] . '"></td>';
                                                        echo '</tr>';
                                                    }
                                                }
                                                ?>
                                                </tbody>
                                                <tr>
                                                    <td colspan="3">
                                                        <div class="text-center" style="margin-top: 20px">
                                                            <botton class="btn btn-primary addLuckyFoxRewardTrBtn" onclick="addStealBottleConfTr()">添加
                                                            </botton>
                                                            <botton class="btn btn-danger del-tr" onclick="delStealBottleConfTr(this)">删除</botton>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </form>
                                    </div>
                                    <!--                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_1" dataType="betSpinsRule" pid=""><i class="fa fa-plus-square"></i>添加</button>-->

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

<div class="content_wrapper">
    <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">
                            <div style="margin-bottom: 10px;">
                                <button type="button" style="width: 80px;" class="btn btn-danger commitBtn" id="commitBtn_2">提交</button>

                                <span id="filespan2" class="btn btn-success fileinput-button" style="margin-left: 50px;top: 0;">
                                    <label style="margin-bottom: 0" for="upfile2">导入</label>
                                    <input type="file" id="upfile2">
                                </span>
                                <input type="button" style="display: none;margin: 5px;top: 0;width: 80px;" class="btn btn-success" value="上传" id="btn2"
                                       onclick="importSpinLuckConf()"/>
                                <a type="button" href="/Export/spinsLuckConf" style="margin: 5px;" 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="2">
                                            <div class="form-group">
                                                <label style="text-align: right;" class="col-sm-2 control-label m-b;">随机数(浮点数): </label>
                                                <div class="col-sm-3 input-group">
                                                    <input type="number" style="text-align: center" class="form-control"
                                                           name="conf[rand][min]"
                                                           placeholder="0.0"
                                                           value="<?php echo $list3['rand']['min'] ?>">
                                                    <span class="input-group-addon">-</span>
                                                    <input type="number" style="text-align: center" class="form-control"
                                                           name="conf[rand][max]"
                                                           placeholder="0.0"
                                                           value="<?php echo $list3['rand']['max'] ?>">
                                                </div>
                                            </div>
                                            <table id="roleTable_3" class="table table-bordered table-hover roleTable">
                                                <thead>
                                                <tr>
                                                    <th width="20%">Index</th>
                                                    <th>倍率</th>
                                                    <th>消耗值</th>
                                                </tr>
                                                </thead>
                                                <tbody id="spinBottleConf">
                                                <?php
                                                if (is_array($list3['mulSpend']) && !empty($list3['mulSpend'])) {
                                                    foreach ($list3['mulSpend'] as $key => $val) {
                                                        echo '<tr id="spinsBottleTr_' . $key . '" data-idx="' . $key . '">';
                                                        $index = $key + 1;
                                                        echo '<td width="120"><input type="number" class="form-control" name="" value="' . $index . '" readonly></td>';
                                                        echo '<td><input type="number" class="form-control" name="conf[mulSpend][' . $key . '][mul]" value="' . $val['mul'] . '"></td>';
                                                        echo '<td><input type="number" class="form-control" name="conf[mulSpend][' . $key . '][spend]" value="' . $val['spend'] . '"></td>';
                                                        echo '</tr>';
                                                    }
                                                }
                                                ?>
                                                </tbody>
                                                <tr>
                                                    <td colspan="3">
                                                        <div class="text-center" style="margin-top: 20px">
                                                            <botton class="btn btn-primary addLuckyFoxRewardTrBtn" onclick="addSpinsBottleConfTr()">添加
                                                            </botton>
                                                            <botton class="btn btn-danger del-tr" onclick="delSpinsBottleConfTr(this)">删除</botton>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </form>
                                    </div>
                                    <!--                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_1" dataType="betSpinsRule" pid=""><i class="fa fa-plus-square"></i>添加</button>-->

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

<div class="content_wrapper">
    <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 commitBtn" >提交</button>

                            <div class="col-sm-12 form_boxs">
                                <div class="table-responsive">
                                    <form action="">
                                        <input type="hidden" name="type" value="joker">
                                        <input type="hidden" id="jokerStatus" name="conf[status]" value="<?=$joker['status']??0 ?>">
                                        <div class="form-group">
                                            <label style="text-align: right;" class="col-sm-2 ">保底功能开关: </label>
                                            <div class="col-sm-3 ">
                                                <input  class="updateStatusSwitch " <?php echo $joker['status'] == 1 ? 'checked' : '';?>  type="checkbox"  data-on-text="开启" data-off-text="关闭" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label style="text-align: right;" class="col-sm-2 ">保底触发值: </label>
                                            <div class="col-sm-3 input-group">
                                                <input class="form-control" name="conf[triggerNum]" value="<?=$joker['triggerNum']??0 ?>" />
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                <!--                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_1" dataType="betSpinsRule" pid=""><i class="fa fa-plus-square"></i>添加</button>-->

                            </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>
    //提交表格数据
    $('.commitBtn').click(function () {
        var datas = $(this).parent().parent().find('form').serializeArray();
        // console.log(datas);
        showLoading()
        $.ajax({
            type: 'POST',
            dataType: 'json',
            data: datas,
            url: 'config/actionUserLuck',
            success: function (data) {
                hideLoading()
                console.log(data);
                if (data.ret == 0) {
                    window.location.reload()
                } else {
                    msgTip.messager().error(data.msg);
                }
            },
            error:function(xhr, error){
                alert('请求失败！')
                hideLoading()
                console.log(xhr,error);
            }
        });
    });

    function addStealBottleConfTr() {
        var lvIdx = $('#stealBottleConf').find('tr:last').data('idx')
        lvIdx = lvIdx === undefined ? 0 : parseInt(lvIdx) + 1

        var html = `
        <tr id="stealBottleTr_${lvIdx}"  data-idx="${lvIdx}">
            <td width="120"><input type="text"  class="form-control" value="${lvIdx + 1}" readonly ></td>
            <td><input name="conf[mulSpend][${lvIdx}][mul]" type="number"  class="form-control" value="0"></td>
            <td><input name="conf[mulSpend][${lvIdx}][spend]" type="number"  class="form-control" value="0"></td>
        </tr>`;

        $('#stealBottleConf').append(html)
    }

    function delSpinsBottleConfTr() {
        var lvIdx = $('#spinBottleConf').find('tr:last').data('idx')
        $('#spinsBottleTr_' + lvIdx).remove()
    }

    function addSpinsBottleConfTr() {
        var lvIdx = $('#spinBottleConf').find('tr:last').data('idx')
        lvIdx = lvIdx === undefined ? 0 : parseInt(lvIdx) + 1

        var html = `
        <tr id="spinsBottleTr_${lvIdx}"  data-idx="${lvIdx}">
            <td width="120"><input type="text"  class="form-control" value="${lvIdx + 1}" readonly ></td>
            <td><input name="conf[mulSpend][${lvIdx}][mul]" type="number"  class="form-control" value="0"></td>
            <td><input name="conf[mulSpend][${lvIdx}][spend]" type="number"  class="form-control" value="0"></td>
        </tr>`;

        $('#spinBottleConf').append(html)
    }

    function delSpinsBottleConfTr() {
        var lvIdx = $('#spinBottleConf').find('tr:last').data('idx')
        $('#spinsBottleTr_' + lvIdx).remove()
    }

    // function addStealLuckConfTr() {
    //     var lvIdx = $('#stealLuckConf').find('tr:last').data('idx')
    //     lvIdx = lvIdx === undefined ? 0 : parseInt(lvIdx) + 1
    //
    //     var html = `
    //     <tr id="stealLuckTr_${lvIdx}"  data-idx="${lvIdx}">
    //         <td><input type="number" class="form-control" name="" value="${lvIdx}"></td>
    //         <td><input name="conf[${lvIdx}][0]" type="number"  class="form-control" value="0"></td>
    //         <td><input name="conf[${lvIdx}][1]" type="number"  class="form-control" value="0"></td>
    //     </tr>`;
    //
    //     $('#stealLuckConf').append(html)
    // }
    //
    // function delStealLuckConfTr() {
    //     var lvIdx = $('#stealLuckConf').find('tr:last').data('idx')
    //     $('#stealLuckTr_' + lvIdx).remove()
    // }

    // 导入
    function importStealLuckConf() {
        var formData = new FormData();
        formData.append("file", document.getElementById(`upfile1`).files[0]);
        console.log(formData);

        $.ajax({
            type: "POST", // 数据提交类型
            url: "Config/importStealLuckConf", // 发送地址
            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(data.msg);
                }
            }
        });
    }

    // 导入
    function importSpinLuckConf() {
        var formData = new FormData();
        formData.append("file", document.getElementById(`upfile2`).files[0]);
        console.log(formData);

        $.ajax({
            type: "POST", // 数据提交类型
            url: "Config/importSpinLuckConf", // 发送地址
            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(data.msg);
                }
            }
        });
    }

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

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


    $('.updateStatusSwitch').bootstrapSwitch({});
    var bootstrapSwitch = $('.bootstrap-switch')
    // if (bootstrapSwitch.width() > bootstrapSwitch.find('.bootstrap-switch-handle-on').width()*2.5 ){
    //     bootstrapSwitch.width(bootstrapSwitch.find('.bootstrap-switch-handle-on').width() * 2)
    // }
    $('.updateStatusSwitch').on('switchChange.bootstrapSwitch', function (event,state) {
        var status = state ? 1 : 0;
        console.log(status)
        $('#jokerStatus').val(status)
    });
</script>

