自动化立体仓库 - WMS系统
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
var locDetlLayerIdx;
var locDetlData = [];
function getCol() {
    var cols = [
    ];
    arrRemove(plaCols,  'type', 'checkbox');
    cols.push.apply(cols, plaCols);
    cols.push({fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 80})
    return cols;
}
 
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function() {
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var admin = layui.admin;
 
    tableIns = table.render({
        elem: '#chooseData',
        headers: {token: localStorage.getItem('token')},
        data: [],
        totalRow: true, // 开启合计行
        height: function(){
            var otherHeight = $('.function-area').outerHeight() + $('#search-box').outerHeight(); // 自定义其他区域的高度
            console.log($(window).height() - otherHeight);
            return $(window).height() - otherHeight - 100; // 返回 number 类型
        },
        //height: 'full',
        even: true,
        toolbar: '#toolbar',
        cellMinWidth: 50,
        cols: [function(){
            var arr = getCol();
 
            // 初始化筛选状态
            var local = layui.data('table-filter-test'); // 获取对应的本地记录
            layui.each(arr, function(index, item){
                if(item.field in local){
                    item.hide = local[item.field];
                }
            });
            return arr;
        }() ],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            console.log(res)
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records,
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            // 记录筛选状态
            var that = this;
            that.elem.next().on('mousedown', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]+', function(){
                var input = $(this).prev()[0];
                // 此处表名可任意定义
                layui.data('table-filter-test', {
                    key: input.name
                    ,value: input.checked
                })
            });
 
            //$(".lavui-table-grid-down").hide();
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            tableData = table.cache.locDetl;
            console.log(tableData);
            pageCurr=curr;
            limit();
            form.on('checkbox(tableCheckbox)', function (data) {
                var _index = $(data.elem).attr('table-index')||0;
                if(data.elem.checked){
                    res.data[_index][data.value] = 'Y';
                }else{
                    res.data[_index][data.value] = 'N';
                }
            });
            let headerTop = $('.layui-table-header').offset().top; //获取表格头到文档顶部的距离
            let headerPage = $('.layui-table-page').offset().top; //获取表格底部文档顶部的距离
            $(window).scroll(function () {
                if ((headerTop - $(window).scrollTop()) < 0) { //超过了
                    $('.layui-table-header').addClass('table-header-fixed'); //添加样式,固定住表头
                } else { //没超过
                    $('.layui-table-header').removeClass('table-header-fixed'); //移除样式
                }
            });
        }
    });
 
    // 页面修改
    table.on('edit(chooseData)', function (obj) {
        let index = obj.tr.attr("data-index");
        let data = locDetlData[index];
        let modify = true;
        if (obj.field === 'count'){
            let vle = Number(obj.value);
            if (isNaN(vle)) {
                layer.msg("请输入数字", {icon: 2});
                modify = false;
            } else {
                if (vle <= 0) {
                    layer.msg("数量必须大于零", {icon: 2});
                    modify = false;
                }
                if (vle > Number(data.anfme)) {
                    layer.msg("出库数量不得大于库存数量", {icon: 2});
                    modify = false;
                }
            }
        }
        if (modify) {
            data[obj.field] = obj.value;
        }
        tableIns.reload({data: locDetlData});
    });
 
    // 监听头工具栏事件
    table.on('toolbar(chooseData)', function (obj) {
        switch (obj.event) {
            case 'outbound':
                if (locDetlData.length === 0){
                    layer.msg('请先提取商品库存', {icon: 2});
                } else {
                    var data = locDetlData;
                    var brand;
 
                    for(var i=0; i<data.length; i++){
                        if(data[i].status === "暂入库" || data[i].status === "待入库" || data[i].status === "全部出库"|| data[i].weightAnfme < data[i].qtyAnfme){
                            layer.msg("选中的明细还未入库或者已全部出库或者没有剩余可出重量,请重新选择");
                            return;
                        }
 
                        brand = brand ? brand : data[i].brand;
 
                        if(brand != data[i].brand){
                            layer.msg("选中的明细中含有多种牌号,请重新选择");
                            return;
                        }
                        // if(data[i].stockFreeze === 0){
                        //     layer.msg("选中的明细中含有冻结的库存,请解冻后操作");
                        //     return;
                        // }
                    }
 
                    layer.open({
                        type: 2,
                        title: '出库',
                        maxmin: true,
                        area: ['800px', top.detailHeight],
                        shadeClose: false,
                        content: 'sellout.html',
                        success: function(layero, index){
                            //layer.getChildFrame('#data-detail-submit-edit', index).hide();
                            top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                            layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
 
                            var iframe = window['layui-layer-iframe' + index];
                            iframe.child(locDetlData)
                        }
                    });
                }
                break;
        }
    });
 
    // 监听行工具事件
    table.on('tool(chooseData)', function(obj){
        switch (obj.event) {
            case 'remove':
                let index = obj.tr.attr("data-index");
                locDetlData.splice(index, 1);
                tableIns.reload({data: locDetlData});
                break;
        }
    });
 
    // 获取出库口
    function getOutBound(){
        $.ajax({
            url: baseUrl+"/available/take/site",
            headers: {'token': localStorage.getItem('token')},
            method: 'POST',
            async: false,
            success: function (res) {
                if (res.code === 200){
                    var tpl = $("#takeSiteSelectTemplate").html();
                    var template = Handlebars.compile(tpl);
                    var html = template(res);
                    $('#staNoSelect').append(html);
                    form.render('select');
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                }else {
                    layer.msg(res.msg)
                }
            }
        })
    }
 
 
 
    $(document).on('click','#mat-query', function () {
        let loadIndex = layer.msg('请求中...', {icon: 16, shade: 0.01, time: false});
        locDetlLayerIdx = layer.open({
            type: 2,
            title: false,
            closeBtn: false,
            maxmin: false,
            area: ['90%', '85%'],
            shadeClose: true,
            content: 'locDetlQuery.html',
            success: function(layero, index){
                layer.close(loadIndex);
            }
        });
    })
 
})
 
// 添加表格数据
function addTableData(data) {
    for (var i=0;i<data.length;i++){
        let pass = false;
        for (var j=0;j<locDetlData.length;j++){
            if (data[i].matnr === locDetlData[j].matnr && data[i].batch === locDetlData[j].batch && data[i].packageNo === locDetlData[j].packageNo) {
                pass = true;
                break;
            }
        }
        if (pass) {
            data.splice(i--, 1);
        } else {
            data[i]["count"] = data[i]["anfme"];
        }
    }
    locDetlData.push.apply(locDetlData, data);
    tableIns.reload({data: locDetlData});
    layer.close(locDetlLayerIdx);
}
 
function clearTable(){
    locDetlData = [];
    tableIns.reload({data: locDetlData});
    parent.location.reload();
}