From daac5618fc2322620a82d25603c5b4d15465c5ef Mon Sep 17 00:00:00 2001
From: lty <876263681@qq.com>
Date: 星期四, 05 三月 2026 08:04:21 +0800
Subject: [PATCH] #检验流程

---
 src/main/webapp/static/js/order/order.js |  162 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 160 insertions(+), 2 deletions(-)

diff --git a/src/main/webapp/static/js/order/order.js b/src/main/webapp/static/js/order/order.js
index 8ad67ce..fcf88db 100644
--- a/src/main/webapp/static/js/order/order.js
+++ b/src/main/webapp/static/js/order/order.js
@@ -1,7 +1,16 @@
 var insTbCount = 0;
 var insTb;
-    var insLookTb;
-    layui.config({
+var insLookTb;
+
+function generateInspectionOrderNo(buyerCode) {
+    var now = new Date();
+    var year = String(now.getFullYear()).slice(-2);
+    var code = (buyerCode || '').toUpperCase();
+    var seq = String(now.getTime() % 100000).padStart(5, '0');
+    return 'INS' + year + code + '/' + seq;
+}
+
+layui.config({
     base: baseUrl + "/static/layui/lay/modules/"
 }).use(['layer', 'form', 'table', 'util', 'admin', 'xmSelect', 'laydate'], function () {
     var $ = layui.jquery;
@@ -187,6 +196,10 @@
         showEditModel();
     });
 
+    $("#createInspectionBtn").click(function () {
+        openInspectionDialog('');
+    });
+
     // 宸ュ叿鏉$偣鍑讳簨浠�
     table.on('tool(order)', function (obj) {
         var data = obj.data;
@@ -250,6 +263,151 @@
         }
     });
 
+    function openInspectionDialog(buyerCode) {
+        admin.open({
+            type: 1,
+            title: I18n.t('create_inspection_order'),
+            content: $('#inspectionDialog').html(),
+            area: '1200px',
+            end: function () {
+                $(document).off('i18n:languageChanged.inspection');
+            },
+            success: function (layero, dIndex) {
+                I18n.updatePage($(layero));
+                $(layero).children('.layui-layer-content').css('overflow', 'visible');
+                var $container = $(layero);
+                function getMatchingLocationCols() {
+                    return [[
+                        {type: 'numbers'},
+                        {field: 'locNo', title: (typeof I18n !== 'undefined' ? I18n.t('location_no') : 'Location No')},
+                        {field: 'specs', title: (typeof I18n !== 'undefined' ? I18n.t('style') : 'Style')},
+                        {field: 'color', title: (typeof I18n !== 'undefined' ? I18n.t('color') : 'Color')},
+                        {field: 'anfme', title: (typeof I18n !== 'undefined' ? I18n.t('qty') : 'Qty')}
+                    ]];
+                }
+                var inspectionTable = table.render({
+                    elem: '#matchingLocationsTable',
+                    data: [],
+                    page: true,
+                    cellMinWidth: 80,
+                    cols: getMatchingLocationCols(),
+                    text: {none: (typeof I18n !== 'undefined' ? I18n.t('no_data') : 'No Data')},
+                    done: function () {
+                        I18n.updateLayuiPagination();
+                        $(layero).find('.layui-table-view').css('margin', '0');
+                    },
+                    size: ''
+                });
+
+                $(document).on('i18n:languageChanged.inspection', function () {
+                    if (typeof I18n !== 'undefined') {
+                        I18n.updatePage($container);
+                    }
+                    inspectionTable.reload({
+                        cols: getMatchingLocationCols(),
+                        text: {none: (typeof I18n !== 'undefined' ? I18n.t('no_data') : 'No Data')}
+                    });
+                });
+
+                function updateSummary(records) {
+                    if (!records || !records.length) {
+                        $container.find('#poSummaryBuyerPo').text('');
+                        $container.find('#poSummaryTotalStyles').text(0);
+                        $container.find('#poSummaryTotalColors').text(0);
+                        $container.find('#poSummaryTotalCartons').text(0);
+                        $container.find('#poSummaryTotalQty').text(0);
+                        return;
+                    }
+                    var buyerPo = records[0].sku || '';
+                    var styleSet = {};
+                    var colorSet = {};
+                    var cartonSet = {};
+                    var totalQty = 0;
+                    for (var i = 0; i < records.length; i++) {
+                        var r = records[i];
+                        if (r.specs) styleSet[r.specs] = true;
+                        if (r.color) colorSet[r.color] = true;
+                        if (r.batch) cartonSet[r.batch] = true;
+                        if (r.anfme) totalQty += Number(r.anfme) || 0;
+                    }
+                    $container.find('#poSummaryBuyerPo').text(buyerPo);
+                    $container.find('#poSummaryTotalStyles').text(Object.keys(styleSet).length);
+                    $container.find('#poSummaryTotalColors').text(Object.keys(colorSet).length);
+                    $container.find('#poSummaryTotalCartons').text(Object.keys(cartonSet).length);
+                    $container.find('#poSummaryTotalQty').text(totalQty);
+                }
+
+                var lastSearchRecords = [];
+                form.on('submit(inspectionSearch)', function (data) {
+                    var searchParam = data.field || {};
+                    $.ajax({
+                        url: baseUrl + "/order/inspection/matchingLocations/auth",
+                        headers: {'token': localStorage.getItem('token')},
+                        data: searchParam,
+                        method: 'GET',
+                        success: function (res) {
+                            if (res.code === 200) {
+                                var records = res.data && res.data.records ? res.data.records : (res.data || []);
+                                lastSearchRecords = records;
+                                inspectionTable.reload({data: records, page: {curr: 1}});
+                                updateSummary(records);
+                            } else if (res.code === 403) {
+                                top.location.href = baseUrl+"/";
+                            } else {
+                                layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
+                            }
+                        }
+                    });
+                    return false;
+                });
+
+                $container.find('#inspectionCreateBtn').click(function () {
+                    var buyerCodeInput = ($container.find('input[name="buyerShortCode"]').val() || buyerCode || '').trim();
+                    if (!buyerCodeInput) {
+                        var msg = 'Buyer short code涓嶈兘涓虹┖';
+                        if (typeof I18n !== 'undefined') {
+                            msg = I18n.t('buyer_short_code') + I18n.t('form_required');
+                        }
+                        layer.msg(msg, {icon: 2});
+                        return;
+                    }
+                    if (!lastSearchRecords || lastSearchRecords.length === 0) {
+                        layer.msg('璇峰厛妫�绱㈠嚭鍖归厤搴撲綅鏁版嵁', {icon: 2});
+                        return;
+                    }
+                    var orderNo = generateInspectionOrderNo(buyerCodeInput);
+                    
+                    layer.load(2);
+                    $.ajax({
+                        url: baseUrl + "/order/inspection/create/auth",
+                        headers: {'token': localStorage.getItem('token')},
+                        contentType: 'application/json;charset=UTF-8',
+                        data: JSON.stringify({
+                            orderNo: orderNo,
+                            buyerShortCode: buyerCodeInput,
+                            records: lastSearchRecords
+                        }),
+                        method: 'POST',
+                        success: function (res) {
+                            layer.closeAll('loading');
+                            if (res.code === 200) {
+                                layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 1});
+                                layer.close(dIndex);
+                                insTb.reload({page: {curr: 1}});
+                            } else {
+                                layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
+                            }
+                        },
+                        error: function() {
+                            layer.closeAll('loading');
+                            layer.msg(typeof I18n !== 'undefined' ? I18n.t('load_failed') : 'Load failed', {icon: 2});
+                        }
+                    });
+                });
+            }
+        });
+    }
+
     // 鏄剧ず琛ㄥ崟寮圭獥
     function showEditModel(expTpe) {
         admin.open({

--
Gitblit v1.9.1