<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
    .table-striped-left{
        width: 41%;
        /*margin-right: 4px;*/
    }
    .table-striped-right{
        /*right: -10px;*/
        width: 58%;
        float: right;
    }
    .info_text{
        float: right;
    }
    .info_text li{
        font-size: 16px;
    }
    .info_text li span{
        font-size: 20px;
        font-weight: bold;
        color: rgb(28,132,198);
    }
    .table-title{
        font-size: 12px;
        font-weight: 800;
        color: rgb(28,132,198);
    }
    button{
        border-radius: 100px;
        float: left;
    }
    .container-div .row {
        height: 0%;
    }
</style>
<body class="gray-bg">
<div class="container-div">

    <div class="row">
        <div class="col-sm-12 select-info">
            <form id="dept-form">
                <div class="select-list">
                    <div class="col-sm-5">
                        <ul class="select-list">
                            <li><span class="table-title">收货单号:</span></li>
                        </ul>
                        <div class="dropdown">
                            <button class="btn btn-success dropdown-toggle" data-toggle="dropdown" id="btn1">
                                此处为上游单号!!!
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                            </ul>
                        </div>
                    </div>
                    <div class="col-sm-7">
                        <ul class="info_text">
                            <li>物料总数:<span id="material_length"></span></li>
                            <li>总单据数量:<span id="qty_length"></span></li>
                            <li>已收货数量:<span id="qtyCompleted_length"></span></li>
                        </ul>
                    </div>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-info table-striped-left" style="padding-top: 20px;">
            <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                <div class="panel panel-default">
                    <div class="panel-heading" role="tab" id="heading0">
                        <h4 class="panel-title">
                            <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                未选择
                            </a>
                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading0">
                        <table id="bootstrap-table-0" data-mobile-responsive="true" class="table table-bordered  table-hover"></table>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading" role="tab" id="heading1">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                                未选择
                            </a>
                        </h4>
                    </div>
                    <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading1">
                        <table id="bootstrap-table-1" data-mobile-responsive="true" class="table table-bordered  table-hover"></table>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading" role="tab" id="heading2">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseTwo">
                                未选择
                            </a>
                        </h4>
                    </div>
                    <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading2">
                        <table id="bootstrap-table-2" data-mobile-responsive="true" class="table table-bordered  table-hover"></table>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading" role="tab" id="heading3">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFour" aria-expanded="false" aria-controls="collapseTwo">
                                未选择
                            </a>
                        </h4>
                    </div>
                    <div id="collapseFour" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading3">
                        <table id="bootstrap-table-3" data-mobile-responsive="true" class="table table-bordered  table-hover"></table>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading" role="tab" id="heading4">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFive" aria-expanded="false" aria-controls="collapseTwo">
                                未选择
                            </a>
                        </h4>
                    </div>
                    <div id="collapseFive" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading4">
                        <table id="bootstrap-table-4" data-mobile-responsive="true" class="table table-bordered  table-hover"></table>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading" role="tab" id="heading5">
                        <h4 class="panel-title">
                            <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseSix" aria-expanded="false" aria-controls="collapseTwo">
                                未选择
                            </a>
                        </h4>
                    </div>
                    <div id="collapseSix" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading5">
                        <table id="bootstrap-table-5" data-mobile-responsive="true" class="table table-bordered  table-hover"></table>
                    </div>
                </div>
            </div>

        </div>
        <div class="col-sm-12 select-info table-striped-right">
            <ul class="select-list">
                <li style="display: none">id:<input type="text" id="detailId"  /></li>
                <li>收货数量:<input type="text" id="receiveNum"  disabled/></li>
                <li>容器编号:<input type="text" id="containerCode"  /></li>
                <li><button class="btn btn-sm btn-success" onclick="receipt()">组盘</button></li>
            </ul>
            <hr style="border-top:1px solid white;">
            <ul class="select-list">
                <li><span class="table-title">本物料库存</span></li>
            </ul>
            <table id="bootstrap-table1" data-mobile-responsive="true" class="table table-bordered table-hover"></table>
            <ul class="select-list">
                <li><span class="table-title">地面储位</span></li>
            </ul>
            <table id="bootstrap-table5" data-mobile-responsive="true" class="table table-bordered table-hover"></table>
            <ul class="select-list">
                <li><span class="table-title">本物料交易</span></li>
            </ul>
            <table id="bootstrap-table2" data-mobile-responsive="true" class="table table-bordered table-hover"></table>
