@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>

                            <form class="well form-inline margin-top-20" method="get"
                                  action='/admin/channel/recharge_game'>
                                <span style="padding-left: 5px">{{ __('auto.游戏：') }}</span>
                                <input type="text" name="ChannelPackageName" value="{{$list['ChannelPackageName']}}"
                                       class="form-control">&nbsp;&nbsp;
                                <input type="submit" class="btn btn-sm btn-gradient-dark btn-icon-text" value="{{ __('auto.搜索') }}"/>&nbsp;&nbsp;
                                <a href="/admin/channel/recharge_game"
                                   class="btn btn-sm btn-gradient-warning btn-icon-text">{{ __('auto.清空') }}&{{ __('auto.刷新') }}</a>&nbsp;&nbsp;

                                <button class="btn-sm btn-gradient-dark" onclick="OpenGamesFunc(-1,'');return false;">
                                    {{ __('auto.开启游戏默认配置') }}
                                </button>
                                &nbsp;
                                <a class="layer-dialog btn-sm btn-gradient-dark"
                                   href="/admin/channel/withdrawal_configall">{{ __('auto.除103修改免审茶叶渠道') }}</a>
                                &nbsp;
                                <a class="layer-dialog btn-sm btn-gradient-dark"
                                   href="/admin/channel/withdrawal_switch">{{ __('auto.茶叶可审核状态切换') }}</a>
                                &nbsp;
                                <button class="btn-sm btn-gradient-dark" onclick="addNewPlatform();return false;">
                                    {{ __('auto.添加新渠道') }}
                                </button>


                            </form>


                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th >{{ __('auto.游戏包名') }}</th>
                                    <th >{{ __('auto.渠道号') }}</th>
                                    <th >{{ __('auto.审核中') }}</th>
                                    <th width="10%">{{ __('auto.展示开放游戏') }}</th>
                                    <th >{{ __('auto.开放咖啡渠道') }}</th>
{{--                                    <th >{{ __('auto.开放游戏配置修改') }}</th>--}}
                                    <th width="6%" >{{ __('auto.咖啡渠道修改') }}</th>
                                    <th width="6%">{{ __('auto.免审茶叶渠道修改') }}</th>
                                    <th width="6%">{{ __('auto.分享链接') }}</th>
                                    <th >{{ __('auto.备注') }}</th>
                                    <th >APPKEY</th>
                                    <th >{{ __('auto.上个控最小携带') }}</th>
                                    <th >{{ __('auto.个控分数') }}</th>
                                    <th >{{ __('auto.个控概率') }}</th>

                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list['list'] as $k=>$v)
                                    <tr>
                                        <td>{{$v->PackageName}}</td>
                                        <td >{{$v->Channel}}</td>
                                        <td onclick="review(this,{{$v->ID}})">{{$v->InReview}}</td>
                                        <td onclick="OpenGamesFunc({{$v->Channel}},'{{$v->PackageName}}')">{{$v->KindName}}</td>
                                        <td>{{$v->rechargeName}}</td>
{{--                                        <td>--}}
{{--                                            <button class="btn-sm btn-gradient-dark"--}}
{{--                                                    onclick="OpenGamesFunc({{$v->Channel}},'{{$v->PackageName}}')">--}}
{{--                                                {{ __('auto.修改') }}--}}
{{--                                            </button>--}}
{{--                                        </td>--}}
                                        <td>
                                            <a class="btn-sm btn-gradient-dark layer-dialog"
                                                    href="/admin/channel/pay_methods/{{$v->Channel}}">
                                                {{ __('auto.修改') }}
                                            </a>
                                        </td>
                                        <td>
                                            <a class="layer-dialog btn-sm btn-gradient-dark"
                                               href="/admin/channel/withdrawal_config/{{$v->Channel}}">{{ __('auto.修改') }}</a>
                                        </td>
                                        <td style="vertical-align: top">
                                            <a class="btn btn-sm btn-gradient-dark layer-dialog"
                                               href="/admin/channel/share_config/{{$v->ID}}">{{ __('auto.修改') }}</a>
                                        </td>
                                        <td  contentEditable="true"
                                             onblur="remarks(this,{{$v->ID}})" style="vertical-align: top">{{$v->Remarks}}</td>
                                        <td  onclick="makekey(this,{{$v->ID}})"
                                             style="vertical-align: top">{{$v->AppKey}}</td>

                                        <td  contentEditable="true"
                                             onblur="minScore(this,{{$v->ID}})" style="vertical-align: top">{{$v->MinScore}}</td>

                                        <td  contentEditable="true"
                                             onblur="contrlScore(this,{{$v->ID}})" style="vertical-align: top">{{$v->ContrlScore}}</td>

                                        <td  contentEditable="true"
                                             onblur="rateN(this,{{$v->ID}})" style="vertical-align: top">{{$v->Rate}}</td>

                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix" id="pages">
                                {{ __('auto.总共') }} <b>{{ $list['list']->appends([
                                        'list'=>$list['list'],
                                        'ChannelPackageName'=>$list['ChannelPackageName']
])->total() }}</b> {{ __('auto.条,分为') }}<b>{{ $list['list']->lastPage() }}</b>{{ __('auto.页') }}
                                {!! $list['list']->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>

        // 开放游戏默认配置
        function addNewPlatform() {
            layer.open({
                type: 2,
                title: '{{ __('auto.添加新的渠道') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['50%', '50%'],
                content: '/admin/channel/channel_new'
            });
        }

        // 开放游戏默认配置
        function defaultOpenGamesFunc() {
            layer.open({
                type: 2,
                title: '{{ __('auto.开放游戏默认配置') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '70%'],
                content: '/admin/channel/default_open_games'
            });
        }

        // 开放游戏配置修改
        function OpenGamesFunc(id, ChannelPackageName) {
            layer.open({
                type: 2,
                title: '{{ __('auto.开放游戏配置修改') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '70%'],
                content: '/admin/channel/open_games/' + id + '?ChannelPackageName=' + ChannelPackageName
            });
        }

        // 咖啡配置修改
        function OpenRechargeFunc(id, ChannelPackageName) {
            layer.open({
                type: 2,
                title: '{{ __('auto.咖啡配置修改') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '70%'],
                content: '/admin/channel/open_recharge/' + id + '?ChannelPackageName=' + ChannelPackageName
            });
        }
        function pasteboard(str)
		{
			if (navigator.clipboard) {
				// clipboard api 复制
				navigator.clipboard.writeText(str);
			}else {
				var save = function (e) {
					e.clipboardData.setData('text/plain', str);
					e.preventDefault();
				}
				document.addEventListener('copy', save);
				document.execCommand('copy');
				document.removeEventListener('copy', save);
			}

		}
        function makekey(obj,id){
            let appkey= $(obj).html();
            if(!appkey){
                myRequest("/admin/channel/appkey/" + id, "post", {}, function (res) {
                     $(obj).html(res.data)
                });

            }else{

                layer.open({
                    type: 2,
                    title: '{{ __('auto.修改app配置') }}',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '80%'],
                    content: '/admin/channel/app_key_set/'+id
                });

                //pasteboard(appkey)
                //layer.msg("COPY SUCCESS")
            }

        }
        function review(obj,id){
            let status= parseInt($(obj).html())?0:1;
            myConfirm("{{ __('auto.操作不可逆,是否继续') }}"+(status?"{{ __('auto.打开') }}":"{{ __('auto.关闭') }}")+"{{ __('auto.审核') }}?", function () {
                 myRequest("/admin/channel/review/" + id, "post", {status}, function (res) {
                     $(obj).html(res.data)
                     layer.msg("{{ __('auto.修改审核状态为：') }}"+res.data)
                });
            })

        }
        function remarks(obj,id) {
            remark = $(obj).html();
            myRequest("/admin/channel/remarks/" + id, "post", {remark}, function (res) {
                layer.msg(res.msg)
                setTimeout(function () {
                    // window.location.reload();
                }, 1500)
            });
        }

        function minScore(obj,id) {
            MinScore = $(obj).html();
            myRequest("/admin/channel/minScore/" + id, "post", {MinScore}, function (res) {
                layer.msg(res.msg)
                setTimeout(function () {
                    // window.location.reload();
                }, 1500)
            });
        }

        function contrlScore(obj,id) {
            ContrlScore = $(obj).html();
            myRequest("/admin/channel/contrlScore/" + id, "post", {ContrlScore}, function (res) {
                layer.msg(res.msg)
                setTimeout(function () {
                    // window.location.reload();
                }, 1500)
            });
        }

        function rateN(obj,id) {
            Rate = $(obj).html();
            myRequest("/admin/channel/rateN/" + id, "post", {Rate}, function (res) {
                layer.msg(res.msg)
                setTimeout(function () {
                    // window.location.reload();
                }, 1500)
            });
        }

        // 分享URL
        function ShareUrl(obj,id) {
            ShareUrl = $(obj).html();
            myRequest("/admin/channel/shareUrl/" + id, "post", {ShareUrl}, function (res) {
                layer.msg(res.msg)
                setTimeout(function () {
                    // window.location.reload();
                }, 1500)
            });
        }

        function switch_control(id, ChannelIndex, AndroidVersion, type) {

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


        function update(ChannelType, ChannelIndex, AndroidVersion, ChannelName) {
            layer.open({
                type: 2,
                title: '{{ __('auto.添加备注') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['50%', '50%'],
                content: '/admin/channel/update/' + ChannelType + '?ChannelIndex=' + ChannelIndex + '&ChannelName=' + ChannelName + '&AndroidVersion=' + AndroidVersion
            });
        }


    </script>
@endsection
