<!DOCTYPE html>
<html>

<head>

@include('admin.common_bak.commonMedia')
<!-- Core stylesheets -->
    <link rel="stylesheet" href="{{ asset('xadmin/css/form.css')}}">
    {{--<link rel="stylesheet" href="http://local.www.offcncloud.com/css/xadmin.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;
        }
        .col-form-label{
            margin-top: 6px;
        }
        .role-label{
            margin-left: 20px;
            position: relative;
        }
    </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">

                <!--***** FORM GROUP *****-->
                <div class="card form" id="form5">
                    <div class="card-header">
                        <h3>编辑权限</h3>
                    </div>
                    <br>
                    <form  id="newForm">
                        <input type="hidden" name="id" value="{{$role_info['id']}}">
                        <input type="hidden" name="_token" value="{{csrf_token()}}">
                        <div class="row">

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

                                <div class="form-group row">
                                    <label for="example-text-input"  class=" col-form-label">&nbsp;&nbsp;&nbsp;*角色名</label>
                                    <div class="col-10">
                                        <input class="form-control" type="text" name="name" value="{{$role_info['name']}}" id="example-text-input">
                                    </div>
                                </div>

                            </div>
                            <div class="col-md-6 role-label" >
                                <div class="form-group row">
                                    <label for="slug" class="col-form-label">*英文简称</label>
                                    <div class="col-10">

                                        <input type="text" class="form-control" id="slug" name="slug" value="{{$role_info['slug']}}"
                                               placeholder="">
                                    </div>
                                </div>

                            </div>

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

                                <div class="form-group row">
                                    <label class="col-form-label">
                                        &nbsp;拥有权限
                                    </label>
                                    <div class="col-10">
                                        <table class="table table-bordered">
                                            <tbody>
                                            @foreach($rules as $v)
                                                <tr>
                                                    <td>
                                                        <input type="checkbox" name="permission_id[]" value="{{$v['id']}}" lay-skin="primary"
                                                               title="{{$v['name']}}" @if(in_array($v['id'],$role_info['pers'])) checked @endif>{{$v['name']}}
                                                    </td>
                                                    <td>
                                                        @if(count($v['son'])>1)
                                                            <div class="layui-input-block">
                                                                @foreach($v['son'] as $son)
                                                                    <input name="permission_id[]" lay-skin="primary" type="checkbox"
                                                                           title="{{$son['name']}}" value="{{$son['id']}}"
                                                                           @if(in_array($son['id'],$role_info['pers'])) checked @endif>{{$son['name']}}
                                                                @endforeach
                                                            </div>
                                                        @endif
                                                    </td>
                                                </tr>
                                            @endforeach
                                            <tr>
                                                <td>
                                                    关联类别
                                                </td>
                                                <td>
                                                    <select class="form-control" name="parent_id[]" id="pid" multiple row="5">
                                                        <option value="0">请选择栏目</option>
                                                        @foreach($categories as $key => $category)
                                                            @if(isset($category->childCag)&&!empty($category->childCag))
                                                                <option @if(in_array($category->id,$mycatgs)) selected="true"; @endif value="{{$category->id}}" style="font-size: 18px;font-weight:bold;">{{$category->title}}</option>
                                                                <optgroup label="&nbsp;├">
                                                                    @foreach($category->childCag as $childCag)
                                                                        <option @if(in_array($childCag['id'],$mycatgs)) selected="true"; @endif value="{{$childCag['id']}}">{{$childCag['title']}}</option>
                                                                    @endforeach
                                                                </optgroup>
                                                            @else
                                                                <option @if(in_array($category->id,$mycatgs)) selected @endif value="{{$category->id}}">{{$category->title}}</option>
                                                            @endif
                                                        @endforeach
                                                    </select>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>

                                </div>

                            </div>
                            <div class="col-md-12">
                                <div class="form-group row">
                                    <label for="icon" class="col-form-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*描述</label>
                                    <div class="col-10">
                                        <textarea placeholder="请输入内容" id="desc" name="description" class="form-control"
                                              rows="10" style="width: 100%;">{{$role_info['description']}}</textarea>

                                    </div>
                                </div>

                            </div>



                            <div class="col-md-12">
                                <label  class="col-form-label">
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    &nbsp;&nbsp;&nbsp;
                                </label>
                                <button type="submit" class="btn btn-primary" onclick="role_edit();">保存</button>
                            </div>
                        </div>


                    </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 role_edit() {

        $("#newForm").validate({
            rules: {
                name: {
                    required: true,
                    minlength: 2
                },
                password: {
                    required: true,
                    minlength: 5
                },
                confirm_password: {
                    required: true,
                    minlength: 5,
                    equalTo: "#password"
                },
                email: {
                    required: true,
                    email: true
                },
            },
            messages: {
                name: {
                    required: "Please enter a username",
                    minlength: "Your username must consist of at least 2 characters"
                },
                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"
                },
                email: "Please enter a valid email address",
            },
            submitHandler: function (form) {
                var form = document.querySelector("#newForm");
                var formdata = new FormData(form);

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

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

    }

</script>
</body>

</html>
