@extends('layouts.app')
@section('title')财务报表-运输管理@endsection

@section('content')
<div class="d-none" id="editingPanel">
    <div  class="card" id="nav2">
        @component('transport.menu')@endcomponent
        @component('transport.waybill.menu')@endcomponent

            <div class="container-fluid nav3">
                <div class="card menu-third" >
                    <ul class="nav nav-pills">
                        @can('财务报表-查询')
                            <li class="nav-item">
                                <a class="nav-link @if($type=='') active @endif" href="@if(!isset($excepted)) {{url('transport/waybill/waybillFinancialSnapshot')}} @else {{url('transport/waybill/waybillFinancialExcepted')}} @endif">全部</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link @if($type=='ZX') active @endif" href="@if(!isset($excepted)) {{url('transport/waybill/waybillFinancialSnapshot?type=ZX')}} @else {{url('transport/waybill/waybillFinancialExcepted?type=ZX')}} @endif">专线</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link @if($type=='ZF') active @endif" href="@if(!isset($excepted)) {{url('transport/waybill/waybillFinancialSnapshot?type=ZF')}} @else {{url('transport/waybill/waybillFinancialExcepted?type=ZF')}} @endif">直发车</a>
                            </li> @endcan

                    </ul>
                </div>
            </div>
    </div>
    <div class="card " style="width: 3500px">
    <form  method="get" action="@if(!isset($excepted))
    @if($type=='ZF'){{url('transport/waybill/waybillFinancialSnapshot?type=ZF')}}@elseif($type=='ZX'){{url('transport/waybill/waybillFinancialSnapshot?type=ZX')}}@else{{url('transport/waybill/waybillFinancialSnapshot')}}@endif
    @else
    @if($type=='ZF'){{url('transport/waybill/waybillFinancialExcepted?type=ZF')}}@elseif($type=='ZX'){{url('transport/waybill/waybillFinancialExcepted?type=ZX')}}@else{{url('transport/waybill/waybillFinancialExcepted')}}@endif
    @endif ">
    <div class="card-header form-inline">
        <label style="margin-left: 1%"> 开始日期：</label><input style="max-width: 200px" type="date" name="created_at_start" class="form-control form-control-sm"  v-model="filterData.created_at_start">
        <label style="margin-left: 1%"> 截至日期：</label><input style="max-width: 200px" type="date" class="form-control form-control-sm" name="created_at_end" v-model="filterData.created_at_end">
        <input type="text" hidden name="type" v-model="filterData.type" >
        <input type="submit" class="btn btn-sm btn-outline-dark ml-3" value="按条件搜索" >
    </div>
    </form>
<!-- 自定义内容区域 -->
<div>
    @if(!isset($excepted))
    <div class="card-header">
    <label>操作选定记录：</label>
        <span class="dropdown">
            <button class="btn btn-sm form-control-sm dropdown-toggle tooltipTarget"
                    data-toggle="dropdown" title="导出所有页将会以搜索条件得到的筛选结果，将其全部记录（每一页）导出">
                导出Excel
            </button>
            <div class="dropdown-menu">
                <a class="dropdown-item" @click="waybillExport(false)" href="javascript:">导出勾选内容</a>
                <a class="dropdown-item" @click="waybillExport(true)" href="javascript:">导出所有页</a>
            </div>
        </span>
    </div>
    @endif
    <table class="table  table-hover table-bordered text-nowrap td-min-width-80" style="width: 1500px;height: auto" id="table">
        <tbody>
        <tr v-for="(json_content,i) in json_contents" :style="{background:json_content.type=='直发车'?'#F8F8F8':''}" @click="selectedColor(i,$event)">
            @if(!isset($excepted))
            <td>
                <input class="checkItem" type="checkbox" :value="json_content.waybill_id">
            </td>
            @endif
            <td><span>@{{ i+1 }}</span></td>
            <td><span>@{{json_content.type}}</span></td>
            <td><span>@{{json_content.waybill_number}}</span></td>
            <td><span>@{{json_content.owner_name}}</span></td>
            <td><span>@{{json_content.wms_bill_number}}</span></td>
            <td><span>@{{json_content.origination}}</span></td>
            <td><span>@{{json_content.destination}}</span></td>
            <td><span>@{{json_content.recipient}}</span></td>
            <td><span>@{{json_content.recipient_mobile}}</span></td>
            <td><span>@{{json_content.charge}}</span></td>
            <td><span>@{{json_content.ordering_remark}}</span></td>
            <td><span>@{{json_content.carrier_name}}</span></td>
            <td><span>@{{json_content.carrier_bill}}</span></td>
            <td><span>@{{json_content.origination_city_name}}</span></td>
            <td><span>@{{json_content.destination_city_name}}</span></td>
            <td><span>@{{json_content.warehouse_weight}}</span></td>
            <td><span>@{{json_content.warehouse_weight_other}}</span></td>
            <td><span>@{{json_content.carrier_weight_other}}</span></td>
            <td><span>@{{json_content.carrier_weight_other}}</span></td>
            <td><span>@{{json_content.car_type_name}}</span></td>
            <td><span>@{{json_content.car_owner_info}}</span></td>
            <td><span>@{{json_content.fee}}</span></td>
            <td><span>@{{json_content.pick_up_fee}}</span></td>
            <td><span>@{{json_content.other_fee}}</span></td>
            <td><span>@{{json_content.collect_fee}}</span></td>
            <td><span>@{{json_content.dispatch_remark}}</span></td>
            <td><span>@{{json_content.created_at}}</span></td>
            <td><span>@{{json_content.auditLog_user_name }}</span></td>
            <td><span>@{{json_content.total_receivable}}</span></td>
            <td><span>@{{json_content.total_expense}}</span></td>
            <td><span>@{{json_content.gross_margin}}</span></td>
            <td><span>@{{Math.round(json_content.gross_profit_rate*100)}}%</span></td>
        </tr>
        </tbody>
    </table>
        <div class="text-info h5 btn btn">{{$waybillFinancialSnapshots->count()}}/{{$waybillFinancialSnapshots->total()}}</div>
    </div>
