王佳豪
2021-07-10 32bb782c3ff2dee184e485f1ebd71c10313571a1
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/cool.css" media="all">
    <link rel="stylesheet" href="../../static/css/common.css" media="all">
    <link rel="stylesheet" href="../../static/css/print.css" media="all">
 
</head>
<body>
<div>
    <div style="padding-top: 8px; padding-left: 8px">
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <input id="mnemonic" placeholder="请输入生产单号" class="layui-input" lay-verify="mnemonic" autocomplete="off">
            </div>
            <div id="data-search-btn" style="display: inline-block; margin: 0" class="layui-btn-container layui-form-item">
                <button id="search" class="layui-btn layui-btn-primary layui-btn-radius" lay-submit onclick="onSearch()">搜索</button>
                <button id="reset" class="layui-btn layui-btn-primary layui-btn-radius" lay-submit onclick="reload()">重置</button>
            </div>
        </div>
 
    </div>
    <div class="layui-form" style="padding-top: 8px; padding-left: 8px">
        <button style="margin-bottom: 0px" class="layui-btn layui-btn-sm layui-form-item" style="display: inline-block"
                id="outbound" lay-submit
                lay-event="outbound" onclick="outbound()">启动出库
        </button>
    </div>
    <table class="layui-hide" id="stockOut" lay-filter="stockOut" style="margin-top: 0px"></table>
</div>
 
</body>
<script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/js/handlebars/handlebars-v4.5.3.js"></script>
<script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script>
<script>
    var orderData = parent.getOrderData();
    var locData = [];
    var table;
    var sourceData = [];
 
    function getCol() {
        var cols = [
            {type: 'checkbox'}
            , {field: 'warehouseName', align: 'center', title: '库区名称'}
            , {field: 'warehouse', align: 'center', title: '库位编号'}
            , {field: 'anfme', align: 'center', title: '数量', edit: 'text'}
        ];
        cols.push.apply(cols, locNormalCols);
        cols.push({field: 'modiUser$', align: 'center', title: '修改人员', hide: true}
            , {field: 'modiTime$', align: 'center', title: '修改时间', hide: true})
        return cols;
    }
 
    layui.use(['table', 'laydate', 'form'], function () {
        table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer;
        var layDate = layui.laydate;
        var form = layui.form;
        // 数据渲染
        locDetlTableIns = table.render({
            elem: '#stockOut',
            headers: {token: localStorage.getItem('token')},
            url: baseUrl + '/outStock/query/locNormalList?fbillNo=' + orderData.fbillNo,
            page: true,
            limit: 9999,
            limits: [9999],
            even: true,
//            cellMinWidth: 50,
            cols: [getCol()],
            request: {
                pageName: 'curr',
                pageSize: 'limit'
            },
            parseData: function (res) {
                return {
                    'data': res.data,
                    'code': res.code,
                }
            },
            response: {
                statusCode: 200
            },
            done: function (res, curr, count) {
                if (res.code === 403) {
                    top.location.href = baseUrl + "/";
                }
                if (res.code === 200) {
                    locData = res.data;
                    sourceData = [];
                    if (res.data && res.data.length > 0) {
                        res.data.map(function (item) {
                            var obj = {
                                anfme: item.anfme,
                                id: item.id,
                                matnr: item.matnr,
                                supplier: item.supplier,
                                mnemonic: item.mnemonic,
                                warehouse: item.warehouse,
                                warehouseName: item.warehouseName,
                                maktx: item.maktx,
                                lgnum: item.lgnum,
                                type: item.type,
                            }
                            sourceData.push(obj);
                        });
                    }
                }
            }
        });
 
        // 页面修改
        table.on('edit(stockOut)', function (obj) {
            if (obj.field === 'anfme') {
                if (isNaN(obj.value)) {
                    layer.msg("请输入数字");
                    locDetlTableIns.reload();
                }
                // 单元格编辑之前的值进行比较
                for (var i = 0; i < sourceData.length; i++) {
                    if (obj.data.id == sourceData[i].id) {
                        if (Number(obj.value) > sourceData[i].anfme) {
                            layer.msg("数量不可大于库存量");
                            locDetlTableIns.reload();
                        }
                    }
                }
                if (obj.value <= 0) {
                    layer.msg("数量不可小于等于零");
                    locDetlTableIns.reload();
                }
            }
        });
    });
 
    /* 启动出库 */
    function outbound() {
        var checkStatus = table.checkStatus('stockOut');
        var checkData = checkStatus.data;
        var obj = {
            list: checkData,
            supplier: orderData.fbillNo,
        }
        if (checkData.length > 0) {
            $.ajax({
                url: baseUrl + "/outStock/locNormal",
                headers: {'token': localStorage.getItem('token')},
                contentType: 'application/json;charset=UTF-8',
                data: JSON.stringify(obj),
                method: 'POST',
                traditional: true,
                success: function (res) {
                    if (res.code === 200) {
                        parent.closeDetail(res.msg);
                    } else if (res.code === 403) {
                        top.location.href = baseUrl + "/";
                    } else {
                        layer.msg(res.msg)
                    }
                }
            })
        } else {
            layer.msg("请选择需要出库物料");
            return;
        }
    }
 
    function onSearch() {
        var mnemonic = $("#mnemonic").val();
        locDetlTableIns.reload({
            where: {
                mnemonic: mnemonic,
            }
        });
    }
 
    function reload() {
        var mnemonic = ""
        $("#mnemonic").val(mnemonic);
        locDetlTableIns.reload({
            where: {
                mnemonic: mnemonic,
            }
        });
    }
 
    $('body').keydown(function () {
        if (event.keyCode === 13) {
            onSearch();
        }
    });
</script>
</html>