bklLiudl
2024-07-23 277bbae216debe7e6c04e8cc6ee6e1ba9763e14b
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
 
 
var ConveyorInfoManager = {
    UserGrid: undefined,
    Server: function () {
        var config = (function () {
            var URL_GetList = "/ConveyorInfoAjax/GetConveyorInfoRecordList";
            
            
            var URL_Add = "/ConveyorInfoAjax/AddConveyorInfo";
            var URL_Run = "/ConveyorInfoAjax/RunConveyorInfo";
            var URL_JiePi = "/ConveyorInfoAjax/JiePiConveyorInfo";
            var URL_Delete = "/ConveyorInfoAjax/DelConveyorInfo";
 
            return {
                URL_GetList: URL_GetList,
                URL_Delete: URL_Delete,
                URL_Run: URL_Run,
                URL_Add: URL_Add,
                URL_JiePi: URL_JiePi, 
            };
        })();
 
        //数据操作服务
        var dataServer = (function ($, config) {
 
            //查询分页列表
            var GetList = function (data, callback) {
                $.gitAjax({
                    url: config.URL_GetList,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Delete = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Delete,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
 
            var Run = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Run,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Add = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Add,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var JiePi = function (data, callback) {
                $.gitAjax({
                    url: config.URL_JiePi,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
 
            return {
                GetList: GetList,
                Delete: Delete,
                Run: Run,
                Add: Add,
                JiePi: JiePi
            }
 
        })($, config);
        return dataServer;
    },
    Dialog: function (ID, Command) {
        var submit = function (v, h, f) {
            if (v) {
                 
                var TaskNo = h.find('input[name="TaskNo"]').val();
                var PalletNo = h.find('input[name="PalletNo"]').val();
                var StartLocatNo = h.find('input[name="StartLocatNo"]').val();
                var EndLocatNo = h.find('input[name="EndLocatNo"]').val();
                var WcsPos = h.find('input[name="WcsPos"]').val();
 
                if (git.IsEmpty(TaskNo)) {
                    $.jBox.tip("请输入任务号", "warn");
                    return false;
                }
                if (git.IsEmpty(StartLocatNo)) {
                    $.jBox.tip("请输入起始工位", "warn");
                    return false;
                }
                if (git.IsEmpty(EndLocatNo)) {
                    $.jBox.tip("请输入目的工位", "warn");
                    return false;
                }
                if (git.IsEmpty(WcsPos)) {
                    $.jBox.tip("请输入控制字", "warn");
                    return false;
                } 
                
                var param = {};
                param["Operation"] = Command;
                param["TaskNo"] = TaskNo; 
                param["PalletNo"] = PalletNo;
                param["StartLocatNo"] = StartLocatNo;
                param["EndLocatNo"] = EndLocatNo;
                param["WcsPos"] = WcsPos;
                param["Id"] = ID;
                
 
                var Server = ConveyorInfoManager.Server();
                Server.Add(param,
                    function(result) {
                        if (result.Code == 1) {
                            var pageSize = $("#mypager").pager("GetPageSize");
                            var pageIndex = $("#mypager").pager("GetCurrent");
                            if (Command == "Add") {
                                ConveyorInfoManager.PageClick(1, pageSize);
                            } else if (Command == "Edit") {
                                ConveyorInfoManager.Refresh();
                            }
                        } else {
                            $.jBox.tip(result.Message, "warn");
                        }
                    });
            }
                
        }
 
        console.log(Command);
        if (Command === "Add") {
            $.jBox.open("get:/Wcs/ConveyorInfo/AddConveyorInfo", "新增", 310, 320, { buttons: { "确定": true, "关闭": false }, submit: submit });
        }
        else if (Command === "Edit") {
            $.jBox.open("get:/Wcs/ConveyorInfo/AddConveyorInfo?Id=" + ID, "编辑", 310, 320, { buttons: { "确定": true, "关闭": false }, submit: submit });
        }
        else if (Command == "XiangQing") { //详情
            $.jBox.open("get:/Wcs/ConveyorInfo/ConveyDetail?Id=" + ID, "详情", 620, 350, { buttons: { "关闭": false } });
        }
    },
 
    PageClick: function (PageIndex, PageSize) {
        $.jBox.tip("正在努力加载数据...", "loading");
        var Server = ConveyorInfoManager.Server();
        var search = ConveyorInfoManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
        //console.log(JSON.stringify(search));
        Server.GetList(search, function (result) {
            ConveyorInfoManager.SetTable(result);
            $.jBox.closeTip();
        });
    },
    Refresh: function () {
        var PageSize = $("#mypager").pager("GetPageSize");
        var PageIndex = $("#mypager").pager("GetCurrent");
        $.jBox.tip("正在努力加载数据...", "loading");
        var Server = ConveyorInfoManager.Server();
        var search = ConveyorInfoManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
        Server.GetList(search, function (result) {
            ConveyorInfoManager.SetTable(result);
            $.jBox.closeTip();
        });
    },
    SetTable: function (result) {
        var ht = masterUI.MMGridHeight();
        var cols = [
            {
                title: '描述', name: 'Text', width: 140, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '设备级别', name: 'Level', width: 100, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
                    var str = "";
                    switch (data) {
                        case "0":
                            str = "IP级别";
                            break;
                        case "1":
                            str = "DB区域级别";
                            break;
                        case "2":
                            str = "工位号级别";
                            break;
                    }
                    return str;
                }
            },
            {
                title: 'PLCIP地址', name: 'IP', width: 100, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: 'PLC状态', name: 'PlcStatusVal', width: 100, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    var color = "#FFFFFF";
                    switch (data) {
                        case "有货,不可放货":
                            color = "#66CDAA";
                            break;
                        case "空闲":
                            color = "#228B22";
                            break;
                        case "申请储位":
                            color = "#2E8B57";
                            break;
                        case "出库完成":
                            color = "#8B8B7A";
                            break;
                        case "堆垛机可以取货":
                            color = "#8B6914";
                            break;
                        case "堆垛机可以放货":
                            color = "#CDAA7D";
                            break;
                        case "连接PLC失败":
                            color = "#FF0000";
                            break;
                        default:
                    }
                return '<div style="background-color:' + color + ';">' + data + '</div>'
                ////return '<div style="background-color:green;width:100%;height:100%"><span>aaaa</span></div>'
                }
            },
            {
                title: '显示屏ip地址', name: 'LedIP', width: 140, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '工位号', name: 'StationNum', width: 50, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: 'PLC偏移量', name: 'PlcPos', width: 100, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: 'WCS偏移量', name: 'WcsPos', width: 100, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '流程字类型', name: 'PosType', width: 100, align: 'center', lockWidth: false, sortable: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            }, 
            {
                title: '操作', name: 'ID', width: 100, align: 'left', lockWidth: false, renderer: function (data, item, rowIndex) {
                    var html = "";
                    html += '<a class="edit dis" href="javascript:void(0)">编辑&nbsp;&nbsp;</a>';
                    html += '<a class="xiangqing dis" href="javascript:void(0)">详情&nbsp;&nbsp;</a>';
                    return html;
                }
            },
        ];
         
 
        if (this.UserGrid == undefined) {
            this.UserGrid = $("#tabList").mmGrid({
                cols: cols,
                items: result.Result.List,
                checkCol: true,
                nowrap: true,
                fullWidthRows: true,
                remoteSort: true,
                multiSelect: false,
                height: ht
            });
            //绑定事件
            ConveyorInfoManager.BindEvent();
        } else {
            this.UserGrid.load(result.Result.List);
        }
        var pageInfo = result.PageInfo;
        if (pageInfo != undefined) {
            $("#mypager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: ConveyorInfoManager.PageClick });
        }
    },
    BindEvent: function () {
 
        this.UserGrid.off("loadSuccess").on('loadSuccess', function (e, data) {
            LoadBtn.SetBtn();
 
        });
 
 
        //编辑删除事件都绑定
        this.UserGrid.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) {
            if ($(e.target).is("a.run")) {
                var id = item.Id;
                var submit = function (v, h, f) {
                    if (v === "ok") {
                        var list = [];
                        list.push(id);
                        var param = {};
                        param["list"] = JSON.stringify(list);
                        var Server = ConveyorInfoManager.Server();
                        Server.Run(param, function (result) {
                            $.jBox.tip(result.Message, "success");
                            var pageSize = $("#mypager").pager("GetPageSize");
                            ConveyorInfoManager.PageClick(1, pageSize);
                        });
                    }
                }
                $.jBox.confirm("执行当前输送线会关闭当前输送线其他物料类型信息,确定要执行当前信息吗?", "提示", submit);
            } else if ($(e.target).is("a.del")) {
                var id = item.Id;
                var submit = function (v, h, f) {
                    if (v === "ok") {
                        var list = [];
                        list.push(id);
                        var param = {};
                        param["list"] = JSON.stringify(list);
                        var Server = ConveyorInfoManager.Server();
                        Server.Delete(param, function (result) {
                            $.jBox.tip(result.Message, "success");
                            var pageSize = $("#mypager").pager("GetPageSize");
                            ConveyorInfoManager.PageClick(1, pageSize);
                        });
                    }
                }
                $.jBox.confirm("确定要删除当前信息吗?", "提示", submit);
            } else if ($(e.target).is("a.jiePi")) {
                var id = item.Id;
                console.log(id);
                var submit = function (v, h, f) {
                    if (v === "ok") {
                        var list = [];
                        list.push(id);
                        var param = {};
                        param["list"] = JSON.stringify(list);
                        console.log(param)
                        var Server = ConveyorInfoManager.Server();
                        Server.JiePi(param, function (result) {
                            $.jBox.tip(result.Message, "success");
                            var pageSize = $("#mypager").pager("GetPageSize");
                            ConveyorInfoManager.PageClick(1, pageSize);
                        });
                    }
                }
                $.jBox.confirm("确定当前信息结批吗?", "提示", submit);
            } else if ($(e.target).is("a.xiangqing")) {
                var ID = item.Id;
                ConveyorInfoManager.Dialog(ID, "XiangQing");
            } else if ($(e.target).is("a.edit")) {
                var ID = item.Id;
                ConveyorInfoManager.Dialog(ID, "Edit");
            }
        });
    },
    GetSelect: function () {
        var list = [];
        if (this.UserGrid != undefined) {
            var rows = this.UserGrid.selectedRows();
            if (rows != undefined && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    list.push(rows[i].UserCode);
                }
            }
        }
        return list;
    },
    GetSearch: function () {
 
        var searchBar = $("div[data-condition='search']");
 
        var StationNum = searchBar.find("input[name='StationNum']").val();
        var Text = searchBar.find("input[name='Text']").val();
 
        var search = {};
        search["StationNum"] = StationNum;
        search["Text"] = Text;
 
        return search;
    },
    ToolBar: function () {
 
        //工具栏按钮点击事件
        $("div.toolbar").find("a.btn").click(function () {
            var command = $(this).attr("data-command");
 
            if (command === "Add") {
                ConveyorInfoManager.Dialog(undefined, command);
            }  
        });
 
        //搜索
        var searchBar = $("div[data-condition='search']");
        searchBar.find("a[data-command='search']").click(function () {
            ConveyorInfoManager.PageClick(1, 15);
        });
 
        ////监听回车事件,用于扫描
        //$("input[name='UserCode']").keydown(function (event) {
        //    if (event.keyCode == 13) {
        //        var value = $(this).val(); UserChangePass
        //        if (!git.IsEmpty(value)) {
        //            ConveyorInfoManager.PageClick(1, 15);
        //            setTimeout(function () {
        //                $("input[name='UserCode']").val("");
        //                $("input[name='UserCode']").focus();
        //            }, 300);
        //        }
        //    }
        //});
 
        //$("input[name='UserCode']").focus();
        //加载默认数据
        ConveyorInfoManager.PageClick(1, 15);
    }
};