duhe
2024-07-17 c1026f4ea28bb26ba4e047fdd777836707730eaa
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
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; 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="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <!--<script src="../../../layuiadmin/layui/layui.js"></script>-->
    <script src="../../../layuiadmin/zgqCustom/zgqCustom.js"></script>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/Scripts/json2.js"></script>
    <script src="../../../layuiadmin/Scripts/jquery-1.4.1.js"></script>
    <script src="../../../layuiadmin/Scripts/webConfig.js"></script>
    <script src="../../../layuiadmin/PubCustom.js"></script>
 
    <style type="text/css">
        input.layui-input.layui-unselect {
            padding-right: 0;
        }
    </style>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-col-md12">
            <div class="layui-card" style="padding: 1px">
                <div class="layui-card-body" style="padding: 1px;">
                    <form class="layui-form" action="" lay-filter="component-form-group">
                        <div class="layui-collapse">
                            <div class="layui-colla-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 100px">生产任务单号:</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="HBillNo" id="HBillNo" placeholder="请输入后回车" class="layui-input" value="" style="float:left;width:260px;">
                                        <input type="text" name="HBillNo1" id="HBillNo1" style="display:none">
                                    </div>
                                </div>
                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnPack" id="btnPack" style="padding: 0 30px; margin-left: 150px">条码生成</button>
                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnAssembly" id="btnAssembly" style="padding:0 30px">拼装生成</button>
                            </div>
                        </div>
                    </form>
                </div>
 
                <div class="layui-tab layui-tab-card" lay-filter="TabTest">
                    <ul class="layui-tab-title">
                        <li class="layui-this">明细信息</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index', //主入口模块
        }).use(['index', 'form', 'table', 'element', 'laypage', 'laydate'], function () {
            //#region 公共变量
            var $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , table = layui.table
                , form = layui.form
                , element = layui.element
                , laypage = layui.laypage
                , laydate = layui.laydate
                , util = layui.util
            //查询条件
            var option = [];
            //#endregion
 
            //#region 初始化
            //初始化表格
            $("#HBillNo").focus();
            set_InitGrid();
            //#endregion
 
            //#region 点击事件包括on form事件等
            //扫源单
            $('#HBillNo').on('keydown', function (event) {
                if (event.keyCode == 13) {
                    var HBillNo = $('#HBillNo').val();
                    $.ajax({
                        url: GetWEBURL() + 'Sc_ICMOBill/QK_PackingBillByXSBill',
                        type: "GET",
                        data: { "HBillNo": HBillNo },
                        success: function (result) {
                            if (result.count == 1) {
                                option.data = result.data;
                                table.render(option);
                            }
                            else {
                                layer.alert(result.code + result.Message, { icon: 5 });
                            }
                        }, error: function () {
                            layer.close(index0);
                            layer.alert("接口请求失败!", { icon: 5 });
                        }
                    });
                }
            });
            //整箱生成
            form.on('submit(btnPack)', function (data) {
                var flag = "ZZ";
                var sSubStr = table.checkStatus('mainTable');
                if (sSubStr.data.length > 0) {
                    SavePack(flag,sSubStr);
                }
                else {
                    layer.msg('请最少选择1行数据!');
                    return;
                }
            });
            //拼箱生成
            form.on('submit(btnAssembly)', function (data) {
                var flag = "PZ";
                var sSubStr = table.checkStatus('mainTable');
                if (sSubStr.data.length > 1) {
                    SavePack(flag,sSubStr);
                }
                else {
                    layer.msg('请最少选择2行数据!');
                }
            });
            //监听单元格编辑  单元格编辑后 变更
            table.on('edit(mainTable)', function (obj) {
                // 单元格编辑之前的值
                var oldText = $(this).prev().text();
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
 
                switch (field) {
                    case "HSPlanQty":  //最小包装数
                        var HPlanQty = parseInt(isNaN(data.HPlanQty) ? 0 : data.HPlanQty);
                        if (HPlanQty<=0) {
                            layer.msg('数量为空,无可处理数量');
                            obj.update({
                                HSPlanQty: 0,
                                HMinQty: 0,                          //最小包装数
                                HTotalQty:0,      //生成包装数=数量/最小包装数
                                HSpsQty: 0,              //剩余数量=数量%最小包装数
                            });
                        }
                        break;
                    case "HMinQty":  //最小包装数
                        value = parseInt(isNaN(value) ? 0 : value);
                        var HSPlanQty = parseInt(isNaN(data.HSPlanQty) ? 0 : data.HSPlanQty);
                        var HPlanQty = parseInt(isNaN(data.HPlanQty) ? 0 : data.HPlanQty);
                        //同步更新表格和缓存对应的值
                        obj.update({
                            HMinQty: value,                          //最小包装数
                            HTotalQty: Math.floor(HSPlanQty / value),     //生成包装数=数量/最小包装数
                            HSpsQty: HPlanQty-(HSPlanQty - HSPlanQty % value)               //剩余数量=数量%最小包装数
                        });
                        break;
                    default:
                }
            });
            //#endregion
 
 
            //#region 此页面所有方法
            //初始化明细表格
            function set_InitGrid() {
                columns = [
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'HSeOrderBillNo', title: '销售订单号', edit: 'text', width: 100, hide: true }
                    , { field: 'HInterID', title: 'HInterID', edit: 'text', width: 100, hide: true }
                    , { field: 'HEntryID', title: 'HEntryID', edit: 'text', width: 100, hide: true }
                    , { field: 'HBillNo', title: 'HBillNo', edit: 'text', width: 100, hide: true }
                    , { field: 'HMaterID', title: 'HMaterID', edit: 'text', width: 100, hide: true }
                    , { field: 'HMaterNumber', title: 'HMaterNumber', edit: 'text', width: 100, hide: true }
                    , { field: 'HMaterName', title: '物料名称', edit: 'false', width: 100 }
                    , { field: 'HUnitID', title: 'HUnitID', edit: 'text', width: 100, hide: true }
                    , { field: 'HUnitName', title: '计量单位', edit: 'false', width: 100 }
 
                    , { field: 'HPlanQty', title: '数量', edit: 'false', totalRow: true, width: 100 }
                    , { field: 'HSPlanQty', title: '处理数量', edit: 'text', totalRow: true, event: 'HSPlanQty', width: 100 }
                    , { field: 'HMinQty', title: '最小包装数', edit: 'text', totalRow: true, event: 'HMinQty', width: 100 }
                    , { field: 'HTotalQty', title: '生成条数', edit: 'false', totalRow: true, width: 100 }
                    , { field: 'HSpsQty', title: '剩余数量', edit: 'false', totalRow: true, width: 100 }
                    , { field: 'HXH', title: '箱号', edit: 'false', width: 100 }
 
                    , { field: 'FBillNo', title: '销售订单号', edit: 'false', width: 100 }
                    , { field: 'FLXName', title: '联系人', edit: 'text',  width: 100 }
                    , { field: 'FInAddress', title: '收货方地址', edit: 'false', width: 100 }
                    , { field: 'FMaterName', title: '销售物料名称', edit: 'false', width: 100 }
                    , { field: 'FBZFS', title: '包装方式', edit: 'false', width: 100 }
                    , { field: 'FHX', title: '花型', edit: 'false', width: 100 }
                    , { field: 'FQK', title: '墙咔缝', edit: 'false', width: 100 }
                    , { field: 'FWBBZ', title: '外包备注', edit: 'false', width: 100 }
 
                    , { field: 'HCusID', title: 'HCusID', edit: 'text', width: 100, hide: true }
                    , { field: 'HCusName', title: '客户', edit: 'false', width: 100 }
                    , { field: 'HEmpID', title: 'HEmpID', edit: 'text', width: 100, hide: true }
                    , { field: 'HEmpName', title: '业务员', edit: 'false', width: 100 }
                    
                    , { field: 'HDeptID', title: 'HDeptID', edit: 'text', width: 100, hide: true }
                    , { field: 'HDeptName', title: '生产车间', edit: 'false', width: 100 }
 
                    , { field: 'HPlanEndDate', title: '计划完工日期', width: 100, templet: "<div>{{d.HPlanEndDate ==null ?'':layui.util.toDateString(d.HPlanEndDate, 'yyyy-MM-dd')}}</div>"}
                ];
                option = {
                    id: 'mainTable'
                    , elem: '#mainTable'
                    , toolbar: '#toolbarDemo'
                    , page: false
                    , totalRow: true
                    , cellMinWidth: 120
                    , height: 500
                    , cols: [columns]
                    , limit: 500 //每页默认显示的数量
                    , done: function (res, curr, count) {
                    }
                };
                option.data = [{ "HMaterID": 0, "HMaterName": "", "HUnitID": 0, "HUnitName": "", "HPlanQty": 0, "HSPlanQty": 0, "HMinQty": 0, "HTotalQty": 0, "HSpsQty": 0, "HCusID": 0, "HCusName": "", "HEmpID": 0, "HEmpName": "", "HDeptID": 0, "HDeptName": "","HPlanEndDate":"" }];
                table.render(option);
            }
            //生成
            function SavePack(flag,sSubStr) {
                if (!AllowLoadData(sSubStr))//数据验证
                {
                    return false;
                }
                $.ajax(
                    {
                        type: "POST",
                        url: GetWEBURL() + "/Sc_ICMOBill/QK_PackingBillSavePack", //方法所在页面和方法名
                        async: true,
                        data: { "msg": JSON.stringify(sSubStr.data) + ";" + sessionStorage["HUserName"] + ";" + sessionStorage["OrganizationID"] + ";" + flag + ";" + $('#HBillNo').val()},
                        dataType: "json",
                        success: function (data) {
                            if (data.count == 1) { // 说明验证成功了,
                                var PrintIds = data.code;
                                PrintIds = PrintIds.substring(0, PrintIds.length - 1);
                                var Type = "HQKPackBill";
                                var OpenTmp = "";
                                if (sSubStr.data[0].FBZFS == "" && (sSubStr.data[0].FHX != "" || sSubStr.data[0].FMaterName != "")) {
                                    OpenTmp = "花型条码";
                                }
                                else {
                                    OpenTmp = "包装方式条码";
                                }
                                window.open("../../基础资料/公用基础资料/HBarPlanPrint.html?linterid=" + PrintIds.toString() + "&Type=" + Type.toString() + "&OpenTmp=" + OpenTmp.toString());
 
                            }
                            else {
                                f_alert(data.Message);
                                console.log("Reason" + sMainStr + "sub:" + JSON.stringify(layui.table.cache.mainTable));
                            }
                            layer.closeAll("loading");
                        },
                        error: function (err) {
 
                            f_alert("错误:" + err);
                        }
                    });
            }
            
            //非空验证
            function AllowLoadData(sSubStr) {
                var Result = true;
                if (typeof (sSubStr) != "undefined" && typeof (sSubStr) != "") {
                    for (var i = 0; i < sSubStr.data.length; i++) {
                        if (sSubStr.data[i].HMinQty == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,最小包装数不能为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                        if (sSubStr.data[i].HXH == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,箱号不能为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                    }
                }
                else {
                    return Result = true;
                }
                return Result;
            }
            //?
            function f_alert(sMsg) {
                layer.alert(sMsg, { icon: 5 });
 
            }
            //#endregion
            //以上是layui模块
        });
    </script>
</body>
</html>