Selaa lähdekoodia

页面懒加载

Zhouzhendong 4 vuotta sitten
vanhempi
commit
d9d52f53e2

+ 23 - 7
app/Http/Controllers/WaybillController.php

@@ -769,12 +769,11 @@ SQL;
         ])->direct();
     }
 
-    //发运
-    public function delivering(Request $request){
-        if (!Auth::user())return view('exception.login');
-        $waybills= Waybill::query()->where("type","专线")
+    private function deliveringQuery(Request $request): Builder
+    {
+        $waybills= Waybill::query()->where("type","专线")->with(["order","logistic"])
             ->whereNotNull("logistic_id")->whereNotIn("status",["未审核","待重审"])
-            ->orderByDesc("id");
+            ->orderByDesc("id")->limit(10);
         if (!Auth::user()->isSuperAdmin()){
             $carriersUsers=DB::table('logistic_user')->where('user_id',Auth::id())->get();
             $carrierIds=array_column($carriersUsers->toArray(),'logistic_id');
@@ -784,12 +783,29 @@ SQL;
         if ($searchText)$waybills->where(function ($query)use($searchText){
             $query->where("waybill_number",'like','%'.$searchText.'%')->orWhere("carrier_bill",'like','%'.$searchText.'%');
         });
-        $waybills = $waybills->get();
+        $lastId = $request->get("lastId","");
+        if ($lastId)$waybills->where("id","<",$lastId);
+        return $waybills;
+    }
+    //发运
+    public function delivering(Request $request){
+        if (!Auth::user())return view('exception.login');
+        $waybills = $this->deliveringQuery($request)->get();
+        $searchText = $request->get("searchText","");
         return view('transport.waybill.delivering',compact('waybills',"searchText"));
     }
+
+    /**
+     * 懒加载发运数据
+     */
+    public function loadData(Request $request)
+    {
+        if (!Auth::user())$this->error("登录信息失效");
+        $this->success($this->deliveringQuery($request)->get());
+    }
     //承运商提交
     public function storeCarrierBill(Request $request){
-        //if(!Gate::allows("运输管理-承运商调度"))return ["error"=>"无权操作!"];
+        if(!Gate::allows("运输管理-承运商调度"))return ["error"=>"无权操作!"];
         $errors=Validator::make($request->input(),[
             'id'=>'required|integer',
             'carrier_bill'=>'required',

+ 57 - 125
resources/views/transport/waybill/delivering.blade.php

@@ -4,69 +4,17 @@
 @section('content')
     <div id="list" class="d-none container-fluid">
         <div class="card">
-            <table class="card-body table table-sm table-hover table-striped table-bordered d-none d-sm-block p-0 text-nowrap td-min-width-80" style="width: 100%" id="table">
-                <tr v-for="(waybill,i) in waybills">
-                    <td>
-                        <input class="checkItem" type="checkbox" :value="waybill.id">
-                    </td>
-                    <td><span>@{{ i+1 }}</span></td>
-                    <td><span>@{{ waybill.deliver_at }}</span></td>
-                    <td><span>@{{ waybill.carrier_name }}</span></td>
-                    <td><span>@{{ waybill.waybill_number }}</span></td>
-                    <td><span>@{{ waybill.origination }}</span></td>
-                    <td><span>@{{ waybill.owner_name }}</span></td>
-                    <td><span>@{{ waybill.warehouse_weight_other }}</span></td>
-                    <td><span>@{{ waybill.warehouse_weight }}</span></td>
-                    <td><span v-if="waybill.status=='已完结'">已完成</span><span v-else><span v-if="waybill.carrier_bill">已提交</span><span v-if="!waybill.carrier_bill">待提交</span></span></td>
-                    <td>
-                        <span v-if="waybill.isBtn || !waybill.carrier_bill">
-                            <input :id="'carrier_bill'+waybill.id+'PC'" :class="errors['_'+waybill.id]&&errors['_'+waybill.id].carrier_bill?'is-invalid tooltipTargetError':''"
-                                   :title="errors['_'+waybill.id]&&errors['_'+waybill.id].carrier_bill?errors['_'+waybill.id].carrier_bill[0]:''" type="text" class="form-control form-control-sm w-100" :value="waybill.carrier_bill">
-                        </span><span v-else>@{{ waybill.carrier_bill }}</span>
-                    </td>
-                    <td>
-                        <span v-if="waybill.isBtn || !waybill.carrier_bill">
-                            <input :id="'inquire_tel'+waybill.id+'PC'" :class="errors['_'+waybill.id]&&errors['_'+waybill.id].inquire_tel?'is-invalid tooltipTargetError':''"
-                                   :title="errors['_'+waybill.id]&&errors['_'+waybill.id].inquire_tel?errors['_'+waybill.id].inquire_tel[0]:''" type="text" class="form-control form-control-sm w-100" :value="waybill.inquire_tel">
-                        </span><span v-else>@{{ waybill.inquire_tel }} </span>
-                    </td>
-                    <td>
-                        <span v-if="waybill.isBtn || !waybill.carrier_bill">
-                            <input :id="'amount'+waybill.id+'PC'" :class="errors['_'+waybill.id]&&errors['_'+waybill.id].amount?'is-invalid tooltipTargetError':''"
-                                   :title="errors['_'+waybill.id]&&errors['_'+waybill.id].amount?errors['_'+waybill.id].amount[0]:''" type="text" class="form-control form-control-sm w-100" :value="waybill.amount">
-                        </span><span v-else><span v-if="waybill.amount">@{{ waybill.amount }} @{{ waybill.amount_unit_name }}</span></span>
-                    </td>
-                    <td>
-                        <span v-if="waybill.isBtn || !waybill.carrier_bill">
-                            <input :id="'carrier_weight_other'+waybill.id+'PC'" :class="errors['_'+waybill.id]&&errors['_'+waybill.id].carrier_weight_other?'is-invalid tooltipTargetError':''"
-                                   :title="errors['_'+waybill.id]&&errors['_'+waybill.id].carrier_weight_other?errors['_'+waybill.id].carrier_weight_other[0]:''" type="text" class="form-control form-control-sm w-100" :value="waybill.carrier_weight_other">
-                        </span><span v-else>@{{ waybill.carrier_weight_other }}</span>
-                    </td>
-                    <td>
-                        <span v-if="waybill.isBtn || !waybill.carrier_bill">
-                            <input :id="'carrier_weight'+waybill.id+'PC'" :class="errors['_'+waybill.id]&&errors['_'+waybill.id].carrier_weight?'is-invalid tooltipTargetError':''"
-                                   :title="errors['_'+waybill.id]&&errors['_'+waybill.id].carrier_weight?errors['_'+waybill.id].carrier_weight[0]:''" type="text" class="form-control form-control-sm w-100" :value="waybill.carrier_weight">
-                        </span><span v-else>@{{ waybill.carrier_weight }}</span>
-                    </td>
-                    <td>
-                        <span v-if="waybill.status!='已完结'">
-                            <button v-if="!waybill.isBtn&&waybill.carrier_bill" @click="waybill.isBtn=true" class="btn btn-sm btn-outline-dark" >修改</button>
-                            <button v-if="!waybill.isBtn&& !waybill.carrier_bill" @click="submit(waybill.isBtn,waybill.id+'PC',waybill.id);" class="btn btn-sm btn-outline-info" >录入</button>
-                            <button v-if="waybill.isBtn" @click="submit(waybill.isBtn,waybill.id+'PC',waybill.id);" class="btn btn-sm btn-outline-success">确定</button>
-                            <button @click="waybill.isBtn=false" v-if="waybill.isBtn" class="btn btn-sm btn-outline-danger">取消</button>
-                        </span>
-                    </td>
-                </tr>
-            </table>
             <table class="table table-striped table-sm table-bordered table-hover p-0 d-block d-sm-none" style="background: rgb(255, 255, 255);">
                 <tbody>
                 <tr v-for="waybill in waybills">
-                    <td style="filter:grayscale(30%); ">
+                    <td style="filter:grayscale(30%); " :id="'waybill-'+waybill.id">
                         <div :style="waybill.status!='已完结'?'background-color:#f6eee8':''" class="mt-3">
                             <div style="transform:scale(0.9)" class="pl-0">
                                 <span class="mr-3 text-nowrap"><span style="color:#783000">日期:</span><span style="color:#af7651">@{{ waybill.deliver_at }}</span></span>
                                 <span class="mr-3 text-nowrap"><span style="color:#783000">承运商:</span><span style="color:#af7651">@{{ waybill.carrier_name }}</span></span>
-                                <span class="mr-3 text-nowrap"><span style="color:#783000">宝时运单号:</span><span style="color:#af7651">@{{ waybill.waybill_number }}</span></span>
+                                <span class="mr-3 text-nowrap"><span style="color:#783000">宝时运单号:</span><span style="color:#af7651">@{{ waybill.waybill_number }}</span><br></span>
+                                <span class="mr-3 text-nowrap"><span style="color:#783000">目的地:</span><span style="color:#af7651">@{{ waybill.address }}</span><br></span>
+                                <span class="mr-3 text-nowrap"><span style="color:#783000">收货人:</span><span style="color:#af7651">@{{ waybill.recipient }}</span></span>
                                 <span class="mr-3 text-nowrap"><span style="color:#783000">提货仓:</span><span style="color:#af7651">@{{ waybill.origination }}</span></span>
                                 <span class="mr-3 text-nowrap"><span style="color:#783000">预估重量:</span><span style="color:#af7651" v-if="waybill.warehouse_weight_other">@{{ waybill.warehouse_weight_other }} @{{ waybill.warehouse_weight_unit_other_name }}</span></span>
                                 <span class="mr-3 text-nowrap"><span style="color:#783000">预估体积:</span><span style="color:#af7651" v-if="waybill.warehouse_weight">@{{ waybill.warehouse_weight }} @{{ waybill.warehouse_weight_unit_name }}</span></span>
@@ -173,74 +121,77 @@
                     carrier_weight_other:'{{$waybill->carrier_weight_other}}',
                     status:'{{$waybill->status}}',
                     amount:'{{$waybill->amount}}',
-                    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->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 : ''}}',
-                    carrier_weight_unit_other_name:'{{$waybill->carrier_weight_unit_other ? $waybill->carrier_weight_unit_other->name : ''}}',
                     isBtn:!!!'{{$waybill->carrier_bill}}',
                     subjoin_fee:'{{$waybill->subjoin_fee}}',
+                    recipient:'{{$waybill->order->consignee_name ?? $waybill->recipient}}',
+                    address:'{{$waybill->order ? $waybill->order->province.$waybill->order->city.$waybill->order->district : $waybill->destination}}',
                 },
                 @endforeach
             ],
-            filterData:{
-                created_at_start:'',created_at_end:'',waybill_number:'',carrier_bill:''
-            },
             errors:{},
-            sum:{!! $waybills->count() !!},
             searchText:"{{$searchText}}",
+            lastId:"",
+            lastHeight:"",
         },
         mounted:function(){
-            let _this=this;
             $(".tooltipTarget").tooltip({'trigger':'hover'});
-            _this.initInputs();
+            if (this.waybills.length>0)this.lastId = this.waybills[this.waybills.length-1].id;
+            this.listener();
             if (navigator.userAgent.indexOf("Android")!==-1)this.isAndroid = true;
             this.pageInit();
             $("#list").removeClass('d-none');
-            if (this.isAndroid)return;
-            let column = [
-                {name:'index',value: '序号', neglect: true},
-                {name:'created_at',value: '日期', class:"color1"},
-                {name:'carrier_name',value: '承运商', class:"color1"},
-                {name:'waybill_number',value: '宝时运单号', class:"color1"},
-                {name:'origination',value: '提货仓', class:"color1"},
-                {name:'owner_name',value: '货主', class:"color1"},
-                {name:'warehouse_weight_other',value: '预估重量', neglect: true, class:"color1"},
-                {name:'warehouse_weight',value: '预估体积', neglect: true, class:"color1"},
-                {name:'status',value: '状态', class:"color2"},
-                {name:'carrier_bill',value: '专线运单号', class:"color2"},
-                {name:'inquire_tel',value: '查件电话', class:"color2"},
-                {name:'amount',value: '件数', neglect: true, class:"color2"},
-                {name:'carrier_weight_other',value: '重量', neglect: true, class:"color2"},
-                {name:'carrier_weight',value: '体积', neglect: true, class:"color2"},
-                {name:'operation',value: '操作', neglect: true},
-            ];
-            new Header({
-                el: "table",
-                name: "waybillDelivering",
-                column: column,
-                data: this.waybills,
-                restorationColumn: 'id',
-                fixedTop:($('#form_div').height())+2,
-            }).init();
         },
