@extends('layouts.app')
@section('title')动库报表-库存管理@endsection
@section('content')
    @component('inventory.statement.menu')@endcomponent
<div id="list" class="d-none card container-fluid" style="min-width: 1500px">
    <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="processExport(false)" href="javascript:">导出勾选内容</a>
            <a class="dropdown-item" @click="processExport(true)" href="javascript:">导出所有页</a>
        </div>
    </span>
    <table class="table table-sm table-striped table-bordered table-hover text-nowrap card-body mt-2 td-min-width-80" id="table">
        <tr v-for="(oracleActTransactingLog,i) in oracleActTransactingLogs" @click="selectedColor(oracleActTransactingLog.id,$event)">
            <td>
                <input class="checkItem" type="checkbox" :value="oracleActTransactingLog">
            </td>
            <td><span>@{{ i+1 }}</span></td>
            <td class="text-primary"><span>@{{ oracleActTransactingLog.货主 }}</span></td>
            <td class="text-muted"><span>@{{ oracleActTransactingLog.库位 }}</span></td>
            <td class="text-muted"><span>@{{ oracleActTransactingLog.产品编码 }}</span></td>
            <td class="text-muted"><span>@{{ oracleActTransactingLog.产品条码 }}</span></td>
            <td :title="oracleActTransactingLog.商品名称" class="tooltipTarget" style="max-width: 200px;overflow:hidden"><span>@{{ oracleActTransactingLog.商品名称 }}</span></td>
            <td class="text-muted"><span>@{{ oracleActTransactingLog.属性仓 }}</span></td>
            <td class="text-muted"><span>@{{ oracleActTransactingLog.质量状态 }}</span></td>
            <td class="text-muted"><span>@{{ oracleActTransactingLog.失效日期 }}</span></td>
            <td class="text-muted"><span>@{{ oracleActTransactingLog.批号 }}</span></td>
            <td v-if="!isTotalStock"><span>@{{ oracleActTransactingLog.移出数量 }}</span></td>
            <td v-if="!isTotalStock"><span>@{{ oracleActTransactingLog.移入数量 }}</span></td>
            <td><span v-if="oracleActTransactingLog.在库数量">@{{ oracleActTransactingLog.在库数量 }}</span><span v-else>0</span></td>
            <td><span v-if="oracleActTransactingLog.占用数量">@{{ oracleActTransactingLog.占用数量 }}</span><span v-else>0</span></td>
        </tr>
    </table>
    <div>
        <button type="button" @click="pageUp()" :readonly="page>1?false:true" class="btn btn-sm " :class="page>1?'btn-outline-info':''">上一页</button>
        <button type="button" @click="pageDown()" :readonly="page<maxPage?false:true" class="btn btn-sm m-3" :class="page<maxPage?'btn-outline-info':''">下一页</button>
        <div v-if="isPage">
            <input  @keyup.enter="pageSkip($event)" class="form-control-sm ml-3 tooltipTarget" :placeholder="'当前页数：'+page+'/'+maxPage" title="去往指定页">
            <span class="text-muted m-1">共 @{{ sum }} 条</span>
        </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>
        let vue=new Vue({
            el:"#list",
            data:{
                oracleActTransactingLogs:{!! $oracleActTransactingLogs !!},
                page:Number('{{$page}}'),
                owners:[
                    @foreach($owners as $owner)
                    {name:'{{$owner->code}}',value:'{{$owner->name}}'},
                    @endforeach
                ],
                maxPage:1,
                sum:0,
                isPage:true,
                date:[{name:'1',value:'近一天'},{name:'3',value:'近三天'},{name:'7',value:'近一周'},{name:'30',value:'近一月'},],
                isTotalStock : "{{ $isTotalStock }}",
                selectTr:''
            },
            mounted:function () {
                $(".tooltipTarget").tooltip({'trigger':'hover'});
                $("#list").removeClass('d-none');
                if (this.oracleActTransactingLogs.length>0){
                    this.maxPage=Math.ceil(this.oracleActTransactingLogs[0].sum/50);
                    this.sum=this.oracleActTransactingLogs[0].sum;
                }
                let data=[
                    [
                        {name:['date_start','range'],type:'dateTime_select',tip:['选择创建日期的起始时间','查询内容的日期范围'],placeholder:['','查询内容的日期范围'],data: this.date
                            ,killings:[['range'],['date_start']]},
                        {name:'TOLocation',type:'input',tip:'可支持多库位,糊模查找需要在左边打上%符号',placeholder: '库位'},
                        {name:'LotAtt05',type:'input',tip:'可支持多属性仓,糊模查找需要在左边打上%符号',placeholder: '属性仓'},
                        {name:'LotAtt02_start',type:'dateTime',tip:'选择显示失效日期的起始时间'},
                        {name:'customerid',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表，回车确定','选择要显示的客户'],
                            placeholder:['货主','定位或多选货主'],data:this.owners},
                    ],
                    [
                        {name:'date_end',type:'dateTime',tip:'选择创建日期的结束时间',killings:['range']},
                        {name:'SKU',type:'input',tip:'可支持多产品编码,糊模查找需要在左边打上%符号',placeholder: '产品编码'},
                        {name:'ALTERNATE_SKU1',type:'input',tip:'可支持多产品条码,糊模查找需要在左边打上%符号',placeholder: '产品条码'},
                        {name:'LotAtt02_end',type:'dateTime',tip:'选择显示失效日期的结束时间'},
                    ],
                ];
                this.form = new query({
                    el:'#form_div',
                    condition:data
                });
                this.form.init();
                let thisUrl=document.URL;
                let parameter=thisUrl.split('?',2);
                if (parameter.length > 1){
                    let _this=this;
                    let list=['ALTERNATE_SKU1','LotAtt05','LotAtt02_start','descr_c','LotAtt02_end'];
                    let param=parameter[1].split('&');
                    param.every(function (data) {
                        let arr=data.split('=');
                        if (arr.length > 1){
                            if (list.includes(arr[0]) && arr[1]){
                                _this.isPage = false;
                                return false;
                            }
                        }
                        return true;
                    });
                }
                let column = [
                    {name:'index',value: '序号', neglect: true},
                    {name:'货主',value: '货主', class:'text-primary'},
                    {name:'库位',value: '库位', class:'text-muted'},
                    {name:'产品编码',value: '产品编码', class:'text-muted'},
                    {name:'产品条码',value: '产品条码', class:'text-muted'},
                    {name:'商品名称',value: '商品名称'},
                    {name:'属性仓',value: '属性仓', class:'text-muted'},
                    {name:'质量状态',value: '质量状态', class:'text-muted'},
                    {name:'失效日期',value: '失效日期', class:'text-muted'},
                    {name:'批号',value: '批号', class:'text-muted'},
                    @if(!$isTotalStock)
                    {name:'移出数量',value: '移出数量', neglect: true},
                    {name:'移入数量',value: '移入数量', neglect: true},
                    @endif
                    {name:'在库数量',value: '在库数量', neglect: true},
                    {name:'占用数量',value: '占用数量', neglect: true},
                ];
                new Header({
                    el: "table",
                    name: "changeInventory",
                    column: column,
                    data: this.oracleActTransactingLogs,
                    restorationColumn: 'rn',
                    isRestorationColumnAsc:true,
                    fixedTop:($('#form_div').height())+2,
                }).init();

            },
            methods:{
                selectedColor(id,e){
                    $('#headerParent tr[class=focusing]').removeClass('focusing')
                    if (id==this.selectTr){
                        this.selectTr='';
                        return;
                    }
                    this.selectTr=id;
                    $(e.target).parent('tr').addClass('focusing')
                },
                pageUp(){
                    if (this.page<=1)return;
                    this.href(this.page-1);
                },
                pageDown(){
                    if (this.page>=this.maxPage)return;
                    this.href(this.page+1);
                },
                pageSkip(e){
                    if (Number(e.target.value)<=0 || Number(e.target.value)>this.maxPage){
                        tempTip.setDuration(2000);
                        tempTip.show('页数不存在！ ');
                        return
                    }
                    this.href(e.target.value);
                },
                href(page){
                    let url = document.URL;
                    if (url.indexOf('page='+this.page) != -1){
                        url = url.replace("page="+this.page,"page="+page);
                    }else{
                        if (url.indexOf('?') == -1) url += "?page="+page;
                        else url += "&page="+page;
                    }
                    window.location.href=url;
                },
                processExport(checkAllSign){
                    let url = '{{url('inventory/statement/allInventory/export')}}';
                    if (!this.isTotalStock)
                         url = '{{url('inventory/statement/changeInventory/export')}}';
                    let token='{{ csrf_token() }}';
                    let data= JSON.stringify( checkData );
                    excelExport(checkAllSign,data,url,this.sum,token);
                },
            },
            filters:{
                json(value) {
                    return JSON.stringify(value);
                }
            },
        });
    </script>
@endsection

