@extends('base.base')
@section('base')

    <style>
        .form-control:disabled, .form-control[readonly] {
            background-color: white;
            opacity: 1;
        }
    </style>

    <button type="button" class="btn btn-sm btn-gradient-success btn-icon-text" onclick="add()">
        <i class="mdi mdi-plus btn-icon-prepend"></i>
        {{ __('auto.增加控制档位') }}
    </button>

    <form onsubmit="return false;" id="form">
        <table class="table table-striped">

            <tr>
                <th>{{ __('auto.等级') }}</th>
                <th>{{ __('auto.概率') }}</th>
                <th>{{ __('auto.倍数（输入小数点）') }}</th>
                <th>{{ __('auto.操作') }}</th>
            </tr>
            @foreach($list as $val)
                <tr>
                    <td><input type="text" name="GemstoneLevel[]" value="{{$val->GemstoneLevel}}" class="form-control"></td>
                    <td><input type="text" name="RewardRate[]" value="{{$val->RewardRate}}" class="form-control"></td>
                    <td><input type="text" name="RewardMul[]" value="{{$val->RewardMul}}" class="form-control"></td>
                    <td>
                        <button class="btn btn-sm btn-gradient-danger" onclick="del(this)">{{ __('auto.删除') }}</button>
                    </td>
                </tr>
            @endforeach


        </table>

        <button type="button" onclick="commit()"
                class="btn btn-sm btn-gradient-primary btn-icon-text">
            <i class="mdi mdi-file-check btn-icon-prepend"></i>
            {{ __('auto.提交') }}
        </button>
        <button type="button" onclick="cancel()"
                class="btn btn-sm btn-gradient-warning btn-icon-text">
            <i class="mdi mdi-reload btn-icon-prepend"></i>
            {{ __('auto.取消') }}
        </button>
    </form>
@endsection

<script>
    function del(obj) {

        $(obj).parents('tr').remove()
        return false;

    }

    function commit() {
        if (!checkForm()) {
            return false;
        }
        var data = $("#form").serializeArray();
        console.log(data)
        myRequest("/admin/group_control/gemstone_update", "post", data, function (res) {
            layer.msg(res.msg)
            if (res.code == 200){
                setTimeout(function () {
                    parent.location.reload();
                }, 1500)
            }
        });
    }

    function cancel() {
        parent.location.reload();
    }

    function add() {

        html = '<tr>' +
            '<td><input type="text" name="GemstoneLevel[]" value="" class="form-control"></td>' +
            '<td><input type="text" name="RewardRate[]" value="" class="form-control"></td>' +
            '<td><input type="text" name="RewardMul[]" value="" class="form-control"></td>' +
            '<td><button class="btn btn-sm btn-gradient-danger" onclick="del(this)">{{ __('auto.删除') }}</button></td>' +
            ' </tr>'


        $('.table').append(html)
    }
</script>
