<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
    .table-striped-left {
        width: 67%;
    }
    .table-striped-right {
        width: 32%;
        float: right;
    }

    .left,.right{
        height: 480px;
    }

    #stationInfo{
        font-size:20px;
        line-height:30px;
        color:rgb(28,132,198);
        font-weight:800;
        font-family:FangSong;
    }

    .select-list li{
        margin: 2px;
    }

    #Grids{
        width: 100%;
        margin-top: 45px;
        padding-left: 5%;
    }

    .grid{
        /*display: flex;*/
        display: -webkit-box;
        -webkit-box-pack:center;
        -webkit-box-align:center;
        -webkit-box-orient: vertical;
        width: 180px;
        height:60px;
        background-color: #4F94CD;
        margin: 2px 20px 0 0;
        border-radius: 5px;
        text-align: center;
        text-overflow:ellipsis;
        /*overflow-y: scroll;*/
    }
    .grid span{
        font-size:1vh;
    }
    .form-font label,.form-font input{
        font-size: 18px;
        font-weight: 800;
        padding-right: 0;
    }
    .toolbox-btn a{
        width: 16%;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <!--<div class="col-sm-9 select-info table-striped-left "  style="padding-top: 20px">-->
            <div class="wrapper wrapper-content animated fadeInRight ibox-content">
                <form class="form-horizontal m form-font" id="form-inventoryTransaction-add" style="transform: scale(1.2);padding-top: 20px;">
                    <div class="form-group" style="display: none;">
                        <label class="col-sm-3 control-label">id:</label>
                        <div class="col-sm-8">
                            <input id="id" name="id" class="form-control" type="text" readonly>
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label class="col-sm-3 control-label">taskId:</label>
                        <div class="col-sm-8">
                            <input id="taskId" name="taskId" class="form-control" type="text" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">容器编码:</label>
                        <div class="col-sm-2">
                            <input id="containerCode" name="containerCode" class="form-control" type="text" style="font-size: 16px">
                        </div>
                        <label class="col-sm-2 control-label">仓库:</label>
                        <div class="col-sm-4">
                            <input id="uWarehouseName" name="uWarehouseName" class="form-control" type="text" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                    <label class="col-sm-2 control-label">单号:</label>
                        <div class="col-sm-8">
                            <input id="sourceCode" name="sourceCode" class="form-control" type="text" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">存货编码:</label>
                        <div class="col-sm-8">
                            <input id="materialCode" name="materialCode" class="form-control" type="text" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">存货代码:</label>
                        <div class="col-sm-8">
                            <input id="barCode" name="barCode" class="form-control" type="text" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">物料名称:</label>
                        <div class="col-sm-8">
                            <input id="materialName" name="materialName" class="form-control" type="text" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">规格型号:</label>
                        <div class="col-sm-8">
                            <input id="specification" name="specification" class="form-control" type="text" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">任务类型:</label>
                        <div class="col-sm-1">
                            <span id="type" name="type" class="form-control" type="text" readonly>
                        </span>
                        </div>
                        <label class="col-sm-1 control-label">数量:</label>
                        <div class="col-sm-2">
                            <input id="num" name="num" class="form-control" type="text" >
                        </div>
                        <label class="col-sm-2 control-label">剩余库存:</label>
                        <div class="col-sm-2">
                            <input id="remainder" name="remainder" class="form-control" type="text" readonly >
                        </div>
                    </div>
                    <div class="form-group" style="text-align: right">
                        <div class="col-sm-7 toolbox-btn" style="text-align: right">
                            <a class="btn btn-primary btn-success btn-sm" onclick="Complete()">上下料完成</a>
                            <a class="btn btn-primary btn-info btn-sm" onclick="replenIn()"  id="trans-btnss">补充入库</a>
                            <a class="btn btn-primary btn-info btn-sm" onclick="emptyIn()"  id="trans-btns">空托入库</a>
                            <a class="btn btn-primary btn-danger btn-sm" onclick="emptyOut()" id="cans-btn">空托出库</a>
<!--                            <a class="btn btn-primary btn-danger btn-sm" onclick="replaceClick()"  id="replace-btn">更换容器</a>-->
                        </div>
                    </div>
                </form>
            <!--</div>-->
        </div>
        <div class="col-sm-12 select-info bottom" >
            <table id="bootstrap-table1" 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 prefix = ctx + "task/lkMenuTask";
    var prefixs = ctx + "inventory/inventoryHeader";
    var taskTypes=[[${@dict.getType('taskType')}]];
    var company =[[${@companyService.getCode()}]];
    var ID;

    $("#bootstrap-table").bootstrapTable({
        iconSize: "outline",
        toolbar: "#toolbar",
        showRefresh: true,//刷新
        showToggle:true, //视图切换
        clickToSelect: true,
        showColumns:true, //列选择
        showExport: true, //导出
        exportDataType: "all", //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
        modalName: "入库组盘头",
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 50,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50,100],
        contentType: "application/x-www-form-urlencoded",
        onRefresh:function(){
            getGoodsShelfNo();
            getTable2();
        },
        onClickRow:function(row){
            $("#id").val(row.id);
            $("#taskId").val(row.taskId);
            $("#uWarehouseName").val(row.uWarehouseName);
            $("#sourceCode").val(row.referenceCode);
            $("#materialCode").val(row.materialCode);
            $("#barCode").val(row.materialOldCode);
            $("#materialName").val(row.materialName);
            $("#specification").val(row.materialSpec);
            $("#containerCode").val(row.containerCode);
            $("#warehouseQty").val(row.warehouseQty);
            $("#num").val(row.qty);
            $("#remainder").val(row.remainder);
        },
        columns: [
            {
                radio: true
            },
            {
                title: '操作',
                align: 'center',
                events:'operateEvents',
                formatter: function(value, row, index) {
                    var actions = [];
                    actions.push('<a id="cancel" class="btn btn-success btn-lg " href="#" onclick="Complete(\'' + row.id + '\',\'' + row.taskId + '\')"><i class="fa fa-edit"></i>完成</a> ');
                    return actions.join('');
                }
            },
            {
                field : 'lastUpdatedBy',
                title : '操作人',
                sortable: true
            },
            {
                field : 'materialCode',
                title : '存货编码',
                sortable: true
            },
            {
                field : 'materialOldCode',
                title : '存货代码',
                sortable: true
            },
            {
                field : 'materialName',
                title : '物料名称',
                sortable:true
            },
            {
                field : 'materialSpec',
                title : '规格',
                sortable: true
            },
            {
                field : 'containerCode',
                title : '容器编码',
                sortable:true
            },
            {
                field : 'qty',
                title : '数量'
            },
            {
                field : 'referenceCode',
                title : 'U8单据',
                sortable: true
            },
            {
                field : 'companyName',
                title : '货主',
                sortable: true
            },
            {
                field : 'uWarehouseName',
                title : 'u8仓库',
                sortable: true
            },
            {
                field : 'taskType',
                title : '任务类型' ,
                align: 'center',
                sortable: true,
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(taskTypes, value);
                }

            },

            {
                field : 'warehouseQty',
                title : '库存'
            },
        ]
    });

    $("#bootstrap-table1").bootstrapTable({
        iconSize: "outline",
        toolbar: "#toolbar",
        showRefresh: true,//刷新
        showToggle:true, //视图切换
        clickToSelect: true,
        showColumns:true, //列选择
        showExport: true, //导出
        exportDataType: "all", //导出类型basic', 'all', 'selected'.当前页、所有数据、选中数据
        modalName: "入库组盘头",
        pagination: true,   // 是否显示分页(*)
        pageNumber: 1,                                      // 初始化加载第一页,默认第一页
        pageSize: 50,                                       // 每页的记录行数(*)
        pageList: [10, 25, 50,100],
        contentType: "application/x-www-form-urlencoded",
        columns: [
            {
                radio: true
            },
            {
                field : 'lastUpdatedBy',
                title : '操作人',
                sortable: true
            },
            {
                field : 'materialCode',
                title : '存货编码',
                sortable: true
            },
            {
                field : 'materialOldCode',
                title : '存货代码',
                sortable: true
            },
            {
                field : 'materialName',
                title : '物料名称',
                sortable:true
            },
            {
                field : 'materialSpec',
                title : '规格',
                sortable: true
            },
            {
                field : 'containerCode',
                title : '容器编码',
                sortable:true
            },
            {
                field : 'qty',
                title : '数量'
            },
            {
                field : 'referenceCode',
                title : 'U8单据',
                sortable: true
            },
            {
                field : 'companyCode',
                title : '货主',
                sortable: true,
                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 : 'uWarehouseName',
                title : 'u8仓库',
                sortable: true
            },
            {
                field : 'taskType',
                title : '任务类型' ,
                align: 'center',
                sortable: true,
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(taskTypes, value);
                }

            },
            {
                field : 'warehouseQty',
                title : '库存'
            },
        ]
    });

    $(function () {
        //监听浏览器宽度的改变
        window.onresize = function(){
            resize();
        };
        resize();
        // getTable2();

        //货架input
        $("#containerCode").bind('input propertychange keypress',function (e) {
            let theEvent = e || window.event;
            let code = theEvent.keyCode || theEvent.which || theEvent.charCode;
            if (code === 13) {
                e.preventDefault();
                //回车执行查询
                getContainerCode();
                getTable2()
            }
        });
    });

    // 重新加载
    function reload(code, msg){
        debugger;
        $("#containerCode").val(code);
        getContainerCode();
        getTable2()
        $.modal.msgSuccess(msg);
    }

    //完成
    function Complete(id, taskId) {
        let url = ctx + 'task/lkMenuTask/completeTaskByLK',Id=id||$("#id").val(),TaskId=taskId||$("#taskId").val();
        let num=$("#num").val()||null,data = { "id" : Id ,"taskId":TaskId ,"num":num };
        // $.operate.post(url, data);
        $.ajax({
            url,
            data,
            type: 'post',
            success: function(res) {
                $.operate.ajaxSuccess(res);
                getContainerCode();
                getTable2();
            }
        });
        $("#containerCode").focus();
    }

    //表2
    function getTable2(){
        let containerCode=$("#containerCode").val();
        $.ajax({
            url:prefix+'/getLkTasks',
            type:'post',
            data:{
                containerCode:containerCode
            },
            success:function (res) {
                if(res.length){
                    $("#bootstrap-table1").bootstrapTable('load',res)
                }
                else {
                    $("#bootstrap-table1").bootstrapTable('removeAll');
                }
            }
        })
    }

    function resize(){
        $("#containerCode").focus();
    }

    //货架
    function getContainerCode() {
        $("#bootstrap-table1").bootstrapTable('removeAll');
        resize();
        let containerCode=$("#containerCode").val();
        if(containerCode){
            $.ajax({
                url:prefix+'/getLkTasks',
                type:'post',
                data:{
                    containerCode:containerCode,
                },
                success:function (res) {
                    if (res.length>0){
                        $("#id").val(res[0].id);
                        $("#taskId").val(res[0].taskId);
                        $("#uWarehouseName").val(res[0].uWarehouseName);
                        $("#sourceCode").val(res[0].referenceCode);
                        $("#materialCode").val(res[0].materialCode);
                        $("#barCode").val(res[0].materialOldCode);
                        $("#materialName").val(res[0].materialName);
                        $("#specification").val(res[0].materialSpec);
                        $("#warehouseQty").val(res[0].warehouseQty);
                        $("#type").html($.table.selectDictLabel(taskTypes, res[0].taskType));
                        $("#num").val(res[0].qty);
                        $("#remainder").val(res[0].remainder);
                    }
                    else{
                        $("#id").val('');
                        $("#taskId").val('');
                        $("#uWarehouseName").val('');
                        $("#sourceCode").val('');
                        $("#materialCode").val('');
                        $("#barCode").val('');
                        $("#materialName").val('');
                        $("#specification").val('');
                        $("#warehouseQty").val('');
                        $("#type").val('');
                        $("#num").val('');
                        $("#remainder").val('');
                        $("#bootstrap-table1").bootstrapTable('removeAll');
                    }
                    resize()
                }
            });
        }
        else{
            layer.tips('请输入容器号!','#containerCode',{tips:[1,"rgb(28,132,198)"],time:1000,area:'auto',maxWidth: '1000'})
        }
    }

    function emptyIn() {
        $.modal.open("空托盘入库",prefixs+"/emptyIn")
    }

    function replenIn() {
        $.modal.open("补充入库",prefix+"/replenIn")
    }



    function emptyOut() {
        $.modal.open("空托盘出库",prefixs+"/emptyOut")
    }

    function replaceClick(){
        var rows = $("#bootstrap-table1").bootstrapTable('getOptions').data;
        if (rows.length == 0) {
            $.modal.alertWarning("任务详情不存在!");
            return;
        }
        var ids = "";
        for(var i=0; i<rows.length; i++) {
            ids = ids + rows[i].id + ","
        }
        var code = $('#containerCode').val();
        var url = prefix+"/replaceContainer/"+ code+"/"+ids;
        $.modal.open("更换容器", url);
    }



</script>
</body>
</html>