<title>体力瓶配置</title>
<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>

<!-- 最新版本的 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">


<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>体力瓶奖励配置</header>
                    <section>
                        <div class="container-fluid">
                            <button type="button" class="btn btn-success" id="submitBtn">提交</button>
                            <div class="row">
                                <form action="" >
                                <div class="form-group" >
                                    <label class="col-sm-1 control-label">是否开启</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="conf[isOpen]" value="<?php echo $list['baseCfg']['isOpen'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">开启等级</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="conf[spinsPotStartLevel]" value="<?php echo $list['baseCfg']['spinsPotStartLevel'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">回购时间(单位/秒)</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="conf[spinsPotReBuyDay]" value="<?php echo $list['baseCfg']['spinsPotReBuyDay'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">弹出间隔</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="conf[showTimes]" value="<?php echo $list['baseCfg']['showTimes'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">主题目录</label>
                                    <div class="col-sm-2">
                                        <select class="form-control" name="conf[resourceDir]">
                                            <?php foreach ($resourceDirs as $k=>$v){
                                                $selected ="";
                                                if($list['baseCfg']['resourceDir']==$v['type']){
                                                    $selected = "selected";
                                                }
                                                echo '<option value="'.$v['type'].'" '.$selected.'>'.$v["name"].'</option>';
                                            }?>
                                        </select>
                                    </div>
                                </div>
                                </form>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>


<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>体力瓶奖励配置</header>
                    <section>
                        <div class="container-fluid">
                            <div class="container-fluid">
                                <div class="row"  style="margin-bottom: 10px">
                                    <button type="button" style="margin-right:10px;width: 80px;" class="btn btn-danger"  id="commitBtn_2">提交</button>

                                    <span id="upfile_b" class="btn btn-success fileinput-button">
                                        <span>导入</span>
                                        <input type="file" id="upfile2">
                                    </span>
                                    <input type="button" style="display: none;width: 80px;" class="btn btn-success" value="上传" id="upfileBtn2"/>
                                    <a type="button" href="/Export/spinsPotGiftOut" style="width: 80px;" class="btn btn-success">导出</a>
                                </div>
                            </div>
                            <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 width="140">开始等级</td>
                                                    <td width="140">结束等级</td>
                                                    <td width="140">起始值</td>
                                                    <td>首次</td>
                                                    <td>复购</td>
                                                    <td>长时间未购</td>
                                                    <td width="120">操作</td>
                                                </tr>
                                                </thead>
                                                <tbody class="dataline">

                                                </tbody>
                                            </table>
                                        </form>
                                    </div>
                                    <button type="button"  class="btn btn-primary addLine"  id="addBtn_1" dataType="betSpinsRule" lineNum="<?php echo count($list['giftPack'])?>"><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>
                <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="form4" action="#" style="margin-top: 20px">
                    <header><i class="fa fa-fw fa-file"></i>体力瓶权重配置</header>
                    <section style="padding-left: 15px;">
                        <div class="container-fluid">
                            <div class="row" style="margin-bottom: 10px;">
                        <span id="upfile_a" class="btn btn-success fileinput-button">
                            <span>导入</span>
                            <input type="file" id="upfile1">
                        </span>
                                <input type="button" style="display: none;margin-bottom: 10px;width: 80px;" class="btn btn-success" value="上传" id="upfileBtn1"/>
                                <a type="button" href="/Export/spinsPotWeightOut" style="width: 80px;" class="btn btn-success">导出</a>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="table-responsive">
                                    <table id="roleTable2" class="table table-bordered table-hover"
                                           data-toggle="table"
                                           data-classes="table table-hover"
                                           data-show-columns="true"
                                           data-striped="true"
                                           data-height="500">
                                        <thead>
                                        <tr>
                                            <th>用户等级</th>
                                            <th>一个瓶权重</th>
                                            <th>一个瓶分值</th>
                                            <th>两个瓶权重</th>
                                            <th>两个瓶分值</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php
                                        if(!empty($list['spinsWeight'])){
                                            foreach ($list['spinsWeight'] as $key => $vl) { ?>
                                                <tr>
                                                    <td><?php echo $vl['levelId'];?></td>
                                                    <td><?php echo $vl['weightOne'];?></td>
                                                    <td><?php echo $vl['scoreOne'];?></td>
                                                    <td><?php echo $vl['weightTwo'];?></td>
                                                    <td><?php echo $vl['scoreTwo'];?></td>
                                                </tr>
                                            <?php } } else{?>
                                            <tr>
                                                <td colspan="5">暂无数据</td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                                <nav>
                                    <ul class="pagination">
                                        <li class="disabled"><a href="#">共<span class="pagetotal"><?php echo count($list['spinsWeight']);?></span>条</a></li>
                                    </ul>
                                </nav>
                            </div>
                        </div>
                    </section>
                </form>
            </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>
    //提交表格数据
    $('#submitBtn').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/saveSpinsPotBaseCfg',
            success: function(data){
                // console.log(data);
                if(data.ret == 1){
                    alert(data.msg);
                    window.location.reload()
                }else{
                    msgTip.messager().error(data.msg);
                }
            }
        });
    });
</script>

