
@extends('layouts.app')
@section('title')称重查询-包裹管理@endsection

@section('content')
    <span id="nav2">
        @component('package.menu')@endcomponent
        @component('package.weigh.menu')@endcomponent
        @component('package.weigh.record.menu')@endcomponent
    </span>
    <div class="d-none" id="list">
        <div class="container-fluid">
            <div id="form_div"></div>
            <span class="dropdown">
                <button class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget mt-1 mb-1"
                        data-toggle="dropdown" title="导出所有页将会以搜索条件得到的筛选结果，将其全部记录（每一页）导出">
                    导出Excel
                </button>
                <div class="dropdown-menu">
                    <a class="dropdown-item" @click="packageExport(false)" href="javascript:">导出勾选内容</a>
                    <a class="dropdown-item" @click="packageExport(true)" href="javascript:">导出所有页</a>
                </div>
            </span>
            <div>
                <table class="table table-bordered table-striped table-sm text-nowrap table-hover td-min-width-80" id="table">
                    <tr v-for="(package,i) in packages" @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
                        <td>
                            <input class="checkItem" type="checkbox" :value="package.id">
                        </td>
                        <td><span>@{{ i+1  }}</span></td>
                        <td><span>@{{package.ownerName}}</span></td>
                        <td><span>@{{package.logisticNumber}}</span></td>
                        <td class="text-muted"><span>@{{package.batchNumber}}</span></td>
                        <td><span>@{{package.orderCode}}</span></td>
                        <td class="text-muted"><span>@{{package.logisticName}}</span></td>
                        <td class="text-muted"><span>@{{package.measuringMachineName}}</span></td>
                        <td><span>@{{package.weight}}</span></td>
                        <td><span>@{{package.length|upDigit}}</span><a v-if="package.length" class="text-primary">*</a>@{{package.width|upDigit}}<a class="text-primary" v-if="package.width">*</a>@{{package.height|upDigit}}</td>
                        <td><span>@{{package.bulk|upCubic}}</span></td>
                        <td><span>@{{package.paperBoxName}}</span></td>
                        <td :class="[package.uploaded_to_wms==='是'?'text-success':'']"><span>@{{package.status}}</span></td>
                        <td class="text-muted"><span>@{{package.batchRule}}</span></td>
                        <td class="text-muted"><span>@{{package.weighed_at}}</span></td>
                        <td class="text-muted"><span>@{{package.recipient}}</span></td>
                        <td class="text-muted"><span>@{{package.recipientMobile}}</span></td>
                    </tr>
                </table>
                <div class="text-info h5 btn btn">{{$packages->count()}}/{{$packages->total()}}</div>
                {{$packages->appends($paginateParams)->links()}}
            </div>
        </div>
    </div>
@endsection

@section('lastScript')
    <script type="text/javascript" src="{{mix('js/queryForm/export.js')}}"></script>
    <script type="text/javascript" src="{{mix('js/queryForm/queryForm.js')}}"></script>
    <script type="text/javascript" src="{{mix('js/queryForm/header.js')}}"></script>{{--新版2--}}
    <script>
            @if(isset($request))
        let request={!! json_encode($request) !!};
        @endif
        let vue = new Vue({
            el:"#list",
            data:{
                packages:[
                        @foreach($packages as $package)
                    {id:'{{$package->id}}',ownerName:'{{$package->order ? ($package->order->owner ? $package->order->owner->name : '') : ''}}',
                        orderCode:'{{$package->order ? $package->order->code : ''}}',
                        logisticName:'{{$package->order ? ($package->order->logistic ? $package->order->logistic->name : '') : ''}}',
                        batchNumber:'{{$package->order ? ($package->order->batch ? $package->order->batch->code : '') : ''}}',
                        batchRule:'{{$package->order ? ($package->order->batch ? $package->order->batch->wms_type : '') : ''}}',
                        recipient:'{{$package->order ? preg_replace('/[\s\n]/','',$package->order->consignee_name) : ''}}',
                        recipientMobile:'{{$package->order ? $package->order->consignee_phone : ''}}',
                        logisticNumber:'{{$package->logistic_number}}',
                        measuringMachineName:'{{$package->measuringMachine ? $package->measuringMachine->name : ''}}',
                        weight:'{{$package->weight}}', length:'{{$package->length}}',width:'{{$package->width}}',height:'{{$package->height}}',
                        bulk:'{{$package->bulk}}',paperBoxName:'{{$package->paperBox ? $package->paperBox->name : ''}}',
                        status:'{{$package->status}}',created_at:'{{$package->created_at}}',weighed_at:'{{$package->weighed_at}}',
                        paperBox : {!! $package->paperBox??'""' !!} },
                    @endforeach
                ],
                i:0,
                owners:[
                    @foreach($owners as $owner)
                    {name:'{{$owner->id}}',value:'{{$owner->name}}'},
                    @endforeach
                ],
                form:'',
                sum:{!! $packages->total() !!},
                selectTr:0
            },
            mounted:function(){
                $(".tooltipTarget").tooltip({'trigger':'hover'});
                $('#list').removeClass('d-none');
                let _this = this;
                let data = [[
                    {name:'weighed_at_start',type:'time',tip:['选择显示称重日期的起始时间','选择显示称重日期的起始时间']},
                    {name:'owner_id',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表，回车确定','选择要显示的客户'],
                        placeholder:['货主','定位或多选货主'],data:_this.owners},
                    {name:'logistic_number',type:'input',tip:'可支持多快递单号，糊模查找需要在右边打上%符号',placeholder:'快递单号'},
                    {name:'is_weighed',type:'checkbox',tip:'是否已称重', data: [{name: 'true', value: '是否已称重'}]}
                ],[
                    {name:'weighed_at_end',type:'time',tip:['选择显示称重日期的结束时间','选择显示称重日期的结束时间']},
                    {name:'batch_number',type:'input',tip:'可支持多波次号，糊模查找需要在右边打上%符号',placeholder:'波次号'}
                ]];

                _this.form = new query({
                    el:'#form_div',
                    condition:data,
                });
                _this.form.init();
                let column = [
                    {name:'index',value: '序号', neglect: true},
                    {name:'ownerName',value: '货主'},
                    {name: 'logisticNumber', value: '快递单号'},
                    {name: 'batchNumber', value: '波次号'},
                    {name:'order_code',value: '订单号'},
                    {name: 'logisticName', value: '物流公司'},
                    {name: 'measuringMachineName', value: '设备'},
                    {name: 'weight', value: '重(KG)'},
                    {name:'length_width_height',value: '长*宽*高(cm)', neglect: true},
                    {name: 'bulk', value: '体积(cm³)'},
                    {name: 'paperBoxName', value: '纸箱'},
                    {name: 'status', value: '状态'},
                    {name:'batchRule',value: '波次规则'},
                    {name:'weighed_at',value: '称重时间'},
                    {name:'recipient',value: '收件人'},
                    {name:'recipientMobile',value: '收件人电话'},
                ];
                new Header({
                    el: "table",
                    name: "weight",
                    column: column,
                    data: this.packages,
                    fixedTop:($('#form_div').height())+2,
                }).init();
            },
            methods:{
                packageExport(checkAllSign){
                    let url = '{{url('package/export')}}';
                    let token='{{ csrf_token() }}';
                    excelExport(checkAllSign,checkData,url,this.sum,token);
                },
            },
            filters:{
                upDigit(val){
                    if(!val)return;
                    return Math.round(Number(val)*10)/100;
                },
                upCubic(val){
                    if(!val)return;
                    return Math.round(Number(val)/10)/100;
                }
            }
        });
    </script>
@endsection
