
@extends('layouts.app')
@section('title')统计-二次加工单@endsection

@section('content')
    <span id="nav2">
        @component('process.menu')@endcomponent
    </span>
    <div class="d-none container-fluid" id="statistics" style="width: 2070px">
        <div id="form_div"></div>
        <span class="dropdown">
            <button class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget"
                    data-toggle="dropdown" title="导出所有页将会以搜索条件得到的筛选结果，将其全部记录（每一页）导出">
                导出Excel
            </button>
            <div class="dropdown-menu">
                <a class="dropdown-item" @click="processStatisticExport(false)"  href="javascript:">导出勾选内容</a>
                <a class="dropdown-item" @click="processStatisticExport(true)"  href="javascript:">导出所有页</a>
            </div>
        </span>
        <table class="table table-striped text-nowrap table-hover td-min-width-80" style="background: #fff;" id="table">
            <tr v-for="(processStatistic,i) in processStatistics" :class="processStatistic.gross_profit_rate?'text-success':''">
                <td><label><input class="checkItem" type="checkbox" :value="processStatistic.process_id"></label></td>
                <td><span>@{{ i+1 }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.code }}</span></td>
                <td><span v-if="processStatistic.operatorLog && processStatistic.operatorLog.user">@{{ processStatistic.operatorLog.user.name }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.owner_name }}</span></td>
                <td><span>@{{ processStatistic.started_at }}</span></td>
                <td><span>@{{ processStatistic.ended_at }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.created_at }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.unit_price }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.amount }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.completed_amount }}</span></td>
                <td><span>@{{ processStatistic.revenue }}</span></td>
                <td><span>@{{ processStatistic.duration_days }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.duration_man_hours }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.process_method_name }}</span></td>
                <td><span>@{{ processStatistic.top_capacity }}</span></td>
                <td><span>@{{ processStatistic.bottom_capacity }}</span></td>
                <td><span>@{{ processStatistic.average_capacity }}</span></td>
                <td><span>@{{ processStatistic.total_cost }}</span></td>
                <td><span>@{{ processStatistic.gross_profit }}</span></td>
                <td><b v-if="processStatistic.gross_profit_rate">@{{ (processStatistic.gross_profit_rate)*100 | money}}%</b></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.status }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.remark }}</span></td>
                <td><span v-if="processStatistic.process">@{{ processStatistic.process.balance_remark }}</span></td>
            </tr>
        </table>
        {{$processStatistics->appends($params)->links()}}
    </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>
        new Vue({
            el:"#statistics",
            data:{
                processStatistics:[
                    @foreach($processStatistics as $processStatistic)
                    {!! $processStatistic !!},
                    @endforeach
                ],
                owners:[
                    @foreach($owners as $owner)
                    {name:'{{ $owner->id }}',value:'{{ $owner->name }}'},
                    @endforeach
                ],
                processMethods:[
                    @foreach($processMethods as $processMethod)
                    {name:'{{ $processMethod->id }}',value:'{{ $processMethod->name }}'},
                    @endforeach
                ],
                sum:{!! $processStatistics->total() !!},
                filterData:{paginate:'50',started_at:'',ended_at:'',owner_id:'',code:'',status:''},
                status:[
                    {name:'待审核',value:'待审核'},{name:'待接单',value:'待接单'},{name:'待加工',value:'待加工'},
                    {name:'已驳回',value:'已驳回'},{name:'加工中',value:'加工中'},{name:'待验收',value:'待验收'},
                    {name:'交接完成',value:'交接完成'},
                ],
            },
            mounted:function(){
                $(".tooltipTarget").tooltip({'trigger':'hover'});
                $('#statistics').removeClass('d-none');
                let data=[
                    [
                        {name: 'started_at_start', type: 'dateTime', tip: '选择显示指定日期的起始时间'},
                        {
                            name: 'owner_id', type: 'select_multiple_select', tip: ['输入关键词快速定位下拉列表，回车确定', '选择要显示的客户'],
                            placeholder: ['货主', '定位或多选货主'], data: this.owners
                        },
                        {name: 'process_method_id', type: 'select', placeholder: '加工类型', data: this.processMethods},
                    ],
                    [
                        {name: 'started_at_end', type: 'dateTime', tip: '选择显示指定日期的结束时间'},
                        {name: 'code', type: 'input', tip: '可支持多任务号,模糊搜索可在两侧增加百分号(%)进行', placeholder: '任务号'},
                        {name: 'status', type: 'select', placeholder: '状态', data: this.status},
                    ],
                ];
                this.form = new query({
                    el: "#form_div",
                    condition: data,
                });
                this.form.init();
                let column = [
                    {name:'index',value: '序号', neglect: true},
                    {name:'code',value: '任务号', neglect: true},
                    {name:'user',value: '接单人', neglect: true},
                    {name:'owner_name',value: '货主', neglect: true},
                    {name:'started_at',value: '开始日期', neglect: true},
                    {name:'ended_at',value: '完成日期', neglect: true},
                    {name:'created_at',value: '创建日期', neglect: true},
                    {name:'unit_price',value: '单价', neglect: true},
                    {name:'amount',value: '预期数量', neglect: true},
                    {name:'completed_amount',value: '完成数量', neglect: true},
                    {name:'revenue',value: '收入合计', neglect: true},
                    {name:'duration_days',value: '完成时间(天)', neglect: true},
                    {name:'duration_man_hours',value: '总工时', neglect: true},
                    {name:'process_method_name',value: '加工类型', neglect: true},
                    {name:'top_capacity',value: '最高日产能', neglect: true},
                    {name:'bottom_capacity',value: '最低日产能', neglect: true},
                    {name:'average_capacity',value: '日均产能', neglect: true},
                    {name:'total_cost',value: '合计成本', neglect: true},
                    {name:'gross_profit',value: '毛利润', neglect: true},
                    {name:'gross_profit_rate',value: '毛利率', neglect: true},
                    {name:'status',value: '状态', neglect: true},
                    {name:'remark',value: '加工备注', neglect: true},
                    {name:'balance_remark',value: '结算备注', neglect: true},
                ];
                new Header({
                    el: "table",
                    name: "processStatistic",
                    column: column,
                    data: this.processStatistics,
                    restorationColumn: 'id',
                    fixedTop:($('#form_div').height())+2,
                }).init();
            },
            methods: {
                //导出excel
                processStatisticExport(checkAllSign){
                    let url = '{{url('process/statistic/export')}}';
                    let token='{{ csrf_token() }}';
                    excelExport(checkAllSign,checkData,url,this.sum,token);
                },
            },
            filters:{
                money:function(value){
                    return _.round(value,2);
                }
            }
        });
    </script>
@endsection