<script>
    var priceArr = <?php echo json_encode($priceArr)?>;
    var dataList = <?php echo json_encode($list['giftPack'])?>;
        console.log(dataList);
    var lineNum =0;
    function getOneHtml(typ,data) {
        var html = '<div class="ibox-content">';
        html += '<div class="form-group row">';
        html +='<label class="col-sm-3">体力值:</label><div class="col-sm-6"><input class="form-control" type="text" name="conf['+lineNum+']['+typ+'][maxNum]" value="'+data.maxNum+'">';
        html+='</div></div>';
        html += '<div class="form-group row">';
        html +='<label class="col-sm-3">价格:</label><div class="col-sm-6"><select name="conf['+lineNum+']['+typ+'][price]" class="select form-control selectSku">';
        for(let i in priceArr){
            one = priceArr[i];
            var sel = "";
            if (one.price== data.price){
                sel = "selected";
            }
            html +='<option value="'+one.price+'" '+sel+'>'+one.price+'</option>';
        }
        html +='</select></div></div>';
        html +='<input  class="form-control shuclass" type="hidden" name="conf['+lineNum+']['+typ+'][sku]" value="'+data.sku+'">';
        html +="</div>";
        return html;
    }
    function getLineHtml(data){
        let html = '<tr class="tr_line">';
        html += '<td><input class="form-control" type="text" name="conf[' + lineNum + '][startlv]" value="' + data.startlv + '"></td>';
        html += '<td><input class="form-control" type="text" name="conf[' + lineNum + '][endlv]" value="' + data.endlv + '"></td>';
        html += '<td><input class="form-control" type="text" name="conf[' + lineNum + '][initval]" value="' + (data.initval ?? '') + '"></td>';

        html +='<td>';
        html += getOneHtml("firstcfg",data.firstcfg);
        html +='</td>';
        html +='<td>';
        html += getOneHtml("againcfg",data.againcfg);
        html +='</td>';
        html +='<td>';
        html += getOneHtml("longtimecfg",data.longtimecfg);
        html +='</td>';

        html +='<td><button type="button"  class="btn btn-danger delete-row" ><i class="fa fa-minus-square"></i>删除</button></td>';
        html +=" </tr>";
        return html;
    }
    $.each(dataList, function(i,v){
        lineNum++;
        html =getLineHtml(v);
        $('.dataline').append(html)
    });
    //
    $(document).on('change','.selectSku',function (e) {
        var sku = "";
        console.log($(this).val());
        for(let i in priceArr){
            one = priceArr[i];
            if (one.price== $(this).val()){
                sku = one.sku
            }
        }
        console.log(sku);
        $(this).parent().next('.shuclass').val(sku)
    });

    //新增一行
    $('.addLine').on('click', function () {
        lineNum = $(this).attr("lineNum");
        lineNum = parseInt(lineNum) + 1;

        let data = {"startlv": 1, "endlv": 49, "initval": 0, "firstcfg": {"maxNum": 1000, "sku": "com.gworld.cc.gift08", "price": 2.99}, "againcfg": {"maxNum": 1000, "sku": "com.gworld.cc.gift04", "price": 4.99}, "longtimecfg": {"maxNum": 2000, "sku": "com.gworld.cc.gift04", "price": 4.99}};
        let html = getLineHtml(data);
        $(this).parent().find('.dataline').append(html);

        $(this).attr("lineNum", 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_2').click(function () {
        var datas = $(this).parent().parent().parent().find('form').serializeArray();
        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:datas,
            url:'config/saveSpinsPotGift',
            success: function(data){
                console.log(data);
                alert(data.msg);

                if(data.ret == 1){
                    window.location.reload()
                }
            }
        });
    });

</script>


<script>
    //上传体力权重表
    $("#upfile_a").on("change", "input[type='file']", function() {
        var filePath = $(this).val();
        //如果仅上传图片 if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1) {
        if (filePath) {
            $('#upfile_a').hide();
            $("#upfileBtn1").show();
        } else {
            return false
        }
    });
    //导入权重配置
    $("#upfileBtn1").click(function(){
        var formData = new FormData();
        formData.append("file",document.getElementById("upfile1").files[0]);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Import/spinsPotWeightIn", // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调
                data = JSON.parse(data);
                // console.log(data);
                if(data.ret == 0){
                    // console.log(data)
                    alert(data.msg);
                    window.location.reload();
                }else {
                    // msgTip = $('#msg-tip');
                    alert(data.msg);
                    // window.location.reload();
                }
            }
        });
    });
    //=======================
    //上传体力瓶奖励表
    $("#upfile_b").on("change", "input[type='file']", function() {
        var filePath = $(this).val();
        //如果仅上传图片 if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1) {
        if (filePath) {
            $('#upfile_b').hide();
            $("#upfileBtn2").show();
        } else {
            return false
        }
    });
    //导入体力瓶奖励表
    $("#upfileBtn2").click(function(){
        var formData = new FormData();
        formData.append("file",document.getElementById("upfile2").files[0]);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Import/spinsPotGiftIn", // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调


                data = JSON.parse(data);
                // console.log(data)
                if(data.ret == 0){
                    // console.log(data)
                    alert(data.msg);
                    window.location.reload();
                }else {
                    alert(data.msg);
                    // window.location.reload();
                }
            }
        });
    });
</script>

