@extends('layouts.app')
@section('title')录入-快递计费-计费模型@endsection

@section('content')
    <div id="nav2">
        @component('maintenance.menu')@endcomponent
        @component('maintenance.priceModel.logistic.menu')
            @if(isset($model))
                <li class="nav-item">
                    <a class="nav-link" href="{{URL::current()}}" :class="{active:isActive('edit',5)}">编辑</a>
                </li>
            @endif
        @endcomponent
    </div>
    <div class="container-fluid mt-2 card" id="container">
        <form method="POST" action="{{url('maintenance/priceModel/logistic')}}@if(isset($model))/{{$model->id}}/edit @endif" class="card-body offset-3">
            @csrf
            <div class="row">
                <label for="name" class="col-2"><b class="text-danger">* </b>价格名称</label>
                <input id="name" type="text" name="name" required class="col-6 form-control"
                       :class="errors.name ? 'is-invalid' : ''" v-model="model.name">
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.name">
                    <strong>@{{ errors.name[0] }}</strong>
                </span>
            </div>
            <div class="row mt-3">
                <label for="pick_up_price" class="col-2">提货费</label>
                <input id="pick_up_price" type="number" min="0" step="0.01" name="pick_up_price" class="col-3 form-control"
                       :class="errors.pick_up_price ? 'is-invalid' : ''" v-model="model.pick_up_price">
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.pick_up_price">
                    <strong>@{{ errors.pick_up_price[0] }}</strong>
                </span>
            </div>
            <div class="row mt-3">
                <label for="fuel_price" class="col-2">燃油附加费</label>
                <input id="fuel_price" type="number" min="0" step="0.01" name="fuel_price" class="col-3 form-control"
                       :class="errors.fuel_price ? 'is-invalid' : ''" v-model="model.fuel_price">
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.fuel_price">
                    <strong>@{{ errors.fuel_price[0] }}</strong>
                </span>
            </div>
            <div class="row mt-3">
                <label for="service_price" class="col-2">信息服务费</label>
                <input id="service_price" type="number" min="0" step="0.01" name="service_price" class="col-3 form-control"
                       :class="errors.service_price ? 'is-invalid' : ''" v-model="model.service_price">
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.service_price">
                    <strong>@{{ errors.service_price[0] }}</strong>
                </span>
            </div>
            <div class="row mt-3">
                <label for="unit_id" class="col-2"><b class="text-danger">* </b>单位一</label>
                <select id="unit_id" name="unit_id" class="col-2 form-control" required
                        v-model="model.unit_id" :class="errors.unit_id ? 'is-invalid' : ''">
                    <option v-for="unit in units" :value="unit.id">@{{ unit.name }}</option>
                </select>
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.unit_id">
                    <strong>@{{ errors.unit_id[0] }}</strong>
                </span>
                <label for="unit_range" class="col-2 text-right"><b class="text-danger">*</b>区间值</label>
                <input id="unit_range" type="text" placeholder="文字描述区间逗号(,)间隔,示例：0-5,10-30,30-" required
                       v-model="model.unit_range" name="unit_range" class="col-3 form-control" :class="errors.unit_range ? 'is-invalid' : ''">
                <span class="invalid-feedback mt-0 offset-6" role="alert" v-if="errors.unit_range">
                    <strong>@{{ errors.unit_range[0] }}</strong>
                </span>
            </div>
            <div class="row mt-3">
                <label for="other_unit_id" class="col-2"><b class="text-danger">* </b>单位二</label>
                <select id="other_unit_id" name="other_unit_id" class="col-2 form-control" required
                        v-model="model.other_unit_id" :class="errors.other_unit_id ? 'is-invalid' : ''">
                    <option v-for="unit in units" :value="unit.id">@{{ unit.name }}</option>
                </select>
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.other_unit_id">
                    <strong>@{{ errors.other_unit_id[0] }}</strong>
                </span>
                <label for="other_unit_range" class="col-2 text-right"><b class="text-danger">*</b>区间值</label>
                <input id="other_unit_range" type="text" placeholder="文字描述区间逗号(,)间隔,示例：0-5,10-30,30-" required
                       v-model="model.other_unit_range" name="other_unit_range" class="col-3 form-control" :class="errors.other_unit_range ? 'is-invalid' : ''">
                <span class="invalid-feedback mt-0 offset-6" role="alert" v-if="errors.other_unit_range">
                    <strong>@{{ errors.other_unit_range[0] }}</strong>
                </span>
            </div>
            <div class="row mt-3">
                <label class="col-2" for="owner_id">项目</label>
                <select id="owner_id" class="selectpicker" multiple data-live-search="true" title="项目(多选)"
                        v-model="model.owner_id" :class="errors.owner_id ? 'is-invalid' : ''">
                    <option v-for="owner in owners" :value="owner.id">@{{ owner.name }}</option>
                </select>
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.owner_id">
                    <strong>@{{ errors.owner_id[0] }}</strong>
                </span>
                <label hidden><input name="owner_id" type="text" :value="model.owner_id"></label>
            </div>
            <div class="row mt-3">
                <label class="col-2" for="logistic_id">承运商</label>
                <select id="logistic_id" class="selectpicker" multiple data-live-search="true" title="承运商(多选)"
                        v-model="model.logistic_id" :class="errors.logistic_id ? 'is-invalid' : ''">
                    <option v-for="logistic in logistics" :value="logistic.id">@{{ logistic.name }}</option>
                </select>
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.logistic_id">
                    <strong>@{{ errors.logistic_id[0] }}</strong>
                </span>
                <label hidden><input name="logistic_id" type="text" :value="model.logistic_id"></label>
            </div>
            <div class="row mt-3 offset-1">
                <button type="submit" class="btn btn-success col-7">提交</button>
            </div>
        </form>
    </div>
