<!DOCTYPE html>
<html>

<head>

@include('admin.common_bak.commonMedia')
<!-- Core stylesheets -->
    <link rel="stylesheet" href="{{ asset('xadmin/css/form.css')}}">
    <style>
        form.cmxform label.error, label.error {
            /* remove the next line when you have trouble in IE6 with labels in list */
            color: red;
            font-style: italic;
            margin-top: 11px;
        }
    </style>
</head>

<body>

<!--====================================================
                     MAIN NAVBAR
======================================================-->
@include('admin.common_bak.header')

<!--====================================================
                    PAGE CONTENT
======================================================-->
<div class="page-content d-flex align-items-stretch">

    <!--***** SIDE NAVBAR *****-->
    @include('admin.common_bak.left')

    <div class="content-inner form-cont">
        <div class="row">
            <div class="col-md-12">

                <div class="card form">
                    <div class="card-header">
                        <h3><i class="fa fa-user-circle"></i> 编辑栏目</h3>
                    </div>
                    <br>
                    <form id="form1">
                        <input type="hidden" name="_token" value="{{csrf_token()}}">
                        {{ method_field('PUT') }}
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="name">栏目名称</label>
                                    <input type="text" class="form-control" name="title" value="{{$result[0]['title']}}" id="name" placeholder="栏目名称">
                                </div>
                                <input type="hidden" name="id" value="{{$result[0]['id']}}"/>

                            </div>
                            {{--<div class="col-md-6">--}}
                            {{--<div class="form-group">--}}
                            {{--<label for="icon">图标</label>--}}
                            {{--<input type="text" class="form-control" id="icon" name="icon" placeholder="图标">--}}
                            {{--</div>--}}

                            {{--<div class="form-group has-success">--}}
                            {{--<label for="slug">方法名称</label>--}}
                            {{--<input type="text" class="form-control is-valid" name="slug" id="slug" placeholder="控制器.方法名">--}}
                            {{--</div>--}}
                            {{--</div>--}}

                            <div class="col-md-6">

                                <div class="form-group">
                                    <label for="pid">父类</label>
                                    {{--<select class="form-control" name="parent_id" id="pid">--}}
                                        {{--<option value="0">请选择父类</option>--}}
                                        {{--@if (count($parent) > 0)--}}
                                            {{--@foreach($parent as $v)--}}
                                                {{--<option value="{{$v['id']}}" @if($result[0]['parent_id'] == $v['id']) selected @endif>{{$v['title']}}</option>--}}
                                            {{--@endforeach--}}
                                        {{--@endif--}}
                                    {{--</select>--}}

                                    <select class="form-control" name="parent_id" id="pid">
                                        <option value="0">请选择栏目</option>
                                        @foreach($categories as $key => $category)
                                            @if(isset($category->childCag)&&!empty($category->childCag))
                                                <option @if($result[0]['parent_id'] == $category->id) selected @endif value="{{$category->id}}" style="font-size: 18px;font-weight:bold;">{{$category->title}}</option>
                                                <optgroup label="&nbsp;├">
                                                    @foreach($category->childCag as $childCag)
                                                        <option @if($result[0]['parent_id'] == $childCag['id']) selected @endif value="{{$childCag['id']}}">{{$childCag['title']}}</option>
                                                    @endforeach
                                                </optgroup>
                                            @else
                                                <option @if($result[0]['parent_id'] == $category->id) selected @endif value="{{$category->id}}">{{$category->title}}</option>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>

                            </div>

                            {{--<div class="col-md-12">--}}

                                {{--<div class="form-group">--}}
                                    {{--<label for="show">是否显示</label>--}}
                                    {{--<input type="radio" id="show" name="show" @if($result[0]['show']=='1') checked @endif value="1">是--}}
                                    {{--<input type="radio" id="show" name="show" @if($result[0]['show']=='0') checked @endif value="0">否--}}
                                {{--</div>--}}
                            {{--</div>--}}

                            <div class="col-md-12">

                                <div class="form-group">
                                    <label for="is_dynamic">是否为动态</label>
                                    <input type="radio" id="is_dynamic" name="is_dynamic" @if($result[0]['is_dynamic']=='1') checked @endif value="1">是
                                    <input type="radio" id="is_dynamic" name="is_dynamic" @if($result[0]['is_dynamic']=='0') checked @endif value="0">否
                                </div>
                            </div>

                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="sort">排序（正序）</label>
                                    <input type="number" class="form-control" id="sort" name="sort" placeholder="排序" min="0" value="{{$result[0]['sort']}}">
                                </div>

                            </div>

                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="description">描述</label>
                                    <input type="text" class="form-control" id="description" name="description" placeholder="描述" value="{{$result[0]['description']}}">
                                </div>
                            </div>

                        </div>

                        <button type="submit" onclick="addPrivilege();" class="btn btn-general btn-blue mr-2">保存</button>
                        <button type="reset" class="btn btn-general btn-white">取消</button>
                    </form>
                </div>

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

<!--Global Javascript -->
@include('admin.common_bak.foot')


<script src="{{ asset('xadmin/extra/toast/js/toast.js')}}"></script>
<script src="{{ asset('xadmin/js/jquery.validate.js')}}"></script>

{{--<link rel="stylesheet" href="{{ asset('xadmin/extra/toast/css/toast.css')}}">--}}


<!--Core Javascript -->
<script type="text/javascript">


    function addPrivilege() {

        $("#form1").validate({
            rules: {
                name: {
                    required: true,
                    minlength: 2
                },
                password: {
                    link: true,
                    minlength: 5
                },
                // slug: {
                //     required: true,
                // },
                // email: {
                //     required: true,
                //     email: true
                // },
            },
            messages: {
                name: {
                    required: "栏目名称不能为空",
                    minlength: "栏目名称至少两个字符"
                },
                // password: {
                //     required: "Please provide a password",
                //     minlength: "Your password must be at least 5 characters long"
                // },
                // confirm_password: {
                //     required: "Please provide a password",
                //     minlength: "Your password must be at least 5 characters long",
                //     equalTo: "Please enter the same password as above"
                // },
                // slug: "Please enter a valid slug",
            },
            submitHandler: function (form) {
                var form = document.querySelector("#form1");
                var formdata = new FormData(form);

                fetch_response('PUT', "/web/news_category/{{$result[0]['id']}}", formdata).then(function (res) {
                    if (res.code == 200) {
                        console.log('dsfsfsd',res)
                        $('body').toast({
                            position: 'fixed',
                            content: res.msg,
                            duration: 1000,
                            top: '50%'
                        });
                        setTimeout(function () {
                            window.location.href = '/web/news_category';
                        }, 2000)

                    } else {
                        $('body').toast({
                            position: 'fixed',
                            content: res.msg,
                            duration: 1000,
                            top: '50%'
                        });
                    }
                });


            },
            invalidHandler: function(form, validator) {
                console.log('fomr',form)
                return false;
            }

        });

    }

</script>
</body>

</html>