@extends('layouts.app')
@section('title')库存盘点-库存管理@endsection

@section('content')
    @component('inventory.stockInventory.menu')
        <li class="nav-item">
            <a  class="nav-link" href="{{URL::current()}}" :class="{active:isActive('enterStockInventory',3)}">盘点中({!! $inventoryAccount->id !!})</a>
        </li>
    @endcomponent
    <div class="text-center h5 mt-2" id="loadingPage">
        载入中……
    </div>
    <div id="list" class="d-none container-fluid" >
        <div class="mt-3">
            <span class="mt-3" >
                @can('库存管理-盘点-完结')
                    <span><button class="btn btn-sm btn-outline-info" v-if="inventory.status==='复盘中' &&!listMode" @click="完结盘点任务(inventory.id,inventory.owner.name,inventory.type)">完结</button></span>
                @endcan

                @can('库存管理-盘点-查看')
                    <button class="btn btn-sm" @click="listMode?listMode=false:listMode=true" :class="listMode?'btn-dark':'btn-outline-dark'" v-if="!listMode">切换为列表</button>
                @endcan
                @can('库存管理-盘点')
                    <button class="btn btn-sm" @click="listMode?listMode=false:listMode=true" :class="listMode?'btn-dark':'btn-outline-dark'" v-if="listMode&&inventory.status!=='已完成'&&inventory.status!=='已审核'">切换为盘点</button>
                @endcan
            </span>

            <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="inventoryAccountMissionExport(false)" href="javascript:">导出勾选内容</a>
                    <a class="dropdown-item" @click="inventoryAccountMissionExport(true)" href="javascript:">导出所有</a>
                </div>
            </span>
            <span>
            <button class="btn btn-sm" @click="盲收()" :class="listMode?'btn-dark':'btn-outline-dark'" v-if="!listMode&&!blindReceive">盲收</button>
                <button class="btn btn-sm" @click="正常盘点()" :class="blindReceive?'btn-dark':'btn-outline-dark'" v-if="blindReceive">正常盘点</button>
            </span>
            <span>
                <button class="btn btn-outline-dark btn-sm form-control-sm tooltipTarget"
                        @click="批量跳过或确认差异()"  title="勾选指定盘点记录行，进行批量跳过或批量确认差异">
                    批量跳过
                </button>
            </span>
            <span>
                <button class="btn btn-sm btn-info" @click="新增盘点记录()" :class="listMode?'btn-dark':'btn-outline-dark'" v-if="!listMode&&!addInventoryMission">新增盘点记录</button>
                 <button class="btn btn-sm" @click="收起新增()" :class="addInventoryMission?'btn-dark':'btn-outline-dark'" v-if="addInventoryMission">收起新增</button>
            </span>


            <span class="form-group  mb-5">
            <label class="text-muted">货主:</label><span class="font-weight-bold">@{{ inventory.owner.name }}</span>
        </span>
            <span class="form-group  p-2 mb-5">
            <label >盘点单号:</label><span>@{{ inventory.id }}</span>
        </span>
            <span class="form-group p-2 mb-5">
            <label class="text-muted">时间范围:</label><span>@{{ inventory.start_at }} 至 @{{ inventory.end_at }}</span>
        </span>
        </div>

        <div class="mt-3">
        <span class="h5">
            <span class="form-group mb-5" v-if="inventory.status==='盘点中' || inventory.status==='待盘点'">
                <label class=" font-weight-bold">已盘点:</label><span>@{{ inventory.processed }}/总数:@{{ inventory.total }}</span>
            </span>
            <span class="form-group mb-5" v-if="inventory.status==='盘点中' || inventory.status==='待盘点'">
                <label class=" font-weight-bold">剩余数:</label><span>@{{ inventory.surplus }}</span>
            </span>
            <span class="form-group mb-5" v-if="inventory.status==='复盘中'&&未复盘有差异列">
                <label class=" font-weight-bold">有差异未复盘数:</label><span>@{{ 未复盘有差异列.length }}</span>
            </span>
            <span class="form-group mb-5" v-if="inventory.status==='复盘中'&&未盘列">
                <label class=" font-weight-bold">未盘点数:</label><span>@{{ 未盘列.length }}</span>
            </span>
            <span class="form-group mb-5" v-if="inventory.status==='复盘中'">
                <label class=" font-weight-bold">总数:</label><span>@{{ inventory.total }}</span>
            </span>
            </span>
        </div>


        <div class="mt-3" >
        <span v-if="!listMode" class="btn  col-md-2 font-weight-bold"  style="cursor: default;max-width: 160px" :class="inventory.status=='盘点中' ||inventory.status=='待盘点'?'bg-info':'btn-outline-info disabled'">
            @{{ inventory.type }}
        </span>
            <span v-if="!listMode">
                 @can('库存管理-盘点-结束初盘')
                    <span v-if="inventory.status==='盘点中' ||inventory.status=='待盘点'" class="btn  col-md-2 font-weight-bold btn-outline-secondary" style="max-width: 160px" @click="stockInventoryEnd(inventory.id)">结束</span>
                @endcan
            <span v-if="inventory.status==='复盘中'" class="btn  col-md-2 font-weight-bold" style="cursor: default;max-width: 160px" :class="inventory.status=='盘点中' ||inventory.status=='待盘点'?'btn-outline-info disabled':'bg-info'">复盘</span>
        </span>
        </div>

        <div v-if="blindReceive">
            <audio src="{{asset('sound/warning_otherBarcode.mp3')}}" controls="controls" preload id="soundWarning" hidden>
            </audio>
            <audio src="{{asset('sound/ding.mp3')}}" controls="controls" preload id="soundDing" hidden>
            </audio>
            <div class="row mt-2 mb-2 rounded" style="border:solid 3px #999999;">
                <div class="col-12" id="scanColumn">
                    <div class="card" :class="borderByMode">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12">
                                    <div >
                                        <div class="text-danger font-weight-bold">
                                            库位(必填项)：
                                        </div>
                                        <input type="text" class="form-control mb-2" v-model="location" @focusin="focusOutDocument"  @focusout="focusDocument" @keyup="oninputEnter">
                                    </div>
                                    <p class="text-muted" style="font-size: 0.5em" v-if="inputMode=='regular'">常规：可输入效期，相同条码记录不会合并</p>
                                    <p class="text-muted" style="font-size: 0.5em" v-if="inputMode=='increasing'">逐一扫描：处理单一重复商品，每扫一次对应隔口总数量自动递增，扫到不同条码会提示</p>
                                    <p class="text-muted" style="font-size: 0.5em" v-if="inputMode=='multiIncreasing'">边扫边分：处理多种商品，自动将扫到的不同条码数量递增到各自隔口号</p>
                                    <ul class="nav nav-tabs mb-4 mt-n3">
                                        <li class="nav-item"><a href="#" class="nav-link" :class="inputMode=='regular'?'active':''"
                                                                @click="inputMode='regular';changeToManualInputAmount();cleanInputs();inputting.fromIncreasing=false">常规</a></li>
                                        <li class="nav-item"><a href="#" class="nav-link" :class="inputMode=='increasing'?'active':''"
                                                                @click="inputMode='increasing';changeToScanInputAmount();cleanInputs();inputting.fromIncreasing=true;">逐一扫描</a></li>
                                        <li class="nav-item"><a href="#" class="nav-link" :class="inputMode=='multiIncreasing'?'active':''"
                                                                @click="inputMode='multiIncreasing';changeToScanInputAmount();cleanInputs();inputting.fromIncreasing=true">边扫边分</a></li>
                                    </ul>
                                </div>
                                <div class="col-6">
                                    <div v-if="inputMode=='regular'">
                                        <div class="btn btn-sm btn-outline-primary"
                                             v-if="!isManualInputtingBarcode" @click="changeToManualInputBarcode">手动输入</div>
                                        <div class="btn btn-sm btn-outline-danger"
                                             @click="changeToScanInputBarcode" v-if="isManualInputtingBarcode">扫描输入</div>
                                    </div>
                                    <input type="text" id="barcode" class="form-control" :disabled="status.barcodeDisable" placeholder="扫入条码" @focusin="focusOutDocument" @focusout="focusDocument" v-model="inputting.barcode" autocomplete="off">
                                    <div v-if="inputMode=='regular'">
                                        <div class="card-title">
                                            生产日期：
                                        </div>
                                        <input type="date" class="form-control mb-2" v-model="inputting.produce_date" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter">
                                    </div>
                                    <div v-if="inputMode=='regular'">
                                        <div class="card-title">
                                            失效日期：
                                        </div>
                                        <input type="date" class="form-control mb-2" v-model="inputting.valid_date" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter">
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="card-title" id="amountLabel">
                                        手动输入数量：
                                    </div>
                                    <div class="input-group mt-n2 mb-2">
                                        <input type="number" id="amount" class="form-control" placeholder="" :disabled="status.amountDisable"
                                               v-model="inputting.amount" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter"
                                               style='height: 40px;font-size: 1.6em;color:blue;font-weight: bolder;padding: 3px;text-align: center'>
                                    </div>
                                    {{--                                    <div class="card-title">--}}
                                    {{--                                        格口号：--}}
                                    {{--                                    </div>--}}
                                    {{--                                    <input type="number" id="bin" class="form-control mt-n2 mb-2"--}}
                                    {{--                                           v-model="inputting.bin"--}}
                                    {{--                                           :disabled="status.binDisable" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter"--}}
                                    {{--                                           style='height: 80px;font-size: 5em;color:red;font-weight: bolder;padding: 3px;text-align: center'>--}}
                                    <div v-if="inputMode=='regular'">
                                        <div class="card-title">
                                            批次号：
                                        </div>
                                        <input type="text" class="form-control mb-2" v-model="inputting.batch_number" @focusin="focusOutDocument" @focusout="focusDocument" @keyup="oninputEnter">
                                    </div>
                                </div>
                                <div class="col-12" v-if="commitButtonVisible && inputMode=='regular'" >
                                    <button class="btn btn-success btn form-control" @click="commitGoods">确定</button>
                                </div>
                            </div>
                            <p class="card-text text-muted mt-3 mb-n3 text-center">
                                已完成：
                            </p>
                            <hr>
                            <table class="table table-sm  table-striped" v-if="goodses.length>0">
                                <tr>
                                    {{--                                    <th>隔口号</th>--}}
                                    <th>数量</th>
                                    <th>条码</th>
                                    <th>生产日期</th>
                                    <th>失效日期</th>
                                    <th>批次号</th>
                                    <th>操作</th>
                                </tr>
                                <tr v-for="goods in goodses" @click="selectedColor(goods.id,$event)">
                                    {{--                                    <td>@{{ goods.bin }}</td>--}}
                                    <td>@{{ goods.amount }}</td>
                                    <td>@{{ goods.barcode }}</td>
                                    <td>@{{ goods.produce_date }}</td>
                                    <td>@{{ goods.valid_date }}</td>
                                    <td>@{{ goods.batch_number }}</td>
                                    <td>
                                        <button class="btn btn-outline-danger btn-sm" @click="removeGoods($event,goods.barcode)">删</button>
                                    </td>
                                </tr>
                            </table>
                            <hr>
                            <span class="btn btn-outline-dark btn form-control" style="cursor: pointer" @click="submitStockInventory">结束并生成盘点</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <form id="form">
            <div v-if="!blindReceive">
                <div class="mt-3 form-inline " v-if="!listMode" :class="inventory.status=='盘点中' ||inventory.status=='待盘点'?'row-cols-3':'row-cols-5'">
        <span class="form-group">
            <label for="location" class="text-secondary font-weight-bold">请输库位</label>
            <input id="locationInput"  @keypress="locationPress($event)"
                   @change="locationChange($event)"
                   name="location" type="text" class="form-control  input"  autocomplete="off" value="@if(old('location')){{old('location')}}@endif">
        </span>
                    <span class="form-group ml-4" v-if="addInventoryMission">
            <label for="barcode" class="text-secondary font-weight-bold">请输产品条码</label>
                <input id="barcodeInput" name="barcode"  @keypress="barcodePress($event)"
                       @change="barcodeChange($event)"
                       type="text" value="@if(old('barcode')){{old('barcode')}}@endif" class="form-control  input" autocomplete="off">

        </span>

                    <span class="form-group ml-4" v-if="dataExtraStatus.addingNew&&addInventoryMission" id="countBlock">
                        <label for="count" class="text-secondary font-weight-bold">请输盘点数</label>
                        <input type="number" id="amountInput"  @keypress="amountPress($event)"
                               name="count" class="form-control input" value="@if(old('count')){{old('count')}}@endif"  autocomplete="off">
                    </span>
                    <span type="button" class="btn btn-sm btn-outline-danger col-md-2 form-group ml-4" v-if="location" style="max-width: 160px" @click="stockInventoryByLocation()">盘点该库位下所有记录</span>
                </div>
            </div>
            <!--相同库位和条码 pc端-->

            <div class="row d-none d-xl-block">
                <div class="col-12 col-md-12 col-sm-12 showBlueTable d-none">
                    <table class="table table-sm table-bordered table-info mt-2" :class="!listMode?'':'d-none'" id="blueTablePc">
                        <tr>
                            <td class="font-weight-bold">输入盘点数</td>
                            <td>操作</td>
                            <td>库位</td>
                            <td>产品名</td>
                            <td>产品条码</td>
                            <td>产品编码</td>
                            <td>生产日期</td>
                            <td>失效时期</td>
                            <td>批号</td>
                            <th>属性仓</th>
                            <th>质量状态</th>
                            <td>盘点数量</td>
                            <td>复盘数量</td>
                            <td>复盘差异</td>
                        </tr>
                        <tr  class="selectingRow" id="blueTrPc">
                            <td>
                                <input type="number"  onkeypress="listVue.selectingRow(event)" name="amount" class="form-control-sm blueAmountPc"   autocomplete="off"  oninput="inputs.amount=event.target.value">
                            </td>
                            <td>
                                <span class="btn btn-sm btn-outline-primary stockButtonPc"  onclick="listVue.盘点选中任务(event)">选定盘点</span>
                            </td>
                            <td class="location"></td>
                            <td class="commodity_name"></td>
                            <td class="commodity_barcode"></td>
                            <td class="commodity_sku"></td>
                            <td><input type="date" class="form-control-sm produced_at" name="produced_at" onchange="producedAtChange(event)"></td>
                            <td><input type="date" class="form-control-sm valid_at" name="valid_at"  onchange="validAtChange(event)"></td>
                            <td><input type="text" class="form-control-sm batch_number" name="batch_number" onchange="batchNumberChange(event)"></td>
                            <td class="erp_type_position"></td>
                            <td class="quality"></td>
                            <td class="verified_amount font-weight-bold text-success"></td>
                            <td class="re_checked_amount"></td>
                            <td class="difference_amount"></td>
                        </tr>
                    </table>
                </div>
            </div>
            <!--相同库位和条码 移动端-->
            <div class="showBlueTable d-none">
                <table class="table table-striped table-sm table-bordered table-hover p-0 d-xl-none mt-2" style="background: rgb(179, 214, 245);" {{--v-if="!listMode"--}} :class="!listMode?'':'d-none'" id="blueTable">
                    <tr class="selectingRow移动端" id="blueTr">
                        <td style="filter:grayscale(30%); ">
                            <div class="mt-3">
                                <div>
                                    <span  class="mr-3 text-nowrap"><span class="font-weight-bold">输入盘点数：</span>
                                        <span>
                                                <input type="number"  onkeypress="listVue.selectingRow(event)" name="amount" class="form-control-sm blueAmount"  autocomplete="off"  oninput="inputs.amount=event.target.value">
                                        </span>
                                    </span>
                                    <span class="mr-3 text-nowrap"><span class="font-weight-bold">操作：</span><span class="btn btn-sm btn-outline-primary stockButton" onclick="listVue.盘点选中任务(event)">选定盘点</span></span>
                                </div>
                                <div style="transform:scale(0.9)" class="pl-0">
                                    <span class="mr-3 text-nowrap"><span class="font-weight-bold">库位：</span><span class="location"></span></span>
                                    <span class="mr-3 text-nowrap"><span class="font-weight-bold">产品名称：</span><span class="commodity_name"></span></span>
                                    <span class="mr-3 text-nowrap"><span class="font-weight-bold">产品条码：</span><span class="commodity_barcode"></span>
                                    </span>
                                    <span class="mr-3 text-nowrap"><span class="font-weight-bold">产品编码：</span><span class="commodity_sku"></span></span>
                                    <span class="mr-3 text-nowrap"><span class="font-weight-bold">生产日期：</span><input type="date" class="form-control-sm produced_at" name="produced_at" onchange="producedAtChange(event)"></span>
                                    <span class="mr-3 text-nowrap"><span class="font-weight-bold">失效时期：</span><input type="date" class="form-control-sm valid_at" name="valid_at" onchange="validAtChange(event)"></span>
                                    <span class="mr-3 text-nowrap"><span class="font-weight-bold">批号：</span><input type="text" class="form-control-sm batch_number" name="batch_number" onchange="batchNumberChange(event)"></span>
                                    <span class="mr-3 text-nowrap"><span>属性仓：</span><span class="erp_type_position"></span></span>
                                    <span class="mr-3 text-nowrap"><span>质量状态：</span><span class="quality"></span></span>
                                    <div>
                                        <span class="mr-3 text-nowrap"><span style="color:#783000">盘点数量：</span><span  class="verified_amount font-weight-bold text-success"></span></span>
                                        <span class="mr-3 text-nowrap"><span style="color:#783000">复盘数量：</span><span style="color:#af7651" class="re_checked_amount"></span></span>
                                        <span class="mr-3 text-nowrap"><span style="color:#783000">盘点差异：</span><span class="difference_amount"></span></span>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </form>
        <div class="card-body pt-1">
            <table class="table table-sm table-striped d-none d-xl-block p-0 text-nowrap table-bordered td-min-width-80"
                   id="table" ref="boxPc">
                <tr v-for="(inventoryMission, i) in 显示记录列" :key="i"
                    :style="{'opacity': inventoryMission.mark==='跳过'?'0.7':'','opacity': inventoryMission.mark==='确认差异'?'0.7':''}" :class="[
                    inventoryMission.mark==='已复盘有差异'?'td-cool':'',
                    inventoryMission.mark==='已复盘无差异'?'td-cool text-muted':'',
                    inventoryMission.mark==='未复盘有差异'?'td-warm font-weight-bold':'',
                    inventoryMission.mark==='确认差异'?'td-warm font-weight-bold':'',
                    inventoryMission.mark==='无差异'?'text-muted':'',
                    inventoryMission.mark==='未盘'?'td-yellow':'',
                    inventoryMission.mark==='跳过'?'text-muted':'',
                    ]">
                    <td>
                        <input type="checkbox" :value="inventoryMission">
                        <span :id="'lockLine'+(i+1)"></span>
                    </td>
                    <td><span>@{{ i+1 }}</span></td>
                    <td><span>@{{ inventoryMission.location }}</span></td>
                    <td v-if="inventoryMission.commodity"><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.commodity.name }}</span>
                    </td>
                    <td>
                        <span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">
                        <span
                            v-if="inventoryMission.commodity_barcodes && inventoryMission.commodity_barcodes.length>0">
                            <span v-if="inventoryMission.commodity_barcodes.length==1">
                                @{{ inventoryMission.commodity_barcodes[0].code }}
                            </span>
                            <span v-if="inventoryMission.commodity_barcodes.length>1">
                                <small
                                    v-for="barcode in inventoryMission.commodity_barcodes">@{{ barcode.code }}<br></small>
                            </span>
                        </span>
                        </span>
                    </td>

                    <td v-if="inventoryMission.commodity"><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.commodity.sku }}</span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.produced_at }}</span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.valid_at }}</span>
                    </td>
                    <td class="text-muted"><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.batch_number }}</span>
                    </td>

                    <td v-if="inventoryMission.stockInventoryPersons" class="text-muted"
                        :rowspan="inventoryMission.is_multi_row?2:''">
                        <span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">
                        <a href="#" v-if="inventoryMission.stockInventoryPersons.length>0" class="dropdown-toggle"
                           data-toggle="dropdown">
                            @{{ inventoryMission.stockInventoryPersons[0].mark }}<b class="caret"></b>
                        </a>
                        <div
                            style="position: absolute;width:320px;margin-left:-100px;background-color: white;max-height:150px ;overflow-y:auto"
                            class="small mt-0 dropdown-menu">
                            <table class="table table-sm table-striped table-bordered">
                                <tr>
                                    <th>盘点人</th>
                                    <th>时间</th>
                                </tr>
                                <tr v-for="stockInventoryPerson in inventoryMission.stockInventoryPersons">
                                    <td>@{{ stockInventoryPerson.mark }}</td>
                                    <td>@{{ stockInventoryPerson.created_at }}</td>
                                </tr>
                            </table>
                        </div>
                        </span>
                    </td>

                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.erp_type_position }}</span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">
                        <span v-if="listMode">@{{ inventoryMission.quality }}</span>
                        <select v-else class="form-control-sm" name="quality" id="quality"
                                v-model="inventoryMission.quality"
                                @change="updateQuality(inventoryMission.id,inventoryMission.location,inventoryMission.commodity.sku,inventoryMission.quality,inventory.owner.code)">
                            <option value="正品">正品</option>
                            <option value="残次">残次</option>
                        </select>
                        </span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.stored_amount }}</span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.valid_amount }}</span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.verified_amount }}
                            <span v-if="inventoryMission.checked==='跳过'" class="badge badge-pill badge-secondary">跳过</span></span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.re_checked_amount }}</span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.difference_amount }}</span>
                    </td>
                    <td><span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">@{{ inventoryMission.occupied_amount }}</span>
                    </td>
                    @can('库存管理-盘点')
                        <td>
                            {{--                            <span class="btn  btn-sm btn-outline-danger" @click="删除盘点记录(inventoryMission.id,inventory.id,inventoryMission.commodity.name)">删除</span>--}}
                            <span class="btn  btn-sm btn-outline-secondary" v-if="inventoryMission.checked==='否'"
                                  @click="跳过盘点记录(inventoryMission.id,inventory.id,inventoryMission.commodity.name)">跳过</span>
                            <span class="btn  btn-sm btn-outline-secondary" v-if="inventoryMission.mark==='已复盘有差异'||inventoryMission.mark==='未复盘有差异'"
                                  @click="确认盘点差异(inventoryMission.id,inventory.id,inventoryMission.commodity.name)">跳过</span>
                            <span class="btn  btn-sm btn-outline-secondary"
                                  v-if="inventory.type=='动盘'&& inventoryMission.mark=='未盘' &&!listMode"
                                  @click="选中盘点起始位置(inventoryMission.id,inventoryMission.location)">以此为起点</span>
                        </td>
                    @endcan
                </tr>
            </table>
        </div>
        <!--盘点记录移动端-->
        <table id="listOnPad" class="table table-striped table-sm table-bordered table-hover p-0 d-table  d-xl-none"
               style="background: rgb(255, 255, 255);" ref="box">
            <tbody>
            <tr {{--v-for="(inventoryMission,i) in 显示记录列"--}} v-for="(inventoryMission, i) in 显示记录列" :key="i"
                :style="{'opacity': inventoryMission.mark==='跳过'?'0.7':'','opacity': inventoryMission.mark==='确认差异'?'0.7':''}"
                :class="[
                    inventoryMission.mark==='已复盘有差异'?'td-cool':'',
                    inventoryMission.mark==='已复盘无差异'?'td-cool text-muted':'',
                    inventoryMission.mark==='未复盘有差异'?'td-warm font-weight-bold':'',
                    inventoryMission.mark==='确认差异'?'td-warm font-weight-bold':'',
                    inventoryMission.mark==='无差异'?'text-muted':'',
                    inventoryMission.mark==='未盘'?'td-yellow':'',
                    inventoryMission.mark==='跳过'?'text-muted':'',
                    ]">
                <td style="filter:grayscale(30%); ">
                    <span :id="'lockLinePhone'+(i+1)"></span>
                    <div class="mt-3">
                        <div style="transform:scale(0.9)" class="pl-0">
                            <span type="hidden">@{{ i+1 }}</span>
                            <span class="mr-3 text-nowrap"><span class="font-weight-bold">库位：</span><span
                                    style="color:#af7651">
                                    @{{ inventoryMission.location }}</span></span>
                            <span class="mr-3 text-nowrap"
                                  v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode"><span
                                    class="font-weight-bold">产品名称：</span><span style="color:#af7651"
                                                                               v-if="inventoryMission.commodity">
                                    @{{ inventoryMission.commodity.name }}</span></span>
                            <span class="mr-3 text-nowrap"
                                  v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">
                                <span class="font-weight-bold">质量状态：</span>
                                <span v-if="listMode">@{{ inventoryMission.quality }}</span>
                        <select v-else class="form-control-sm" name="quality" id="quality"
                                v-model="inventoryMission.quality"
                                @change="updateQuality(inventoryMission.id,inventoryMission.location,inventoryMission.commodity.sku,inventoryMission.quality,inventory.owner.code)">
                        <option value="正品">正品</option>
                        <option value="残次">残次</option>
                         </select>
                            </span>
                            <span class="mr-3 text-nowrap"
                                  v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">
                                <span class="font-weight-bold">产品条码：</span>

                        <span
                            v-if="inventoryMission.checked==='是'||inventoryMission.checked==='确认差异'||inventoryMission.checked==='跳过'||inventory.status==='复盘中'||listMode">
                        <span
                            v-if="inventoryMission.commodity_barcodes && inventoryMission.commodity_barcodes.length>0">
                            <span v-if="inventoryMission.commodity_barcodes.length==1">
                                @{{ inventoryMission.commodity_barcodes[0].code }}
                            </span>
                            <span v-if="inventoryMission.commodity_barcodes.length>1">
                                <small
                                    v-for="barcode in inventoryMission.commodity_barcodes">@{{ barcode.code }}<br></small>
                            </span>
                        </span>
                        </span>
                            </span>
                            <div v-if="inventory.status==='复盘中'">
                                <span class="mr-3 text-nowrap"><span style="color:#783000" class="font-weight-bold">盘点数量：</span><span
                                        style="color:#af7651">
                                        @{{ inventoryMission.verified_amount }}</span></span>
                                <span class="mr-3 text-nowrap"><span style="color:#783000" class="font-weight-bold">复盘数量：</span><span
                                        style="color:#af7651">
                                        @{{ inventoryMission.re_checked_amount }}</span></span>
                                <span class="mr-3 text-nowrap"><span style="color:#783000" class="font-weight-bold">盘点差异：</span><span>
                                        @{{ inventoryMission.difference_amount }}</span></span>
                            </div>
                            @can('库存管理-盘点')
                                <div>
                                <span class="mr-3 text-nowrap" v-if="!listMode"><span
                                        class="font-weight-bold">操作：</span>
{{--                                <span class="btn  btn-sm btn-outline-danger" @click="删除盘点记录(inventoryMission.id,inventory.id,inventoryMission.commodity.name)">删除</span>--}}
                                <span class="btn  btn-sm btn-outline-secondary" v-if="inventoryMission.checked==='否'"
                                      @click="跳过盘点记录(inventoryMission.id,inventory.id,inventoryMission.commodity.name)">跳过</span>
                                     <span class="btn  btn-sm btn-outline-secondary" v-if="inventoryMission.mark==='已复盘有差异'||inventoryMission.mark==='未复盘有差异'"
                                           @click="确认盘点差异(inventoryMission.id,inventory.id,inventoryMission.commodity.name)">跳过</span>
                                        <span class="btn  btn-sm btn-outline-secondary"
                                          v-if="inventory.type=='动盘'&& inventoryMission.mark=='未盘' &&!listMode"
                                          @click="选中盘点起始位置(inventoryMission.id,inventoryMission.location)">以此为起点</span>
                            </span>
                                </div>
                            @endcan
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
        <!--上次盘点记录-->
        <div class="modal" id="lastStockInventoryRecord" tabindex="-1" role="dialog">
            <div class="modal-dialog modal-xl">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title font-weight-bold">该盘点记录已存在,是否覆盖之前记录？</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <table class="table table-sm table-striped table-bordered">
                            <tr class="text-muted text-center">
                                <th>库位</th>
                                <th>产品条码</th>
                                <th>盘点人</th>
                                <th>盘点数量</th>
                                <th>产品名</th>
                                <th>产品编号</th>
                                <th>属性仓</th>
                                <th>质量状态</th>
                                <th>库存数量</th>
                                <th>盘点差异</th>
                                <th>时间</th>
                            </tr>
                            <tr class="text-center ">
                                <td>@{{ lastStockInventoryRecord.location }}</td>
                                <td><span v-if="lastStockInventoryRecord.commodity">@{{ lastStockInventoryRecord.commodity.barcode }}</span></td>
                                <td><span v-if="stockInventoryPersons.length>0">@{{ stockInventoryPersons[stockInventoryPersons.length-1].mark }}</span></td>
                                <td>@{{ lastStockInventoryRecord.verified_amount }}</td>
                                <td><span v-if="lastStockInventoryRecord.commodity">@{{ lastStockInventoryRecord.commodity_name }}</span></td>
                                <td><span v-if="lastStockInventoryRecord.commodity">@{{ lastStockInventoryRecord.commodity.sku }}</span>
                                </td>
                                <td>@{{ lastStockInventoryRecord.erp_type_position }}</td>
                                <td>@{{ lastStockInventoryRecord.quality }}</td>
                                <td>@{{ lastStockInventoryRecord.stored_amount }}</td>
                                <td>@{{ lastStockInventoryRecord.difference_amount }}</td>
                                <td><span v-if="stockInventoryPersons.length>0">@{{ stockInventoryPersons[stockInventoryPersons.length-1].created_at }}</span>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true" class="btn btn-outline-secondary" @click="不覆盖()">否</span>
                        </button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" @click="覆盖()">是</button>
                    </div>
                </div>
            </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/header.js')}}"></script>{{--新版2--}}
    <script>
        let hideHeaderTitle = function () {
            let $listOnPad = $('#listOnPad');
            let $headerRoll = $('#headerRoll');
            if ($listOnPad.css('display') !== 'none') {
                $headerRoll.attr('hidden', true)
            } else {
                $headerRoll.attr('hidden', false)
                $headerRoll.find('tr').css('width', $(document).width());
            }
        };
        window.onresize = hideHeaderTitle;
        window.onscroll = hideHeaderTitle;
        let $showBlueTable=null;
        let $barcodeInput=null;
        let $locationInput=null;
        let $amountInput=null;
        let $prototype_ = null;
        let $blueTable = null;
        let $prototypePc_ = null;
        let $blueTablePc = null;
        let inputs={location:'',barcode:'',amount:'',produced_at:'',valid_at:'',batch_number:''};//双向绑定在本页太慢，所以用外部变量
        let $appointInventoryList=[];
        let $jqueryTable=[];
        function producedAtChange(e){
            inputs.produced_at = e.target.value;
        }
        function validAtChange(e){
            inputs.valid_at = e.target.value;
        }
        function batchNumberChange(e){
            inputs.batch_number = e.target.value;
        }
        let listVue = new Vue({
            el: "#list",
            data: {
                selectingId:'',
                dataExtraStatus:{addingNew:false, displayingLastCounting:false,showBlueTable:false},
                inventory:{!! $inventoryAccount!!},
                inventoryMissions : [
                        @foreach($inventoryAccountMissions as $inventoryMission)
                    {
                        id: '{{$inventoryMission->id}}',
                        location: '{{$inventoryMission->location}}',
                        created_at: '{{$inventoryMission->created_at}}',
                        commodity_name: '{{$inventoryMission->commodity ? $inventoryMission->commodity->name : ''}}',
                        commodity_sku: '{{$inventoryMission->commodity ? $inventoryMission->commodity->sku : ''}}',
                        commodity_barcode: '{{$inventoryMission->commodity ? $inventoryMission->commodity->barcode : ''}}',
                        commodity:{!! $inventoryMission->commodity  !!},
                        stockInventoryPersons:{!! $inventoryMission->stockInventoryPersons  !!},
                        commodity_barcodes: [
                                @foreach($inventoryMission->commodity ? $inventoryMission->commodity->barcodes ?? [] : [] as $barcode)
                            {code: '{{$barcode->code}}'},
                            @endforeach
                        ],
                        stock_persons: [
                                @foreach($inventoryMission->stockInventoryPersons ? $inventoryMission->stockInventoryPersons ?? [] : [] as $person)
                            {name: '{{$person->mark}}'},
                            @endforeach
                        ],
                        produced_at: '{{$inventoryMission->produced_at}}',
                        valid_at: '{{$inventoryMission->valid_at}}',
                        verified_amount: '{{$inventoryMission->verified_amount}}',
                        stored_amount: '{{$inventoryMission->stored_amount}}',
                        valid_amount: '{{$inventoryMission->valid_amount}}',
                        stored_at: '{{$inventoryMission->stored_at}}',
                        batch_number: '{{$inventoryMission->batch_number}}',
                        erp_type_position: '{{$inventoryMission->erp_type_position}}',
                        quality: '{{$inventoryMission->quality}}',
                        difference_amount: '{{$inventoryMission->difference_amount}}',
                        occupied_amount: '{{$inventoryMission->occupied_amount}}',
                        checked: '{{$inventoryMission->checked}}',
                        returned: '{{$inventoryMission->returned}}',
                        re_checked_amount: '{{$inventoryMission->re_checked_amount}}'
                    },
                    @endforeach
                ],
                库位盘点记录:[],
                条码索引_记录: {},
                库位索引_记录: {},
                selectedStyle:'',
                指定盘点记录列:[],
                lastStockInventoryRecord:{},
                stockInventoryPersons:[],
                inventoryAccountMissions:[],
                listMode:false,
                blindReceive:false,
                addInventoryMission:false,
                分割位置id:null,
                显示记录列:[],

                focusing:'document',
                commitButtonVisible:false,
                isManualInputtingBarcode:false,
                isManualInputtingAmount:true,
                lastScannedBarcode:'',
                inputMode:'regular',
                location:'',
                inputting:{
                    barcode:'',amount:'',bin:'',produce_date:'',valid_date:'',batch_number:'',fromIncreasing:false
                },
                status:{
                    scanEndInputted:false,binDisable:false,barcodeDisable:true,amountDisable:false,
                },
                goodses:[],
                selectTr:''
            },
            beforeMount: function () {
                this.重排序并标记全列表类型();
                this.加载下方数据并置空上方数据()//初始化先调用一次
            },
            destroyed() {
                window.removeEventListener('scroll', this.lazy)
            },
            updated: function () {
                $barcodeInput=$('#barcodeInput');
                $locationInput=$('#locationInput');
                $amountInput=$('#amountInput');
            },
            mounted: function () {
                let _this = this;
                _this.lazy();
                window.addEventListener('scroll', this.lazy);
                (function 显示渲染后页面(){
                    $('#loadingPage').remove();
                    $('#list').removeClass('d-none');
                })()
                $(".tooltipTarget").tooltip({'trigger': 'hover'});
                $barcodeInput=$('#barcodeInput');
                $locationInput=$('#locationInput');
                $amountInput=$('#amountInput');
                $showBlueTable=$('.showBlueTable');
                $prototype_ = $('#blueTr');
                $blueTable = $('#blueTable');
                $prototypePc_ = $('#blueTrPc');
                $blueTablePc = $('#blueTablePc');
                this.放置焦点光标至正确位置();
                (function 初始化列表模式() {
                    let listMode = getGetVal('listMode')
                    if (listMode === 'true') {
                        _this.listMode = true;
                        return;
                    }
                    _this.listMode = false;
                })();
                let column = [
                    {name:'index',value: '序号', neglect: true},
                    {name:'location',value: '库位'},
                    {name: 'commodity_name', value: '产品名'},
                    {name: 'commodity_barcode', value: '产品条码'},
                    {name:'commodity_sku',value: '产品编码'},
                    {name: 'produced_at', value: '生产日期', neglect: true},
                    {name: 'valid_at', value: '失效日期', neglect: true},
                    {name: 'batch_number', value: '批号', neglect: true},
                    {name: 'stockInventoryPersons',value: '盘点人', neglect: true},
                    {name: 'erp_type_position', value: 'ERP属性仓', neglect: true},
                    {name: 'quality', value: '质量状态', neglect: true},
                    {name: 'stored_amount', value: '库存数量', neglect: true},
                    {name: 'valid_amount', value: '可用数量', neglect: true},
                    {name: 'verified_amount', value: '盘点数量', neglect: true},
                    {name: 're_checked_amount', value: '复盘数量', neglect: true},
                    {name: 'difference_amount', value: '复盘差异', neglect: true},
                    {name: 'occupied_amount', value: '分配数量', neglect: true},
                    {name: '跳过', value: '操作', neglect: true},
                ];
                new Header({
                    el: "table",
                    name: "inventoryMission",
                    column: column,
                    data: this.inventoryMissions,
                    fixedTop:($('#form').height())+2,
                }).init();
                this.建立记录索引();
            },
            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')
                },
                lazy(){
                    let _this=this;
                    let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;//滚动条距离顶部的高度
                    let scrollHeight = $(document).height();//当前页面的总高度
                    let clientHeight=window.innerHeight;//当前可视的页面高度
                    let count = parseFloat(clientHeight) + parseFloat(scrollTop);//浏览器底部位置
                    if (scrollHeight - count < 40) {
                            if (_this.显示记录列.length < _this.inventoryMissions.length) {
                                _this.加载下方数据并置空上方数据()
                            }
                    }
                },
                加载下方数据并置空上方数据(){
                    let _this=this;
                    const count = _this.显示记录列.length;
                    if (count > 30) {
                        _this.inventoryMissions.map((inventoryMission, index) => {
                            if (_this.显示记录列.length < 5 + count) {
                                if (_this.显示记录列.length < _this.inventoryMissions.length) {
                                    _this.显示记录列.push(_this.inventoryMissions[_this.显示记录列.length]);
                                }
                            }
                        })
                    } else {
                        _this.inventoryMissions.map((inventoryMission, index) => {
                            if (_this.显示记录列.length < 25 + count) {
                                if (_this.显示记录列.length < _this.inventoryMissions.length) {
                                    _this.显示记录列.push(_this.inventoryMissions[_this.显示记录列.length])
                                }
                            }
                        })
                    }
                },
                cloneBlueTrDom($appointInventoryList) {
                    for(let i =0;i<$appointInventoryList.length;i++){
                        let newDom= $prototype_.clone();
                        newDom.find('.location').text($appointInventoryList[i].location);
                        newDom.find('.commodity_name').text($appointInventoryList[i].commodity_name);
                        newDom.find('.commodity_barcode').text($appointInventoryList[i].commodity_barcode);
                        newDom.find('.commodity_sku').text($appointInventoryList[i].commodity_sku);
                        newDom.find('.produced_at').val($appointInventoryList[i].produced_at.substr(0,10));
                        newDom.find('.valid_at').val($appointInventoryList[i].valid_at.substr(0,10));
                        newDom.find('.batch_number').val($appointInventoryList[i].batch_number);
                        newDom.find('.erp_type_position').text($appointInventoryList[i].erp_type_position);
                        newDom.find('.quality').text($appointInventoryList[i].quality);
                        newDom.find('.verified_amount').text($appointInventoryList[i].verified_amount);
                        newDom.find('.re_checked_amount').text($appointInventoryList[i].re_checked_amount);
                        newDom.find('.difference_amount').text($appointInventoryList[i].difference_amount);
                        newDom.show();
                        newDom.find('.blueAmount').attr('data_id', $appointInventoryList[i].id);
                        newDom.find('.blueAmount').attr('stored_amount', $appointInventoryList[i].stored_amount);
                        newDom.find('.stockButton').attr('data_id', $appointInventoryList[i].id);
                        newDom.addClass('blueTr'+i);
                        newDom.appendTo($blueTable);
                        $jqueryTable.push(newDom);
                    }
                    $prototype_.hide();
                },
                cloneBlueTrPcDom($appointInventoryList) {
                    for(let i =0;i<$appointInventoryList.length;i++){
                        let newDom= $prototypePc_.clone();
                        newDom.find('.location').text($appointInventoryList[i].location);
                        newDom.find('.commodity_name').text($appointInventoryList[i].commodity_name);
                        newDom.find('.commodity_barcode').text($appointInventoryList[i].commodity_barcode);
                        newDom.find('.commodity_sku').text($appointInventoryList[i].commodity_sku);
                        newDom.find('.produced_at').val($appointInventoryList[i].produced_at.substr(0,10));
                        newDom.find('.valid_at').val($appointInventoryList[i].valid_at.substr(0,10));
                        newDom.find('.batch_number').val($appointInventoryList[i].batch_number);
                        newDom.find('.erp_type_position').text($appointInventoryList[i].erp_type_position);
                        newDom.find('.quality').text($appointInventoryList[i].quality);
                        newDom.find('.verified_amount').text($appointInventoryList[i].verified_amount);
                        newDom.find('.re_checked_amount').text($appointInventoryList[i].re_checked_amount);
                        newDom.find('.difference_amount').text($appointInventoryList[i].difference_amount);
                        newDom.show();
                        newDom.find('.blueAmountPc').attr('data_id', $appointInventoryList[i].id);
                        newDom.find('.blueAmountPc').attr('stored_amount', $appointInventoryList[i].stored_amount);
                        newDom.find('.stockButtonPc').attr('data_id', $appointInventoryList[i].id);
                        newDom.addClass('blueTrPc'+i);
                        newDom.appendTo($blueTablePc);
                        $jqueryTable.push(newDom);
                    }
                    $prototypePc_.hide();
                },
                inputs() {
                    return inputs;
                },
                barcodePress(e){
                    if(e.key==='Enter') {
                        this.barcodeChange(e);
                    }
                },
                barcodeChange(e){
                    this.inputs().barcode = e.target.value;
                    this.提交部分输入();
                },
                amountPress(e){
                    if(e.key==='Enter'){
                        this.提交新增(e);
                    }
                },
                locationPress(e){
                    if(e.key==='Enter'){
                        this.locationChange(e);
                    }
                },
                locationChange(e){
                    this.inputs().location = e.target.value;
                    this.提交部分输入();
                    if(!this.addInventoryMission){
                        this.location=this.inputs().location ;
                    }
                },
                提交部分输入:_.throttle(function(){
                    let _this = this;
                    this.放置焦点光标至正确位置();
                    _this.显示盘点计数input_按情况();
                    (new Promise(function (resolve, reject) {
                        resolve()
                    })).then(function () {
                        if(_this.addInventoryMission){
                            _this.提交库位和条码();
                        }else{
                            _this.提交库位();
                        }
                        _this.显示盘点计数input_按情况();
                    })

                },100,{trailing:false}),

                提交新增:_.throttle(function(e){
                    this.inputs().amount=e.target.value;
                    this.提交新增并盘点();
                },100,{trailing:false}),
                selectingRow(e){
                    let _this=this;
                    let id = $(e.target).attr('data_id');
                    _this.selectingId=id;
                    if(e.key==='Enter'){
                        _this.提交盘点();
                    }
                },
                提交库位和条码:_.throttle(async function(){
                    let _this=this;
                    this.清空指定盘点记录列();
                    if (!_this.inputs().barcode) return;
                    if(!(await this.is条码存在于WMS(_this.inputs().barcode))){
                        tempTip.setDuration(2000);
                        tempTip.show('输入的商品条码没有对应的商品！');
                    }
                    this.筛选出记录(_this.inputs().location,_this.inputs().barcode);
                },100,{ 'trailing': false }),
                提交库位:_.throttle(async function(){
                    let _this=this;
                    this.清空指定盘点记录列();
                    this.筛选库位出记录(_this.inputs().location);
                },100,{ 'trailing': false }),
                建立记录索引(){
                    let _this=this;
                    _this.inventoryMissions.forEach(function (inventoryMission) {
                        inventoryMission.commodity_barcodes.forEach(function (barcode) {
                            if(!Array.isArray(_this.条码索引_记录[barcode.code])) _this.条码索引_记录[barcode.code]=[];
                            _this.条码索引_记录[barcode.code].push(inventoryMission);
                        })
                        if(!Array.isArray(_this.库位索引_记录[inventoryMission.location])) _this.库位索引_记录[inventoryMission.location]=[];
                        _this.库位索引_记录[inventoryMission.location].push(inventoryMission);
                    });
                },
                清空指定盘点记录列(){
                    let _this=this;
                    $jqueryTable.forEach(function (newDom,i) {
                        newDom.remove();
                    })
                    $appointInventoryList=[];
                    $showBlueTable.attr('class','d-none');
                    _this.selectingId='';
                    _this.location='';
                    _this.库位盘点记录=[];
                },
                显示盘点计数input_按情况(){
                    let _this=this;
                    setTimeout(function(){
                        if($appointInventoryList.length>0){
                            _this.dataExtraStatus.addingNew=false;
                        }else{
                            _this.dataExtraStatus.addingNew=true;
                        }
                    },10)
                },
                async 筛选出记录(库位, 条码){
                    条码=条码.trim();
                    库位=库位.trim();
                    let _this=this;
                    if(!库位)return false;
                    if(!条码)return false;;
                    if (!_this.库位索引_记录[库位]
                        ||(!_this.条码索引_记录[条码]
                            &&!(await _this.is条码存在于WMS(条码)))
                    ) return;
                    if(Array.isArray(_this.条码索引_记录[条码])){
                        _this.条码索引_记录[条码].forEach(function(inventoryMission){
                            if (inventoryMission.location===库位){
                                $appointInventoryList.push(inventoryMission);
                                $appointInventoryList=_this.unique($appointInventoryList);
                            }
                        });
                        $showBlueTable.removeClass('d-none');
                        _this.cloneBlueTrDom($appointInventoryList);
                        _this.cloneBlueTrPcDom($appointInventoryList);
                    }
                },
                async 筛选库位出记录(库位){
                    库位=库位.trim();
                    let _this=this;
                    if(!库位)return false;
                    if (!_this.库位索引_记录[库位]) return;
                    if(Array.isArray(_this.库位索引_记录[库位])){
                        _this.库位索引_记录[库位].forEach(function(inventoryMission){
                            if (inventoryMission.location===库位){
                                $appointInventoryList.push(inventoryMission);
                                $appointInventoryList=_this.unique($appointInventoryList);
                            }
                        });
                        $showBlueTable.removeClass('d-none');
                        _this.cloneBlueTrDom($appointInventoryList);
                        _this.cloneBlueTrPcDom($appointInventoryList);
                    }
                },
                unique(arr){
                    return Array.from(new Set(arr));
                },
                放置焦点光标至正确位置:_.throttle(function(){
                    let _this=this;
                    _this.显示盘点计数input_按情况();
                    if (!$locationInput.val().trim()){
                        $locationInput.focus();
                        return;
                    }
                    if (_this.addInventoryMission){
                        if (!$barcodeInput.val().trim()){
                            $barcodeInput.focus();
                            return;
                        }
                    }
                    setTimeout(function(){
                        if(_this.dataExtraStatus.addingNew){
                            let $count = $('#amountInput');
                            if (!$count.val().trim()){
                                $count.focus();
                                return;
                            }
                        }
                        if ($appointInventoryList.length >0) {
                            $blueTablePc.find('.blueTrPc0 input').first().focus();
                            $blueTable.find('.blueTr0 input').first().focus();
                        }
                    },10)
                },100,{ 'trailing': false }),
                async is条码存在于WMS(条码){
                    条码=条码.trim();
                    let _this=this;
                    if (!条码) return false;
                    if (_this.条码索引_记录[条码]) return true;
                    if (_this.条码索引_记录[条码] === false) return false;
                    let url = '{{url('inventory/stockInventory/searchCommodityByBarcode')}}';
                    let is成功 = false;
                    await axios.post(url, {
                        barcode: 条码,
                        owner_code: _this.inventory.owner.code
                    }).then(function (response) {
                        if (response.data.success) {
                            is成功 = true;
                            _this.条码索引_记录[条码] = {barcodeExsitingAtWMS: true};
                        } else {
                            _this.条码索引_记录[条码] = false;
                        }
                    }).catch(function (err) {
                        tempTip.setDuration(2000);
                        tempTip.show('网络错误' + err);
                    });
                    return is成功;
                },
                is条码存在于当前记录(条码) {
                    条码 = 条码.trim();
                    let _this = this;
                    if (!条码) return false;
                    return !!_this.条码索引_记录[条码];

                },
                is库位存在于当前记录(库位) {
                    库位 = 库位.trim();
                    let _this = this;
                    if (!库位) return false;
                    return !!_this.库位索引_记录[库位];

                },
                提交新增并盘点:async function(){
                    let _this=this;
                    let inventoryId=_this.inventory.id;
                    if(!_this.inputs().location.trim()|| !_this.inputs().barcode.trim() || !_this.inputs().amount.trim())return false;
                    let 条码存在于当前记录 = _this.is条码存在于当前记录(_this.inputs().barcode);
                    let 条码存在于WMS = await _this.is条码存在于WMS(_this.inputs().barcode);
                    let 库位存在于当前记录 = _this.is库位存在于当前记录(_this.inputs().location);

                    if(!条码存在于当前记录 && !条码存在于WMS)return false;
                    if(库位存在于当前记录 && 条码存在于当前记录)return false;
                    if(!confirm('该'+_this.inputs().barcode+'条码和'+_this.inputs().location+'库位相加的条件于WAS系统盘点记录中不存在! 是否确定需要添加至系统盘点记录中？')){return false};
                    let 新增字段标记='';
                    if(!库位存在于当前记录&&!条码存在于当前记录)新增字段标记='库位和商品新增';
                    if(!库位存在于当前记录)新增字段标记='库位新增';
                    if(!条码存在于当前记录)新增字段标记='商品新增';

                    _this.增加系统之外的盘点记录(_this.inputs().location,_this.inputs().barcode,_this.inputs().amount,inventoryId,_this.inventory.owner.code,新增字段标记);
                    return true;
                },
                提交盘点:_.throttle(function(){
                    let _this=this;
                    let 条码=_this.inputs().barcode.trim();
                    let 库位=_this.inputs().location.trim();
                    let 盘点数=_this.inputs().amount.trim();
                    let 选定盘点记录id=_this.selectingId;
                    $appointInventoryList.forEach(function (inventoryMission) {
                            if (inventoryMission.location === 库位) {
                                if (inventoryMission.stockInventoryPersons.length > 0 && inventoryMission.id === _this.selectingId) {
                                    _this.lastStockInventoryRecord = inventoryMission;
                                    _this.stockInventoryPersons = inventoryMission.stockInventoryPersons;
                                    if (_this.inventory.status !== '复盘中'){
                                        $("#lastStockInventoryRecord").modal('show');
                                        return;
                                    }
                                }
                                _this.盘点(选定盘点记录id,库位,条码,_this.inventory.id,盘点数);
                                _this.清空指定盘点记录列();
                            }
                    });
                },100,{ 'trailing': false }),
                //结束初盘任务
                stockInventoryEnd(id) {
                    let _this = this;
                    let url = '{{url('inventory/stockInventoryEnd')}}';
                    if (!confirm('确定要结束初盘任务，进入复盘吗？')) {return;}
                    axios.post(url, {id: id}).then(function (response) {
                        if (!response.data.success) {
                            tempTip.setDuration(2000);
                            tempTip.show('结束初盘失败!' + '   ' + response.data.data);
                        } else {
                            _this.inventory.status = response.data.data;
                            tempTip.setDuration(2000);
                            tempTip.showSuccess('结束初盘，进入复盘！');
                        }
                    }).catch(function (err) {
                        tempTip.setDuration(2000);
                        tempTip.show('结束初盘失败!' + '网络错误' + err);
                    })
                },
                updateQuality(id, location, sku, quality, ownerCode) {
                    let url = '{{url('inventory/修改质量状态')}}';
                    axios.post(url, {
                        id: id,
                        location: location,
                        sku: sku,
                        quality: quality,
                        ownerCode: ownerCode
                    }).then(function (response) {
                        if (!response.data.success) {
                            tempTip.setDuration(3000);
                            tempTip.show('修改质量状态失败!' + '   ' + response.data.data);
                        } else {
                            tempTip.setDuration(2000);
                            tempTip.showSuccess('修改质量状态成功！');
                        }
                    }).catch(function (err) {
                        tempTip.setDuration(2000);
                        tempTip.show('修改质量状态失败!' + '网络错误' + err);
                    })
                },
                重排序并标记全列表类型() {
                    let _this = this;
                    _this.已复盘有差异列 = [];
                    _this.未复盘有差异列 = [];
                    _this.已复盘无差异列 = [];
                    _this.确认差异列=[];
                    _this.无差异列 = [];
                    _this.未盘列 = [];
                    _this.跳过列 = [];
                    _this.未盘列总 = [];
                    _this.未盘列1 = [];
                    _this.未盘列2 = [];
                    _this.inventoryMissions.forEach(function (mission, i) {
                        switch (mission.checked) {
                            case '已复核':
                                if (parseInt(mission.difference_amount)) {
                                    _this.已复盘有差异列.push(mission);
                                    mission.mark = '已复盘有差异';
                                    return;
                                }
                                _this.已复盘无差异列.push(mission);
                                mission.mark = '已复盘无差异';
                                return;
                            case '是':
                                if (parseInt(mission.difference_amount)) {
                                    _this.未复盘有差异列.push(mission);
                                    mission.mark = '未复盘有差异';
                                    return;
                                }
                                _this.无差异列.push(mission);
                                mission.mark = '无差异';
                                return;
                            case '确认差异':
                                _this.确认差异列.push(mission);
                                mission.mark = '确认差异';
                                return;
                            case '否':
                                _this.未盘列.push(mission);
                                mission.mark = '未盘';
                                return;
                            case '跳过':
                                _this.跳过列.push(mission);
                                mission.mark = '跳过';
                                return;
                        }
                    });
                    _this.已复盘有差异列 = _this.按库位排序_且合并SKU一起(_this.已复盘有差异列);
                    _this.未复盘有差异列 = _this.按库位排序_且合并SKU一起(_this.未复盘有差异列);
                    _this.已复盘无差异列 = _this.按库位排序_且合并SKU一起(_this.已复盘无差异列);
                    _this.无差异列 = _this.按库位排序_且合并SKU一起(_this.无差异列);
                    _this.未盘列 = _this.按库位排序_且合并SKU一起(_this.未盘列);
                    if (_this.未盘列.length>0&&!_this.分割位置id) _this.分割位置id = _this.未盘列[0].id;
                    _this.分割位置id = _this.更新分割位置(_this.未盘分隔列2, _this.分割位置id);
                    _this.未盘分隔列 = _this.分隔_基于分割位置(_this.未盘列, _this.分割位置id);
                    _this.未盘分隔列1 = _this.按库位排序_且合并SKU一起(_this.未盘分隔列[0]);
                    _this.未盘分隔列2 = _this.按库位排序_且合并SKU一起(_this.未盘分隔列[1]);
                    _this.确认差异列 = _this.按库位排序_且合并SKU一起(_this.确认差异列);
                    _this.跳过列 = _this.按库位排序_且合并SKU一起(_this.跳过列);
                    _this.inventoryMissions = [];
                    _this.重推入(_this.inventoryMissions, _this.已复盘有差异列);
                    _this.重推入(_this.inventoryMissions, _this.未复盘有差异列);
                    _this.重推入(_this.inventoryMissions, _this.未盘分隔列2);
                    _this.重推入(_this.inventoryMissions, _this.未盘分隔列1);
                    _this.重推入(_this.inventoryMissions, _this.确认差异列);
                    _this.重推入(_this.inventoryMissions, _this.已复盘无差异列);
                    _this.重推入(_this.inventoryMissions, _this.无差异列);
                    _this.重推入(_this.inventoryMissions, _this.跳过列);
                },
                更新分割位置(上次分割列, 旧分割位置id) {
                    if (!上次分割列) return 旧分割位置id;
                    let is不更新 = false;
                    上次分割列.some(function (行) {
                        if (行.id === 旧分割位置id && 行.mark === '未盘') {
                            is不更新 = true;
                            return true;
                        }
                    });
                    if (is不更新) return 旧分割位置id;
                    let 新分割位置id = 旧分割位置id;
                    上次分割列.some(function (行) {
                        if (行.mark !== '未盘') return false;
                        新分割位置id = 行.id;
                        return true;
                    });
                    return 新分割位置id;
                },
                重推入(目标数组, 推入数组) {
                    推入数组.forEach(function (元素) {
                        目标数组.push(元素);
                    })
                },
                按库位排序_且合并SKU一起(inventoryMissions) {
                    let 结果列 = [];
                    let 已出现字典列 = [];
                    inventoryMissions.sort(function (a, b) {
                        if (a.location > b.location) return 1;
                        if (a.location < b.location) return -1;
                        return 0;
                    });

                    function 迭代查重转移(目标列, 进度下标) {
                        if (!进度下标) {
                            进度下标 = 0;
                        }
                        for (; 进度下标 < 目标列.length; 进度下标++) {
                            let 目标 = 目标列[进度下标];
                            if (已出现字典列[目标.commodity.barcode] === true) {
                                目标列.splice(进度下标, 1)
                                let 最后一次重复下标 = -1;//为了给相同条码依次排序设定
                                结果列.some(function (结果, i) {
                                    if (结果.commodity.barcode === 目标.commodity.barcode) {
                                        最后一次重复下标 = i;
                                        if (最后一次重复下标 === 结果列.length - 1) {
                                            结果列.splice(最后一次重复下标 + 1, 0, 目标);
                                            return true;
                                        }
                                    } else if (最后一次重复下标 > -1) {
                                        结果列.splice(最后一次重复下标 + 1, 0, 目标);
                                        return true;
                                    }
                                    return false;
                                })
                                迭代查重转移(目标列, 进度下标);
                                return;
                            }
                            已出现字典列[目标.commodity.barcode] = true;
                            结果列.push(目标);
                        }
                    }

                    迭代查重转移(inventoryMissions)
                    return 结果列;
                },
                选中盘点起始位置(id,location) {
                    this.分割位置id = id;
                    this.重排序并标记全列表类型();
                    tempTip.setDuration(2000);
                    tempTip.showSuccess('已将库位:' + location + '的盘点记录设置为起始盘点记录');
                },
                分隔_基于分割位置(未盘列,分割位置id) {  // return [arr1,arr2]
                    let 分割位置=null;
                    未盘列.forEach(function(行,下标){
                        if(行.id===分割位置id){
                            分割位置=下标;
                        }
                    });
                    let 未盘列1=未盘列.slice(0,分割位置);
                    let 未盘列2=未盘列.slice(分割位置,未盘列.length);
                    return [未盘列1,未盘列2];
                },
                删除盘点记录(inventoryAccountMissionId, inventoryAccountId, name) {
                    let _this = this;
                    if (!confirm('确定要删除商品为：“' + name + '”的盘点记录吗？')) {
                        return
                    }
                    ;
                    let url = '{{url('inventory/删除盘点记录')}}';
                    axios.post(url, {
                        inventoryAccountMissionId: inventoryAccountMissionId,
                        inventoryAccountId: inventoryAccountId
                    }).then(
                        function (response) {
                            if (!response.data.success) {
                                tempTip.setDuration(2000);
                                tempTip.show('盘点单号:' + inventoryAccountMissionId + '删除失败!' + response.data.data);
                            } else {
                                _this.inventoryMissions.every(function (inventoryAccountMission, i) {
                                    if (response.data.data > 0 && inventoryAccountMission.id === inventoryAccountMissionId) {
                                        _this.inventoryMissions.splice(i, 1);
                                        return false;
                                    }
                                    return true
                                });
                                tempTip.setDuration(2000);
                                tempTip.showSuccess('盘点记录:' + inventoryAccountMissionId + '删除成功!');
                            }
                        }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('删除失败,网络链接错误！' + err);
                    });
                },
                跳过盘点记录(inventoryAccountMissionId, inventoryAccountId, name) {
                    let _this = this;
                    if (!confirm('确定要跳过商品为：“' + name + '”的盘点记录吗？')) {return ;}
                    let url = '{{url('inventory/跳过盘点记录')}}';
                    axios.post(url, {
                        inventoryAccountMissionId: inventoryAccountMissionId,
                        inventoryAccountId: inventoryAccountId
                    }).then(
                        function (response) {
                            if (!response.data.success) {
                                tempTip.setDuration(3000);
                                tempTip.show('盘点单号:' + inventoryAccountMissionId + '跳过盘点失败!' + response.data.data);
                            } else {
                                _this.inventoryMissions.every(function (inventoryAccountMission) {
                                    if (inventoryAccountMission.id === inventoryAccountMissionId) {
                                        inventoryAccountMission.checked = response.data.inventoryAccountMission.checked;
                                        return false;
                                    }
                                    return true
                                });
                            }
                            _this.重排序并显示();
                            tempTip.setDuration(3000);
                            tempTip.showSuccess('盘点记录:' + inventoryAccountMissionId + '跳过盘点成功!');
                        }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('跳过盘点记录失败,网络链接错误！' + err);
                    });
                },
                确认盘点差异(inventoryAccountMissionId, inventoryAccountId, name) {
                    let _this = this;
                    if (!confirm('确定提交商品为：“' + name + '”的盘点差异吗？')) {return ;}
                    let url = '{{url('inventory/确认盘点差异')}}';
                    axios.post(url, {
                        inventoryAccountMissionId: inventoryAccountMissionId,
                        inventoryAccountId: inventoryAccountId
                    }).then(
                        function (response) {
                            if (!response.data.success) {
                                tempTip.setDuration(3000);
                                tempTip.show('盘点单号:' + inventoryAccountMissionId + '提交盘点差异失败!' + response.data.data);
                            } else {
                                _this.inventoryMissions.every(function (inventoryAccountMission) {
                                    if (inventoryAccountMission.id === inventoryAccountMissionId) {
                                        inventoryAccountMission.checked = response.data.inventoryAccountMission.checked;
                                        return false;
                                    }
                                    return true
                                });
                            }
                            _this.重排序并显示();
                            tempTip.setDuration(3000);
                            tempTip.showSuccess('盘点记录:' + inventoryAccountMissionId + '提交盘点差异成功!');
                        }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('提交盘点差异记录失败,网络链接错误！' + err);
                    });
                },
                批量跳过或确认差异(){
                    let _this = this;
                    if (!confirm('确定对勾选内容进行批量操作吗？')) {return ;}
                    let url = '{{url('inventory/批量跳过或确认差异')}}';
                    axios.post(url, {checkData: checkData}).then(
                        function (response) {
                            if (!response.data.success) {
                                tempTip.setDuration(3000);
                                tempTip.show('批量操作失败!' + response.data.data);
                            } else {
                                response.data.inventoryAccountMissions.forEach(function (mission) {
                                    _this.库位索引_记录[mission.location].forEach(function(missionInIndex){
                                        if(parseInt(missionInIndex.id)===parseInt(mission.id)){
                                            missionInIndex.checked=mission.checked;
                                        }
                                    });
                                });
                            }
                            _this.重排序并显示();
                            _this.清空checkbox();
                            tempTip.setDuration(3000);
                            tempTip.showSuccess('批量操作成功!');
                        }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('批量操作失败,网络链接错误！' + err);
                    });
                },
                重排序并显示(){
                    let _this=this;
                    _this.显示记录列=[];
                    _this.重排序并标记全列表类型(_this.inventoryMissions);
                    _this.加载下方数据并置空上方数据();
                },
                完结盘点任务(id, owner_name, type) {
                    if (!confirm('确定完结货主为：“' + owner_name + '”的“' + type + '”任务吗？')) {
                        return;
                    }
                    let url = '{{url('inventory/完结盘点任务')}}/' + id;
                    axios.get(url).then(function (response) {
                        if (!response.data.success) {
                            tempTip.setDuration(3000);
                            tempTip.show('修改完结状态失败!');
                        } else {
                            if (response.data.data.id === id) {
                                tempTip.setDuration(3000);
                                tempTip.showSuccess('货主为：“' + owner_name + '”的“' + type + '”任务完结成功');
                                window.setTimeout(function () {
                                    window.location.href = '{{url('inventory/stockInventory/mission')}}';
                                }, 1000);
                            }
                        }
                    }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('修改完结状态失败!  ' + err);
                    })
                },
                增加系统之外的盘点记录(location, barcode, count, inventoryId, owner_code, param) {
                    let _this = this;
                    let url = '{{url('inventory/增加系统之外的盘点记录')}}';
                    axios.post(url, {location:location,barcode:barcode,count:count,inventoryId:inventoryId,owner_code:owner_code,param:param}).then(
                        function (response) {
                            if (!response.data.success) {
                                tempTip.setDuration(3000);
                                tempTip.show('增加系统之外的盘点记录失败!');
                            } else {
                                let inventoryAccountMission=response.data.inventoryAccountMission;
                                inventoryAccountMission.commodity_barcodes = response.data.inventoryAccountMission.commodity.barcodes;
                                inventoryAccountMission.commodity_name = response.data.inventoryAccountMission.commodity.name;
                                inventoryAccountMission.stockInventoryPersons = response.data.stockInventoryPersons;
                                inventoryAccountMission.produced_at = '';
                                inventoryAccountMission.valid_at = '';
                                _this.inventoryMissions.push(inventoryAccountMission);
                                inventoryAccountMission.commodity_barcodes.forEach(function(barcode){
                                    if(!Array.isArray(_this.条码索引_记录[barcode.code])) _this.条码索引_记录[barcode.code]=[];
                                    _this.条码索引_记录[barcode.code].push(inventoryAccountMission);
                                });
                                if(!Array.isArray(_this.库位索引_记录[location])) _this.库位索引_记录[location]=[];
                                _this.库位索引_记录[location].push(inventoryAccountMission);
                                _this.重排序并显示();
                                _this.清空inputs();
                                tempTip.setDuration(3000);
                                tempTip.showSuccess('增加系统之外的盘点记录成功!');
                            }
                        }
                    ).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('增加系统之外的盘点记录失败,网络链接错误！' + err);
                    });
                },
                将相邻同样条目总数匹配的标记_供样式使用(inventoryMissions) {
                    for (let i = 0; i < inventoryMissions.length; i++) {
                        let 相同条码组 = [];

                        function 抽出紧邻相同条码(起始下标) {
                            let 下标B = 起始下标 + 1;
                            if (下标B >= inventoryMissions.length) return;
                            if (inventoryMissions[起始下标].commodity.barcode === inventoryMissions[下标B].commodity.barcode) {
                                if (相同条码组.length <= 1 || 相同条码组[相同条码组.length - 1].id !== inventoryMissions[起始下标].id) {
                                    相同条码组.push(inventoryMissions[起始下标]);
                                }
                                相同条码组.push(inventoryMissions[下标B]);
                                return 抽出紧邻相同条码(下标B);
                            }
                            return 下标B;
                        }

                        i = 抽出紧邻相同条码(i);
                        let 库存总数 = 0;
                        let 实盘总数 = 0;
                        相同条码组.forEach(function (目标) {
                            库存总数 += 目标.stored_amount;
                            实盘总数 += 目标.verified_amount;
                        })
                        if (库存总数 === 实盘总数)
                            相同条码组.forEach(function (目标) {
                                目标.hasLinkingGroup = true;
                            })
                    }
                    ;
                },
                清理标记(mission) {
                    mission.hasLinkingGroup = false;
                },
                盘点(id, location, barcode, inventoryId, count) {
                    let _this = this;
                    let url = '{{url('inventory/stockInventory')}}';
                    axios.post(url, {id:id,location:location,barcode:barcode,count:count,inventoryId:inventoryId})
                        .then(function (response) {
                            if (!response.data.success) {
                                tempTip.setDuration(2000);
                                tempTip.show('盘点失败!' + '   ' + response.data.data);
                                return;
                            }
                            if (_this.inventory.id === response.data.inventory.id) {
                                _this.inventory.processed = response.data.inventory.processed;
                                _this.inventory.surplus = response.data.inventory.surplus;
                                _this.inventory.check_surplus = response.data.inventory.check_surplus;
                            }
                            _this.inventoryMissions.every(function (inventoryMission, i) {
                                if (parseInt(inventoryMission.id) === parseInt(response.data.inventoryMission.id)) {
                                    inventoryMission.checked = response.data.inventoryMission.checked;
                                    inventoryMission.verified_amount = response.data.inventoryMission.verified_amount;
                                    inventoryMission.difference_amount = response.data.inventoryMission.difference_amount;
                                    inventoryMission.re_checked_amount = response.data.inventoryMission.re_checked_amount;
                                    inventoryMission.stockInventoryPersons = response.data.stockInventoryPersons;
                                    _this.inventoryMissions.splice(i, 1)
                                    _this.inventoryMissions.unshift(inventoryMission);
                                    return false;
                                }
                                return true;
                            });
                            _this.重排序并显示();
                            if (response.data.inventoryMission.difference_amount!==0)_this.初盘有盘点差异_确认是否重盘();
                            if (response.data.inventoryMission.difference_amount===0){
                                _this.清空inputs();
                                tempTip.setDuration(3000);
                                tempTip.showSuccess('盘点成功！');
                                _this.放置焦点光标至正确位置();
                            }
                        }).catch(function (err) {
                        tempTip.setDuration(2000);
                        tempTip.show('盘点失败!' + '网络错误' + err);
                    })
                },
                初盘有盘点差异_确认是否重盘(){
                    let _this=this;
                    tempTip.confirm('<p class="text-danger">'+"当前盘点数量存在差异，是否重盘当前盘点记录？"+'</p>',function () {
                            _this.放置焦点光标至正确位置();
                            _this.提交库位和条码();
                        },
                        function () {
                            _this.清空inputs();
                            _this.放置焦点光标至正确位置();
                            tempTip.setDuration(3000);
                            tempTip.showSuccess('盘点成功！');
                        },'是','否')
                },
                清空inputs(){
                    $locationInput.val('');
                    $barcodeInput.val('');
                    $amountInput.val('');
                    for(let key in this.inputs()){
                        this.inputs()[key]='';
                    }
                },
                清空checkbox(){
                    checkData=[];
                },
                不覆盖() {
                    let _this = this;
                    _this.清空指定盘点记录列();
                    _this.清空inputs();
                },
                覆盖(){
                    let _this=this;
                    let location=_this.inputs().location.trim();
                    let barcode=_this.inputs().barcode.trim();
                    let inventoryId=_this.inventory.id;
                    let count=_this.inputs().amount.trim();
                    let id=_this.selectingId;
                    _this.清空指定盘点记录列();
                    this.盘点(id, location, barcode, inventoryId, count);
                },
                盘点选中任务(e){
                    let _this=this;
                    let id = $(e.target).attr('data_id');
                    let inventoryId=_this.inventory.id;
                    let count=_this.inputs().amount.trim();
                    let produced_at=_this.inputs().produced_at.trim();
                    let valid_at=_this.inputs().valid_at.trim();
                    let batch_number=_this.inputs().batch_number.trim();
                    let url = '{{url('inventory/盘点选中任务')}}';
                    axios.post(url, {id:id,count:count,inventoryId:inventoryId,produced_at:produced_at,valid_at:valid_at,batch_number:batch_number}).then(function (response) {
                        if (!response.data.success) {
                            tempTip.setDuration(2000);
                            tempTip.show('盘点失败!' + '   ' + response.data.data);
                            return;
                        }else {
                            if (_this.inventory.id === response.data.inventory.id) {
                                _this.inventory.processed = response.data.inventory.processed;
                                _this.inventory.surplus = response.data.inventory.surplus;
                                _this.inventory.check_surplus = response.data.inventory.check_surplus;
                            }
                                    if (response.data.inventoryMission.length >1) {
                                        response.data.inventoryMission.forEach(function (mission) {
                                            let isToEdit=false;
                                            let commodity_barcodes=mission.commodity_barcodes;
                                            _this.库位索引_记录[_this.inputs().location.trim()].every(function (inventoryMission){
                                                if (parseInt(inventoryMission.id) === parseInt(mission.id)){
                                                    isToEdit=true;
                                                    inventoryMission.checked = mission.checked;
                                                    inventoryMission.verified_amount = mission.verified_amount;
                                                    inventoryMission.difference_amount =mission.difference_amount;
                                                    inventoryMission.re_checked_amount = mission.re_checked_amount;
                                                    inventoryMission.stockInventoryPersons = response.data.stockInventoryPersons;
                                                    return false;
                                                }
                                                return true;
                                            })
                                    if (!isToEdit){
                                        mission.commodity_barcodes= commodity_barcodes;
                                        mission.stockInventoryPersons=response.data.stockInventoryPersons;
                                        _this.inventoryMissions.push(mission);
                                    }
                                });
                            }else {
                                _this.库位索引_记录[_this.inputs().location.trim()].every(function (inventoryMission,i) {
                                    if (parseInt(inventoryMission.id) === parseInt(response.data.inventoryMission.id)){
                                        inventoryMission.checked = response.data.inventoryMission.checked;
                                        inventoryMission.verified_amount = response.data.inventoryMission.verified_amount;
                                        inventoryMission.difference_amount = response.data.inventoryMission.difference_amount;
                                        inventoryMission.re_checked_amount = response.data.inventoryMission.re_checked_amount;
                                        inventoryMission.stockInventoryPersons = response.data.stockInventoryPersons;
                                        _this.inventoryMissions.splice(i, 1);
                                        _this.inventoryMissions.unshift(inventoryMission);
                                        return false;
                                    }
                                    return true;
                                })
                            }
                            _this.重排序并显示();
                            _this.清空inputs();
                            _this.清空指定盘点记录列();
                            tempTip.setDuration(3000);
                            tempTip.showSuccess('盘点成功!');
                        }
                    }).catch(function (err) {
                        tempTip.setDuration(2000);
                        tempTip.show('盘点失败!' + '网络错误' + err);
                    })

                },
                inventoryAccountMissionExport(checkAllSign) {
                    let url = '{{url('inventory/stockInventory/inventoryAccountMission/export')}}';
                    let token = '{{ csrf_token() }}';
                    let allData = [];
                    if (checkAllSign) {
                        allData = JSON.stringify(this.inventoryMissions);
                        let allData1 = JSON.parse(allData);
                        allData1.forEach(function (inventoryMission) {
                            if (inventoryMission.stock_persons.length > 0) inventoryMission.stock_person = inventoryMission.stock_persons[inventoryMission.stock_persons.length - 1].name;
                            if (inventoryMission.stock_persons.length<1) inventoryMission.stock_person='';
                            delete inventoryMission.commodity_barcodes;
                            delete inventoryMission.stock_persons;
                            delete inventoryMission.stockInventoryPersons;
                            delete inventoryMission.commodity;
                        });
                        let data = JSON.stringify(allData1);
                        excelExport(false,data,url,this.sum,token);
                    } else {
                        checkData.forEach(function (inventoryMission) {
                            if (inventoryMission.stock_persons.length > 0) inventoryMission.stock_person = inventoryMission.stock_persons[inventoryMission.stock_persons.length - 1].name;
                            if (inventoryMission.stock_persons.length <1) inventoryMission.stock_person='';
                            delete inventoryMission.commodity_barcodes;
                            delete inventoryMission.stock_persons;
                            delete inventoryMission.stockInventoryPersons;
                            delete inventoryMission.commodity;
                        });
                        let data = JSON.stringify(checkData);
                        excelExport(checkAllSign,data,url,this.sum,token);
                    }
                },
                stockInventoryByLocation(){
                    let _this=this;
                    let inventoryId=_this.inventory.id;
                    let difference=[];
                    let trPc = $("#blueTablePc tr:gt(1)").get();
                    let tr = $("#blueTable tr:gt(0)").get();
                    $(trPc).each(function(item,key){
                         input = $(key).find('.blueAmountPc');
                         let obj=new Object();
                         obj.id=input.attr('data_id');
                         obj.stored_amount=input.attr('stored_amount');
                         obj.amount=input.val();
                         if (input.val()) _this.库位盘点记录.push(obj);
                    });
                    $(tr).each(function(item,key){
                        input = $(key).find('.blueAmount');
                        let obj=new Object();
                        obj.id=input.attr('data_id');
                        obj.stored_amount=input.attr('stored_amount');
                        obj.amount=input.val();
                        if (input.val()) _this.库位盘点记录.push(obj);
                    });
                    let url = '{{url('inventory/stockInventory/batchStockByLocation')}}';
                    axios.post(url,{mission:_this.库位盘点记录,inventoryId:inventoryId}).then(function(response){
                        if (!response.data.success) {
                            tempTip.setDuration(2000);
                            tempTip.show('盘点失败!' + '   ' + response.data.msg);
                            return;
                        }else {
                            if (_this.inventory.id === response.data.inventory.id) {
                                _this.inventory.processed = response.data.inventory.processed;
                                _this.inventory.surplus = response.data.inventory.surplus;
                                _this.inventory.check_surplus = response.data.inventory.check_surplus;
                            }
                                response.data.inventoryMission.forEach(function (mission) {
                                    if(mission.difference_amount>0) difference.push(mission.commodity.barcodes[0].code);
                                    _this.inventoryMissions.every(function (inventoryMission,i){
                                        if (parseInt(inventoryMission.id) === parseInt(mission.id)){
                                            inventoryMission.checked = mission.checked;
                                            inventoryMission.verified_amount = mission.verified_amount;
                                            inventoryMission.difference_amount =mission.difference_amount;
                                            inventoryMission.re_checked_amount = mission.re_checked_amount;
                                            inventoryMission.stockInventoryPersons = response.data.stockInventoryPersons;
                                            _this.inventoryMissions.splice(i, 1);
                                            _this.inventoryMissions.unshift(inventoryMission);
                                            return false;
                                        }
                                        return true;
                                    })
                                });
                            _this.重排序并显示();
                            _this.清空inputs();
                            _this.清空指定盘点记录列();
                            tempTip.setDuration(5000);
                            if (difference.length>0){
                                tempTip.show('给库位下：条码为'+difference+'存在差异，如需重盘请针对该条码重新盘点！');
                                difference=[];
                            }else {
                                tempTip.showSuccess('盘点成功!');
                            }
                        }
                    }).catch(function (err) {
                        tempTip.setDuration(2000);
                        tempTip.show('盘点失败!' + '网络错误' + err);
                    })
                },
                新增盘点记录(){
                    let _this=this;
                    _this.addInventoryMission=true;
                    _this.清空指定盘点记录列();
                },
                收起新增(){
                    let _this=this;
                    _this.addInventoryMission=false;
                    _this.清空指定盘点记录列();
                },
                盲收(){
                    let _this=this;
                    _this.blindReceive=true;
                    _this.scanListening();
                },
                正常盘点(){
                    let _this=this;
                    _this.blindReceive=false;
                    $(document).off('keypress');
                },
                changeToManualInputAmount:function(){
                    this.status.amountDisable=false;
                    this.isManualInputtingAmount=true;
                    $('#amountLabel').text('输入数量：');
                },
                changeToScanInputAmount:function(){
                    this.status.amountDisable=true;
                    this.isManualInputtingAmount=false;
                    $('#amountLabel').text('自动扫入数量：');
                },
                changeToManualInputBarcode:function(){
                    this.status.barcodeDisable=false;
                    this.isManualInputtingBarcode=true;
                    $('#barcode').attr('placeholder','手工输入条码');
                },
                changeToScanInputBarcode:function(){
                    let data = this;
                    this.isManualInputtingBarcode=false;
                    this.inputting.barcode='';

                    let $barcode = $('#barcode');
                    this.status.barcodeDisable=false;
                    setTimeout(function () {
                        $barcode.focus();
                        data.status.barcodeDisable=true;
                    },20);
                    $barcode.attr('placeholder','扫入条码');
                },
                oninputEnter:function(e){
                    if (e.key === 'Enter') {
                        this.focusDocument();
                    }
                },
                focusDocument: function () {
                    this.focusing = 'document';
                    this.showCommitButton();
                },
                focusOutDocument: function () {
                    this.focusing = '';
                    this.autoFillBin();
                },
                scanListening: function () {
                    let data = this;
                    $(document).on('keypress', function (e) {
                        if(data.focusing!=='document'){return}
                        if(data.isManualInputtingBarcode){return}
                        if (e.keyCode !== 13) {
                            if(data.status.scanEndInputted){
                                data.lastScannedBarcode=data.inputting.barcode;
                                data.inputting.barcode='';
                                data.status.scanEndInputted=false;
                            }
                            data.inputting.barcode += String.fromCharCode(e.keyCode);
                        } else {
                            if(data.inputting.barcode.length<=1){
                                window.tempTip.setDuration(4500);
                                window.tempTip.show('未扫入条码，请检查扫码枪设置，尝试调至“直接键盘输出”模式');
                                return;
                            }
                            data.status.scanEndInputted = true;
                            data.showCommitButton();
                            data.autoFillBin();
                            switch(data.inputMode){
                                case 'increasing': data.commitGoodsOnIncreasingMode();break;
                                case 'multiIncreasing': data.commitGoodsOnMultiIncreasingMode();break;
                            }
                        }
                    });
                },
                commitGoodsOnIncreasingMode: function () {
                    let data = this;
                    function doIt(){
                        let repeatedBarcode=data.repeatedIncreasingBarcodeFromSaved();
                        function increase(){
                            data.inputting.bin=repeatedBarcode.bin;
                            repeatedBarcode.amount++;
                            data.inputting.amount=repeatedBarcode.amount;
                            window.tempTip.setDuration(500);
                            window.tempTip.showSuccess(repeatedBarcode.amount);
                            data.focusDocument();
                            data.audioDing();
                        }
                        if(!repeatedBarcode){
                            data.focusOutDocument();
                            data.alertVibrate();
                            window.tempTip.setInputType('number');
                            data.inputting.amount=1;
                            data.goodses.unshift(JSON.parse(JSON.stringify(data.inputting)));
                            data.status.binDisable=true;
                            window.tempTip.setDuration(500);
                            window.tempTip.showSuccess('保存成功');
                            data.focusDocument();
                            data.audioDing();
                        }else{
                            increase();
                        }
                    }
                    if(data.lastScannedBarcode!==data.inputting.barcode && data.lastScannedBarcode){
                        data.audioWarning_otherBarcode();
                        data.focusOutDocument();
                        window.tempTip.confirm('扫到其它条码，是否切换至新条码并记录？',doIt,function () {
                            data.inputting.barcode=data.lastScannedBarcode;
                            data.focusDocument();
                        })
                    }else{
                        doIt()
                    }
                },
                commitGoodsOnMultiIncreasingMode: function () {
                    let data = this;
                    let repeatedBarcode=this.repeatedIncreasingBarcodeFromSaved();
                    function increase(){
                        data.inputting.bin=repeatedBarcode.bin;
                        repeatedBarcode.amount++;
                        data.inputting.amount=repeatedBarcode.amount;
                        window.tempTip.setDuration(500);
                        window.tempTip.showSuccess(repeatedBarcode.amount);
                        data.focusDocument();
                        data.audioDing();
                    }
                    if(!repeatedBarcode){
                        data.focusOutDocument();
                        data.alertVibrate();
                        window.tempTip.setInputType('number');
                        data.inputting.amount=1;
                        data.goodses.unshift(JSON.parse(JSON.stringify(data.inputting)));
                        data.status.binDisable=true;
                        window.tempTip.setDuration(500);
                        window.tempTip.showSuccess('保存成功');
                        data.focusDocument();
                        data.audioDing();
                    }else{
                        increase();
                    }
                },
                audioWarning_otherBarcode: function () {
                    let audio = document.getElementById('soundWarning');
                    audio.currentTime = 0;//重新播放
                    if(audio.paused){
                        audio.play();// 播放
                    }
                    this.alertVibrate();

                },
                audioDing: function () {
                    let audio = document.getElementById('soundDing');
                    audio.currentTime = 0;//重新播放
                    audio.play();// 播放
                    function startVibrate(duration) {
                        if (navigator.vibrate) {
                            navigator.vibrate(duration);
                        } else if (navigator.webkitVibrate) {
                            navigator.webkitVibrate(duration);
                        }
                    }
                    startVibrate(500);
                },
                alertVibrate: function () {
                    function startVibrate(duration) {
                        if (navigator.vibrate) {
                            navigator.vibrate(duration);
                        } else if (navigator.webkitVibrate) {
                            navigator.webkitVibrate(duration);
                        }
                    }
                    let vibrateInterval = setInterval(function() {
                        startVibrate(150);
                    }, 50);
                    setTimeout(function() {
                        clearInterval(vibrateInterval)
                    }, 2000);
                },
                autoFillBin: function () {
                    let data = this;
                    let isNotRepeatingBarcode=this.goodses.every(function(goods){
                        if(goods.barcode===data.inputting.barcode){
                            data.inputting.bin=goods.bin;
                            data.status.binDisable=true;
                            return false;
                        }
                        return true;
                    });
                    if(isNotRepeatingBarcode){
                        data.status.binDisable=false;
                    }
                },
                repeatedIncreasingBarcodeFromSaved: function () {
                    let data = this;
                    let repeatedGoods=null;
                    data.goodses.every(function(goods){
                        if(goods.barcode===data.inputting.barcode && goods.fromIncreasing){
                            repeatedGoods=goods;
                            return false;
                        }
                        return true;
                    });
                    return repeatedGoods;
                },
                commitGoods: function () {
                    let data = this;
                    window.tempTip.setDuration(3500);
                    if(!data.inputting.barcode){window.tempTip.show('请扫入条码');return;}
                    else if(!data.inputting.amount){window.tempTip.show('请输入数量');return;}
                    //else if(!data.inputting.bin){window.tempTip.show('请输入隔口号');return;}
                    data.recordOrPlusGoods();
                    window.tempTip.setDuration(1500);
                    window.tempTip.showSuccess('成功提交：' + data.inputting.barcode);
                    data.cleanInputs();
                    data.audioDing();
                },
                cleanInputs: function () {
                    this.changeToScanInputBarcode();
                    this.inputting.barcode='';
                    this.inputting.amount='';
                    this.inputting.bin='';
                    this.inputting.produce_date='';
                    this.inputting.valid_date='';
                    this.inputting.batch_number='';
                    this.commitButtonVisible=false;
                    this.status.binDisable=false;
                    this.lastScannedBarcode='';
                },
                recordOrPlusGoods: function () {
                    let data = this;
                    if(this.inputMode==='regular'){
                        data.goodses.unshift(JSON.parse(JSON.stringify(data.inputting)));
                        return;
                    }
                    let isNotRepeating=data.goodses.every(function(goods){
                        if(goods.barcode===data.inputting.barcode){
                            goods.amount=parseInt(goods.amount)+parseInt(data.inputting.amount);
                            return false;
                        }
                        return true;
                    });
                    if(isNotRepeating){
                        data.goodses.unshift(JSON.parse(JSON.stringify(data.inputting)));
                    }
                },
                removeGoods: function ($e,barcode) {
                    if(!confirm('确定要删除条码为'+barcode+'的记录吗'))return;
                    let data = this;
                    data.goodses.every(function(goods,i){
                        if(goods.barcode===barcode){
                            data.goodses.splice(i,1)
                            return false;
                        }
                        return true;
                    })
                },
                showCommitButton: function () {
                    let data = this;
                    if(data.inputting.barcode && data.inputting.amount /*&& data.inputting.bin*/){
                        data.commitButtonVisible=true;
                    }else{
                        if (this.inputMode==='regular' && this.status.barcodeDisable && !this.inputting.amount && this.inputting.barcode){
                            this.focusing = '';
                            document.getElementById('amount').focus();
                        }
                    }
                },
                submitStockInventory: function () {
                    let data = this;
                    data.focusOutDocument();
                    if(data.goodses.length===0){
                        window.tempTip.show('请先录入数据再提交盘点');return;
                    }
                    if(!data.location){
                        window.tempTip.setDuration(1500);
                        window.tempTip.show('库位为必填项');
                        return;
                    }
                    window.tempTip.confirm('请检查表格，确定全部完成。提交后数据将全部清空，不能后退',
                        function () {
                            let url='{{url("inventory/stockInventory/baseOnBlindReceive")}}';
                            axios.post(url,{'location':data.location,'goodses':data.goodses,'inventoryId':data.inventory.id,'owner_code':data.inventory.owner.code})
                                .then(function(response){
                                    if(response.data.success){
                                        data.goodses=[];
                                        data.cleanInputs();
                                        window.tempTip.cancelWaitingTip();
                                        if (data.inventory.id === response.data.inventory.id) {
                                            data.inventory.processed = response.data.inventory.processed;
                                            data.inventory.surplus = response.data.inventory.surplus;
                                            data.inventory.check_surplus = response.data.inventory.check_surplus;
                                        }
                                        if (response.data.inventoryMissions.length >0) {
                                            response.data.inventoryMissions.forEach(function (mission) {
                                                let isToEdit=false;
                                                data.inventoryMissions.every(function (inventoryMission){
                                                    if (parseInt(inventoryMission.id) === parseInt(mission.id)){
                                                        isToEdit=true;
                                                        inventoryMission.checked = mission.checked;
                                                        inventoryMission.verified_amount = mission.verified_amount;
                                                        inventoryMission.difference_amount =mission.difference_amount;
                                                        inventoryMission.re_checked_amount = mission.re_checked_amount;
                                                        inventoryMission.stockInventoryPersons = response.data.stockInventoryPersons;
                                                        return false;
                                                    }
                                                    return true;
                                                })
                                                if (!isToEdit){
                                                    mission.commodity_barcodes = mission.commodity.barcodes;
                                                    mission.stockInventoryPersons=response.data.stockInventoryPersons;
                                                    data.inventoryMissions.push(mission);
                                                }
                                            });
                                        }
                                        data.重排序并标记全列表类型(data.inventoryMissions);
                                        window.tempTip.setDuration(1500);
                                        window.tempTip.showSuccess('盲收盘点成功，可返回盘点页面查看');
                                        data.location='';
                                        data.focusDocument();
                                    }else{
                                        window.tempTip.setDuration(1500);
                                        window.tempTip.show('盲收盘点失败：'+response.data.fail_info);
                                        data.focusDocument();
                                        data.alertVibrate()
                                    }
                                })
                                .catch(function (err) {
                                    window.tempTip.setDuration(3500);
                                    window.tempTip.show('网络或系统错误，请将以下信息提交给开发者：'+err);
                                    data.alertVibrate();
                                });
                        },function () {
                            data.focusDocument();
                        })
                }
            },
            computed: {
                borderByMode: function () {
                    return {
                        // 'border-info':this.inputMode==='regular',
                        'border-success':this.inputMode==='increasing',
                        'border-danger':this.inputMode==='multiIncreasing'
                    }
                }
            }



            // 单条排序并着色(inventoryMission){
            //     let _this=this;
            //     let 所在临时分类列=[];
            //     switch(inventoryMission.mark){
            //         case '已复盘有差异':所在临时分类列=_this.已复盘有差异列;break;
            //         case '已复盘无差异':所在临时分类列=_this.已复盘无差异列;break;
            //         case '未复盘有差异':所在临时分类列=_this.未复盘有差异列;break;
            //         case '无差异':所在临时分类列=_this.无差异列;break;
            //         case '未盘':所在临时分类列=_this.未盘列;break;
            //     }
            // },

        });
    </script>
@endsection