-        computed:{
-            isBeingFilterConditions:function(){
-
-                for(let key in this.filterData){
-                    if(this.filterData[key]){
-                        return true
+        methods:{
+            listener(){
+                window.addEventListener('scroll',  ()=>{
+                    let clientHeight = document.documentElement.clientHeight;
+                    let scrollTop = document.documentElement.scrollTop;
+                    let scrollHeight = document.documentElement.scrollHeight;
+                    if (clientHeight + scrollTop >= scrollHeight-40) {
+                        setTimeout(()=>{
+                            if (this.lastHeight===scrollHeight)return;
+                            this.loadData();
+                            this.lastHeight=scrollHeight;
+                        });
                     }
-                }
-                return false;
+                }, false);
+            },
+            loadData(){
+                window.tempTip.postBasicRequest("{{url('transport/waybill/loadData')}}",{searchText:this.searchText,lastId:this.lastId},res=>{
+                    if(!res || res.length<1){
+                        window.removeEventListener("scroll",function (){},false);
+                        return;
+                    }
+                    let waybills = [];
+                    let lastId = "";
+                    res.forEach(waybill=>{
+                        waybills.push({
+                            id:waybill.id,
+                            deliver_at:waybill.deliver_at,
+                            waybill_number:waybill.waybill_number,
+                            origination:waybill.origination,
+                            carrier_bill:waybill.carrier_bill,
+                            warehouse_weight:waybill.warehouse_weight,
+                            carrier_weight:waybill.carrier_weight,
+                            warehouse_weight_other:waybill.warehouse_weight_other,
+                            carrier_weight_other:waybill.carrier_weight_other,
+                            status:waybill.status,
+                            amount:waybill.amount,
+                            inquire_tel:waybill.inquire_tel,
+                            carrier_name:waybill.logistic ? waybill.logistic.name : '',
+                            isBtn:!!!waybill.carrier_bill,
+                            subjoin_fee:waybill.subjoin_fee,
+                            recipient:waybill.order ? waybill.order.consignee_name : waybill.recipient,
+                            address:waybill.order ? waybill.order.province+waybill.order.city+waybill.order.district : waybill.destination,
+                        });
+                        lastId = waybill.id;
+                    });
+                    this.waybills.push.apply(this.waybills, waybills);
+                    this.lastId = lastId;
+                });
             },
-
-        },
-        methods:{
             searchSubmit(){
                 document.getElementById("search").click();
             },
@@ -261,25 +212,6 @@
                 element = document.getElementById("container");
                 if (element)element.style.height = (window.innerHeight-100)+"px";
             },
-            initInputs:function(){
-                let data=this;
-                let uriParts =decodeURI(location.href).split("?");
-                if(uriParts.length>1){
-                    let params = uriParts[1].split('&');
-                    params.forEach(function(paramPair){
-                        let pair=paramPair.split('=');
-                        let key = pair[0], val = pair[1];
-                        $('input[name="'+key+'"]').val(val);
-                        $('select[name="'+key+'"]').val(val);
-                        decodeURI(data.filterData[key]=val);
-                    });
-                }
-            },
-            waybillExport(checkAllSign){
-                let url = '{{url('transport/waybill/deliveringExport')}}';
-                let token='{{ csrf_token() }}';
-                excelExport(checkAllSign,checkData,url,this.sum,token);
-            },
             enlarge(e){
                 e.target.style.width="150px";
             },

+ 1 - 0
routes/web.php

@@ -392,6 +392,7 @@ Route::group(['middleware'=>'auth'],function ($route){
             Route::post('expressFaceList','WaybillController@expressFaceList');
             Route::post('changeExpressTag','WaybillController@changeExpressTag');
             Route::post('appendSubjoinFee','WaybillController@appendSubjoinFee');
+            Route::post('loadData','WaybillController@loadData');
         });
         Route::resource('waybill','WaybillController');
     });