自动化立体仓库 - WMS系统
#
lty
2 天以前 e8e108b1f18fb0b73f9752ac6cedaf47f1ce26f1
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
layui.use(['table', 'laydate', 'form'], function(){
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
 
    // 初始加载
    loadRowsOptions();       // 加载「排」选项(始终需要)
    loadLayersOptions();     // 加载「层」选项(提前准备)
    getLocTable('byRow', 1); // 默认按排 + 第1排
 
    // 加载所有可用排
    function loadRowsOptions() {
        $.ajax({
            url: baseUrl + "/report/viewLocMapList/rows.action",
            headers: {'token': localStorage.getItem('token')},
            method: 'POST',
            async: false,
            success: function (res) {
                if (res.code === 200) {
                    var tpl = $("#locMastRowTemplate").html();
                    var template = Handlebars.compile(tpl);
                    $('#rowSelect').append(template(res));
                    form.render('select');
                } else if (res.code === 403) {
                    top.location.href = baseUrl + "/";
                }
            }
        });
    }
 
    // 加载所有可用层(需要后端支持新接口)
    function loadLayersOptions() {
        $.ajax({
            url: baseUrl + "/report/viewLocMapList/layers.action",  // ← 需要新增接口
            headers: {'token': localStorage.getItem('token')},
            method: 'POST',
            async: false,
            success: function (res) {
                if (res.code === 200) {
                    var tpl = $("#locMastRowTemplate").html(); // 复用模板
                    var template = Handlebars.compile(tpl);
                    $('#layerSelect').append(template(res));
                    form.render('select');
                }
            }
        });
    }
 
    // 核心:根据模式加载库位表
    function getLocTable(mode, value) {
        var url = baseUrl + "/report/viewLocMapList.action";
        var data = {};
 
        if (mode === 'byRow') {
            data.row = value;
        } else if (mode === 'byLayer') {
            data.layer = value;
        }
        $.ajax({
            url: url,
            headers: {'token': localStorage.getItem('token')},
            data: data,
            method: 'POST',
            success: function (res) {
                if (res.code === 200) {
                    var tpl = $("#locMapTemplate").html();
                    var template = Handlebars.compile(tpl);
                    $('#locMap').html(template(res.data));
                } else if (res.code === 403) {
                    top.location.href = baseUrl + "/";
                } else {
                    layer.msg(res.msg || '加载失败');
                }
            }
        });
    }
 
    // 监听 显示模式 切换
    form.on('select(viewMode)', function (data) {
        var mode = data.value;
 
        if (mode === 'byRow') {
            $('#rowSelectBox').show();
            $('#layerSelectBox').hide();
            // 读取当前选中的排
            var currentRow = $('#rowSelect').val() || 1;
            getLocTable('byRow', currentRow);
        } else if (mode === 'byLayer') {
            $('#rowSelectBox').hide();
            $('#layerSelectBox').show();
            var currentLayer = $('#layerSelect').val() || 1;
            getLocTable('byLayer', currentLayer);
        }
    });
 
    // 监听 排 变化
    form.on('select(row)', function (data) {
        if ($('#viewMode').val() === 'byRow') {
            getLocTable('byRow', data.value);
        }
    });
 
    // 监听 层 变化
    form.on('select(layer)', function (data) {
        if ($('#viewMode').val() === 'byLayer') {
            getLocTable('byLayer', data.value);
        }
    });
});