@extends('layouts.app')

@section('content')
    <div id="nav2">
        @component('maintenance.menu')@endcomponent
        @component('maintenance.authority.menu')@endcomponent
    </div>
    <div class="container-fluid">
        <div class="card col-md-8 offset-md-2">
            <div class="card-body">
                @if(Session::has('successTip'))
                    <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
                @endif
                @error('combinedName')
                    <div class="alert alert-danger h1">{{ $message }}</div>
                @enderror
                <form method="POST" action="{{ url('maintenance/authority') }}">
                    @csrf
                    <div class="form-group row">
                        <label for="name" class="col-2 col-form-label text-right">权限名称</label>
                        <div class="col-8">
                            <input type="text" class="form-control @error('name') is-invalid @enderror @error('combinedName') is-invalid @enderror"
                                   name="name" autocomplete="off" value="{{ old('name') }}" placeholder="（唯一）" >
                            @error('name')
                            <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="name" class="col-2 col-form-label text-right">关联货主</label>
                        <div class="col-8">
                            <div class="input-group">
                                <select name="id_owner" id="id_owner" class="form-control @error('id_owner') is-invalid @enderror @error('combinedName') is-invalid @enderror">
                                    <option value="" {{old("id_owner")==''?"selected":""}}></option>
                                    @foreach($owners as $owner)
                                        <option value="{{$owner->id}}" {{old("id_owner") == $owner->id ? "selected":""}}>{{$owner->name}}</option>
                                    @endforeach
                                </select>
                                <input type="text" class="form-control input-group-prepend" placeholder="输入关键字定位货主名称"
                                       name="locateOwnerSearch" autocomplete="off" oninput="locateOwner($(this).val())">
                            </div>
                            <script>
                                function locateOwner(str) {
                                    str = str.trim();
                                    if (str==='')return ;
                                    $("#id_owner option").attr("selected",false);
                                    $("#id_owner").find("option:contains("+str+")").eq(0).attr("selected",true);
                                }
                            </script>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="parent" class="col-2 col-form-label text-right">父权限</label>
                        <div class="col-8">
                            <select name="parent" disabled class="form-control @error('parent') is-invalid @enderror">
                                <option value="">待开发</option></select>
                            @error('parent')
                            <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="remark" class="col-2 col-form-label text-right">备注</label>
                        <div class="col-8">
                            <input type="text" class="form-control @error('remark') is-invalid @enderror"
                                   name="remark" autocomplete="off" value="{{ old('remark') }}" >
                            @error('remark')
                            <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-8 offset-2">
                            <input type="submit" class="btn btn-success form-control">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