</div>

<!-- 分页  -->
<div>
    <div class="pull-right">
        {{$waybillFinancialSnapshots->render()}}
    </div>
</div>
</div>
@stop

@section('lastScript')
<script type="text/javascript" src="{{mix('js/queryForm/header.js')}}"></script>{{--新版2--}}
<script type="text/javascript" src="{{mix('js/queryForm/export.js')}}"></script>
<script>
    let vue = new Vue({
        el:'#editingPanel',
        data:{
            json_contents:[
                @if(isset($waybillFinancialSnapshots))
                @foreach($waybillFinancialSnapshots as $waybillFinancialSnapshot)
                    {!!$waybillFinancialSnapshot->json_content!!},
                @endforeach
                @endif
            ],
            filterData:{
                created_at_start:'',created_at_end:'',type:'{{$type}}',
            },
            sum:{!! $waybillFinancialSnapshots->total() !!},
            selectTr:''
        },
        mounted:function(){
            this.initInputs();
            $(".tooltipTarget").tooltip({'trigger':'hover'});
            $('#editingPanel').removeClass('d-none');
            let column = [
                {name:'index',value: '序号', neglect: true},
                {name:'type',value: '运单类型', neglect: true},
                {name:'waybill_number',value: '运单号', neglect: true},
                {name:'owner',value: '货主', neglect: true},
                {name:'wms_bill_number',value: 'WMS单号', neglect: true},
                {name:'origination',value: '始发地', neglect: true},
                {name:'destination',value: '目的地', neglect: true},
                {name:'recipient',value: '收件人', neglect: true},
                {name:'recipient_mobile',value: '收件人电话', neglect: true},
                {name:'charge',value: '收费(元)', neglect: true},
                {name:'ordering_remark',value: '下单备注', neglect: true},
                {name:'logistic',value: '承运商', neglect: true},
                {name:'carrier_bill',value: '承运商单号', neglect: true},
                {name:'origination_city',value: '始发市', neglect: true},
                {name:'destination_city',value: '目的市', neglect: true},
                {name:'warehouse_weight',value: '仓库计数(抛)', neglect: true},
                {name:'warehouse_weight_other',value: '仓库计数二', neglect: true},
                {name:'carrier_weight',value: '承运商计数(抛)', neglect: true},
                {name:'carrier_weight_other',value: '承运商计数二', neglect: true},
                {name:'car_type',value: '车型', neglect: true},
                {name:'car_owner_info',value: '车辆信息', neglect: true},
                {name:'fee',value: '运费(元)', neglect: true},
                {name:'pick_up_fee',value: '提货费(元)', neglect: true},
                {name:'other_fee',value: '其他费用(元)', neglect: true},
                {name:'collect_fee',value: '到付金额(元)', neglect: true},
                {name:'dispatch_remark',value: '调度备注', neglect: true},
                {name:'created_at',value: '创建时间', neglect: true},
                {name:'user_name',value: '终审人员', neglect: true},
                {name:'total_receivable',value: '应收款', neglect: true},
                {name:'total_expense',value: '应付款', neglect: true},
                {name:'gross_margin',value: '毛利', neglect: true},
                {name:'gross_profit_rate',value: '毛利率', neglect: true},
            ];
            new Header({
                el: "table",
                name: "waybillBill",
                column: column,
                data: this.json_contents,
                @if(isset($excepted))isCheckAllBox:false,@endif
            }).init();
        },
        methods:{
            selectedColor(id,e){
                $('#headerParent tr[class=focusing]').removeClass('focusing')
                if (id==this.selectedStyle){
                    this.selectedStyle='';
                    return;
                }
                this.selectedStyle=id;
                $(e.target).parent('tr').addClass('focusing')
            },
            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);
                        decodeURI(data.filterData[key]=val);
                    });
                }
            },
            waybillExport(checkAllSign){
                let url='{{url('waybillFinancialSnapshot/export')}}';
                let token='{{ csrf_token() }}';
                excelExport(checkAllSign,checkData,url,this.sum,token);
            },
        }
    })

</script>
@stop
