cbgReceipt.html 20 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head>
    <th:block th:include="include :: header"/>
    <!--    <th:block th:include="include :: select2-css"/>-->
    <script src="/wms/js/jquery.min.js"></script>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-cbgReceipt">
        <div class="form-group">
            <label class="col-sm-1 control-label">单据类型:</label>
            <div class="col-sm-2">
                <select id="receiptType" name="receiptType" class="form-control"
                        th:with="receiptTypeList=${@receiptTypeService.getType()}">
                    <option th:selected="${receiptType['code']} == 'CBGR'" th:each="receiptType : ${receiptTypeList}" th:text="${receiptType['name']}"
                            th:value="${receiptType['code']}"></option>
                </select>
            </div>
            <label class="col-sm-1 control-label">工单号:</label>
            <div class="col-sm-2">
                <div class="input-group">
                    <input class="form-control" type="text" placeholder="请扫描工单号" value="" id="orderCode"/>
                    <span class="input-group-btn">
                        <button type="button" onclick="chooseOrder()" id="chooseOrderBtn"
                                class="btn btn-primary">选取工单
                        </button>
                    </span>
                </div>
            </div>
            <label class="col-sm-1 control-label">生产令号:</label>
            <div class="col-sm-2">
                <input class="form-control" type="text" placeholder="请扫描生产令号" value="" id="orderNumber"/>
            </div>
            <label class="col-sm-1 control-label">生产批号:</label>
            <div class="col-sm-2">
                <input class="form-control" type="text" placeholder="请扫描生产批号" value="" id="batchNumber"/>
            </div>
        </div>
        <div class="col-sm-12 select-info">
            <div id="myTabContent" class="tab-content">
                <div class="form-group" style="margin-top: 10px">
                    <label class="col-sm-1 control-label">盛具编码:</label>
                    <div class="col-sm-2">
                        <input class="form-control" placeholder="请扫描盛具编码" name="vehicleCode"
                               id="vehicleCode"/>
                    </div>
                    <label class="col-sm-1 control-label">追溯码:</label>
                    <div class="col-sm-3">
                        <input class="form-control" id="tracingNo" name="tracingNo" type="text" placeholder="请扫描物料追溯码">
                    </div>
                    <label class="col-sm-1 control-label">数量:</label>
                    <div class="col-sm-1 input-group" style="float: inline-start">
                        <input class="form-control" min="0" placeholder="请输入数量" readonly="readonly" id="qty">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button" onclick="qtySure()" id="qtySureButton">确定</button>
                        </span>
                    </div>
                </div>
                <div class="form-group" style="margin-top: 10px">
                    <div class="col-sm-10" style="display: flex; justify-content: flex-end">
                        <span style="line-height: 34px" id="scanCount"></span>
                    </div>
                    <div class="col-sm-2" style="display: flex; justify-content: flex-end">
                        <a class="btn btn-primary" onclick="cbgReceipt()" type="button">提交</a>&nbsp;&nbsp;
                        <a class="btn btn-danger" onclick="$.modal.close()" type="button">关闭</a>
                    </div>
                </div>
                <table id="bootstrap-table" data-mobile-responsive="true"
                       class="table table-bordered table-hover text-nowrap">
                </table>
            </div>
        </div>
    </form>

