@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.充值档位修改') }}</h4>

                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th width="5%">{{ __('auto.充值档位') }}</th>
                                    <th width="8%">{{ __('auto.客户端显示支持渠道') }}</th>
                                    <th width="8%">{{ __('auto.支持渠道修改') }}</th>
                                    <th width="8%">{{ __('auto.档位显示开关') }}</th>
                                    <th width="8%">{{ __('auto.修改配置') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $k=>$v)
                                    <tr >
                                        <th colspan="5">{{ $v->name }}</th>
                                    </tr>
                                    <tr>
                                        <td>{{ $v->money }}{{ env('CONFIG_24680_CURRENCY') }}</td>

                                        <td>{{$v->gear}}</td>

                                        <td>
                                            <button class="btn btn-sm btn-gradient-dark" onclick="update({{$v->id}})">
                                                {{ __('auto.修改') }}
                                            </button>
                                        </td>
                                        <td>
                                            @if ($v->status == 1)
                                                <span style="color: #0bb20c">{{ __('auto.已开启') }}</span>
                                                <button type="button" class="btn btn-sm btn-danger"
                                                        onclick="switch_control({{$v->id}},'off')">{{ __('auto.关闭') }}
                                                </button>
                                            @elseif ($v->status == -1)
                                                <span style="color: red">{{ __('auto.已关闭') }}</span>

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

                                        <td>
                                            <button class="btn btn-sm btn-gradient-dark"
                                                    onclick="update_config({{$v->id}})">{{ __('auto.修改配置') }}
                                            </button>
                                        </td>

                                    </tr>
                                @endforeach
                                </tbody>
                                <tr>
                                    <th colspan="5">{{ __('auto.首充档位配置') }}({{ __('auto.旧首充') }})</th>
                                </tr>
                                <tr>
                                    <td>10{{ env('CONFIG_24680_CURRENCY') }}</td>
                                    <td>{{ $oldRechargeChannel }}</td>
                                    <td>
                                        <select name="Template" id="payTemplate" class="form-control" onchange="gradeChange(this.options[this.options.selectedIndex].value)">

                                            <option value="">{{ __('auto.请选择支付渠道') }}</option>
                                            @foreach($pay_list as $key=>$val)
                                                <option value="{{$key}}" @if ($oldRecharge->StatusValue == $key)
                                                selected
                                                    @endif>{{$val}}</option>
                                            @endforeach
                                        </select>
                                    </td>
                                    <td>
                                        @if ($oldRechargeStatus->StatusValue == 1)
                                            <span style="color: #0bb20c">{{ __('auto.已开启') }}</span>
                                            <button type="button" class="btn btn-sm btn-danger"
                                                    onclick="updateStatusFunc(2)">{{ __('auto.关闭') }}
                                            </button>
                                        @else
                                            <span style="color: red">{{ __('auto.已关闭') }}</span>
                                            <button type="button" class="btn btn-sm btn-primary"
                                                    onclick="updateStatusFunc(1)">{{ __('auto.开启') }}
                                            </button>
                                        @endif
                                    </td>
                                    <td>
                                        {{ __('auto.无法修改配置') }}
                                    </td>
                                </tr>
                            </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_config(id) {
            layer.open({
                type: 2,
                title: '{{ __('auto.修改充值档位') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['50%', '50%'],
                content: '/admin/recharge/update_config/' + id
            });
        }

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

        function switch_control(id, type) {

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

        // 推荐充值档位
        function gradeChange(StatusValue) {
            myRequest('/admin/recharge/recomendar_recharge','get',{StatusValue},function (res) {
                layer.msg(res.msg)
            })
        }

        // 10元首充礼包渠道状态修改
        function updateStatusFunc(StatusValue) {
            myRequest('/admin/recharge/first_charge_status','get',{StatusValue},function (res) {
                layer.msg(res.msg)
                window.location.reload();
            })
        }

        // 修改首冲10元礼包渠道
        function gradeChange(StatusValue) {
            myRequest('/admin/recharge/first_charge','get',{StatusValue},function (res) {
                layer.msg(res.msg)
                window.location.reload();
            })
        }
    </script>
@endsection
