<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改活动</title>
    <!-- 最新版本的 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">
        .thumbnail {
            margin: 10px;
        }

        .lang-name {
            margin-left: 42px;
        }

        .upimg {
            cursor: pointer;
        }

    </style>
</head>
<body>
<div id="msg-tip">

</div>
<div class="content_wrapper">
    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="configForm" action="#" style="margin-top: 20px">
                <header><i class="fa fa-fw fa-file"></i>卡片系数</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <button type="button" class="btn btn-success" id="configsubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <div class="row AllTypeControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                            <div class="form-group">
                                <label class="col-sm-1 control-label">
                                    <button type="button" class="btn btn-success showHide">激活修正系数配置</button>
                                </label>
                                <div class="col-sm-10" style="">
                                    <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                        <?php foreach ($activate as $k => $v) { ?>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">未激活卡数*: </label>
                                                <div class="col-sm-2">
                                                    <input type="text" class="form-control" value="<?php echo $v['num']; ?>">
                                                </div>
                                                <label class="col-sm-2 control-label">激活修正系数*: </label>
                                                <div class="col-sm-2">
                                                    <input type="text" class="form-control" name="activate[<?php echo $v['num']; ?>][]"
                                                           value="<?php echo $v['coefficient'][0]; ?>">
                                                </div>
                                                <label class="col-sm-2 control-label">未激活修正系数*: </label>
                                                <div class="col-sm-2">
                                                    <input type="text" class="form-control" name="activate[<?php echo $v['num']; ?>][]"
                                                           value="<?php echo $v['coefficient'][1]; ?>">
                                                </div>
                                            </div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row AllTypeControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                            <div class="form-group">
                                <label class="col-sm-1 control-label">
                                    <button type="button" class="btn btn-success showHide">数量修正系数</button>
                                </label>
                                <div class="col-sm-10" style="">
                                    <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>
                                                            <td>卡片数下限值</td>
                                                            <td>卡片数上限值</td>
                                                            <td>修正系数</td>
                                                        </tr>
                                                        </thead>
                                                        <tbody id="cardCoefficientConf">
                                                        <?php
                                                        if (is_array($num) && !empty($num)) {
                                                            foreach ($num as $key => $val) {
                                                                echo '<tr id="coefficientTr_' . $key . '" data-idx="' . $key . '">';
                                                                echo '<td><input type="number" class="form-control" name="num[' . $key . '][numMin]" value="' . $val['numMin'] . '"></td>';
                                                                echo '<td><input type="number" class="form-control" name="num[' . $key . '][numMax]" value="' . $val['numMax'] . '"></td>';
                                                                echo '<td><input type="number" class="form-control" name="num[' . $key . '][coefficient]" value="' . $val['coefficient'] . '"></td>';
                                                                echo '</tr>';
                                                            }
                                                        }
                                                        ?>
                                                        </tbody>
                                                        <tr>
                                                            <td colspan="3">
                                                                <div class="text-center" style="margin-top: 20px">
                                                                    <botton class="btn btn-primary addLuckyFoxRewardTrBtn" onclick="addCoefficientTr()">添加
                                                                    </botton>
                                                                    <botton class="btn btn-danger del-tr" onclick="delCoefficientTr(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>
                            </div>
                        </div>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

<script>
    function addCoefficientTr() {
        const node = $('#cardCoefficientConf')
        let lvIdx = node.find('tr:last').data('idx')
        lvIdx = lvIdx === undefined ? 0 : parseInt(lvIdx) + 1

        var html = `
        <tr id="coefficientTr_${lvIdx}"  data-idx="${lvIdx}">
            <td><input name="num[${lvIdx}][numMin]" type="number"  class="form-control" value="0"></td>
            <td><input name="num[${lvIdx}][numMax]" type="number"  class="form-control" value="0"></td>
            <td><input name="num[${lvIdx}][coefficient]" type="number"  class="form-control" value="0"></td>
        </tr>`;

        node.append(html)
    }

    function delCoefficientTr() {
        var lvIdx = $('#cardCoefficientConf').find('tr:last').data('idx')
        $('#coefficientTr_' + lvIdx).remove()
    }

    $(function () {
        $('.showHide').on("click", function () {
            if ($(this).parent().next().css("display") == "block") {
                $(this).parent().next().hide(300);
            } else {
                $(this).parent().next().show(300);
            }
        });
        $('#configsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("configForm"));
            $.ajax({
                url: rootPath + 'config/actionCardCoefficient',
                type: 'POST',
                data: data,
                dataType: 'json',
                contentType: false,
                processData: false,
                success: function (data) {
                    alert(data.msg);
                    window.location.reload();
                },
                error: function (msg) {
                    alert(data.msg);
                }
            });
        });
    });
</script>
</html>
