@extends('layouts.app')
@section('title')编辑-价格模型@endsection

@section('content')
    <div id="nav2">
        @component('maintenance.priceModel.waybillPriceModel.menu')
                <li class="nav-item">
                    <a class="nav-link" href="{{URL::current()}}" :class="{active:isActive('edit',5)}">修改</a>
                </li>
        @endcomponent
    </div>
    <div class="container-fluid" id="list">
        <div class="card">
            <div class="card-body">
                <form method="POST" action='{{url("maintenance/priceModel/waybillPriceModel/{$waybillPriceModel->id}")}}'>
                    @csrf
                    @method('PUT')
                    <div class="form-group row">
                        <label for="logistic_id" class="col-2 col-form-label text-right">承运商</label>
                        <div class="col-8">
                            <select name="WaybillPriceModel[logistic_id]" v-model="inputting.WaybillPriceModel.logistic_id" style="width: 30%;" class="form-control">
                                <option v-for="logistic in logistics" :value="logistic.id">@{{logistic.name}}</option>
                            </select>

                            <div class="col-sm-5">
                                <p class="form-control-static text-danger small font-weight-bold">{{ $errors->first('WaybillPriceModel.logistic_id') }}</p>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="province_id"  class="col-2 col-form-label text-right">选择省份</label>
                        <div class="col-8" >
                            <select id="province_id" name="WaybillPriceModel[province_id]" v-model="inputting.WaybillPriceModel.province_id" style="width: 30%;"
                            class="form-control">
                                <option v-for="province in regions" :value="province.id" v-if="province.type==1">@{{province.name}}</option>
                            </select>

                            <div class="col-sm-5">
                                <p class="form-control-static text-danger small font-weight-bold">{{ $errors->first('WaybillPriceModel.province_id') }}</p>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="city_id"  class="col-2 col-form-label text-right">选择城市</label>
                        <div class="col-8" >
                            <select id="city_id" name="WaybillPriceModel[city_id]" v-model="inputting.WaybillPriceModel.city_id" style="width: 30%;" class="form-control">
                                <option v-for="city in regions" :value="city.id" v-if="city.type==2 && city.parent_id == inputting.WaybillPriceModel.province_id">@{{city.name}}</option>
                            </select>

                            <div class="col-sm-5">
                                <p class="form-control-static text-danger small font-weight-bold">{{ $errors->first('WaybillPriceModel.city_id') }}</p>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="unit_id"  class="col-2 col-form-label text-right">货物单位</label>
                        <div class="col-8" >
                            <select name="WaybillPriceModel[unit_id]" v-model="inputting.WaybillPriceModel.unit_id" style="width: 30%;" class="form-control">
                                <option v-for="unit in units" :value="unit.id" >@{{unit.name}}</option>
                            </select>

                            <div class="col-sm-5">
                                <p class="form-control-static text-danger small font-weight-bold">{{ $errors->first('WaybillPriceModel.unit_id') }}</p>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="range_min" class="col-2 col-form-label text-right">计价区间</label>
                        <div class="col-8 form-inline">
                            <input type="text" style="width: 20%" class="form-control @error('WaybillPriceModel.range_min') is-invalid @enderror"
                                   name="WaybillPriceModel[range_min]" autocomplete="off" value="{{old('WaybillPriceModel')['range_min']?old('WaybillPriceModel')['range_min']:$waybillPriceModel->range_min}}" >&nbsp;&nbsp;--&nbsp;&nbsp;
                            <input type="text"  style="width: 20%" class="form-control @error('WaybillPriceModel.range_max') is-invalid @enderror"
                                   name="WaybillPriceModel[range_max]" autocomplete="off" value="{{old('WaybillPriceModel')['range_max']?old('WaybillPriceModel')['range_max']:$waybillPriceModel->range_max}}" >
                            @error('WaybillPriceModel.range_min')
                            <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                            @enderror
                            @error('WaybillPriceModel.range_max')
                            <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="unit_price" class="col-2 col-form-label text-right">单价</label>
                        <div class="col-8">
                            <input type="text"  class="form-control @error('WaybillPriceModel.unit_price') is-invalid @enderror"
                                   name="WaybillPriceModel[unit_price]" autocomplete="off" value="{{old('WaybillPriceModel')['unit_price']?old('WaybillPriceModel')['unit_price']:$waybillPriceModel->unit_price}}" >
                            @error('WaybillPriceModel.unit_price')
                            <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="base_fee" class="col-2 col-form-label text-right">起步费(元)</label>
                        <div class="col-8">
                            <input type="text" class="form-control @error('WaybillPriceModel.base_fee') is-invalid @enderror"
                                   name="WaybillPriceModel[base_fee]" autocomplete="off" value="{{old('WaybillPriceModel')['base_fee']?old('WaybillPriceModel')['base_fee']:$waybillPriceModel->base_fee}}" >
                            @error('WaybillPriceModel.base_fee')
                            <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="initial_weight" class="col-2 col-form-label text-right">最低计数</label>
                        <div class="col-8">
                            <input type="text" class="form-control @error('WaybillPriceModel.initial_weight') is-invalid @enderror"
                                   name="WaybillPriceModel[initial_weight]" autocomplete="off" value="{{old('WaybillPriceModel')['initial_weight']?old('WaybillPriceModel')['initial_weight']:$waybillPriceModel->initial_weight}}" >
                            @error('WaybillPriceModel.initial_weight')
                            <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-outline-dark form-control">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection

@section('lastScript')
    <script>
        let insertVue=new Vue({
            el:'#list',
            data:{
                inputting:{
                    WaybillPriceModel:{
                        logistic_id:'{{old('WaybillPriceModel')['logistic_id']?old('WaybillPriceModel')['logistic_id']:$waybillPriceModel->logistic_id}}',
                        province_id:'{{old('WaybillPriceModel')['province_id']?old('WaybillPriceModel')['province_id']:$waybillPriceModel->province_id}}',
                        city_id:'{{old('WaybillPriceModel')['city_id']?old('WaybillPriceModel')['city_id']:$waybillPriceModel->city_id}}',
                        unit_id:'{{old('WaybillPriceModel')['unit_id']?old('WaybillPriceModel')['unit_id']:$waybillPriceModel->unit_id}}',
                    }
                },
                regions:[
                    @foreach($regions as $region)
                    {id:"{{$region->id}}",parent_id:"{{$region->parent_id}}",type:"{{$region->type}}",name:"{{$region->name}}"},
                    @endforeach
                ],
                logistics:[
                     @foreach($logistics as $logistic)
                    {id:'{{$logistic->id}}',name:'{{$logistic->name}}'},
                    @endforeach
                ],
                units:[
                    @foreach($units as $unit)
                    {id:'{{$unit->id}}',name:'{{$unit->name}}'},
                    @endforeach
                ],
                waybillPriceModel:[
                        {id:'{{$waybillPriceModel->id}}',created_at:'{{$waybillPriceModel->created_at}}',
                            logistic_id:'{{$waybillPriceModel->logistic_id}}',province_id:'{{$waybillPriceModel->province_id}}',
                        city_id:'{{$waybillPriceModel->city_id}}',unit_id:'{{$waybillPriceModel->unit_id}}',
                        section:'{{$waybillPriceModel->section}}',unit_price:'{{$waybillPriceModel->unit_price}}',initial_weight:'{{$waybillPriceModel->initial_weight}}'},
                ]
            },
            mounted:function(){
                this.inputting.WaybillPriceModel.city_id='{{$waybillPriceModel->city_id}}';
            },
        });

    </script>
@endsection
