懒羊羊
2023-11-14 8286c62256f23bc2367a6729c0f46f84215e380b
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
layui.use(['table', 'admin', 'ax','laydate', 'func', 'form', 'element','upload'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var element = layui.element;
    var laydate = layui.laydate;
    var form = layui.form;
    var upload = layui.upload;
    /**
     * 生产工单管理
     */
    var ProductionOrdeInfo = {
        tableId: "productionOrdeInfoTable"
    };
 
    //下载excel导入模板
    $("#btnDownloadExc").click(function () {
        window.location.href = Feng.ctxPath + "/productionOrdeInfo/downloadExcelTemplate"
    });
 
    //执行实例,导入excel
    var uploadInst = upload.render({
        elem: '#btnUploadExc'
        , url: '/productionOrdeInfo/uploadExcel'
        ,accept: 'file'
        , done: function (res) {
            Feng.success("导入成功!");
            table.reload(ProductionOrdeInfo.tableId, {url: Feng.ctxPath + "/productionOrdeInfo/list"});
        }
        , error: function () {
            //请求异常回调
            Feng.success("导入失败!");
        }
    });
    /**
     * 初始化表格的列
     */
    ProductionOrdeInfo.initColumn = function () {
        return [[
            {type: 'radio'},
            {align: 'center', toolbar: '#tableBar', title: '操作',minWidth:330},
            {field: 'id', hide: true, title: 'ID'},
            /*{field: 'salesOrderNo', sort: true, title: '销售工单号'},*/
 
            {field: 'workOrderNo', sort: true, title: '生产工单号',minWidth:150},
 
            /*{field: 'drawingNo', sort: true, title: '图号'},*/
            /*{field: 'productionLine', sort: true, title: '生产线',minWidth:100},*/
            {field: 'materialCode', sort: true, title: '产品编号',minWidth:160},
            // {field: 'materialCode', sort: true, title: '产品编号',minWidth:120,
            //     event: 'materialCodeClick',
            //     style: 'cursor: pointer;color: blue;font-style: italic;text-decoration: underline;'},
            {field: 'materialName', sort: true, title: '产品名称',minWidth:280},
          /*  {field: 'custom', sort: true, title: '客户编号',minWidth:120},*/
 
            {field: 'orderStatus', sort: true, title: '状态',align:'center',width:80,templet: '#orderStatusTpl'},
 
            {field: 'planQty', sort: true, title: '计划数量',align:'center',minWidth:120},
            {field: 'actualQty', sort: true, title: '完成数量',align:'center',minWidth:120},
            // {field: 'actualOnlineQty', sort: true, title: '实际上线数量',minWidth:120},
            /*{field: 'scrapQty', sort: true, title: '报废数量'},
            {field: 'repairQty', sort: true, title: '返修数量'},
            {field: 'actualOnlineQty', sort: true, title: '实际上线数量'},
            {field: 'onlineCompletionMark', sort: true, title: '上线完工标记'},
            {field: 'demandDate', sort: true, title: '需求日期'},*/
            {field: 'planStartTimeString', sort: true, title: '计划开始时间',minWidth:160},
            {field: 'planEndTimeString', sort: true, title: '计划结束时间',minWidth:160},
 
           /* {field: 'serialNumber', sort: true, title: '顺序号'},*/
 
            {field: 'actualStartTime', sort: true, title: '实际开始时间',minWidth:160},
            {field: 'actualEndTime', sort: true, title: '实际结束时间',minWidth:160},
           /* {field: 'marketAreaCode', sort: true, title: '市场区域编码',minWidth:120},*/
            {field: 'softwareVersionCode', sort: true, title: '产品型号',minWidth:120},
            {field: 'productCompanyCode', sort: true, title: '班次',minWidth:120},
 
            /* {field: 'spareField1', sort: true, title: '预留字段1'},
             {field: 'spareField2', sort: true, title: '预留字段2'},
             {field: 'spareField3', sort: true, title: '预留字段3'},
             {field: 'spareField4', sort: true, title: '预留字段4'},
             {field: 'createTime', sort: true, title: '创建时间'},
             {field: 'updateTime', sort: true, title: '更新时间'},
             {field: 'createUser', sort: true, title: '创建人'},
             {field: 'updateUser', sort: true, title: '修改人'},*/
             {field: 'remarks', sort: true, title: '备注'}
 
        ]];
    };
 
    /**
     * 点击查询按钮
     */
    ProductionOrdeInfo.search = function () {
        var queryData = {};
        queryData['workOrderNo'] = $("#workOrderNo").val();
        queryData['materialCode'] = $("#materialCode").val();
        queryData['orderStatus'] = $("#orderStatus").val();
 
        table.reload(ProductionOrdeInfo.tableId, {
            where: queryData, page: {curr: 1}
        });
    };
 
    /**
     * 跳转到添加页面
     */
    ProductionOrdeInfo.jumpAddPage = function () {
        window.location.href = Feng.ctxPath + '/productionOrdeInfo/add'
    };
 
    /**
    * 跳转到编辑页面
    *
    * @param data 点击按钮时候的行数据
    */
    ProductionOrdeInfo.jumpEditPage = function (data) {
        window.location.href = Feng.ctxPath + '/productionOrdeInfo/edit?id=' + data.id
    };
 
    /**
     * 导出excel按钮
     */
    ProductionOrdeInfo.exportExcel = function () {
        var checkRows = table.checkStatus(ProductionOrdeInfo.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };
 
 
    /**
     * 点击开始工单
     */
    ProductionOrdeInfo.startOrder = function (data) {
        var ajax1 = new $ax(Feng.ctxPath + "/productionOrdeInfo/orderCount?orderStatus=3");
        var result1 = ajax1.start();
        if(result1.data===0) {
            var operation = function () {
                var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) {
                    Feng.success("开始工单成功!");
                    table.reload(ProductionOrdeInfo.tableId);
                }, function (data) {
                    Feng.error("开始工单失败!" + data.responseJSON.message + "!");
                });
                ajax.set(data);
                ajax.set("flag","true");
                ajax.start();
            };
            Feng.confirm("是否开始生产?", operation);
        }else {
            layer.open({
                title: "操作提示",
                icon: 0,
                closeBtn: 2,
                area: ['450px', '200px'],
                time: 5000,
                content: '<span style="font-size: 30px;color: red">开始失败,只能有一条生产中的工单进行生产!</span>'
            });
        }
    };
 
    /**
     * 点击冻结工单
     */
    ProductionOrdeInfo.freezeOrder = function (data) {
        // var ajax1 = new $ax(Feng.ctxPath + "/productionOrdeInfo/orderCount?orderStatus=3");
        // var result1 = ajax1.start();
        // if(result1.data>1) {
            var operation = function () {
                var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) {
                    Feng.success("冻结工单成功!");
                    table.reload(ProductionOrdeInfo.tableId);
                }, function (data) {
                    Feng.error("冻结工单失败!" + data.responseJSON.message + "!");
                });
                ajax.set(data);
                ajax.start();
            };
            Feng.confirm("是否冻结工单?", operation);
        // }else {
        //     layer.open({
        //         title: "操作提示",
        //         icon: 0,
        //         closeBtn: 2,
        //         area: ['450px', '200px'],
        //         time: 5000,
        //         content: '<span style="font-size: 30px;color: red">解冻失败,只能有一条生产中的工单进行生产!</span>'
        //     });
        // }
 
    };
 
    /**
     * 点击解冻工单
     */
    ProductionOrdeInfo.thawOrder = function (data) {
        var ajax1 = new $ax(Feng.ctxPath + "/productionOrdeInfo/orderCount?orderStatus=3");
        var result1 = ajax1.start();
        if(result1.data === 0) {
            var operation = function () {
                var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) {
                    Feng.success("解冻工单成功!");
                    table.reload(ProductionOrdeInfo.tableId);
                }, function (data) {
                    Feng.error("解冻工单失败!" + data.responseJSON.message + "!");
                });
                ajax.set(data);
                ajax.start();
            };
            Feng.confirm("是否解冻工单?", operation);
        }else {
            layer.open({
                title: "操作提示",
                icon: 0,
                closeBtn: 2,
                area: ['450px', '200px'],
                time: 5000,
                content: '<span style="font-size: 30px;color: red">解冻失败,只能有一条生产中的工单进行生产!</span>'
            });
        }
    };
 
    /**
     * 点击启用工单
     */
    ProductionOrdeInfo.enableOrder = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) {
                Feng.success("启用工单成功!");
                table.reload(ProductionOrdeInfo.tableId);
            }, function (data) {
                Feng.error("启用工单失败!" + data.responseJSON.message + "!");
            });
            ajax.set(data);
            ajax.start();
        };
        Feng.confirm("是否启用工单?", operation);
    };
    /**
     * 点击关闭工单
     */
    ProductionOrdeInfo.closeOrder = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) {
                Feng.success("关闭工单成功!");
                table.reload(ProductionOrdeInfo.tableId);
            }, function (data) {
                Feng.error("关闭工单失败!" + data.responseJSON.message + "!");
            });
            ajax.set(data);
            ajax.start();
        };
        Feng.confirm("是否关闭工单?", operation);
    };
 
    ProductionOrdeInfo.materialCodeClick = function (data){
        layer.open({
            type: 2,
            area: ['1000px', '600px'],
            title: '物料信息列表',
            content: Feng.ctxPath + '/productionOrdeInfo/materialList',
            success: function (layero, index) {
                window.materialType = '成品';
            },
        });
    }
 
 
    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    ProductionOrdeInfo.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(ProductionOrdeInfo.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };
    var now = new Date();
 
    /**
     * 点击完成
     *
     * @param data 点击按钮时候的行数据
     */
    ProductionOrdeInfo.finish = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) {
                Feng.success("已完成!");
                table.reload(ProductionOrdeInfo.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set(data);
            ajax.start();
        };
        Feng.confirm("是否完成?", operation);
    };
 
    // 渲染表格
    var tableResult = table.render({
        elem: '#' + ProductionOrdeInfo.tableId,
        url: Feng.ctxPath + '/productionOrdeInfo/list',
        toolbar: '#toolbarDemo',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: ProductionOrdeInfo.initColumn()
    });
 
    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        ProductionOrdeInfo.search();
    });
 
    // 添加按钮点击事件
