1
chenhaozhe
2025-07-02 fe50d723e5d050113c4ecc493220e264f39d8e5f
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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>工厂日历(批量)</title>
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/ext/soulTable.css" media="all">
    <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>
    <script src="../../../layuiadmin/xm-select.js"></script>
    <script src="../../../layuiadmin/zgqCustom/zgqCustom.js"></script>
    <!--<script src="../../../layuiadmin/soulTable.slim.js"></script>--> <!--标题筛选不能引用此js文件-->
</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="formData">
                        <div class="layui-collapse">
                            <div class="layui-colla-item">
                                <div class="layui-colla-title layui-inline">
                                    <div class="layui-inline">
                                        <span>更多</span>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 85px;padding: 9px 18px;">生产车间</label>
                                    <div class="layui-input-block" style="margin-left: 77px;">
                                        <input type="hidden" class="layui-input" lay-filter="HDeptID" name="HDeptID" id="HDeptID" value="0" style="background-color:#efefef4d;width: 60%;display: inline-block;" readonly>
                                        <input type="text" class="layui-input" lay-filter="HDeptName" name="HDeptName" id="HDeptName" value="" style="width: 60%;display: inline-block;">
                                        <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnHDeptID" id="btnHDeptID" style="padding: 0 10px;float: right;margin-right: 3px;">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                        </button>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">日期间隔</label>
                                    <div class="layui-input-block">
                                        <select name="HInitTimeCycle" id="HInitTimeCycle" class="ForFilteringSchemes" lay-filter="HInitTimeCycle" style="width:190px;">
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 85px;">开始日期</label>
                                    <div class="layui-input-block" style="margin-left: 120px;">
                                        <input type="date" class="layui-input" lay-verify="HBeginDate" name="HBeginDate" id="HBeginDate" lay-filter="HBeginDate" style="padding-left: 58px;width:160px;">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 85px;">至:</label>
                                    <div class="layui-input-block" style="margin-left: 120px;">
                                        <input type="date" class="layui-input" lay-verify="HEndDate" name="HEndDate" id="HEndDate" lay-filter="HEndDate" style="padding-left: 58px;width:160px;">
                                    </div>
                                </div>
                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnSave" id="btnSave">批量更新</button>
                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnExit" id="btnExit"  style="padding:0 5px">退出</button>
                            </div>
                        </div>
                        <div class="layui-row" style="padding:10px 0">
                            <div class="layui-col-xs4 layui-inline" style="border: solid 1.5px #e0d6d64d;">
                                <div id="SourceTable" lay-filter ="SourceTable" style="width:99.5%;"></div>
                            </div>
                            <div class="layui-col-xs7 layui-inline" style="padding-left: 10px;">
                                <table class="" id="mainTable" lay-filter="mainTable"></table>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script>
 
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块       
        soulTable: '../ext/soulTable'
    }).use(['tree', 'index', 'form', 'table', 'element', 'laypage', 'laydate', 'util', 'soulTable', 'tableSelect'], 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
            , tree = layui.tree
            , util = layui.util
            , soulTable = layui.soulTable
            , tableSelect = layui.tableSelect;
        var sWhere = "";
        var option = [];
        var sourceOption = [];
        var ins;                        //用于导出excel
        var HModName = "Sc_SHopCalendarNew";
        var titleData = [];
        //#endregion
 
        //#region 进入页面即加载
 
        //初始化界面
        set_ClearBill();
 
        //#endregion
 
        //#region 触发事件:包括form.on(){}格式的所有点击事件、选择事件等
 
        //#region 点击行选中高亮
        table.on('row(SourceTable)', function (obj) {
            //选中行改变颜色
            var flag = !obj.tr.find(':checkbox:first').prop('checked');
            obj.tr.find(':checkbox').prop('checked', flag);
            if (flag) {
                obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
                $('div[lay-id="SourceTable"]').find(obj.tr.selector).attr({
                    "style": "background:#ceedfa;color:black"
                });
            } else {
                obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
                $('div[lay-id="SourceTable"]').find(obj.tr.selector).attr({ "style": "background:" });//取消当前tr颜色
            }
            //mainTable 为表格ID   注意此处如果ID不正确将导致你在监听复选框时获取不到你选择的数据,前面的只是添加或删除选中未选中样式以及设置背景色,字体颜色
            layui.each(table.cache.SourceTable, function (i, l) {
                if (obj.tr.index() == l.LAY_TABLE_INDEX) {
                    l.LAY_CHECKED = flag;
                }
            });
        })
            //#endregion
 
 
        //退出按钮
        form.on('submit(btnExit)', function () {
            Pub_Close(2);
        })
        //退出按钮
        form.on('submit(btnSave)', function () {
            set_SaveBill();
        })
 
 
        //#region 日期间隔下拉列表监听
        form.on('select(HInitTimeCycle)', function (data) {
            var HInitTimeCycle = $("#HInitTimeCycle").val() * 1;
            //若日期间隔不为 任意间隔,则禁用开始日期与结束日期的选择
            if (HInitTimeCycle != -1) {
                //$('#HDate').prop('disabled', true);
                //$('#HDate1').prop('disabled', true);
 
                $("#HBeginDate").val(Format(new Date().setDate(new Date().getDate()), "yyyy-MM-dd"));//欠料日期
                $("#HEndDate").val(Format(new Date().setDate(new Date().getDate() + HInitTimeCycle), "yyyy-MM-dd"));//至
 
            } else {
                //$('#HDate').prop('disabled', false);
                //$('#HDate1').prop('disabled', false);
            }
        });
            //#endregion
 
        //#region 生产车间
        form.on('submit(btnHDeptID)', function (data) {
            btnHDeptID();
        });
        //#endregion
 
 
        //#endregion
 
        //#region 本页面被调用的所有方法
 
        //#region 初始化界面
        function set_ClearBill() {
            //初始化日期间隔、开始日期、结束日期
            setSelect_HInitTimeCycle();
            //若日期间隔不为 任意间隔,则禁用开始日期与结束日期的选择
            var HInitTimeCycle = $("#HInitTimeCycle").val() * 1;
            //初始化日期
            $("#HBeginDate").val(Format(new Date(new Date()), "yyyy-MM-dd"));//提料日期
            $("#HEndDate").val(Format(new Date().setDate(new Date().getDate() + HInitTimeCycle), "yyyy-MM-dd"));//至
            //初始化表格
            set_InitGrid();
            //获取默认车间
            GetDefValByUser();
            //查询
            get_DisplaySource();
        }
        //#endregion
 
        //#region 初始化表格方法
        function set_InitGrid() {
            //部门输入框
            tableSelect.render({
                elem: '#HDeptName',//输入框dom选择
                searchKey: '部门名称,HItemID',//查询的列名
                sWhere: " and 禁用标记 = '' and 车间标记 = 'Y' ",//table搜索sWhere条件 //默认筛选项
                ajaxSelect: function (sWhere) {
                    var data = '';
                    $.ajax({
                        url: GetWEBURL() + '/Gy_Department/list',
                        type: "GET",
                        data: { "sWhere": sWhere, "user": sessionStorage["HMaker"], "Organization": sessionStorage["Organization"] },
                        async: false,
                        success: function (data1) {
                            if (data1.count == 1) {
                                data = data1.data
                            }
                        },
                        error: function () {
                            layer.alert('获取列表失败!', { icon: 15, title: '通信错误' });
                        }
                    });
                    return data;
                },//设置前端分页时可以设置的
                table: {
                    //url: GetWEBURL() + 'Gy_Supplier/page',
                    //where: { user: '翁涛涛', Organization: '浙江智云迈思' },
                    cols: [[
                        { type: 'radio', fixed: 'left' },//需要加这个fixed属性不然点击checkbox会触发行点击导致无法正确点击
                        { field: 'HItemID', title: 'HItemID' },
                        { field: '部门名称', title: '部门名称' },
                    ]],
                    page: true,
                    limit: 5,
                    limits: [5]
                },
                done: function (elem, data) {
                    if (data != []) {
                        $("#HDeptName").val(data.data[0]['部门名称']);
                        $("#HDeptID").val(data.data[0]['HItemID']);
                        get_DisplaySource();
                    }
 
                }
            })
            option = {
                elem: '#mainTable'
                //, toolbar: '#toolbarDemo'
                , height: 'full-50'
                , page: true
                , cellMinWidth: 90
                , totalRow: true
                , limit: 50
                , limits: [50, 500, 1000, 5000]
                //, loading: false               
                , cols: [[
                    { type: 'numbers', title: '序号', width: 80},
                    { field: 'week', title: '星期', width: 120 },
                    { field: 'workHours', title: '上班时间', width: 120, edit: 'text' }
                ]]
                , data: [
                    { "week": "星期日", "workHours": 0 },
                    { "week": "星期一", "workHours": 0 },
                    { "week": "星期二", "workHours": 0 },
                    { "week": "星期三", "workHours": 0 },
                    { "week": "星期四", "workHours": 0 },
                    { "week": "星期五", "workHours": 0 },
                    { "week": "星期六", "workHours": 0 }
                ]
                , done: function (res, curr, count) {
                    soulTable.render(this);
                }
            };
            table.render(option);
            sourceOption = {
                elem: '#SourceTable'
                //, toolbar: '#toolbarDemo'
                , height: 'full-50'
                , page: false
                , cellMinWidth: 90
                , totalRow: true
                , limit: 50
                , cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'HItemID', title: 'HItemID', width: 200, hide: true },
                    { field: '生产资源代码', title: '生产资源代码', width: 120 },
                    { field: '生产资源名称', title: '生产资源名称', width: 120 },
                ]]
                , done: function (res, curr, count) {
                    soulTable.render(this);
                }
            };
        }
        //#endregion
 
        //#region 生产车间选择按钮
        function btnHDeptID() {
            layer.open({
                type: 2 //类型
                , skin: 'layui-layer-rim'//加上边框
                , area: ['90%', '90%']//大小
                , title: '部门列表'//标题
                , shift: 2//弹出动画
                , content: ['../../基础资料/公用基础资料/Gy_DepartmentList.html?Type=1&HOrgName=' + sessionStorage["Organization"] , 'yes']
                , btn: ['确定', '取消']
                , btn1: function (index, layero) {//按钮【按钮一】的回调
                    var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
                    var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//获取table的elem:"#test"
                    if (checkStatus.data.length === 0) {
                        return layer.msg('请选择数据');
                    }
                    //获取数据
                    $("#HDeptID").val(checkStatus.data[0].HItemID);
                    $("#HDeptName").val(checkStatus.data[0].部门名称);
                    layer.close(index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                }
                , btn2: function (index, layero) { }
                , end: function () {
                    get_DisplaySource();
                }
            })
        }
        //#endregion
 
        //#region 获取对应车间生产资源
        function get_DisplaySource() {
            var HDeptID = $("#HDeptID").val();
            if (HDeptID != 0 && HDeptID != "") {
                var sWhere = " and 禁用标记 != 'Y' and HDeptID=" + HDeptID
                //进入页面显示的缓存列表
                $.ajax({
                    url: GetWEBURL() + '/Gy_Source/list',
                    type: "GET",
                    async: false,
                    data: { "sWhere": sWhere, "user": sessionStorage["HUserName"] },
                    success: function (data1) {
                        if (data1.count == 1) {
                            sourceOption.data = data1.data;
                            table.render(sourceOption);
                        } else {
                            layer.alert(data1.code + data1.Message, { icon: 5 });
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
 
                });
            }
 
        }
        //#endregion
 
        //#region 初始日期间隔 下拉列表
        function setSelect_HInitTimeCycle() {
            var valueList = [7,30, 45, 60];
            var titleList = ["近7天","近一月", "近45天", "近60天"];
 
            var HInitTimeCycle_ArrayList = '<option  value="-1" selected="selected" >任意间隔</option>';
            for (var i = 0; i < valueList.length; i++) {
                HInitTimeCycle_ArrayList += '<option  style="color:blue;" value="' + valueList[i] + '">' + titleList[i] + '</option>';
            }
 
            $("#HInitTimeCycle").empty();
            $("#HInitTimeCycle").append(HInitTimeCycle_ArrayList);
            
 
            $("#HInitTimeCycle").val("7");
            form.render('select');
        }
            //#endregion
 
        //#region 时间列表相关函数
        function generateWorkHoursData(startDate, endDate, originalData) {
            const result = [];
            const currentDate = new Date(startDate);
            const lastDate = new Date(endDate);
 
            // 创建一个星期映射表(中文星期名 -> workHours)
            const weekHoursMap = {};
            originalData.forEach(item => {
                weekHoursMap[item.week] = item.workHours;
            });
 
            // 遍历日期范围
            while (currentDate <= lastDate) {
                const dayOfWeek = currentDate.toLocaleDateString('zh-CN', { weekday: 'long' }); // 获取中文星期名,如 "星期一"
                const formattedDate = currentDate.toISOString().split('T')[0]; // 格式化为 YYYY-MM-DD
 
                result.push({
                    date: formattedDate,
                    week: dayOfWeek,
                    workHours: weekHoursMap[dayOfWeek] || 0, // 如果没有匹配的星期,默认 0
                });
 
                currentDate.setDate(currentDate.getDate() + 1); // 下一天
            }
 
            return result;
        }
        //#endregion
 
        //#region 通过登录用户获取默认值
        function GetDefValByUser() {
            var index = layer.load();
            $.ajax({
                url: GetWEBURL() + "/Cj_StationInBill/GetDefValByUser",
                type: "GET",
                async: false,
                data: { "Czybm": sessionStorage["Czybm"], "Czymc": sessionStorage["HUserName"] },
                success: function (result) {
                    var data = result.data[0];
 
                    form.val("formData", {
                        "HDeptID": data.HDeptID,
                        "HDeptName": data.部门名称,
                    });
                    layer.close(index);
                }
                , error: function () {
                    layer.close(index);
                    layer.msg("接口请求失败");
                }
            })
        }
            //#endregion
 
        //#region 保存方法
        function set_SaveBill() {
            var checkStatus = table.checkStatus('SourceTable')
                , data = checkStatus.data;
            var sSubStr = table.cache["mainTable"];
            //根据开始时间结束日期生成新数据
            const newData = generateWorkHoursData($("#HBeginDate").val(), $("#HEndDate").val(), sSubStr);
            if (newData.length == 0) {
                return layer.msg("请检查开始时间和结束日期是否合理");
            }
            var sMainSub = JSON.stringify(data) + ';' + JSON.stringify(newData) + ';' + sessionStorage["HUserName"];
            if (data.length > 0) {
                $.ajax({   //异步请求
                    type: "POST",  //请求类型
                    url: GetWEBURL() + "MaterOutEntryReport/Sc_ShopCalendarSaveList", //方法所在页面和方法名
                    async: true,            //是否异步进行请求
                    data: { "sMainSub": sMainSub },    // 将hmaterid作为请求参数发送发送到服务器的数据
                    dataType: "json",              //类型为json
                    success: function (data) {// 当请求成功时执行的回调函数  
                        if (data.count == 1) { // 说明验证成功了,   // 检查返回的数据中count属性的值是否为1,这可能表示操作成功  
                            layer.msg("成功", { icon: 1 }); //使用layer插件显示一个消息,图标为1(通常表示成功)
                        }
                        else {
                            layer.alert(data.Message, { icon: 5 });// 如果操作未成功,显示一个包含错误信息的警告框,图标为5(通常表示错误)  
                        }
                        layer.closeAll("loading");  //关闭所有正在显示的加载层
                    },
                    error: function (err) { // 当请求失败时执行的回调函数  
                        layer.alert("错误:" + err, { icon: 5 });  //示一个包含错误信息的警告框,图标为5  
                        console.log("Reason" + sMainStr); //在控制台打印错误信息
                    }
 
                })
            } else {
                layer.msg("请选择至少一个工作资源")
            }
        }
            //#endregion
 
        //#endregion
        //以上是layui模块
    });
    function GetHDeptNameValue(obj)  //返回车间
    {
        $("#HDeptID").val(obj[0].HItemID);//车间id
        $("#HDeptName").val(obj[0].部门名称);//车间名称
    }
</script>