@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="page-header">
                <h3 class="page-title">
                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
                        <i class="mdi mdi-settings"></i>
                    </span>
                    {{ __('auto.咖啡档位修改') }}
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">{{ __('auto.咖啡管理') }}</a></li>
                        <li class="breadcrumb-item active" aria-current="page">{{ __('auto.咖啡档位修改') }}</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">{{ __('auto.档位：') }}{{$info->money}}{{ __('auto.卢币') }}</h4>

                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th width="5%">{{ __('auto.渠道名称') }}</th>
                                    <th width="8%">{{ __('auto.档位显示开关') }}</th>

                                </tr>
                                </thead>
                                <tbody>

                                @foreach($names as $k=>$v)
                                    <tr>
                                        <td>{{ $v }}</td>

                                        <td>
                                            @if (exist_array($k,$info->gear))
                                                <button type="button" class="btn btn-sm btn-danger"
                                                        onclick="switch_control({{$info->id}},{{$k}},'off')">{{ __('auto.关闭') }}
                                                </button>

                                            @else
                                                <button type="button" class="btn btn-sm btn-primary"
                                                        onclick="switch_control({{$info->id}},{{$k}},'on')">{{ __('auto.开启') }}
                                                </button>
                                            @endif

                                        </td>

                                    </tr>
                                @endforeach
                                </tbody>
                            </table>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>

        function add() {
            layer.open({
                type: 2,
                title: '{{ __('auto.添加咖啡档位') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['50%', '50%'],
                content: '/admin/recharge/add'
            });
        }

        function update() {
            layer.open({
                type: 2,
                title: '{{ __('auto.渠道修改') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['50%', '50%'],
                content: '/admin/recharge/update'
            });
        }

        function switch_control(id, config_id, type) {

            console.log(id)
            myConfirm("{{ __('auto.操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/recharge/gear_switch/" + id, "post", {config_id, type}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1500)
                });
            });
        }


    </script>
@endsection
