@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-flash"></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>
                            <p class="card-description">
                                {{ __('auto.此功能会自动创建渠道并分配权限') }}
                            </p>
                            <form class="forms-sample" id="form">
                                <div class="form-group">
                                    <label for="packageName">{{ __('auto.包名') }} (PackageName) <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" name="packageName" id="packageName"
                                           value="{{ $defaultPackageName }}"
                                           placeholder="{{ __('auto.请输入包名') }}" required>
                                    <small class="form-text text-muted">{{ __('auto.默认值为最后一个包名数字+1') }}</small>
                                </div>

                                <div class="form-group">
                                    <label for="channelName">{{ __('auto.渠道名称') }} <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" name="channelName" id="channelName"
                                           value="{{ $defaultChannelName }}"
                                           placeholder="{{ __('auto.请输入渠道名称') }}" required>
                                    <small class="form-text text-muted">{{ __('auto.默认值为最后一个渠道名数字+1') }}</small>
                                </div>

                                <div class="form-group">
                                    <label for="adminSign">{{ __('auto.权限群组') }} <span class="text-danger">*</span></label>
                                    <select class="form-control" name="adminSign" id="adminSign" required>
                                        <option value="xidu">({{ __('auto.自营') }})</option>
                                    </select>
                                    <small class="form-text text-muted">{{ __('auto.选择该渠道所属的权限群组') }}</small>
                                </div>

                                <div class="alert alert-info" role="alert">
                                    <strong>{{ __('auto.说明') }}：</strong>
                                    <ul class="mb-0">
                                        <li>({{ __('auto.自营') }}): {{ __('auto.自营渠道，渠道名会自动添加 NEW_ 前缀') }}</li>
                                    </ul>
                                </div>

                                <button type="button" onclick="commit()" class="btn btn-gradient-primary btn-icon-text">
                                    <i class="mdi mdi-flash btn-icon-prepend"></i>
                                    {{ __('auto.快速创建') }}
                                </button>
                                <button type="button" onclick="cancel()" class="btn btn-gradient-warning btn-icon-text">
                                    <i class="mdi mdi-close btn-icon-prepend"></i>
                                    {{ __('auto.取消') }}
                                </button>
                            </form>

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

        function commit(){
            var packageName = $('#packageName').val().trim();
            var channelName = $('#channelName').val().trim();
            var adminSign = $('#adminSign').val();

            if(!packageName){
                layer.msg('{{ __('auto.请输入包名') }}');
                return false;
            }

            if(!channelName){
                layer.msg('{{ __('auto.请输入渠道名称') }}');
                return false;
            }

            var data = {
                packageName: packageName,
                channelName: channelName,
                adminSign: adminSign
            };

            layer.confirm('{{ __('auto.确认创建渠道吗') }}？', {
                btn: ['{{ __('auto.确认') }}', '{{ __('auto.取消') }}']
            }, function(index){
                layer.close(index);
                var loadingIndex = layer.load(1, {shade: [0.3, '#000']});

                myRequest("/admin/channel/quick_create_channel","post", data,function(res){
                    layer.close(loadingIndex);
                    if(res.code == 200){
                        layer.msg(res.msg || '{{ __('auto.创建成功') }}', {icon: 1});
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 1500);
                    } else {
                        layer.msg(res.msg || '{{ __('auto.创建失败') }}', {icon: 2});
                    }
                });
            });
        }

        function cancel() {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }

    </script>
@endsection