@stop

@section("lastScript")
    <script>
        new Vue({
            el:"#container",
            data:{
                model:{
                    id: "{{isset($model) ? $model->id : ''}}",
                    owner_id:{!! old('owner_id') ? json_encode(old('owner_id')) : (isset($model) ? json_encode($model->owner_id) : '[]') !!},
                    logistic_id:{!! old('logistic_id') ? json_encode(old('logistic_id')) : (isset($model) ? json_encode($model->logistic_id) : '[]') !!},
                    name:"{{old('name') ?? (isset($model) ? $model->name : '')}}",
                    pick_up_price:"{{old('pick_up_price') ?? (isset($model) ? $model->pick_up_price : '')}}",
                    fuel_price:"{{old('fuel_price') ?? (isset($model) ? $model->fuel_price : '')}}",
                    service_price:"{{old('service_price') ?? (isset($model) ? $model->service_price : '')}}",
                    unit_id:"{{old('unit_id') ?? (isset($model) ? $model->unit_id : '')}}",
                    unit_range:"{{old('unit_range') ?? (isset($model) ? $model->unit_range : '')}}",
                    other_unit_id:"{{old('other_unit_id') ?? (isset($model) ? $model->other_unit_id : '')}}",
                    other_unit_range:"{{old('other_unit_range') ?? (isset($model) ? $model->other_unit_range : '')}}",
                },
                units : [
                    @foreach($units as $unit)
                    {id:"{{$unit->id}}",name:"{{$unit->name}}"},
                    @endforeach
                ],
                owners : [
                    @foreach($owners as $owner)
                    {id:"{{$owner->id}}",name:"{{$owner->name}}"},
                    @endforeach
                ],
                logistics : [
                    @foreach($logistics as $logistic)
                    {id:"{{$logistic->id}}",name:"{{$logistic->name}}"},
                    @endforeach
                ],
                errors:{!! $errors !!}
            },
        });
    </script>
@stop