@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">
                            <div class="button-group">
                                <a href="/admin/recharge/clear_cache" class="btn btn-sn btn-primary layer-switch"
                                   data-remind="{{ __('auto.你确定要清除缓存吗？') }}">{{ __('auto.清除缓存') }}</a>
                            </div>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th width="8%">{{ __('auto.排序') }}</th>
                                    <th width="8%">{{ __('auto.图片') }}</th>
                                    <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($methods as $k=>$v)
                                    <tr>
                                        <td contentEditable="true"
                                            onblur="update_sort(this,{{$v->id}})"> {{$v->sort}} </td>

                                        <td><img src="{{ $v->config_value }}" alt="" width="80px"></td>
                                        <td>{{ $v->name }}</td>
                                        <td>{{$v->account}}</td>
                                        <td>{{$v->updated_at}}</td>
                                        <td>
                                            @if ($v->status == 1)
                                                <span style="color: #0bb20c"> {{ __('auto.已开启') }}</span>
                                            @elseif ($v->status == -1)
                                                <span style="color: red">{{ __('auto.已关闭') }}</span>
                                            @endif
                                        </td>
                                        <td>
                                            @if ($v->status == 1)
                                                <button type="button" class="btn btn-sm btn-danger" onclick="switch_control({{$v->id}},'off')">{{ __('auto.关闭') }}</button>
                                            @elseif ($v->status == -1)
                                                <button type="button" class="btn btn-sm btn-primary" onclick="switch_control({{$v->id}},'on')">{{ __('auto.开启') }}</button>
                                            @endif
                                            <button class="btn btn-sm btn-gradient-dark" onclick="updatePic({{ $v->id }})">{{ __('auto.修改图片') }}</button>
                                            <a class="btn btn-sm btn-gradient-dark layer-dialog"
                                               href="/admin/recharge/config/{{$v->config_key}}">{{ __('auto.查看渠道') }}</a>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>

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

        // 修改图片地址
        function updatePic(id) {

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

        }

        function switch_control(id,type){

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

        function update_sort(obj,id) {
            sort = $(obj).html();
            if(sort != ''){
                myRequest("/admin/recharge/update_sort/" + id, "post", {sort}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500)
                });
            }else {
                window.location.reload();
            }

        }

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

    </script>
@endsection
