浏览代码

运输管理-绑定订单

Zhouzhendong 5 年之前
父节点
当前提交
8c07c3a594

+ 1 - 0
app/Console/Commands/SyncBatchTask.php

@@ -169,6 +169,7 @@ sql;
             $batchMapping[$detail->orderno] = $detail->waveno;
         }
         $orders = Order::query()->select("id","batch_id","code")->whereIn("code",$orderCodes)->get();
+        if (count($orderCodes) != count($orders))LogService::log(__CLASS__,"格口号-订单存在差异",json_encode($orderCodes));
         if ($orders){
             $orderIds = [];
             $orderMap = [];

+ 1 - 1
app/Http/Controllers/PriceModelController.php

@@ -370,7 +370,7 @@ class PriceModelController extends Controller
                 }
             }],
             'strategy'=>['required'],
-            'name'=>['required',$id?"unique:owner_price_operations,name,$id":'unique:owner_price_operations,name'],
+            'name'=>['required'/*,$id?"unique:owner_price_operations,name,$id":'unique:owner_price_operations,name'*/],
             'priority'=>['sometimes','required','integer','min:0','max:100'],
             'items.*.strategy'=>['required'],
             'items.*.amount'=>["required","integer"],

+ 44 - 26
app/Http/Controllers/WaybillController.php

@@ -5,7 +5,6 @@ namespace App\Http\Controllers;
 
 use App\Components\AsyncResponse;
 use App\Services\CarTypeService;
-use App\Services\CityService;
 use App\Services\LogisticService;
 use App\Services\OwnerService;
 use App\Services\UnitService;
@@ -17,7 +16,6 @@ use App\WaybillAuditLog;
 use App\WaybillOnTop;
 use App\WaybillPriceModel;
 use App\City;
-use App\Owner;
 use App\Unit;
 use App\Waybill;
 use App\WaybillPayoff;
@@ -28,7 +26,6 @@ use Exception;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Http\Request;
-use Illuminate\Http\UploadedFile;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Gate;
@@ -79,26 +76,32 @@ class WaybillController extends Controller
     public function store(Request $request)
     {
         if(!Gate::allows('运输管理-录入')){ return redirect(url('/'));  }
-        $id=false;
-        $this->validatorWaybill($request,$id)->validate();
+        $this->validatorWaybill($request,false)->validate();
         /** @var WaybillService */
         $waybill=app('waybillService')->store($request);
         app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
         return redirect('waybill/index')->with('successTip','新运单“'.$waybill->waybill_number.'”录入成功');
     }
 