<!--            <ul class="select-list">-->
<!--                <li><span class="table-title">空储位</span></li>-->
<!--            </ul>-->
<!--            <table id="bootstrap-table3" data-mobile-responsive="true" class="table table-bordered table-hover"></table>-->
<!--            <ul class="select-list">-->
<!--                <li><span class="table-title">同仓储位</span></li>-->
<!--            </ul>-->
<!--            <table id="bootstrap-table4" data-mobile-responsive="true" class="table table-bordered table-hover"></table>-->
        </div>
    </div>

</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var addFlag = [[${@permission.hasPermi('receipt:receiving:add')}]];
    var removeFlag = [[${@permission.hasPermi('receipt:receiving:remove')}]];
    var prefix = ctx + "receipt/receiving";
    // var inventoryStatus = [[${@dict.getType('inventoryStatus')}]];
    var uWarehouseNames = [[${@warehouseWu.getName()}]];
    var company =[[${@companyService.getCode()}]];
    var arr=[];
    function list_select(code,num) {
        $.ajax({
            url: prefix + "/scanReferCodeBill",
            type: 'post',
            datatype: 'json',
            data: {
                code: code
            },
            error:function (response) {
                console.log(response);
            },
            success: function (value) {
                debugger;
                var qty_show=0;
                var qtyCompleted_show=0;
                console.log('#heading'+num+' '+'h4'+' '+'a');
                $('#heading'+num+' '+'h4'+' '+'a').html(code);
                $('#bootstrap-table'+'-'+num).bootstrapTable('removeAll');
                if(value.data){
                    for (var i = 0; i < value.data.length; i++) {
                        if (value.data[i].qty > value.data[i].taskQty) {
                            $('#bootstrap-table'+'-'+num).bootstrapTable('insertRow', {
                                index: 0, row: {
                                    companyCode:value.data[i].companyCode,
                                    uWarehouseCode:value.data[i].uWarehouseCode,
                                    id: value.data[i].id,
                                    receiptId: value.data[i].receiptId,
                                    receiptCode: value.data[i].receiptCode,
                                    materialCode: value.data[i].materialCode,
                                    materialName: value.data[i].materialName,
                                    materialSpec: value.data[i].materialSpec,
                                    qty: value.data[i].qty,
                                    taskQty: value.data[i].taskQty,
                                    inventorySts: value.data[i].inventorySts,
                                    unit: value.data[i].unit,
                                    zoneCode:value.data[i].zoneCode,
                                    referCode:value.data[i].referCode,
                                    referLineNum:value.data[i].referLineNum,
                                }
                            });
                        }
                        qty_show=value.data[i].qty + qty_show;
                        qtyCompleted_show=value.data[i].taskQty + qtyCompleted_show;
                    }
                    // $("#material_length").text(value.data.length);
                    // $("#qty_length").text(qty_show);
                    // $("#qtyCompleted_length").text(qtyCompleted_show);
                    var obj={
                        "material_length":value.data.length,
                        "qty_length":qty_show,
                        "qtyCompleted_length":qtyCompleted_show
                    }
                    arr.push(obj);
                }
                else    {
                    console.log("收货单不存在!")
                }
            }
        })
    }

    $("#list-btn").click(initTable);

    $("body").bind("keypress",function(e){
        // 兼容FF和IE和Opera
        var theEvent = e || window.event;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            e.preventDefault();
            //回车执行查询
            initTable();
        }
    });

    function initTable(result){
        debugger;
        arr=[];
        if(result){
            for (var i = 0; i < result.length; i++) {
                debugger;
                const num = i;
                list_select(result[num],num);
            }
        }else {
            $("#containerCode").val("");
        }
        $("#bootstrap-table1").bootstrapTable('removeAll');
        $("#bootstrap-table2").bootstrapTable('removeAll');
        // $("#bootstrap-table3").bootstrapTable('removeAll');
        // $("#bootstrap-table4").bootstrapTable('removeAll');
        $("#bootstrap-table5").bootstrapTable('removeAll');
    }

    function setInit(value,qty_show,qtyCompleted_show){
        $("#material_length").text(value);
        $("#qty_length").text(qty_show);
        $("#qtyCompleted_length").text(qtyCompleted_show);
    }
    $("#bootstrap-table-0").bootstrapTable({
        // url: prefix + "/list",
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        clickToSelect: true,
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 50,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50,100],
        modalName: "收货",
        contentType: "application/x-www-form-urlencoded",
        onClickRow:function(row,ele,field){
            let code=result[0];
            $("#btn1").html(code).append("<span class=\"caret\"></span>");
            $("#detailId").val(row.id);
            $("#receiveNum").val(row.qty-row.taskQty);
            setInit(arr[0].material_length,arr[0].qty_length,arr[0].qtyCompleted_length);
            $.ajax({
                url:prefix+'/getReceiptInfoByReferBillKS',
                type:'post',
                data:{
                    code:code,
                    id:row.id
                },
                success:res=>{
                    $("#bootstrap-table1").bootstrapTable('load',res.data.list);
                    $("#bootstrap-table5").bootstrapTable('load',res.data.containers);
                    $("#bootstrap-table2").bootstrapTable('load',res.data.transactionList);
                    // $("#bootstrap-table3").bootstrapTable('load',res.data.containerList);
                    // $("#bootstrap-table4").bootstrapTable('load',res.data.inventoryList);
                }
            })
        },
        columns: [
            {
                field : 'id',
                title : '明细id',
                sortable:false
            },
            {
                field : 'materialCode',
                title : '存货编码',
                sortable:true
            },
            {
                field:"materialName",
                title:"名称",
                sortable:true
            },
            {
                field:"materialSpec",
                title:"规格",
                sortable:true
            },
            {
                field : 'qty',
                title : '单据数量'
            },
            {
                field : 'taskQty',
                title : '已入数量'
            },
            {
                field : 'inventorySts',
                title : '库存状态'
            },
            {
                field : 'referCode',
                title : '上游订单号'
            },
            {
                field : 'referLineNum',
                title : '上游订单行号'
            },
            {
                field : 'lot',
                title : '批号'
            },
        ]
    });
    $("#bootstrap-table-1").bootstrapTable({
        // url: prefix + "/list",
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        clickToSelect: true,
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 50,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50,100],
        modalName: "收货",
        contentType: "application/x-www-form-urlencoded",
        onClickRow:function(row,ele,field){
            let code=result[1];
            $("#btn1").html(code).append("<span class=\"caret\"></span>");
            $("#detailId").val(row.id);
            $("#receiveNum").val(row.qty-row.taskQty);
            setInit(arr[1].material_length,arr[1].qty_length,arr[1].qtyCompleted_length);
            $.ajax({
                url:prefix+'/getReceiptInfoByReferBillKS',
                type:'post',
                data:{
                    code:code,
                    id:row.id
                },
                success:res=>{
                    $("#bootstrap-table1").bootstrapTable('load',res.data.list);
                    $("#bootstrap-table5").bootstrapTable('load',res.data.containers);
                    $("#bootstrap-table2").bootstrapTable('load',res.data.transactionList);
                    // $("#bootstrap-table3").bootstrapTable('load',res.data.containerList);
                    // $("#bootstrap-table4").bootstrapTable('load',res.data.inventoryList);
                }
            })
        },
        columns: [
            {
                field : 'id',
                title : '明细id',
                sortable:false
            },
            {
                field : 'materialCode',
                title : '存货编码',
                sortable:true
            },
            {
                field:"materialName",
                title:"名称",
                sortable:true
            },
            {
                field:"materialSpec",
                title:"规格",
                sortable:true
            },
            {
                field : 'qty',
                title : '单据数量'
            },
            {
                field : 'taskQty',
                title : '已入数量'
            },
            {
                field : 'inventorySts',
                title : '库存状态'
            },
            {
                field : 'referCode',
                title : '上游订单号'
            },
            {
                field : 'referLineNum',
                title : '上游订单行号'
            },
            {
                field : 'lot',
                title : '批号'
            },
        ]
    });
    $("#bootstrap-table-2").bootstrapTable({
        // url: prefix + "/list",
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        clickToSelect: true,
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 50,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50,100],
        modalName: "收货",
        contentType: "application/x-www-form-urlencoded",
        onClickRow:function(row,ele,field){
            let code=result[2];
            $("#btn1").html(code).append("<span class=\"caret\"></span>");
            $("#detailId").val(row.id);
            $("#receiveNum").val(row.qty-row.taskQty);
            setInit(arr[2].material_length,arr[2].qty_length,arr[2].qtyCompleted_length);
            $.ajax({
                url:prefix+'/getReceiptInfoByReferBillKS',
                type:'post',
                data:{
                    code:code,
                    id:row.id
                },
                success:res=>{
                    $("#bootstrap-table1").bootstrapTable('load',res.data.list);
                    $("#bootstrap-table5").bootstrapTable('load',res.data.containers);
                    $("#bootstrap-table2").bootstrapTable('load',res.data.transactionList);
                    // $("#bootstrap-table3").bootstrapTable('load',res.data.containerList);
                    // $("#bootstrap-table4").bootstrapTable('load',res.data.inventoryList);
                }
            })
        },
        columns: [
            {
                field : 'id',
                title : '明细id',
                sortable:false
            },
            {
                field : 'materialCode',
                title : '存货编码',
                sortable:true
            },
            {
                field:"materialName",
                title:"名称",
                sortable:true
            },
            {
                field:"materialSpec",
                title:"规格",
                sortable:true
            },
            {
                field : 'qty',
                title : '单据数量'
            },
            {
                field : 'taskQty',
                title : '已入数量'
            },
            {
                field : 'inventorySts',
                title : '库存状态'
            },
            {
                field : 'referCode',
                title : '上游订单号'
            },
            {
                field : 'referLineNum',
                title : '上游订单行号'
            },
            {
                field : 'lot',
                title : '批号'
            },
        ]
    });
    $("#bootstrap-table-3").bootstrapTable({
        // url: prefix + "/list",
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        clickToSelect: true,
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 50,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50,100],
        modalName: "收货",
        contentType: "application/x-www-form-urlencoded",
        onClickRow:function(row,ele,field){
            let code=result[3];
            $("#btn1").html(code).append("<span class=\"caret\"></span>");
            $("#detailId").val(row.id);
            $("#receiveNum").val(row.qty-row.taskQty);
            setInit(arr[3].material_length,arr[3].qty_length,arr[3].qtyCompleted_length);
            $.ajax({
                url:prefix+'/getReceiptInfoByReferBillKS',
                type:'post',
                data:{
                    code:code,
                    id:row.id
                },
                success:res=>{
                    $("#bootstrap-table1").bootstrapTable('load',res.data.list);
                    $("#bootstrap-table5").bootstrapTable('load',res.data.containers);
                    $("#bootstrap-table2").bootstrapTable('load',res.data.transactionList);
                    // $("#bootstrap-table3").bootstrapTable('load',res.data.containerList);
                    // $("#bootstrap-table4").bootstrapTable('load',res.data.inventoryList);
                }
            })
        },
        columns: [
            {
                field : 'id',
                title : '明细id',
                sortable:false
            },
            {
                field : 'materialCode',
                title : '存货编码',
                sortable:true
            },
            {
                field:"materialName",
                title:"名称",
                sortable:true
            },
            {
                field:"materialSpec",
                title:"规格",
                sortable:true
            },
            {
                field : 'qty',
                title : '单据数量'
            },
            {
                field : 'taskQty',
                title : '已入数量'
            },
            {
                field : 'inventorySts',
                title : '库存状态'
            },
            {
                field : 'referCode',
                title : '上游订单号'
            },
            {
                field : 'referLineNum',
                title : '上游订单行号'
            },
            {
                field : 'lot',
                title : '批号'
            },
        ]
    });
    $("#bootstrap-table-4").bootstrapTable({
        // url: prefix + "/list",
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        clickToSelect: true,
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 50,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50,100],
        modalName: "收货",
        contentType: "application/x-www-form-urlencoded",
        onClickRow:function(row,ele,field){
            let code=result[4];
            $("#btn1").html(code).append("<span class=\"caret\"></span>");
            $("#detailId").val(row.id);
            $("#receiveNum").val(row.qty-row.taskQty);
            setInit(arr[4].material_length,arr[4].qty_length,arr[4].qtyCompleted_length);
            $.ajax({
                url:prefix+'/getReceiptInfoByReferBillKS',
                type:'post',
                data:{
                    code:code,
                    id:row.id
                },
                success:res=>{
                    $("#bootstrap-table1").bootstrapTable('load',res.data.list);
                    $("#bootstrap-table5").bootstrapTable('load',res.data.containers);
                    $("#bootstrap-table2").bootstrapTable('load',res.data.transactionList);
                    // $("#bootstrap-table3").bootstrapTable('load',res.data.containerList);
                    // $("#bootstrap-table4").bootstrapTable('load',res.data.inventoryList);
                }
            })
        },
        columns: [
            {
                field : 'id',
                title : '明细id',
                sortable:false
            },
            {
                field : 'materialCode',
                title : '存货编码',
                sortable:true
            },
            {
                field:"materialName",
                title:"名称",
                sortable:true
            },
            {
                field:"materialSpec",
                title:"规格",
                sortable:true
            },
            {
                field : 'qty',
                title : '单据数量'
            },
            {
                field : 'taskQty',
                title : '已入数量'
            },
            {
                field : 'inventorySts',
                title : '库存状态'
            },
            {
                field : 'referCode',
                title : '上游订单号'
            },
            {
                field : 'referLineNum',
                title : '上游订单行号'
            },
            {
                field : 'lot',
                title : '批号'
            },
        ]
    });
    $("#bootstrap-table-5").bootstrapTable({
        // url: prefix + "/list",
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        clickToSelect: true,
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 50,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50,100],
        modalName: "收货",
        contentType: "application/x-www-form-urlencoded",
        onClickRow:function(row,ele,field){
            let code=result[5];
            $("#btn1").html(code).append("<span class=\"caret\"></span>");
            $("#detailId").val(row.id);
            $("#receiveNum").val(row.qty-row.taskQty);
            setInit(arr[5].material_length,arr[5].qty_length,arr[5].qtyCompleted_length);
            $.ajax({
                url:prefix+'/getReceiptInfoByReferBillKS',
                type:'post',
                data:{
                    code:code,
                    id:row.id
                },
                success:res=>{
                    $("#bootstrap-table1").bootstrapTable('load',res.data.list);
                    $("#bootstrap-table5").bootstrapTable('load',res.data.containers);
                    $("#bootstrap-table2").bootstrapTable('load',res.data.transactionList);
                    // $("#bootstrap-table3").bootstrapTable('load',res.data.containerList);
                    // $("#bootstrap-table4").bootstrapTable('load',res.data.inventoryList);
                }
            })
        },
        columns: [
            {
                field : 'id',
                title : '明细id',
                sortable:false
            },
            {
                field : 'materialCode',
                title : '存货编码',
                sortable:true
            },
            {
                field:"materialName",
                title:"名称",
                sortable:true
            },
            {
                field:"materialSpec",
                title:"规格",
                sortable:true
            },
            {
                field : 'qty',
                title : '单据数量'
            },
            {
                field : 'taskQty',
                title : '已入数量'
            },
            {
                field : 'inventorySts',
                title : '库存状态'
            },
            {
                field : 'referCode',
                title : '上游订单号'
            },
            {
                field : 'referLineNum',
                title : '上游订单行号'
            },
            {
                field : 'lot',
                title : '批号'
            },
        ]
    });

    $("#bootstrap-table1").bootstrapTable({
        removeUrl: ctx + "receipt/receiptContainerDetail/remove",
        clickToSelect: true,
        showColumns:true, //列选择
        showExport: true, //导出
        iconSize: "outline",
        toolbar: "#toolbar1",
        exportDataType: "all",  //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
        modalName: "入库组盘",
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 5,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50],
        contentType: "application/x-www-form-urlencoded",
        columns: [
            {
                title: '操作',
                align: 'center',
                events:'operateEvents',
                formatter: function(value, row, index) {
                    let actions = [];
                    if(row.zoneCode==='PK'){
                        actions.push('<a id="cancel" class="btn btn-success btn-xs" style="background-color: #ac2925" href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.containerCode +'\')"><i class="fa fa-edit"></i>组盘</a> ');
                    }
                    else{
                        actions.push('<a id="cancel" class="btn btn-success btn-xs " href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.containerCode +'\')"><i class="fa fa-edit"></i>组盘</a> ');
                    }
                    return actions.join('');
                }
            },
            // {
            //     field : 'id',
            //     title : 'id'
            // },

            {
                field : 'containerCode',
                title : '容器编号'
            },
            {
                field : 'materialCode',
                title : '存货编码'
            },
            {
                field : 'materialOldCode',
                title : '存货代码'
            },
            {
                field : 'materialName',
                title : '物料名称'
            },
            {
                field : 'materialSpec',
                title : '物料规格'
            },
            {
                field : 'qty',
                title : '数量'
            },
            {
                field: 'companyCode',
                title: '货主',
                align: 'center',
                formatter: function(value, row, index) {
                    var actions = [];
                    $.each(company, function(index, dict) {
                        if (dict.code == value) {
                            actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                            return false;
                        }
                    });
                    return actions.join('');
                }
            },
            {
                field : 'uWarehouseCode',
                title : 'U8仓库',
                formatter: function(value, row, index) {
                    var actions = [];
                    $.each(uWarehouseNames, function (index, dict) {
                        if (dict.uWarehouseCode == value) {
                            actions.push("<span class='badge badge-info'>" + dict.uWarehouseName + "</span>");
                            return false;
                        }
                    });
                    return actions.join('');
                }
            },
            {
                field : 'locationCode',
                title : '库位编号'
            },
            {
                field : 'moCode',
                title : '工作令号' ,
                sortable:true
            },
            {
                field : 'supplierCode',
                title : '供应商编码',
                visible:false
            },
            {
                field : 'inventorySts',
                title : '库存状态'
            },
        ]
    });
    $("#bootstrap-table2").bootstrapTable({
        removeUrl: ctx + "receipt/receiptContainerDetail/remove",
        clickToSelect: true,
        showColumns:true, //列选择
        showExport: true, //导出
        iconSize: "outline",
        toolbar: "#toolbar2",
        exportDataType: "all",  //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
        modalName: "入库组盘",
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 5,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50],
        contentType: "application/x-www-form-urlencoded",
        columns: [
            {
                title: '操作',
                align: 'center',
                events:'operateEvents',
                formatter: function(value, row, index) {
                    let actions = [];
                    if(row.zoneCode==='PK'){
                        actions.push('<a id="cancel" class="btn btn-success btn-xs" style="background-color: #ac2925" href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.containerCode +'\')"><i class="fa fa-edit"></i>组盘</a> ');
                    }
                    else{
                        actions.push('<a id="cancel" class="btn btn-success btn-xs " href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.containerCode +'\')"><i class="fa fa-edit"></i>组盘</a> ');
                    }
                    return actions.join('');
                }
            },
            // {
            //     field : 'id',
            //     title : 'id'
            // },

            {
                field : 'containerCode',
                title : '容器编号'
            },
            {
                field : 'materialCode',
                title : '存货编码'
            },
            {
                field : 'materialOldCode',
                title : '存货代码'
            },
            {
                field : 'materialName',
                title : '物料名称'
            },
            {
                field : 'materialSpec',
                title : '物料规格'
            },
            {
                field : 'taskQty',
                title : '数量'
            },
            {
                field: 'companyCode',
                title: '货主',
                align: 'center',
                formatter: function(value, row, index) {
                    var actions = [];
                    $.each(company, function(index, dict) {
                        if (dict.code == value) {
                            actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                            return false;
                        }
                    });
                    return actions.join('');
                }
            },
            {
                field : 'uWarehouseCode',
                title : 'U8仓库',
                formatter: function(value, row, index) {
                    var actions = [];
                    $.each(uWarehouseNames, function (index, dict) {
                        if (dict.uWarehouseCode == value) {
                            actions.push("<span class='badge badge-info'>" + dict.uWarehouseName + "</span>");
                            return false;
                        }
                    });
                    return actions.join('');
                }
            },
            {
                field : 'created',
                title : '创建时间',
                sortable:true,
                formatter: function(value, row, index) {
                    let time=value.slice(5,10);
                    return `<span>${time}</span>`
                }
            },
            {
                field : 'moCode',
                title : '工作令号' ,
                sortable:true
            },
        ]
    });
    // $("#bootstrap-table3").bootstrapTable({
    //     removeUrl: ctx + "receipt/receiptContainerDetail/remove",
    //     clickToSelect: true,
    //     showColumns:true, //列选择
    //     showExport: true, //导出
    //     iconSize: "outline",
    //     toolbar: "#toolbar3",
    //     exportDataType: "all",  //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
    //     modalName: "入库组盘",
    //     pagination: true,   // 是否显示分页(*)
    //     pageNumber: 1,                                      // 初始化加载第一页,默认第一页
    //     pageSize: 5,                                       // 每页的记录行数(*)
    //     pageList: [10, 25, 50],
    //     contentType: "application/x-www-form-urlencoded",
    //     columns: [
    //         {
    //             title: '操作',
    //             align: 'center',
    //             events:'operateEvents',
    //             formatter: function(value, row, index) {
    //                 let actions = [];
    //                 if(row.zoneCode==='PK'){
    //                     actions.push('<a id="cancel" class="btn btn-success btn-xs" style="background-color: #ac2925" href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.containerCode +'\')"><i class="fa fa-edit"></i>组盘</a> ');
    //                 }
    //                 else{
    //                     actions.push('<a id="cancel" class="btn btn-success btn-xs " href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.containerCode +'\')"><i class="fa fa-edit"></i>组盘</a> ');
    //                 }
    //                 return actions.join('');
    //             }
    //         },
    //         {
    //             field : 'uWarehouseName',
    //             title : 'U8仓库'
    //         },
    //         {
    //             field : 'locationCode',
    //             title : '库位编号'
    //         },
    //         {
    //             field : 'code',
    //             title : '容器编号'
    //         },
    //     ]
    // });
    // $("#bootstrap-table4").bootstrapTable({
    //     removeUrl: ctx + "receipt/receiptContainerDetail/remove",
    //     clickToSelect: true,
    //     showColumns:true, //列选择
    //     showExport: true, //导出
    //     iconSize: "outline",
    //     toolbar: "#toolbar4",
    //     exportDataType: "all",  //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
    //     modalName: "入库组盘",
    //     pagination: true,   // 是否显示分页(*)
    //     pageNumber: 1,                                      // 初始化加载第一页,默认第一页
    //     pageSize: 5,                                       // 每页的记录行数(*)
    //     pageList: [10, 25, 50],
    //     contentType: "application/x-www-form-urlencoded",
    //     columns: [
    //         {
    //             title: '操作',
    //             align: 'center',
    //             events:'operateEvents',
    //             formatter: function(value, row, index) {
    //                 let actions = [];
    //                 if(row.zoneCode==='PK'){
    //                     actions.push('<a id="cancel" class="btn btn-success btn-xs" style="background-color: #ac2925" href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.containerCode +'\')"><i class="fa fa-edit"></i>组盘</a> ');
    //                 }
    //                 else{
    //                     actions.push('<a id="cancel" class="btn btn-success btn-xs " href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.containerCode +'\')"><i class="fa fa-edit"></i>组盘</a> ');
    //                 }
    //                 return actions.join('');
    //             }
    //         },
    //         {
    //             field : 'id',
    //             title : 'id'
    //         },
    //         {
    //             field : 'companyName',
    //             title : '货主编码'
    //         },
    //         {
    //             field : 'uWarehouseName',
    //             title : 'U8仓库'
    //         },
    //         {
    //             field : 'containerCode',
    //             title : '容器编号'
    //         },
    //         {
    //             field : 'materialCode',
    //             title : '存货编码'
    //         },
    //         {
    //             field : 'materialOldCode',
    //             title : '存货代码'
    //         },
    //         {
    //             field : 'materialName',
    //             title : '物料名称'
    //         },
    //         {
    //             field : 'materialSpec',
    //             title : '物料规格'
    //         },
    //         {
    //             field : 'qty',
    //             title : '数量'
    //         },
    //         {
    //             field : 'moCode',
    //             title : '工作令号',
    //             sortable:true
    //         },
    //         {
    //             field : 'status',
    //             title : '库存状态' ,
    //             align: 'center',
    //             formatter: function(value, row, index) {
    //                 return $.table.selectDictLabel(inventoryStatus, value);
    //             }
    //         }
    //     ]
    // });
    $("#bootstrap-table5").bootstrapTable({
        removeUrl: ctx + "receipt/receiptContainerDetail/remove",
        clickToSelect: true,
        showColumns:true, //列选择
        showExport: true, //导出
        iconSize: "outline",
        toolbar: "#toolbar5",
        exportDataType: "all",  //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
        modalName: "入库组盘",
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 5,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50],
        contentType: "application/x-www-form-urlencoded",
        columns: [
            {
                title: '操作',
                align: 'center',
                events:'operateEvents',
                formatter: function(value, row, index) {
                    let actions = [];
                    if(row.zoneCode==='PK'){
                        actions.push('<a id="cancel" class="btn btn-success btn-xs" style="background-color: #ac2925" href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.code +'\')"><i class="fa fa-edit"></i>组盘</a> ');
                    }
                    else{
                        actions.push('<a id="cancel" class="btn btn-success btn-xs " href="#" onclick="Receiving(\'' + row.locationCode + '\',\'' + row.code +'\')"><i class="fa fa-edit"></i>组盘</a> ');
                    }
                    return actions.join('');
                }
            },
            {
                field: 'companyCode',
                title: '货主',
                align: 'center',
                formatter: function(value, row, index) {
                    var actions = [];
                    $.each(company, function(index, dict) {
                        if (dict.code == value) {
                            actions.push("<span class='badge badge-info'>" + dict.name + "</span>");
                            return false;
                        }
                    });
                    return actions.join('');
                }
            },
            {
                field : 'uWarehouseCode',
                title : 'U8仓库',
                formatter: function(value, row, index) {
                    var actions = [];
                    $.each(uWarehouseNames, function (index, dict) {
                        if (dict.uWarehouseCode == value) {
                            actions.push("<span class='badge badge-info'>" + dict.uWarehouseName + "</span>");
                            return false;
                        }
                    });
                    return actions.join('');
                }
            },
            {
                field : 'locationCode',
                title : '库位编号'
            },
            {
                field : 'code',
                title : '容器编号'
            },
        ]
    });
    window.operateEvents = {
        'click #qty': function (e, value, row, index) {
            var url = prefix + '/add?';
            jQuery.each(row, function(key, val) {
                url = url + key + "=" + encodeURI(val) + "&";
            });
            var modalName="入库组盘";
            $.modal.open("添加"+modalName,url);
        }
    };
    /**
     * 组盘
     * @param locationCode
     * @param containerCode
     */
    function Receiving(locationCode,containerCode) {
        let sourceCode=$("#btn1").html().split("<",1).toString();
        let num=$("#receiveNum").val();
        let receiptDetailId=$("#detailId").val();
        $.ajax({
            url:ctx + "receipt/receiving/save",
            type:'post',
            data:{
                sourceCode:sourceCode,
                qty: num,
                receiptDetailId:receiptDetailId,
                locationCode:locationCode,
                containerCode:containerCode
            },
            success:function (data) {
                console.log(data)
                debugger;
                if(data.code===200){
                    $.modal.msgSuccess('成功');
                    initTable(result);
                }
                else{
                    $.modal.msg(data.msg);
                }
            }
        })
    }
    var result;
    function receiving_refresh() {
        debugger;
        var referCodes = localStorage.getItem("referCodes");
        result= referCodes.split(",");
        debugger;
        for (var i = 0; i < result.length; i++) {
            // $(".dropdown-menu").append("<option value='"+res[i].goodsShelfNo+"'>"+ res[i].goodsShelfNo +"</option>");
            $(".dropdown-menu").append("<li><a href='#'>"+result[i]+"</a>"+"</li>");
        }
        if (referCodes) {
            result= result.filter(function (s) {
                return s&&s.trim();
            })
            initTable(result);
        }
        localStorage.removeItem("referCodes");
    }
    receiving_refresh();
    function receipt() {
        let containerCode = $("#containerCode").val();
        let locationCode = '';
        Receiving(locationCode, containerCode);
    }
    $(".dropdown .dropdown-menu").find("a").click(function() {
        debugger;
        let v = $(this).html();
        $("#btn1").html($(this).html()).append("<span class=\"caret\"></span>");
        result.forEach(
            function(value,index,array) {
                //let v = $('#heading'+index+' '+'h4'+' '+'a').html();
                if(value==v){
                    $("div[role='tabpanel']").removeClass("in");
                    $("div[aria-labelledby='heading"+index+"']").addClass('in');

                }
            }
        );


    })
</script>
</body>
</html>