@extends('layouts.app')
@section('title')编辑-作业类型@endsection

@section('content')
    <div id="nav2">
        @component('maintenance.menu')@endcomponent
        @component('maintenance.processMethod.menu')
            @if(isset($method))@can('作业类型-编辑')
                <li class="nav-item">
                    <a class="nav-link" href="{{URL::current()}}" :class="{active:isActive('edit',4)}">编辑</a>
                </li> @endcan @endif
        @endcomponent
    </div>
    <div class="container-fluid card" id="container">
        <div class="card-body offset-3 mt-2">
            <form method="post" :action="method.id ? '{{url('maintenance/processMethod')}}/'+method.id : '{{url('maintenance/processMethod')}}'">
                @csrf
                @if(isset($method)) @method('PUT') @endif
                <div class="row">
                    <label class="col-2 text-info" for="name">作业类型名称</label>
                    <input type="text" class="form-control col-6" :class="errors.name ? 'is-invalid' : ''" id="name" name="name"
                           v-model="method.name" required>
                    <span class="offset-2 mt-0 invalid-feedback" v-if="errors.name">
                        <strong>@{{errors.name[0]}}</strong>
                    </span>
                </div>
                <div class="row mt-3">
                    <label class="col-2" for="unit_id">作业类型单位</label>
                    <select class="form-control col-3" :class="errors.unit_id ? 'is-invalid' : ''" id="unit_id" name="unit_id"
                            v-model="method.unit_id">
                            <option v-for="unit in units" :value="unit.id">@{{ unit.name }}</option>
                    </select>
                    <span class="offset-2 mt-0 invalid-feedback" v-if="errors.unit_id">
                        <strong>@{{errors.unit_id[0]}}</strong>
                    </span>
                </div>
                <div class="row mt-3">
                    <label class="col-2" for="unit_price">作业类型单价</label>
                    <input type="number" min="0" step="0.001" class="form-control col-6" id="unit_price" name="unit_price"
                           :class="errors.unit_price ? 'is-invalid' : ''" v-model="method.unit_price">
                    <span class="offset-2 mt-0 invalid-feedback" v-if="errors.unit_price">
                        <strong>@{{errors.unit_price[0]}}</strong>
                    </span>
                </div>
                <div class="row mt-3 offset-1">
                    <button class="btn btn-success col-7">提交</button>
                </div>
            </form>
        </div>
    </div>
@stop

@section('lastScript')
    <script>
        new Vue({
            el:"#container",
            data:{
                method:{
                    id : "{{isset($method) ? $method->id : ''}}",
                    name : "{{old("name") ?? (isset($method) ? $method->name : '')}}",
                    unit_id : "{{old("unit_id") ?? (isset($method) ? $method->unit_id : '')}}",
                    unit_price : "{{old("unit_price") ?? (isset($method) ? $method->unit_price : '')}}",
                },
                errors : {!! $errors !!},
                units : [
                    @foreach($units as $unit)
                    {id:"{{$unit->id}}",name:"{{$unit->name}}"},
                    @endforeach
                ],
            },
        });
    </script>
@stop