</div>
<th:block th:include="include :: footer"/>
<!--<th:block th:include="include :: select2-js"/>-->
<script type="text/javascript">
    let prefix = ctx + "inventory/inventoryHeader"
    $("#form-cbgReceipt").validate({
        rules: {
            orderCode: {
                required: true,
            },
        },
    });

    let vehicleData = null;  // 当前扫描的盛具
    let material = null; // 扫描的物料
    let tableDataList = []; //表格中的数据
    let currentX = 1; //当前x坐标
    let currentY = 1; //当前y坐标

    $(function () {
        // 表格初始化
        $("#bootstrap-table").bootstrapTable({
            showToggle: false,
            showRefresh: false,
            showColumns: false,
            showSearch: false,
            columns: [
                {
                    field: 'vehicleCode',
                    title: '盛具编码'
                },
                {
                    field: 'materialCode',
                    title: '物料编码'
                },
                {
                    field: 'materialName',
                    title: '物料名称'
                },
                {
                    field: 'materialSpec',
                    title: '物料规格'
                },
                {
                    field: 'materialUnit',
                    title: '物料单位'
                },
                {
                    field: 'description',
                    title: '物料描述'
                },
                {
                    field: 'weight',
                    title: '药量(g)'
                },
                {
                    field: 'high',
                    title: '高度(cm)'
                },
                {
                    field: 'x',
                    title: 'x坐标'
                },
                {
                    field: 'y',
                    title: 'y坐标'
                },
                {
                    field: 'scTracingNo',
                    title: '生产追溯码'
                },
                {
                    field: 'bqTracingNo',
                    title: '标签追溯码'
                },
                {
                    field: 'supplierCode',
                    title: '供应商编码'
                },
                {
                    field: 'supplierBatch',
                    title: '供应商批次码'
                },
                {
                    field: 'supplierTracingNo',
                    title: '供应商SN码'
                },
                {
                    field: "action",
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (index !== 0) {
                            return
                        }
                        let rowStr = JSON.stringify(row)
                        let actions = [];
                        actions.push(`<a class='btn btn-danger btn-xs' href='#' onclick='remove(${rowStr})'><i class='fa fa-trash-o'></i>删除</a>`);
                        return actions.join('');
                    }
                }]
        });

        // 追溯码输入框输入事件
        $('#tracingNo').on('input', debounce(function () {
            let value = this.value;
            if ($.common.isEmpty(value)) {
                return;
            }
            if ($.common.isEmpty(vehicleData)) {
                $("#vehicleCode").focus();
                $.modal.msgWarning("请先扫描盛具码")
                clearTracingNo();
                return;
            }

            handleM(value);
        }, 600));

        // 盛具编码绑定输入事件
        $('#vehicleCode').on('input', debounce(function () {
            let vehicleCode = this.value;
            if ($.common.isEmpty(vehicleCode) || (vehicleData != null && vehicleCode === vehicleData.code)) {
                return
            }
            $.ajax({
                cache: true,
                type: "get",
                dataType: "json",
                url: "/wms/config/vehicle/getVehicleData",
                async: false,
                data: {
                    vehicleCode: vehicleCode,
                },
                contentType: "application/json",
                error: function (result) {
                    $.operate.ajaxSuccess(result);
                },
                success: function (result) {
                    if (result.code === web_status.SUCCESS) {
                        vehicleData = result.data;
                        tableDataList = [];
                        material = null;
                        loadTable();
                    } else {
                        $.modal.msgError(result.msg);
                    }
                }
            });
        }, 600))
    });

    function handleM(value) {
        //示例:M240108200001|Z000000105|1|0000058|5-23|0028-3-21-B。解析条码内容
        //生产追溯码|物料编码|供应商编码|供应商批次码|供应商SN码
        let splitArray = value.split("|");
        let bqTracingNo = splitArray[0];
        let materialCode = splitArray[1];
        let qty = parseInt(splitArray[2]);
        let supplierCode = splitArray[3];
        let supplierBatch = splitArray[4];
        let supplierTracingNo = splitArray[5];
        if (!checkMaterial(materialCode)) {
            return;
        }
        getMaterialInfo(materialCode);
        if ($.common.isNotEmpty(material)) {
            let tracingType = material.tracingType;
            if ($.common.isNotEmpty(tracingType) && tracingType !== undefined) {
                $.modal.msgWarning("请扫描物料的生产追溯码进行入库");
                return;
            }
            if (qty === 1) {
                addSerial(bqTracingNo, null, supplierCode, supplierTracingNo, supplierBatch);
                clearTracingNo();
            } else if (qty > 1) {
                $("#qty").removeAttr("readonly").focus();
            } else {
                $.modal.msgWarning("数量错误");
                return;
            }
            loadTable();
        }
    }

    // 添加批次
    function addBatch(bqTracingNo, qty, supplierCode, supplierBatch, supplierTracingNo) {
        // 校验数量
        if ($.common.isEmpty(qty) || qty <= 0) {
            $.modal.msgWarning("数量错误");
            return;
        }
        clearTableData()
        resetXY();
        clearTracingNo()
        clearVehicleCodeAndFocus();
        if (qty > vehicleData.maxX * vehicleData.maxY) {
            $.modal.msgWarning(`盛具最大可盛放 ${vehicleData.maxX * vehicleData.maxY} 个物料`);
            return
        }
        // 每次扫码完追溯码先清空再生成
        tableDataList = [];
        for (let i = 0; i < qty; i++) {
            tableDataList.push({
                vehicleCode: vehicleData.code,
                materialCode: material.code,
                materialName: material.name,
                materialSpec: material.spec,
                materialUnit: material.unit,
                description: material.description,
                weight: material.weight,
                high: material.high,
                qty: 1,
                x: currentX,
                y: currentY,
                bqTracingNo: bqTracingNo,
                supplierCode: supplierCode,
                supplierBatch: supplierBatch,
                supplierTracingNo: supplierTracingNo,
            });
            if (currentX === vehicleData.maxY) {
                currentX = 1;
                currentY++;
            } else {
                currentX++;
            }
        }
    }

    // 提交方法
    function cbgReceipt() {
        let orderCode = $("#orderCode").val();
        let orderNumber = $("#orderNumber").val();
        let batchNumber = $("#batchNumber").val();
        let materialDataList = []
        //let vehicleCode = $("#vehicleCode").val()
        if ($.common.isEmpty(orderCode)) {
            $.modal.msgWarning("请选择或输入工单号");
            return;
        }
        if ($.common.isEmpty(orderNumber)) {
            $.modal.msgWarning("请选择或输入生产令号");
            return;
        }
        if ($.common.isEmpty(batchNumber)) {
            $.modal.msgWarning("请选择或输入生产批号");
            return;
        }
        /*if ($.common.isEmpty(vehicleCode)) {
            $.modal.msgWarning("请扫描盛具编码");
            return;
        }*/
        if ($.common.isEmpty(tableDataList)) {
            $.modal.msgWarning("入库物料信息为空");
            return;
        }
        tableDataList.forEach(data => {
            materialDataList.push({
                "vehicleCode": data.vehicleCode,
                "materialCode": data.materialCode,
                "locationNoX": data.x,
                "locationNoY": data.y,
                "qty": data.qty,
                "tracingNo": data.bqTracingNo || data.scTracingNo,
                "qualityStatus": true,
                "supplierCode": data.supplierCode,
                "supplierBatch": data.supplierBatch,
                "supplierTracingNo": data.supplierTracingNo
            })
        });
        let json = {
            "orderCode": orderCode,
            "orderNumber": orderNumber,
            "batchNumber": batchNumber,
            //"vehicleCode": vehicleCode,
            "materialDataList": materialDataList
        }
        $.ajax({
            cache: true,
            type: "POST",
            dataType: "json",
            url: "/wms/inventory/inventoryHeader/cbgReceipt",
            async: false,
            data: JSON.stringify(json),
            contentType: "application/json",
            error: function (request) {
                $.operate.ajaxSuccess(request);
            },
            success: function (result) {
                if (result.code === web_status.SUCCESS) {
                    layer.msg("保存成功,正在刷新数据请稍后……", {
                            icon: $.modal.icon(modal_status.SUCCESS),
                            time: 500,
                            shade: [0.1, '#8F8F8F']
                        }
                    )
                    // 请求成功,不关闭页面。清空页面所有数据方便再次组盘
                    vehicleData = null;
                    tableDataList = [];
                    loadTable();
                    $("#vehicleCode").val("").focus();
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        });
    }

    // 清除表格信息
    function clearTableData() {
        tableDataList = tableDataList.filter(data => data.vehicleCode !== vehicleData.code)
        loadTable();
    }

    /**
     * 重置坐标
     */
    function resetXY() {
        currentY = 1;
        currentX = 1;
    }

    function checkMaterial(materialCode) {
        if ($.common.isNotEmpty(tableDataList)) {
            let sameMaterial = tableDataList.find(x => x.materialCode === materialCode);
            if ($.common.isEmpty(sameMaterial)) {
                $.modal.msgWarning("物料不一致错误,盛具上的物料必须一致才能入库");
                clearTracingNo();
            }
        }
        return true
    }

    // 清空追溯码文本框
    function clearTracingNo() {
        $("#tracingNo").val("");
    }

    // 重新加载表格
    function loadTable() {
        tableDataList.sort((a, b) => {
            if (a.vehicleCode === b.vehicleCode) {
                return -(a.y - b.y) || -(a.x - b.x)
            }
            return a.vehicleCode - b.vehicleCode
        })
        $("#bootstrap-table").bootstrapTable('load', tableDataList);
        if (tableDataList.length !== 0) {
            const res = new Map()
            let vehicleCount = tableDataList.filter((item) => !res.has(item.vehicleCode) && res.set(item.vehicleCode, 1)).length
            let currentQty = tableDataList.filter(x => x.vehicleCode === vehicleData.code).length;
            $("#scanCount").text(`盛具数量:${vehicleCount},扫码总数量:${tableDataList.length},当前扫码数量:${currentQty}`).show()
        } else {
            $("#scanCount").hide();
        }
    }

    /**
     * 根据物料编码搜索物料信息
     */
    function getMaterialInfo(materialCode) {
        $.ajax({
            cache: true,
            type: "get",
            dataType: "json",
            url: "/wms/config/material/getByCode",
            async: false,
            data: {
                materialCode: materialCode
            },
            contentType: "application/json",
            error: function (res) {
                $.modal.msgError(res.msg);
            },
            success: function (res) {
                if (res.code === web_status.SUCCESS) {
                    material = res.data;
                } else {
                    $.modal.msgWarning(res.msg);
                    clearTracingNo();
                }
            }
        });
    }

    /**
     * 防抖
     * |param fn 业务方法
     * |param delay 延迟时间
     * |returns {(function(): void)|*}
     */
    function debounce(fn, delay) {
        let timeout = null;
        return function () {
            if (timeout !== null) {
                clearTimeout(timeout);
            }
            timeout = setTimeout(() => {
                //利用call(),让this的指针从指向window 转成指向input
                fn.call(this);
            }, delay);
        }
    }

    // 选取工单按钮点击事件
    function chooseOrder() {
        $.modal.open("选取工单", ctx + "workOrder/getUsableOrder", 800, 570)
    }

    // 输入工单事件
    // 工单号绑定事件
    $('#orderCode').on('input', debounce(function () {
        let orderCode = this.value;
        if ($.common.isEmpty(orderCode)) {
            return;
        }
        $.ajax({
            cache: true,
            type: "get",
            dataType: "json",
            url: "/wms/workOrder/getOrderByCode",
            async: false,
            data: {
                orderCode: orderCode
            },
            contentType: "application/json",
            success: function (result) {
                if (result.code === web_status.SUCCESS) {
                    if (result) {
                        $("#orderCode").val(result.orderCode);
                        $("#orderNumber").val(result.orderNumber);
                        $("#batchNumber").val(result.batchNumber);
                    }
                    $("#vehicleCode").focus();
                } else {
                    $("#orderCode").val("").focus();
                    $("#orderNumber").val("");
                    $("#batchNumber").val("");
                    $.modal.msgWarning(result.msg);
                }
            }
        });
    }, 1000));

    // 数量确认按钮点击事件
    function qtySure() {
        let qty = $("#qty").val();
        if ($.common.isEmpty(qty)) {
            return;
        }
        if (qty <= 0) {
            $.modal.msgWarning("输入数量有误");
            return
        }
        let value = $("#tracingNo").val();

        let splitArray = value.split("|");
        let bqTracingNo = splitArray[0];
        let supplierCode = splitArray[3];
        let supplierBatch = splitArray[4];
        let supplierTracingNo = splitArray[5];
        addBatch(bqTracingNo, qty, supplierCode, supplierBatch, supplierTracingNo)
        clearQty();
        loadTable();
    }

    function clearQty(){
        $("#qty").val("");
    }

    function clearVehicleCodeAndFocus() {
        $("#vehicleCode").val("").focus();
    }

    /**
     * 回传事件
     */
    $("#qty").keyup(function (event) {
        if (event.keyCode === 13) {
            $("#qtySureButton").trigger("click");
        }
    })

    // 删除生成的记录
    function remove(row) {
        tableDataList = tableDataList.filter(data => data.x !== row.x || data.y !== row.y);
        loadTable();
    }
</script>
</body>
</html>