<div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal">
        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
    <h4 class="modal-title">返佣规则</h4>
</div>
<form id="form" class="form-horizontal">
    <input type="hidden" name="login" value="<?= Yii::$app->getRequest()->get('login') ?>">
    <div class="modal-body">
        <div class="tabs-container">
            <ul class="nav nav-tabs">
                <?php foreach ($parents as $key => $parent):?>
                    <li class="<?= $key+1 == count($parents) ? 'active' : '' ?>">
                        <a data-toggle="tab" href="#tab-<?= $key ?>"><?= $key+1 ?>级-<?= $parent['name'] ?></a></li>
                <?php endforeach;?>
            </ul>
            <div class="tab-content">
                <?php foreach ($parents as $key => $parent):?>
                    <div id="tab-<?= $key ?>" class="tab-pane <?= $key+1 == count($parents) ? 'active' : '' ?>">
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <tr>
                                        <th>
                                            FOREX
                                        </th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input name="f<?= $parent['id'] ?>" type="number" class="form-control" placeholder="FOREX每手佣金" value="<?= !empty($parent['comm']) ? $parent['comm']['forex'] : '' ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            METAL
                                        </th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input name="m<?= $parent['id'] ?>" type="number" class="form-control" placeholder="METAL每手佣金" value="<?= !empty($parent['comm']) ? $parent['comm']['metal'] : '' ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            CFD
                                        </th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input name="c<?= $parent['id'] ?>" type="number" class="form-control" placeholder="CFD每手佣金" value="<?= !empty($parent['comm']) ? $parent['comm']['cfd'] : '' ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            黄金（优先级比METAL高）
                                        </th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input name="h<?= $parent['id'] ?>" type="number" class="form-control" placeholder="黄金每手佣金" value="<?= !empty($parent['comm']) ? $parent['comm']['gold'] : '' ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            白银（优先级比METAL高）
                                        </th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input name="b<?= $parent['id'] ?>" type="number" class="form-control" placeholder="白银每手佣金" value="<?= !empty($parent['comm']) ? $parent['comm']['silver'] : '' ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            外佣
                                        </th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input name="wy<?= $parent['id'] ?>" type="number" class="form-control" placeholder="外佣" value="<?= !empty($parent['comm']) ? $parent['comm']['wy'] : '' ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            股指
                                        </th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input name="g<?= $parent['id'] ?>" type="number" class="form-control" placeholder="股指每手佣金" value="<?= !empty($parent['comm']) ? $parent['comm']['stock'] : '' ?>">
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>
                                            BTC
                                        </th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input name="bt<?= $parent['id'] ?>" type="number" class="form-control" placeholder="BTC每手佣金" value="<?= !empty($parent['comm']) ? $parent['comm']['btc'] : '' ?>">
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                <?php endforeach;?>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
        <button id="submit" type="button" class="btn btn-primary">提交</button>
    </div>
</form>
<script type="text/javascript">
    $("#submit").on("click", function () {
        $.ajax({
            type: "POST",
            url: "<?= \yii\helpers\Url::to(['set-commission']) ?>",
            data: $('#form').serialize(),
            dataType: "json",
            beforeSend: function () {
            },
            success: function (data) {
                if (data.isSuccess) {
                    $("#modal").modal("hide");
                    location.reload();
                } else {
                    toastr.error(data.msg, "提示");
                }
            },
            complete: function (XMLHttpRequest, textStatus) {
            },
            error: function () {
            }
        });
    });
</script>