/*    $('body').on('click', '#btnAdd', function() {*/
    $('#btnAdd').click(function () {
        ProductionOrdeInfo.jumpAddPage();
    });
 
    // 导出excel
    $('#btnExp').click(function () {
        ProductionOrdeInfo.exportExcel();
    });
 
 
 
    var data_tr;
    table.on('radio(' + ProductionOrdeInfo.tableId + ')', function (obj) {
        data_tr = $(this);
    });
 
    // 上移按钮点击事件
    $('body').on('click', '#btnUpTr', function() {
        var checkRows = table.checkStatus(ProductionOrdeInfo.tableId);
        if (checkRows.data.length != 1) {
            layer.msg("请选择一行数据!");
            return;
        }
        var tr=$(data_tr).parent().parent().parent();
        if($(tr).prev().html()==null){
            layer.msg("已经是最顶部了!");
            return;
        }else {
            var tbData = table.cache.productionOrdeInfoTable;
            //未上移前,记录本行和上一行数据
            var tem = tbData[tr.index()];
            var tem2 = tbData[tr.prev().index()];
 
            //将本身插入到目标tr之前
            $(tr).insertBefore($(tr).prev());
 
            var num1 = tem.serialNumber;
            var num2 = tem2.serialNumber;
 
            tem.serialNumber = num2;
            tem2.serialNumber = num1;
            //上移之后,数据交换
            tbData[tr.index()]=tem;
            tbData[tr.next().index()]=tem2;
        }
    });
 
    // 下移按钮点击事件
    $('body').on('click', '#btnDownTr', function() {
        var checkRows = table.checkStatus(ProductionOrdeInfo.tableId);
        if (checkRows.data.length != 1) {
            layer.msg("请选择一行数据!");
            return;
        }
        var tr=$(data_tr).parent().parent().parent();
        if($(tr).next().html()==null){
            layer.msg("已经是最低部了!");
            return;
        }else {
            var tbData = table.cache.productionOrdeInfoTable;
            //未上移前,记录本行和下一行数据
            var tem = tbData[tr.index()];
            var tem2 = tbData[tr.next().index()];
 
            // 将本身插入到目标tr的后面
            $(tr).insertAfter($(tr).next());
 
            var num1 = tem.serialNumber;
            var num2 = tem2.serialNumber;
 
            tem.serialNumber = num2;
            tem2.serialNumber = num1;
            //上移之后,数据交换
            tbData[tr.index()]=tem;
            tbData[tr.prev().index()]=tem2;
        }
    });
 
    // 保存顺序
    $('body').on('click', '#btnSaveSort', function() {
        var tbData = table.cache.productionOrdeInfoTable;
        $.ajax({
            url: "/productionOrdeInfo/editItemAll",
            data: JSON.stringify(tbData),
            type: "post",
            contentType: "application/json",
            dataType: "json",
            success: function(data) {
                Feng.success("更新成功!");
                table.reload(ProductionOrdeInfo.tableId);
            },
            error: function (data) {
                if (me.error !== undefined) {
                    me.error(data);
                }
            }
        });
 
    });
 
    //获取当前日期
    function getDateTime(){
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        let time = date.toLocaleTimeString();
        // 对月份进行处理,1-9月在前面添加一个“0”
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        //对日期进行处理,1-9日在前面添加一个“0”
        if (day >= 0 && day <= 9) {
            day = "0" + day;
        }
        let separator = "-"; //添加分隔符“-”
        this.dateTime = year + separator + month + separator + day + " " + time;
        return this.dateTime;
    }
 
 
    // 工具条点击事件
    table.on('tool(' + ProductionOrdeInfo.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
 
        if (layEvent === 'edit') {//编辑
            ProductionOrdeInfo.jumpEditPage(data);
        }
        else if (layEvent === 'start') {//开始
            data.orderStatus = '3';
            //data.actualStartTime = getDateTime();
            ProductionOrdeInfo.startOrder(data);
        }else if (layEvent === 'freeze') {//冻结
            data.orderStatus = '4';
            ProductionOrdeInfo.freezeOrder(data);
        }else if (layEvent === 'thaw') {//解冻
            data.orderStatus = '3';
            ProductionOrdeInfo.thawOrder(data);
        }else if (layEvent === 'close') {//关闭
            data.orderStatus = '6';
            ProductionOrdeInfo.closeOrder(data);
        }else if (layEvent === 'enable') {//启用
            data.orderStatus = '1';
            ProductionOrdeInfo.enableOrder(data);
        }else if (layEvent === 'delete') {
            ProductionOrdeInfo.onDeleteItem(data);
        }else if (layEvent === 'materialCodeClick') {
            ProductionOrdeInfo.materialCodeClick(data);
        }else if (layEvent === 'finish') {//完成
            data.orderStatus = '5';
            data.actualEndTime = getDateTime();
            ProductionOrdeInfo.finish(data);
        }
    });
 
});