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

@section('content')
    <div id="nav2">
        @component('maintenance.menu')@endcomponent
        @component('maintenance.priceModel.express.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/express')}}@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"
                       v-model="model.name" :class="errors.name ? 'is-invalid' : ''">
                <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="initial_weight" class="col-2"><b class="text-danger">* </b>首重单位</label>
                <input type="number" min="0" step="0.01" id="initial_weight" name="initial_weight" class="col-3 form-control" required
                        v-model="model.initial_weight" :class="errors.initial_weight ? 'is-invalid' : ''">
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.initial_weight">
                    <strong>@{{ errors.initial_weight[0] }}</strong>
                </span>
            </div>
            <div class="row mt-3">
                <label for="additional_weight" class="col-2"><b class="text-danger">* </b>续重单位</label>
                <input type="number" min="0" step="0.01" id="additional_weight" name="additional_weight" class="col-3 form-control" required
                       v-model="model.additional_weight" :class="errors.additional_weight ? 'is-invalid' : ''">
                <span class="invalid-feedback mt-0 offset-2" role="alert" v-if="errors.additional_weight">
                    <strong>@{{ errors.additional_weight[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 : '')}}",
                    initial_weight:"{{old('initial_weight') ?? (isset($model) ? $model->initial_weight : '')}}",
                    additional_weight:"{{old('additional_weight') ?? (isset($model) ? $model->additional_weight : '')}}",
                },
                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