-    public function edit($id,LogisticService $logisticService,CarTypeService $carTypeService,
-                         CityService $cityService,UnitService $unitService)
+    public function edit($id,LogisticService $logisticService,CarTypeService $carTypeService,UnitService $unitService)
     {
         if(!Gate::allows('运输管理-编辑')){ return redirect(url('/'));  }
-        /** @var WaybillService */
         $waybill = app('waybillService')->find($id);
+        if ($waybill->order_id){
+            /** @var Waybill $waybill */
+            $waybill->load("order.owner");
+            $waybill->destination_city_id = app("RegionService")->getCity($waybill->order->city ?? '',$waybill->order->province ?? '');
+        }else{
+            /** @var Waybill $waybill */
+            $waybill->load("owner");
+        }
+        /** @var \stdClass $waybill */
         if (!$waybill)return view("exception.default",["code"=>"500","message"=>"数据已被删除或丢失"]);
         if ($waybill->deliver_at){
             $waybill->deliver_at_date=Carbon::parse($waybill->deliver_at)->format('Y-m-d');
             $waybill->deliver_at_time=Carbon::parse($waybill->deliver_at)->format('H:i:s');
         }
-        $cities=$cityService->getSelection();
+        $cities=app("RegionService")->getSelection(2);
         $units=$unitService->getSelection();
         $carTypes=$carTypeService->getSelection();
         return view('waybill/edit',['waybill'=>$waybill,'logistics'=>$logisticService->getSelection(["id","name"],"物流"),'cities'=>$cities,'units'=>$units,'carTypes'=>$carTypes]);
@@ -134,7 +137,7 @@ class WaybillController extends Controller
             if ($waybillPriceModel_id){
                 $carrier_weight=$request->input('carrier_weight');
                 $waybillPriceModel=$waybillPriceModelService->find($waybillPriceModel_id);
-                $logistic=$logisticService->find($waybill->logistic_id);
+                $logistic=$logisticService->find($waybill->order->logistic_id ?? $waybill->logistic_id);
                 if ($carrier_weight<$waybillPriceModel->initial_weight){
                     $fee=(($waybillPriceModel->unit_price)*($waybillPriceModel->initial_weight))+$logistic->delivery_fee;
                 }else{
@@ -368,14 +371,14 @@ class WaybillController extends Controller
     public function waybillEdit($id){
         if(!Gate::allows('运输管理-编辑')){ return redirect(url('/'));  }
         $waybill=app('waybillService')->find($id);
-        $owners=Owner::get();
+        $owners=app("OwnerService")->getIntersectPermitting();
         return view('waybill.waybillEdit',['waybill'=>$waybill,'owners'=>$owners]);
     }
     public function waybillRetreatAudit(Request $request){
         if(!Gate::allows('运输管理-调度')){ return redirect(url('/'));  }
         $id=$request->input('id');
         $waybill=app('waybillService')->find($id);
-        WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->delete();
+        WaybillAuditLog::query()->whereRaw('waybill_id = ? and audit_stage = ?',[$id,"运单阶段"])->delete();
         $waybill->status='待重审';
         $result=$waybill->save();
         app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($waybill),Auth::user()['id']);
@@ -430,23 +433,25 @@ class WaybillController extends Controller
 
     //生成报表数据
     private function createReportData($waybill,$waybillPayoff){
+        /** @var Waybill $waybill */
+        $waybill->loadMissing(["order.owner",'order.logistic']);
         return [
             "type"=>$waybill->type,
             "waybill_number"=>$waybill->waybill_number,
-            "owner_name"=>$waybill->owner ? $waybill->owner->name : null,
+            "owner_name"=>$waybill->order->owner->name ?? ($waybill->owner->name ?? null),
             "wms_bill_number"=>$waybill->wms_bill_number,
             "source_bill"=>$waybill->source_bill,
             "origination"=>$waybill->origination,
-            "destination"=>$waybill->destination,
-            "recipient"=>$waybill->recipient,
-            "recipient_mobile"=>$waybill->recipient_mobile,
+            "destination"=>$waybill->order->address ?? $waybill->destination,
+            "recipient"=>$waybill->order->consignee_name ?? $waybill->recipient,
+            "recipient_mobile"=>$waybill->order->consignee_phone ?? $waybill->recipient_mobile,
             "charge"=>$waybill->charge,
             "collect_fee"=>$waybill->collect_fee,
             "ordering_remark"=>$waybill->ordering_remark,
-            "carrier_name"=>$waybill->logistic ? $waybill->logistic->name : null,
+            "carrier_name"=>$waybill->order->logistic->name ?? ($waybill->logistic->name ?? null),
             "carrier_bill"=>$waybill->carrier_bill,
             "origination_city_name"=>$waybill->originationCity ? $waybill->originationCity->name : null,
-            "destination_city_name"=>$waybill->destinationCity ? $waybill->destinationCity->name : null,
+            "destination_city_name"=>$waybill->order->city ?? ($waybill->destinationCity->name ?? null),
             "warehouse_weight"=>$waybill->warehouse_weight.($waybill->warehouseWeightUnit ? $waybill->warehouseWeightUnit->name : ''),
             "carrier_weight"=>$waybill->carrier_weight.($waybill->carrierWeightUnit ? $waybill->carrierWeightUnit->name : ''),
             "warehouse_weight_other"=>$waybill->warehouse_weight_other.($waybill->warehouseWeightUnitOther ? $waybill->warehouseWeightUnitOther->name : ''),
@@ -685,16 +690,17 @@ class WaybillController extends Controller
     protected function validatorWaybill(Request $request,$id){
         if ($id){$wms_bill_number=$id;};
         $validator=Validator::make($request->input(),[
-            'owner_id'=>'required',
+            'owner_id'=>'required_without:order_id',
             'wms_bill_number'=>['nullable','max:50',isset($wms_bill_number)?"unique:waybills,wms_bill_number,$wms_bill_number":'unique:waybills,wms_bill_number'],
             'origination'=>'required|max:255',
-            'destination'=>'required|max:255',
-            'recipient'=>'required|max:50',
-            'recipient_mobile'=>['required','regex:/^(\d{7,11})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
+            'destination'=>'required_without:order_id|max:255',
+            'recipient'=>'required_without:order_id|max:50',
+            'recipient_mobile'=>['required_without:order_id','regex:/^(\d{7,11})|(1[3|4|5|7|8][0-9]\d{4,8})$/'],
             'charge'=>'nullable|min:0|max:999999|numeric',
             'collect_fee'=>'nullable|min:0|numeric',
         ],[
             'required'=>':attribute 为必填项',
+            'required_without'=>':attribute 为必填项',
             'alpha_num'=>':attribute 应为字母或数字',
             'max'=>':attribute 字符过多或输入值过大',
             'regex'=>':attribute 输入有误',
@@ -716,7 +722,7 @@ class WaybillController extends Controller
     }
     protected function validatorWaybillDispatch(Request $request,$id){
         $rule=[
-            'logistic_id'=>'required|integer',
+            'logistic_id'=>'required_without:order_id|integer',
             'carrier_bill'=>"sometimes|nullable|max:50|unique:waybills,carrier_bill,$id",
             'fee'=>'sometimes|nullable|min:0|numeric|max:999999',
             'other_fee'=>'sometimes|nullable|min:0|numeric|max:999999',
@@ -725,7 +731,7 @@ class WaybillController extends Controller
             'amount'=>'nullable|numeric|min:0',
             'amount_unit_id'=>'required',
             'origination_city_id'=>'sometimes|required|integer',
-            'destination_city_id'=>'sometimes|required|integer',
+            'destination_city_id'=>'sometimes|required_without:order_id|integer',
             'warehouse_weight_other'=>'sometimes|nullable|min:0|numeric|max:999999',
             'warehouse_weight_unit_id_other'=>'sometimes|required_with:warehouse_weight_other|nullable|integer',
             'pick_up_fee'=>'sometimes|nullable|min:0|numeric|max:999999',
@@ -738,10 +744,11 @@ class WaybillController extends Controller
         ];
         if ($request->type == '专线'){
             $rule['origination_city_id']='required|integer';
-            $rule['destination_city_id']='required|integer';
+            $rule['destination_city_id']='required_without:order_id|integer';
         }
         $validator=Validator::make($request->input(),$rule,[
             'required'=>':attribute 为必填项',
+            'required_without'=>':attribute 为必填项',
             'alpha_num'=>':attribute 应为字母或数字',
             'max'=>':attribute 字符过多或输入值过大',
             'min'=>':attribute 不得为负',
@@ -806,7 +813,7 @@ class WaybillController extends Controller
         if(!Gate::allows('运输管理-删除')){return redirect('/');}
         $paginate = $request->input('paginate')??50;
         /** @var Collection $waybills */
-        $waybills = Waybill::query()->with(['owner','logistic','amountUnit','warehouseWeightUnit','carrierWeightUnit',
+        $waybills = Waybill::query()->with(['owner','order.owner','order.logistic','logistic','amountUnit','warehouseWeightUnit','carrierWeightUnit',
             'warehouseWeightUnitOther','carrierWeightUnitOther','carType','waybillAuditLogs' => function ($query) {
             /** @var Builder $query */
             $query->with('user');
@@ -905,4 +912,15 @@ class WaybillController extends Controller
         return ['success'=>true,'warehouseWeight'=>$warehouseWeight];
     }
 
+    //寻找订单
+    public function seekOrder()
+    {
+        $this->gate("运输管理");
+        $code = request("code");
+        if (!$code)$this->error("暂无绑定订单");
+        $order = app("OrderService")->first(["code"=>$code]);
+        if (!$order)$this->error("暂无绑定订单");
+        $this->success($order);
+    }
+
 }

+ 20 - 5
app/Order.php

@@ -15,11 +15,26 @@ class Order extends Model
     use ModelTimeFormat;
 
     protected $fillable = [
-        'id', 'batch_id',  'owner_id', 'status',
-        'created_at', 'code', 'shop_id',  'client_code',
-        'logistic_id', 'consignee_name', 'consignee_phone', 'province',
-        'city', 'district', 'address','warehouse_id',
-        'wms_edittime', 'wms_status','order_type','frozen'
+        'id',
+        'batch_id',
+        'owner_id',
+        'status',
+        'created_at',
+        'code',
+        'shop_id',
+        'client_code',
+        'logistic_id',
+        'consignee_name',
+        'consignee_phone',
+        'province',
+        'city',
+        'district',
+        'address',
+        'warehouse_id',
+        'wms_edittime',
+        'wms_status',
+        'order_type',
+        'frozen'
     ];
 
     /*

+ 7 - 0
app/Services/RegionService.php

@@ -128,4 +128,11 @@ class RegionService
         }
         return $name;
     }
+
+    public function getSelection($type = null, $columns = ["id","name"])
+    {
+        $regions = Region::query()->select($columns);
+        if ($type)$regions->where("type",$type);
+        return $regions->get();
+    }
 }

+ 0 - 7
app/Services/WaybillService.php

@@ -83,13 +83,6 @@ class WaybillService
         return DB::transaction(function ()use($request){
             $waybill=new Waybill();
             $inputs = $request->all();
-            if ($inputs["wms_bill_number"]){
-                $order = app("OrderService")->first(["code"=>$inputs["wms_bill_number"]]);
-                if ($order){
-                    $inputs["destination_city_id"] = app("RegionService")->getCity($order->city,$order->province);
-                    $inputs["district_id"] = app("RegionService")->getDistrict($order->district,$order->city);
-                }
-            }
             $inputs['status']='未审核';
             $inputs['waybill_number']=Uuid::uuid1();
             $waybill->fill($inputs);

+ 65 - 10
app/Waybill.php

@@ -18,11 +18,47 @@ class Waybill extends Model
     use ModelTimeFormat;
     use SoftDeletes;
     protected $fillable=[
-        'status','type','waybill_number','owner_id','wms_bill_number','origination','destination','recipient','recipient_mobile','charge','ordering_remark',
-        'logistic_id','carrier_bill','origination_city_id','destination_city_id','warehouse_weight','warehouse_weight_unit_id','carrier_weight','carrier_weight_unit_id','carType_id',
-        'car_owner_info','fee','pick_up_fee','other_fee','collect_fee','dispatch_remark','waybill_price_model_id','warehouse_weight_other','warehouse_weight_unit_id_other'
-        ,'carrier_weight_other','carrier_weight_unit_id_other','source_bill','mileage','amount','inquire_tel','amount_unit_id','other_charge','other_charge_remark','deliver_at',
-        "district_id"
+        'status',
+        'type',
+        'waybill_number',
+        'owner_id',
+        'wms_bill_number',
+        'origination',
+        'destination',
+        'recipient',
+        'recipient_mobile',
+        'charge',
+        'ordering_remark',
+        'logistic_id',
+        'carrier_bill',
+        'origination_city_id',
+        'destination_city_id',
+        'warehouse_weight',
+        'warehouse_weight_unit_id',
+        'carrier_weight',
+        'carrier_weight_unit_id',
+        'carType_id',
+        'car_owner_info',
+        'fee',
+        'pick_up_fee',
+        'other_fee',
+        'collect_fee',
+        'dispatch_remark',
+        'waybill_price_model_id',
+        'warehouse_weight_other',
+        'warehouse_weight_unit_id_other',
+        'carrier_weight_other',
+        'carrier_weight_unit_id_other',
+        'source_bill',
+        'mileage',
+        'amount',
+        'inquire_tel',
+        'amount_unit_id',
+        'other_charge',
+        'other_charge_remark',
+        'deliver_at',
+        "district_id",
+        "order_id"
     ];
 
     public function district()
@@ -71,9 +107,11 @@ class Waybill extends Model
     public function uploadFile(){
         return $this->hasOne('App\UploadFile','table_id','id')->where('table_name','waybills');
     }
-//    public function getOrderingRemarkAttribute($val){
-//        return
-//    }
+    public function order()
+    {   //订单
+        return $this->belongsTo(Order::class);
+    }
+
 
 
     static public function setWeightByOrderCode($orderCode,$weight){
@@ -92,8 +130,25 @@ class Waybill extends Model
      * @return Builder
      */
     public static function filterAuthorities(){
-        $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
-        return (new static)->newQuery()->whereIn('owner_id',$owner_ids);
+        $ids=app('UserService')->getPermittingOwnerIds(auth()->user());
+        return (new static)->newQuery()->leftJoin("orders","waybills.wms_bill_number","orders.code")
+            ->leftJoin("owners","orders.owner_id","owners.id")
+            ->leftJoin("logistics","orders.logistic_id","logistics.id")
+            ->selectRaw(<<<column
+            owners.name as owner_name,
+            logistics.name as logistic_name,
+            orders.consignee_name as order_consignee_name,
+            orders.consignee_phone as order_consignee_phone,
+            orders.province as order_province,
+            orders.city as order_city,
+            orders.district as order_district,
+            orders.address as order_address
+column
+)
+            ->where(function ($query)use($ids){
+            /** @var Builder  $query */
+            $query->whereIn('waybills.owner_id',$ids)->orWhereIn("orders.owner_id",$ids);
+        });
     }
 
 

+ 0 - 32
database/migrations/2021_02_22_175630_change_waybills_table_add_order_id_column.php

@@ -1,32 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-class ChangeWaybillsTableAddOrderIdColumn extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::table('waybills', function (Blueprint $table) {
-            //
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::table('waybills', function (Blueprint $table) {
-            //
-        });
-    }
-}

+ 40 - 0
database/migrations/2021_02_23_175630_change_waybills_table_add_order_id_column.php

@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeWaybillsTableAddOrderIdColumn extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('waybills', function (Blueprint $table) {
+            $table->bigInteger("order_id")->index()->nullable()->comment("订单");
+            $table->bigInteger('owner_id')->nullable()->comment('货主')->change();
+            $table->string('destination',50)->nullable()->comment('目的地')->change();
+            $table->string('recipient',50)->nullable()->comment('收件人')->change();
+            $table->string('recipient_mobile',50)->nullable()->comment('收件人电话')->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('waybills', function (Blueprint $table) {
+            $table->dropColumn("order_id");
+            $table->bigInteger('owner_id')->comment('货主')->change();
+            $table->string('destination',50)->comment('目的地')->change();
+            $table->string('recipient',50)->comment('收件人')->change();
+            $table->string('recipient_mobile',50)->comment('收件人电话')->change();
+        });
+    }
+}

+ 1 - 1
resources/views/customer/project/create.blade.php

@@ -634,7 +634,7 @@
                     if (this.model.operation.isDiscount){
                         let sign = false;
                         this.model.operation.discount_count.forEach((item,i)=>{
-                            if (!item || (i!==0 && item<=this.model.operation.discount_count[i-1])){
+                            if (!item || (i!==0 && Number(item)<=Number(this.model.operation.discount_count[i-1]))){
                                 this.$set(this.errors,"discount_count_"+i,["非法满减值"]);
                                 sign = true;
                             }

+ 55 - 27
resources/views/waybill/create.blade.php

@@ -23,7 +23,7 @@
             <div class="card-body">
                 <form method="POST" action="{{ url('waybill') }}">
                     @csrf
-                    <input name="type" hidden value="{{$type}}">
+                    <label hidden><input name="type" value="{{$type}}"></label>
                     <div class="h5 text-center mb-3">
                         <ul class="nav nav-tabs">
                             <li class="nav-item offset-5"><a class="nav-link @if($type=='专线') active @endif" href="{{url('waybill/create?type=ZX')}}">专线</a></li>
@@ -31,12 +31,12 @@
                         </ul>
                     </div>
                     <div class="form-group row">
-                        <label for="owner_id" class="col-2 col-form-label text-right text-primary">货主{{old('owner_id')}} *</label>
+                        <label for="owner_id" class="col-2 col-form-label text-right text-primary">货主 *</label>
                         <div class="col-8 form-inline">
-                            <select id="owner_id" name="owner_id" class="form-control @error('owner_id') is-invalid @enderror" v-model="owner_id"  style="width: 30%" required>
+                            <select id="owner_id" :disabled="!!model.order_id" :name="model.order_id ? '' : 'owner_id'" class="form-control @error('owner_id') is-invalid @enderror" v-model="model.owner_id"  style="width: 30%" required>
                                 <option v-for="owner in owners" :value="owner.id">@{{owner.name}}</option>
                             </select>
-                            <input class="form-control-sm ml-2" placeholder="输入关键字定位" @input="owner_seek">
+                            <label v-if="!model.order_id"><input class="form-control-sm ml-2" placeholder="输入关键字定位" @input="owner_seek"></label>
                         </div>
                         <div class="col-sm-5">
                             <p class="form-control-static text-danger small font-weight-bold" style="margin-left: 50%">{{ $errors->first('owner_id') }}</p>
@@ -45,15 +45,16 @@
                     <div class="form-group row">
                         <label for="wms_bill_number" class="col-2 col-form-label text-right text-muted">WMS单号</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('wms_bill_number') is-invalid @enderror"
+                            <input id="wms_bill_number" @change="bindOrder($event)" type="text" class="form-control @error('wms_bill_number') is-invalid @enderror"
                                    name="wms_bill_number" autocomplete="off" value="{{ old('wms_bill_number') }}"  >
                             @error('wms_bill_number')
                             <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                                <strong>{{ $message }}</strong>
+                            </span>
                             @enderror
                         </div>
                     </div>
+                    <label hidden><input :value="model.order_id" name="order_id"></label>
                     <div class="col-8" style="margin-left: 15%">
                         <button type="button" class="btn btn-outline-primary btn-sm" @click="origination='松江区泗砖仓'" style="transform: scale(0.9)">松江泗砖仓</button>
                         <button type="button" class="btn btn-outline-primary btn-sm" @click="origination='松江区九干仓'" style="transform: scale(0.9)">松江九干仓</button>
@@ -62,7 +63,7 @@
                     <div class="form-group row">
                         <label for="origination" class="col-2 col-form-label text-right text-primary">始发地址 *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('origination') is-invalid @enderror"
+                            <input id="origination" type="text" class="form-control @error('origination') is-invalid @enderror"
                                    name="origination" autocomplete="off" value="{{ old('origination') }}"  v-model="origination" required>
                             @error('origination')
                             <span class="invalid-feedback" role="alert">
@@ -74,20 +75,22 @@
                     <div class="form-group row">
                         <label for="destination" class="col-2 col-form-label text-right text-primary">目的地址 *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('destination') is-invalid @enderror"
-                                   name="destination" autocomplete="off" value="{{ old('destination') }}"  required>
+                            <input id="destination" type="text" class="form-control @error('destination') is-invalid @enderror" autocomplete="off"
+                                   :readonly="!!model.order_id" required
+                                   :name="model.order_id ? '' : 'destination'" :value="model.order_id ? order.address : '{{ old('destination') }}'" >
                             @error('destination')
                             <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                                <strong>{{ $message }}</strong>
+                            </span>
                             @enderror
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="recipient" class="col-2 col-form-label text-right text-primary">收件人 *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('recipient') is-invalid @enderror"
-                                   name="recipient" autocomplete="off" value="{{ old('recipient') }}"  required>
+                            <input id="recipient" type="text" class="form-control @error('recipient') is-invalid @enderror"
+                                   :readonly="!!model.order_id" autocomplete="off"  required
+                                   :name="model.order_id ? '' : 'recipient'" :value="model.order_id ? order.consignee_name : '{{ old('recipient') }}'">
                             @error('recipient')
                             <span class="invalid-feedback" role="alert">
                                         <strong>{{ $message }}</strong>
@@ -98,12 +101,13 @@
                     <div class="form-group row">
                         <label for="recipient_mobile" class="col-2 col-form-label text-right text-primary">收件人电话 *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('recipient_mobile') is-invalid @enderror"
-                                   name="recipient_mobile" autocomplete="off" value="{{ old('recipient_mobile') }}"  required>
+                            <input id="recipient_mobile" type="text" class="form-control @error('recipient_mobile') is-invalid @enderror"
+                                   :readonly="!!model.order_id" autocomplete="off"  required
+                                   :name="model.order_id ? '' : 'recipient_mobile'" :value="model.order_id ? order.consignee_phone : '{{ old('recipient_mobile') }}'">
                             @error('recipient_mobile')
                             <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                                <strong>{{ $message }}</strong>
+                            </span>
                             @enderror
                         </div>
                     </div>
@@ -190,24 +194,48 @@
             el:'#list',
             data:{
                 owners:[
-                        @foreach($owners as $owner)
+                    @foreach($owners as $owner)
                     {id:'{{$owner->id}}',name:'{{$owner->name}}'},
                     @endforeach
                 ],
-                owner_id:'{{old('owner_id')}}',
                 origination:'{{old('origination')}}',
+                model:{
+                    order_id : "{{old("order_id")}}",
+                    owner_id:'{{old('owner_id')}}',
+                },
+                order:{},
+            },
+            mounted(){
+                if (this.model.order_id)this._codeGetOrder("{{ old('wms_bill_number') }}");
             },
             methods:{
                 owner_seek:function (e) {
-                    let _this=this;
-                    let $val=e.target.value;
-                    if($val==='')_this.owner_id='';
-                    else
-                        _this.owners.forEach(function (owner) {
-                            if (owner.name.includes($val)){
-                                _this.owner_id=owner.id;
+                    if (model.order_id)return;
+                    let val=e.target.value;
+                    if(!val)this.model.owner_id='';
+                    else{
+                        this.owners.every(owner=> {
+                            if (owner.name.includes(val)){
+                                this.model.owner_id=owner.id;
+                                return false;
                             }
+                            return true;
                         });
+                    }
+                },
+                bindOrder(e){
+                    this.model.order_id = "";
+                    this.model.owner_id = "";
+                    let val = e.target.value;
+                    this._codeGetOrder(val);
+                },
+                _codeGetOrder(val){
+                    let url = "{{url('waybill/seekOrder')}}";
+                    window.tempTip.postBasicRequest(url,{code:val},res=>{
+                        this.order = res;
+                        this.model.order_id = res.id;
+                        this.model.owner_id = res.owner_id;
+                    });
                 },
             },
         });

+ 2 - 2
resources/views/waybill/delivering.blade.php

@@ -193,8 +193,8 @@
                     amount_unit_id:'{{$waybill->amount_unit_id}}',
                     amount_unit_name:'{{$waybill->amount_unit ? $waybill->amount_unit->name : ''}}',
                     inquire_tel:'{{$waybill->inquire_tel}}',
-                    carrier_name:'{{$waybill->logistic ? $waybill->logistic->name : ''}}',
-                    owner_name:'{{$waybill->owner ? $waybill->owner->name : ''}}',
+                    carrier_name:'{{$waybill->logistic_name ?? ($waybill->logistic->name ?? '')}}',
+                    owner_name:'{{$waybill->owner_name ?? ($waybill->owner->name ?? '')}}',
                     warehouse_weight_unit_name:'{{$waybill->warehouse_weight_unit ? $waybill->warehouse_weight_unit->name : ''}}',
                     carrier_weight_unit_name:'{{$waybill->carrier_weight_unit ? $waybill->carrier_weight_unit->name : ''}}',
                     warehouse_weight_unit_other_name:'{{$waybill->warehouse_weight_unit_other ? $waybill->warehouse_weight_unit_other->name : ''}}',

+ 49 - 58
resources/views/waybill/edit.blade.php

@@ -15,7 +15,7 @@
                     @csrf
                     @method('PUT')
                     <div class="form-group row">
-                        <label class="col-2 col-form-label text-right text-secondary">运单类型</label>
+                        <label for="type" class="col-2 col-form-label text-right text-secondary">运单类型</label>
                         <div class="col-8">
                             <div class="h5 mb-3 col-8">
                                 <button type="button" @click="waybill.type='专线'" class="btn" :class="waybill.type=='专线'?'btn-primary':'btn-outline-primary'">专线</button>
@@ -25,9 +25,9 @@
                         </div>
                     </div>
                     <div class="form-group row">
-                        <label class="col-2 col-form-label text-right text-secondary">运单号</label>
+                        <label for="waybill_number" class="col-2 col-form-label text-right text-secondary">运单号</label>
                         <div class="col-8">
-                            <input type="text" class="form-control" disabled="disabled" :value="waybill.waybill_number" >
+                            <input id="waybill_number" type="text" class="form-control" disabled="disabled" :value="waybill.waybill_number" >
                         </div>
                     </div>
                     <div class="form-group row">
@@ -127,8 +127,9 @@
                     <div class="form-group row" style="margin-bottom: 20px">
                         <label for="logistic_id" class="col-2 col-form-label text-right text-primary">承运商 *</label>
                         <div class="col-8" style="position: relative">
-                            <select name="logistic_id" class="form-control @error('logistic_id') is-invalid @enderror"
-                                    :class="errors['logistic_id'] ? 'is-invalid' :''" id="logistic_id" v-model="waybill.logistic_id" style="width: 30%; ">
+                            <select class="form-control @error('logistic_id') is-invalid @enderror" id="logistic_id" style="width: 30%; "
+                                    :name="waybill.order_id ? '' : 'logistic_id'" :disabled="!!waybill.order_id"
+                                    :class="errors['logistic_id'] ? 'is-invalid' :''"  v-model="waybill.logistic_id">
                                 <option v-for="logistic in logistics" :value="logistic.id">@{{logistic.name}}</option>
                             </select>
                             <div v-if="errors['logistic_id'] && errors['logistic_id'].length>0" class="invalid-feedback" role="alert" style="position: relative">
@@ -166,8 +167,9 @@
                         <div class="form-group row">
                             <label for="destination_city_id" class="col-2 col-form-label text-right text-primary">目的市 *</label>
                             <div class="col-8 form-inline">
-                                <select class="form-control @error('destination_city_id') is-invalid @enderror" name="destination_city_id"
-                                        :class="errors['destination_city_id'] ? 'is-invalid' :''" id="destination_city_id" v-model="waybill.destination_city_id" style="width: 30%; " >
+                                <select class="form-control @error('destination_city_id') is-invalid @enderror" id="destination_city_id" style="width: 30%; "
+                                        :name="waybill.order_id ? '' : 'destination_city_id'" :disabled="!!waybill.order_id"
+                                        :class="errors['destination_city_id'] ? 'is-invalid' :''"  v-model="waybill.destination_city_id">
                                     <option v-for="city in cities" :value="city.id">@{{city.name}}</option>
                                 </select>
                                 <input type="text" class="form-control-sm  form-control tooltipTarget" style="vertical-align: middle"
@@ -376,6 +378,7 @@
                     </div>
                     <input type="hidden" name="status" value="待终审">
                     <input type="hidden" name="waybillPriceModel" id="waybillPriceModel">
+                    <input type="hidden" name="order_id" :value="waybill.order_id">
                     <div class="form-group row">
                         <div class="col-8 offset-2">
                             <input type="button" @click="submitForm" class="btn btn-outline-dark form-control" value="提交">
@@ -392,48 +395,52 @@
         let vueList=new Vue({
             el:'#list',
             data:{
-                cities:[
-                        @foreach($cities as $city)
-                    {
-                        id:'{{$city->id}}',name:'{{$city->name}}',type:'{{$city->type}}',
-                    },
-                    @endforeach
-                ],
-                units:[
-                        @foreach($units as $unit){
-                        id:'{{$unit->id}}',name:'{{$unit->name}}',
-                    },
-                    @endforeach
-                ],
-                logistics:[
-                    @foreach($logistics as $logistic)
-                        {id:'{{$logistic->id}}',name:'{{$logistic->name}}',},
-                    @endforeach
-                ],
-                carTypes:[
-                    @foreach($carTypes as $carType)
-                    {!! $carType !!},
-                    @endforeach
-                ],
+                cities:[@foreach($cities as $city){id:'{{$city->id}}',name:'{{$city->name}}',type:'{{$city->type}}',},@endforeach],
+                units:[@foreach($units as $unit){id:'{{$unit->id}}',name:'{{$unit->name}}',},@endforeach],
+                logistics:[@foreach($logistics as $logistic){id:'{{$logistic->id}}',name:'{{$logistic->name}}',},@endforeach],
+                carTypes:[@foreach($carTypes as $carType){!! $carType !!},@endforeach],
                 errors:[],
                 waybill:{
-                    id:'{{$waybill->id}}',type:'{{$waybill->type}}',waybill_number:'{{$waybill->waybill_number}}',owner_name:'{{$waybill->owner_name}}',
-                    wms_bill_number:'{{$waybill->wms_bill_number}}',origination:'{{$waybill->origination}}',destination:'{{$waybill->destination}}',
-                    recipient:'{{$waybill->recipient}}',recipient_mobile:'{{$waybill->recipient_mobile}}',ordering_remark:'{{$waybill->ordering_remark}}',
-                    charge:'{{$waybill->charge}}',logistic_id:'{{$waybill->logistic_id}}',carrier_bill:'{{$waybill->carrier_bill}}',
-                    warehouse_weight_other:'{{$waybill->warehouse_weight_other}}',warehouse_weight_unit_id_other:'{{$waybill->warehouse_weight_unit_id_other}}',amount:'{{$waybill->amount}}',
-                    amount_unit_id:'{{$waybill->amount_unit_id}}',mileage:'{{$waybill->mileage}}',carType_id:'{{$waybill->carType_id}}',
-                    car_owner_info:'{{$waybill->car_owner_info}}',fee:'{{$waybill->fee}}',other_fee:'{{$waybill->other_fee}}',
-                    other_charge:'{{$waybill->other_charge}}',other_charge_remark:'{{$waybill->other_charge_remark}}',dispatch_remark:'{{$waybill->dispatch_remark}}',
-                    origination_city_id:'{{$waybill->origination_city_id}}',destination_city_id:'{{$waybill->destination_city_id}}',warehouse_weight:'{{$waybill->warehouse_weight}}',
-                    warehouse_weight_unit_id:'{{$waybill->warehouse_weight_unit_id}}',carrier_weight:'{{$waybill->carrier_weight}}',carrier_weight_unit_id:'{{$waybill->carrier_weight_unit_id}}',
-                    carrier_weight_other:'{{$waybill->carrier_weight_other}}',carrier_weight_unit_id_other:'{{$waybill->carrier_weight_unit_id_other}}',pick_up_fee:'{{$waybill->pick_up_fee}}',
+                    id:'{{$waybill->id}}',
+                    waybill_number:'{{$waybill->waybill_number}}',
+                    order_id:'{{$waybill->order_id}}',
+                    owner_name:'{{$waybill->order->owner->name ?? $waybill->owner->name}}',
+                    wms_bill_number:'{{$waybill->wms_bill_number}}',origination:'{{$waybill->origination}}',
+                    destination:'{{$waybill->order->address ?? $waybill->destination}}',
+                    recipient:'{{$waybill->order->consignee_name ?? $waybill->recipient}}',
+                    recipient_mobile:'{{$waybill->order->consignee_phone ?? $waybill->recipient_mobile}}',ordering_remark:'{{$waybill->ordering_remark}}',
+
+                    charge:'{{ old("charge") ?? $waybill->charge}}',
+                    logistic_id:'{{ $waybill->order->logistic_id ?? (old("logistic_id") ?? $waybill->logistic_id)}}',
+                    carrier_bill:'{{ old("carrier_bill") ?? $waybill->carrier_bill}}',
+                    type:'{{ old("type") ?? $waybill->type}}',
+                    warehouse_weight_other:'{{ old("warehouse_weight_other") ?? $waybill->warehouse_weight_other}}',
+                    warehouse_weight_unit_id_other:'{{ old("warehouse_weight_unit_id_other") ?? $waybill->warehouse_weight_unit_id_other }}',
+                    amount:'{{ old('amount') ?? $waybill->amount}}',
+                    amount_unit_id:'{{ old('amount_unit_id') ?? $waybill->amount_unit_id}}',
+                    mileage:'{{ old("mileage") ?? $waybill->mileage}}',
+                    carType_id:'{{ old("carType_id") ?? $waybill->carType_id}}',
+                    car_owner_info:'{{ old("car_owner_info") ?? $waybill->car_owner_info}}',
+                    fee:'{{ old("fee") ?? $waybill->fee}}',
+                    other_fee:'{{ old("other_fee") ?? $waybill->other_fee}}',
+                    other_charge:'{{ old("other_charge") ?? $waybill->other_charge}}',
+                    other_charge_remark:'{{ old("other_charge_remark") ?? $waybill->other_charge_remark}}',
+                    dispatch_remark:'{{ old("dispatch_remark") ?? $waybill->dispatch_remark}}',
+                    origination_city_id:'{{ old("origination_city_id") ?? $waybill->origination_city_id}}',
+                    destination_city_id:'{{ old("destination_city_id") ?? $waybill->destination_city_id}}',
+                    warehouse_weight:'{{ old("warehouse_weight") ?? $waybill->warehouse_weight}}',
+                    warehouse_weight_unit_id:'{{ old("warehouse_weight_unit_id") ?? $waybill->warehouse_weight_unit_id}}',
+                    carrier_weight:'{{ old("carrier_weight") ?? $waybill->carrier_weight}}',
+                    carrier_weight_unit_id:'{{$waybill->carrier_weight_unit_id}}',
+                    carrier_weight_other:'{{$waybill->carrier_weight_other}}',
+                    carrier_weight_unit_id_other:'{{$waybill->carrier_weight_unit_id_other}}',
+                    pick_up_fee:'{{$waybill->pick_up_fee}}',
                 },
+                order:{!! $waybill->order ?? '{}' !!},
                 waybillTemp:{!! $waybill !!}
             },
             mounted:function(){
                 let _this=this;
-                //console.log(_this.waybillPriceModel.amount_unit_id)
                 $(".tooltipTarget").tooltip({'trigger':'hover'});
                 this.units.every(function (unit) {
                     switch (unit.name) {
@@ -547,7 +554,6 @@
                                     tempTip.confirm('该目的地与计量单位对应的计费模型不存在,如录入将会标为异常记录,请通知相关负责人添加计费模型,点击'+'<b class="text-primary">"确定"</b>'+'则确认提交 ',
                                         function () {
                                             document.getElementById('deliver_at').value= document.getElementById('deliver_at_date').value+' '+ document.getElementById('deliver_at_time').value;
-                                            // document.getElementById('waybillForm').submit();
                                             _this.executeSubmit();
                                         });
                                 }else{
@@ -560,20 +566,6 @@
                 },
                 executeSubmit(){
                     document.getElementById('waybillForm').submit();
-         /*           let data=['origination','charge','carrier_bill', 'warehouse_weight','warehouse_weight_unit_id',
-                        'warehouse_weight_other','warehouse_weight_unit_id_other','carrier_weight','carrier_weight_unit_id'
-                        ,'carrier_weight_other','carrier_weight_unit_id_other','mileage','carType_id'
-                        ,'car_owner_info','pick_up_fee','fee','other_fee','other_charge','other_charge_remark','dispatch_remark'];
-                    let waybill=this.waybill;
-                    let waybillTemp=this.waybillTemp;
-                    data.forEach(function (name) {
-                        if (waybill[name] === waybillTemp[name]){
-                            if (document.getElementById(name))document.getElementById(name).removeAttribute('name');
-                        }
-                    });*/
-                    /*setTimeout(function () {
-                        document.getElementById('waybillForm').submit();
-                    },1);*/
                 },
                 spliceDeliverAt:function () {
                         document.getElementById('deliver_at').value= document.getElementById('deliver_at_date').value+' '+ document.getElementById('deliver_at_time').value;
@@ -590,7 +582,6 @@
                         this.is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,carrier_weight_other,carrier_weight_unit_id_other);
                     }else {
                         document.getElementById('deliver_at').value= document.getElementById('deliver_at_date').value+' '+ document.getElementById('deliver_at_time').value;
-                        // document.getElementById('waybillForm').submit();
                         this.executeSubmit();
                     }
                 },

+ 8 - 14
resources/views/waybill/index.blade.php

@@ -290,23 +290,17 @@
                         status:'{{$waybill->status}}',
                         type:'{{$waybill->type}}',
                         waybill_number:'{{$waybill->waybill_number}}',
-                        owner:'{{$waybill->owner ? $waybill->owner->name : ''}}',
+                        owner:'{{$waybill->owner_name ?? ($waybill->owner->name ?? '')}}',
                         source_bill:'{{$waybill->source_bill}}',
                         wms_bill_number:'{{$waybill->wms_bill_number}}',
                         origination:'{{$waybill->origination}}',
-                        destination:'{{--{{$waybill->destination_city_id}}'?
-                            (('{{$waybill->destination}}'.indexOf('{{$waybill->destinationCity ? $waybill->destinationCity->name : ''}}')===-1 &&
-                                '{{$waybill->destination}}'.indexOf('{{$waybill->destinationCity ? ($waybill->destinationCity->province ? $waybill->destinationCity->province->name : '') : ''}}')===-1)?
-                                '{{($waybill->destinationCity ? ($waybill->destinationCity->province ? $waybill->destinationCity->province->name : '') : '').($waybill->destinationCity ? $waybill->destinationCity->name : '').($waybill->destination)}}'
-                                :'{{$waybill->destination}}')
-                            :'{{$waybill->destination}}--}}{{$waybill->destination}}',
-                        recipient:'{{$waybill->recipient}}',
-                        recipient_mobile:'{{$waybill->recipient_mobile}}',
+                        destination:'{{$waybill->order_address ?? $waybill->destination}}',
+                        recipient:'{{$waybill->order_consignee_name ?? $waybill->recipient}}',
+                        recipient_mobile:'{{$waybill->order_consignee_phone ?? $waybill->recipient_mobile}}',
                         charge:'{{$waybill->charge}}',
                         ordering_remark:'{{preg_replace("/[\n\s]/",' ',($waybill->ordering_remark??""))}}',
-                        carrier:'{{$waybill->logistic ? $waybill->logistic->name : ''}}',
+                        carrier:'{{$waybill->logistic_name ?? ($waybill->logistic->name ?? '')}}',
                         carrier_bill:'{{$waybill->carrier_bill}}',
-                        destination_city:'{{$waybill->destinationCity ? $waybill->destinationCity->name : ''}}',
                         warehouse_weight:'{{$waybill->warehouse_weight}}',
                         warehouse_weight_unit:'{{$waybill->warehouse_weight_unit ? $waybill->warehouse_weight_unit->name : ''}}',
                         carrier_weight:'{{$waybill->carrier_weight}}',
@@ -330,9 +324,9 @@
                         waybillAuditLogs:{!! $waybill->waybillAuditLogs !!},
                         btn_refresh_weight:'zoomIn',
                         remark:'{{$waybill->remark ?? ''}}',
-                        province:'{{$waybill->destinationCity->province->name ?? ''}}',
-                        city:'{{$waybill->destinationCity->name ?? ''}}',
-                        district:'{{$waybill->district->name ?? ''}}',
+                        province:'{{$waybill->order_province ?? ($waybill->destinationCity->province->name ?? '')}}',
+                        city:'{{$waybill->order_city ?? ($waybill->destinationCity->name ?? '')}}',
+                        district:'{{$waybill->order_district ?? ($waybill->district->name ?? '')}}',
                     },
                     @endforeach
                 ],

+ 6 - 7
resources/views/waybill/recycle.blade.php

@@ -138,21 +138,20 @@
                         status:'{{$waybill->status}}',
                         type:'{{$waybill->type}}',
                         waybill_number:'{{$waybill->waybill_number}}',
-                        owner:'{{$waybill->owner ? $waybill->owner->name : ''}}',
+                        owner:'{{ $waybill->order->owner->name ?? ($waybill->owner->name ?? '') }}',
                         source_bill:'{{$waybill->source_bill}}',
                         wms_bill_number:'{{$waybill->wms_bill_number}}',
                         origination:'{{$waybill->origination}}',
-                        destination:'{{$waybill->destination}}',
-                        recipient:'{{$waybill->recipient}}',
-                        recipient_mobile:'{{$waybill->recipient_mobile}}',
+                        destination:'{{$waybill->order->address ?? $waybill->destination}}',
+                        recipient:'{{$waybill->order->consignee_name ?? $waybill->recipient}}',
+                        recipient_mobile:'{{$waybill->order->consignee_phone ?? $waybill->recipient_mobile}}',
                         charge:'{{$waybill->charge}}',
                         ordering_remark:'{{preg_replace("/[\n\s]/",' ',($waybill->ordering_remark??""))}}',
-                        carrier:'{{$waybill->carrier ? $waybill->carrier->name : ''}}',
+                        carrier:'{{$waybill->order->logistic->name ?? ($waybill->logistic->name ?? '')}}',
                         carrier_bill:'{{$waybill->carrier_bill}}',
                         origination_city:'{{$waybill->origination_city ? $waybill->origination_city->name : ''}}',
-                        destination_city:'{{$waybill->destination_city ? $waybill->destination_city->name : ''}}',
+                        destination_city:'{{$waybill->order->city ?? ($waybill->destination_city->name ?? '')}}',
                         warehouse_weight:'{{$waybill->warehouse_weight}}',
-                        destination_province_name:'{{$waybill->destination_city ? ($waybill->destination_city->province ? $waybill->destination_city->province->name : '') : ''}}',
                         warehouse_weight_unit:'{{$waybill->warehouse_weight_unit ? $waybill->warehouse_weight_unit->name : ''}}',
                         carrier_weight:'{{$waybill->carrier_weight}}',
                         carrier_weight_unit:'{{$waybill->carrier_weight_unit ? $waybill->carrier_weight_unit->name : ''}}',

+ 56 - 41
resources/views/waybill/waybillEdit.blade.php

@@ -8,7 +8,7 @@
             </li>
         @endcomponent
     </div>
-    <div class="container-fluid mt-3" id="update">
+    <div class="container-fluid mt-3" id="container">
         <div class="card">
             <div class="card-body">
                 <form method="POST" action='{{url("waybill/waybillUpdate/{$waybill->id}")}}'>
@@ -16,15 +16,16 @@
                     <div class="form-group row">
                         <label for="type" class="col-2 col-form-label text-right text-primary">运单类型 *</label>
                         <div class="h5 mb-3 col-8">
-                            <button type="button" @click="type='专线'" class="btn" :class="type=='专线'?'btn-primary':'btn-outline-primary'">专线</button>
-                            <button type="button" @click="type='直发车'" class="btn ml-2" :class="type!='专线'?'btn-primary':'btn-outline-primary'">直发车</button>
+                            <button type="button" @click="model.type='专线'" class="btn" :class="model.type=='专线'?'btn-primary':'btn-outline-primary'">专线</button>
+                            <button type="button" @click="model.type='直发车'" class="btn ml-2" :class="model.type!='专线'?'btn-primary':'btn-outline-primary'">直发车</button>
                         </div>
                     </div>
-                    <input hidden type="text" name="type" :value="type">
+                    <label hidden><input type="text" name="type" :value="model.type"></label>
                     <div class="form-group row">
-                        <label for="province_id" class="col-2 col-form-label text-right text-primary">货主 *</label>
+                        <label for="owner_id" class="col-2 col-form-label text-right text-primary">货主 *</label>
                         <div class="col-8">
-                            <select name="owner_id" class="form-control" style="width: 30%;">
+                            <select id="owner_id" class="form-control" style="width: 30%;" v-model="model.owner_id"
+                                    :name="model.order_id ? '' : 'owner_id'" :disabled="!!model.order_id">
                                 @foreach($owners as $owner)
                                     @if($owner->id==$waybill->owner_id)
                                         <option value="{{$owner->id}}" selected>{{$owner->name}}</option>
@@ -38,72 +39,62 @@
                     <div class="form-group row">
                         <label for="wms_bill_number" class="col-2 col-form-label text-right text-muted">WMS单号</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('wms_bill_number') is-invalid @enderror"
-                                   name="wms_bill_number" autocomplete="off" value="@if(old('wms_bill_number')){{ old('wms_bill_number') }}@else{{$waybill->wms_bill_number}}@endif"  >
+                            <input id="wms_bill_number" type="text" class="form-control @error('wms_bill_number') is-invalid @enderror"
+                                name="wms_bill_number" autocomplete="off" value="@if(old('wms_bill_number')){{ old('wms_bill_number') }}@else{{$waybill->wms_bill_number}}@endif"
+                                @change="bindOrder($event)">
                             @error('wms_bill_number')
-                            <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                            <span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
                             @enderror
                         </div>
                     </div>
+                    <label hidden><input :value="model.order_id" name="order_id"></label>
                     <div class="form-group row">
                         <label for="origination" class="col-2 col-form-label text-right text-primary">始发地 *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('origination') is-invalid @enderror"
+                            <input id="origination" type="text" class="form-control @error('origination') is-invalid @enderror"
                                    name="origination" autocomplete="off" value="@if(old('origination')){{ old('origination') }}@else{{$waybill->origination}}@endif"  >
                             @error('origination')
-                            <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                            <span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
                             @enderror
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="destination" class="col-2 col-form-label text-right text-primary">目的地 *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('destination') is-invalid @enderror"
-                                   name="destination" autocomplete="off" value="@if(old('destination')){{ old('destination') }}@else{{$waybill->destination}}@endif"  >
+                            <input id="destination" type="text" class="form-control @error('destination') is-invalid @enderror" autocomplete="off" required
+                                   :readonly="!!model.order_id" :name="model.order_id ? '' : 'destination'"  :value="model.order_id ? order.address : '{{old('destination') ?? $waybill->destination}}'"  >
                             @error('origination')
-                            <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                            <span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
                             @enderror
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="recipient" class="col-2 col-form-label text-right text-primary">收件人 *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('recipient') is-invalid @enderror"
-                                   name="recipient" autocomplete="off" value="@if(old('recipient')){{ old('recipient') }}@else{{$waybill->recipient}}@endif"  >
+                            <input id="recipient" type="text" class="form-control @error('recipient') is-invalid @enderror" autocomplete="off" required
+                                   :readonly="!!model.order_id" :name="model.order_id ? '' : 'recipient'"  :value="model.order_id ? order.consignee_name : '{{old('recipient') ?? $waybill->recipient}}'">
                             @error('recipient')
-                            <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                            <span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
                             @enderror
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="recipient_mobile" class="col-2 col-form-label text-right text-primary">收件人电话 *</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('recipient_mobile') is-invalid @enderror"
-                                   name="recipient_mobile" autocomplete="off" value="@if(old('recipient_mobile')){{ old('recipient_mobile') }}@else{{$waybill->recipient_mobile}}@endif"  >
+                            <input id="recipient_mobile" type="text" class="form-control @error('recipient_mobile') is-invalid @enderror" autocomplete="off" required
+                                   :readonly="!!model.order_id" :name="model.order_id ? '' : 'recipient_mobile'"  :value="model.order_id ? order.consignee_phone : '{{old('recipient_mobile') ?? $waybill->recipient_mobile}}'">
                             @error('recipient_mobile')
-                            <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                            <span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
                             @enderror
                         </div>
                     </div>
                     <div class="form-group row">
-                        <label for="charge" class="col-2 col-form-label text-right text-primary">运输收费(元) *</label>
+                        <label for="charge" class="col-2 col-form-label text-right text-muted">运输收费(元)</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('charge') is-invalid @enderror"
+                            <input id="charge" type="text" class="form-control @error('charge') is-invalid @enderror"
                                    name="charge" autocomplete="off" value="@if(old('charge')){{ old('charge') }}@else{{$waybill->charge}}@endif"  >
                             @error('charge')
-                            <span class="invalid-feedback" role="alert">
-                                        <strong>{{ $message }}</strong>
-                                    </span>
+                            <span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
                             @enderror
                         </div>
                     </div>
@@ -111,7 +102,7 @@
                     <div class="form-group row">
                         <label for="other_charge" class="col-2 col-form-label text-right text-muted">其他收费(元)</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('other_charge') is-invalid @enderror"
+                            <input id="other_charge" type="text" class="form-control @error('other_charge') is-invalid @enderror"
                                    name="other_charge" autocomplete="off" value="@if(old('other_charge')){{ old('other_charge') }}@else{{$waybill->other_charge}}@endif"  >
                             @error('other_charge')
                             <span class="invalid-feedback" role="alert">
@@ -123,7 +114,7 @@
                     <div class="form-group row">
                         <label for="other_charge_remark" class="col-2 col-form-label text-right text-muted">其他收费备注</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('other_charge') is-invalid @enderror"
+                            <input id="other_charge_remark" type="text" class="form-control @error('other_charge') is-invalid @enderror"
                                    name="other_charge_remark" autocomplete="off" value="@if(old('other_charge_remark')){{ old('other_charge_remark') }}@else{{$waybill->other_charge_remark}}@endif"  >
                             @error('other_charge_remark')
                             <span class="invalid-feedback" role="alert">
@@ -136,7 +127,7 @@
                     <div class="form-group row">
                         <label for="collect_fee" class="col-2 col-form-label text-right text-muted">到付金额(元)</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('collect_fee') is-invalid @enderror"
+                            <input id="collect_fee" type="text" class="form-control @error('collect_fee') is-invalid @enderror"
                                    name="collect_fee" autocomplete="off" value="@if(old('collect_fee')){{ old('collect_fee') }}@else{{$waybill->collect_fee}}@endif"  >
                             @error('collect_fee')
                             <span class="invalid-feedback" role="alert">
@@ -148,7 +139,7 @@
                     <div class="form-group row">
                         <label for="ordering_remark" class="col-2 col-form-label text-right text-muted">下单备注</label>
                         <div class="col-8">
-                            <textarea class="form-control @error('ordering_remark') is-invalid @enderror"
+                            <textarea id="ordering_remark" class="form-control @error('ordering_remark') is-invalid @enderror"
                                       name="ordering_remark" autocomplete="off"  >@if(old('ordering_remark')){{ old('ordering_remark') }}@else{{$waybill->ordering_remark}}@endif</textarea>
                             @error('ordering_remark')
                             <span class="invalid-feedback" role="alert">
@@ -171,9 +162,33 @@
 @section('lastScript')
 <script>
     new Vue({
-        el:"#update",
+        el:"#container",
         data:{
-            type:"{{$waybill->type}}",
+            model:{
+                order_id : "{{old('order_id') ?? $waybill->order_id}}",
+                owner_id : "{{old('owner_id') ?? $waybill->owner_id}}",
+                type:"{{old('type') ?? $waybill->type}}",
+            },
+            order:{},
+        },
+        mounted(){
+            if (this.model.order_id)this._codeGetOrder("{{ old('wms_bill_number') ?? $waybill->wms_bill_number }}");
+        },
+        methods:{
+            bindOrder(e){
+                this.model.order_id = "";
+                this.model.owner_id = "";
+                let val = e.target.value;
+                this._codeGetOrder(val);
+            },
+            _codeGetOrder(val){
+                let url = "{{url('waybill/seekOrder')}}";
+                window.tempTip.postBasicRequest(url,{code:val},res=>{
+                    this.order = res;
+                    this.model.order_id = res.id;
+                    this.model.owner_id = res.owner_id;
+                });
+            },
         },
     });
 </script>

+ 1 - 0
routes/web.php

@@ -257,6 +257,7 @@ Route::group(['prefix'=>'waybill'],function(){
         Route::post('waybillPriceModel','WaybillController@isWaybillPriceModel');
     });
     Route::post('deleteImg','WaybillController@deleteImg');
+    Route::post('seekOrder','WaybillController@seekOrder');
     Route::post('upload','WaybillController@upload');
     Route::get('relating',function (){return view('waybill.menuWaybill');});
     Route::get('recycle', 'WaybillController@recycle');