wtt
2026-04-08 1f0f42d549a5a5759934096ec40cb70c73531da9
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<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">
    <!-- 注意:所有引用路径保持与原项目一致,确保功能完整 -->
    <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/zgqCustom/zgqCustom.js"></script>
    <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/layui/layui.js"></script>
    <script src="../../../layuiadmin/SetColumn.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form" action="" lay-filter="component-form-group" autocomplete="off">
                        <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">生产车间</label>
                                    <div class="layui-input-block">
                                        <select name="HDeptID" id="HDeptID" lay-verify="required" lay-search class="layui-input ForFilteringSchemes">-->
                                            <!-- 动态渲染车间 -->
                                        <!--</select>
                                    </div>
                                </div>-->
                                <!-- 物料 -->
                                <div class="layui-inline">
                                    <label class="layui-form-label">模具</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" name="HMouldNumber" id="HMouldNumber" style="float:left;width:150px;">
                                        <input type="hidden" class="layui-input" name="HMouldID" id="HMouldID" value="0">
                                        <button type="button" lay-submit="" class="layui-btn" lay-filter="HMaterList" style="width:40px;">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                        </button>
                                    </div>
                                </div>
                                <!--<div class="layui-inline">
                                    <label class="layui-form-label">费用项目</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" name="HItMoneyName" id="HItMoneyName" style="float:left;width:150px;">
                                        <input type="hidden" class="layui-input" name="HItMoneyID" id="HItMoneyID" value="0">
                                        <button type="button" lay-submit="" class="layui-btn" lay-filter="HItemMoneyList" style="width:40px;">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                        </button>
                                    </div>
                                </div>-->
                                <!--<div class="layui-inline">
                                    <label class="layui-form-label">成本对象 </label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" name="HCostObjectName" id="HCostObjectName" style="float:left;width:150px;">
                                        <input type="hidden" class="layui-input" name="HCostObjectID" id="HCostObjectID" value="0">
                                        <button type="button" lay-submit="" class="layui-btn" lay-filter="HCostobjList" style="width:40px;">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                        </button>
                                    </div>
                                </div>-->
                                <!--<div class="layui-inline">
                                    <label class="layui-form-label">工序</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" name="HProcName" id="HProcName" style="float:left;width:150px;">
                                        <input type="hidden" class="layui-input" name="HProcID" id="HProcID" value="0">
                                        <button type="button" lay-submit="" class="layui-btn" lay-filter="HProcList" style="width:40px;">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                        </button>
                                    </div>
                                </div>-->
                                <!-- 开始年月 -->
                                <div class="layui-inline" style="margin-left: 20px;">
                                    <label class="layui-form-label">开始年月</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" id="ID-laydate-start-month" placeholder="选择开始年月" readonly>
                                    </div>
                                </div>
 
                                <!-- 结束年月 -->
                                <div class="layui-inline" style="margin-left: 20px;">
                                    <label class="layui-form-label">结束年月</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" id="ID-laydate-end-month" placeholder="选择结束年月" readonly>
                                    </div>
                                </div>
                                <!-- 查询按钮 -->
                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnSearch" id="btnSearch">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                                <!-- 重置按钮 -->
                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnReSearch" id="btnReSearch" style="padding:0 5px">重置</button>
                            </div>
                        </div>
                    </form>
                    <div style="margin-top: 10px;">
                        <table class="" id="mainTable" lay-filter="mainTable"></table>
                        <!-- 表格头工具栏 -->
                        <script type="text/html" id="toolbarDemo">
                            <div class="layui-btn-container">
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-reload2"><i class="layui-icon layui-icon-refresh"></i>刷新</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="get_export2"><i class="layui-icon layui-icon-export"></i>导出</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_HideColumn2"><i class="layui-icon layui-icon-form"></i>列设置</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_SouceExcel" id="set_SouceExcel"><i class="layui-icon layui-icon-delete"></i>导入</button>
                            </div>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
 
    <script>
        layui.config({
            base: '../../../layuiadmin/'
        }).extend({
            index: 'lib/index',
        }).use(['index', 'form', 'table', 'element', 'laydate', 'soulTable', 'tableSelect'], function () {
            var $ = layui.$,
                admin = layui.admin,
                layer = layui.layer,
                table = layui.table,
                form = layui.form,
                element = layui.element,
                laydate = layui.laydate,
                soulTable = layui.soulTable,
                tableSelect = layui.tableSelect;
 
            // 模块名(用于列设置存储)
            var HModName = "Sc_MouldMonthUseReport";
            // 表格选项
            var option = {
                elem: '#mainTable',
                toolbar: '#toolbarDemo',
                height: 'full-120',      // 适当留出底部空间
                page: true,
                cellMinWidth: 90,
                totalRow: true,
                limit: 500,
                limits: [50, 500, 5000, 20000],
                done: function (res, curr, count) {
                    soulTable.render(this);
                },
                cols: [[]]
            };
            // 启动页面
            initPage();
 
            function initPage() {
                // 渲染车间下拉框
                loadDeptSelect();
 
                // 设置默认日期: 开始年月为7个月前,结束年月为今天
                var currentDate = new Date();
                var lastMonth = new Date(currentDate);
                lastMonth.setMonth(currentDate.getMonth() - 6);
 
                // 新增:渲染开始年月选择器
                laydate.render({
                    elem: '#ID-laydate-start-month',
                    type: 'month',
                    format: 'yyyy-MM',
                    value: lastMonth,
                    done: function (value, date) {
                        // 可以选择在这里触发查询
                        // getFastQuery(2);
                    }
                });
 
                // 新增:渲染结束年月选择器
                laydate.render({
                    elem: '#ID-laydate-end-month',
                    type: 'month',
                    format: 'yyyy-MM',
                    value: currentDate,
                    done: function (value, date) {
                        // 可以选择在这里触发查询
                        // getFastQuery(2);
                    }
                });
 
                getFastQuery(2);
                // 重新渲染表单元素(select等)
                form.render('select');
            }
 
            // 获取车间下拉
            function loadDeptSelect() {
                $.ajax({
                    type: "GET",
                    url: GetWEBURL() + "/Sc_ICMOBill/GetHDeptList",
                    async: false,
                    data: { "HOrgID": sessionStorage["OrganizationID"] || 1 }, // 默认组织1
                    success: function (result) {
                        var html = '<option value="0" style="color:red;" selected>全部车间</option>';
                        if (result.count == 1 && result.data) {
                            var data = result.data;
                            for (var i = 0; i < data.length; i++) {
                                html += '<option style="color:blue;" value="' + data[i].HItemID + '">' + data[i].HName + '</option>';
                            }
                        }
                        $("#HDeptID").html(html);
                        form.render('select');
                    },
                    error: function () {
                        layer.alert('获取车间列表失败', { icon: 2 });
                    }
                });
            }
 
 
 
            // 修改后的getFastQuery函数
            function getFastQuery(type) {
                // 修改:从年月选择器获取值,而不是从日期输入框
                var HStartYearMonth = $("#ID-laydate-start-month").val();
                var HEndYearMonth = $("#ID-laydate-end-month").val();
 
                // 新增:验证是否选择了开始年月
                if (!HStartYearMonth) {
                    layer.msg('请选择开始年月', { icon: 2 });
                    return;
                }
 
                // 新增:验证是否选择了结束年月
                if (!HEndYearMonth) {
                    layer.msg('请选择结束年月', { icon: 2 });
                    return;
                }
 
                // 新增:解析开始年月为年和月
                var startParts = HStartYearMonth.split('-');
                var HStartYear = startParts[0];
                var HStartPeriod = startParts[1];
 
                // 新增:解析结束年月为年和月
                var endParts = HEndYearMonth.split('-');
                var HEndYear = endParts[0];
                var HEndPeriod = endParts[1];
 
                // 新增:验证年月范围是否有效
                var startValue = parseInt(HStartYear) * 100 + parseInt(HStartPeriod);
                var endValue = parseInt(HEndYear) * 100 + parseInt(HEndPeriod);
 
                if (startValue > endValue) {
                    layer.msg('开始年月不能大于结束年月', { icon: 2 });
                    return;
                }
 
                var HCostObjID = $("#HMouldID").val() || '0';
                var HWorkShopID = $("#HDeptID").val() || '0';
                var HWorkShopID = $("#HDeptID").val() || '0';
                var HProcID = $("#HProcID").val() || '0';
 
                // 修改:存储过程参数改为开始年、开始月、结束年、结束月、车间、物料
                var spParams = "'" + HStartYear + "','" + HStartPeriod + "','" +
                    HEndYear + "','" + HEndPeriod + "','" +
                    HWorkShopID + "','" + HCostObjID + "'" + ",'" + HProcID+"'";
                sWhere = spParams;
 
                if (type == 2) {
                    get_Display(spParams);
                }
            }
 
            // 加载阶梯计件数据
            function get_Display(params) {
                var loadIndex = layer.load(1, { shade: false });
 
                var sql = "exec h_p_CB_ActualItemMoneyCost" + params;
 
                $.ajax({
                    url: GetWEBURL() + '/CB_ActualItemMoneyCostController/CB_ActualItemMoneyCostList',
                    type: "GET",
                    data: { "sWhere": sql },
                    success: function (data1) {
                        layer.close(loadIndex);
                        if (data1.count == 1) {
                            // 解析列定义
                            var colDefs = []; // 存放 {id, name, Type}
                            if (data1.list && data1.list.length > 0) {
                                for (var k in data1.list) {
                                    colDefs.push({
                                        id: data1.list[k].ColmCols,
                                        name: data1.list[k].ColmCols,
                                        Type: data1.list[k].ColmType
                                    });
                                }
                            }
 
                            // 构建表格列
                            var cols = [];
                            // 多选框列
                            cols.push({ type: 'checkbox', fixed: 'left', totalRowText: '合计' });
 
                            // 辅助判断日期字段(形如"2025-02-20"),原代码用isValidDate但未定义,简单按字段名是否含横线判断,实际根据业务调整
                            for (var i = 0; i < colDefs.length; i++) {
                                var fieldName = colDefs[i].name;
                                var fieldId = colDefs[i].id;
                                var fieldType = colDefs[i].Type;
 
                                // 针对阶梯报表,有些列可能是动态日期(例如“02-20”),原代码用isValidDate判断,我们简单模拟:如果字段名包含 '-' 且长度<=10 视为日期短列
                                var isShortDate = (fieldName.indexOf('-') > 0 && fieldName.length <= 10);
                                if (isShortDate) {
                                    // 显示成 MM-dd 格式,原代码尝试Format但未定义,此处直接显示原字段名
                                    cols.push({
                                        field: fieldId,
                                        title: fieldName,  // 原代码: Format(fieldName,'MM-dd') 但Format函数可能未引入,保持原样
                                        width: 70,
                                        totalRow: true,
                                        filter: true,
                                        align: 'center'
                                    });
                                } else if (fieldType == 'DateTime') {
                                    cols.push({
                                        field: fieldId,
                                        title: fieldName,
                                        align: 'center',
                                        sort: true,
                                        filter: true,
                                        templet: "<div>{{ d." + fieldId + " == '' ? '' : layui.util.toDateString(d." + fieldId + ", 'yyyy-MM-dd HH:mm:ss') }}</div>",
                                        width: 180
                                    });
                                } else {
                                    cols.push({
                                        field: fieldId,
                                        title: fieldName,
                                        align: 'center',
                                        sort: true,
                                        width: 150,
                                        filter: true
                                    });
                                }
                            }
 
                            // 更新表格配置
                            option.cols = [cols];
                            option.data = data1.data || [];
 
                            // 应用列隐藏设置(如果存在)
                            DisPlay_HideColumn(HModName, sessionStorage["HUserName"] || 'admin', option, []);
 
                            // 渲染表格
                            table.render(option);
                        } else {
                            layer.alert(data1.code + ' ' + data1.Message, { icon: 5 });
                        }
                    },
                    error: function () {
                        layer.close(loadIndex);
                        layer.alert("接口请求失败", { icon: 5 });
                    }
                });
            }
 
            // 重置过滤条件
            // 修改后的clearQuery函数
            function clearQuery() {
                var currentDate = new Date();
                var lastMonth = new Date(currentDate);
                lastMonth.setMonth(currentDate.getMonth() - 7);
 
                // 修改:重新设置开始年月选择器的值
                laydate.render({
                    elem: '#ID-laydate-start-month',
                    type: 'month',
                    format: 'yyyy-MM',
                    value: lastMonth,
                    show: false  // 不显示面板
                });
 
                // 修改:重新设置结束年月选择器的值
                laydate.render({
                    elem: '#ID-laydate-end-month',
                    type: 'month',
                    format: 'yyyy-MM',
                    value: currentDate,
                    show: false  // 不显示面板
                });
 
                $("#HDeptID").val(0);
                $("#HMouldID").val("0");
                $("#HMouldNumber").val("");
                $("#HProcID").val("0");
                $("#HProcName").val("");
                form.render('select');
            }
 
            // ---------- 事件绑定 ----------
            // 查询按钮
            form.on('submit(btnSearch)', function () {
                getFastQuery(2);
                return false;
            });
 
            // 重置按钮
            form.on('submit(btnReSearch)', function () {
                clearQuery();
                getFastQuery(2);
                return false;
            });
 
            // 班组弹出框(保留原有弹窗方式,与tableSelect共存,优先使用tableSelect;同时支持弹窗选择)
 
            // 职员弹出框 HItemMoneyList
            form.on('submit(HMaterList)', function () {
                openHMaterDialog();
                return false;
            });
 
            // 打开模具 (原 get_checkEmp)
            function openHMaterDialog() {
                layer.open({
                    type: 2,
                    skin: 'layui-layer-rim',
                    title: '职',
                    closeBtn: 1,
                    shift: 2,
                    area: ['80%', '80%'],
                    maxmin: true,
                    content: ['../../模治具管理/模治具管理/Gy_MouldFileList.html?openType=2', 'yes'],
                    btn: ['确定', '取消'],
                    btn1: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index];
                        var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');
                        if (checkStatus.data.length === 0) {
                            return layer.msg('请选择数据');
                        }
                        $("#HMouldID").val(checkStatus.data[0].hmainid);
                        $("#HMouldNumber").val(checkStatus.data[0].模具名称);
                        layer.close(index);
                    }
                });
            }
 
            // 头工具栏事件 (mainTable)
            table.on('toolbar(mainTable)', function (obj) {
                switch (obj.event) {
                    case 'set_HideColumn2':
                        get_HideColumnNoPage(HModName, sessionStorage["HUserName"] || 'admin', option, function () { getFastQuery(2); });
                        break;
                    case 'btn-reload2':
                        getFastQuery(2);
                        break;
                    case 'get_export2':
                        exportExcel();
                        break;
                    //导入
                    case 'set_SouceExcel': set_SouceExcel();
                        break;
                    default:
                        break;
                }
            });
 
            // 导出Excel (原 get_Export2)
            function exportExcel() {
                var ModRightNameCheck = "Pay_PaymentEntryReportExcel";
                $.ajax({
                    type: "GET",
                    url: GetWEBURL() + "/LMES/getReportByModRightNameCheck",
                    data: { "ModRightNameCheck": ModRightNameCheck, "user": sessionStorage["HUserName"] },
                    success: function (result) {
                        if (result.count == 1) {
                            var data = option.data || [];
                            // 清洗数据
                            data.forEach(function (item) {
                                for (var key in item) {
                                    if (item[key] == null) item[key] = "";
                                    if (typeof item[key] === 'string') {
                                        item[key] = item[key].replace(/[\r\n]+/g, '').replace(/,/g, '');
                                    }
                                }
                            });
                            table.exportFile("mainTable", data, "xls");
                        } else {
                            layer.alert("当前模块没有导出权限!", { icon: 5 });
                        }
                    },
                    error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
            }
 
            //导入
            function set_SouceExcel() {
                layer.open({
                    type: 2
                    , area: ['100%', '100%']
                    , title: '资料导入'
                    , shift: 0//弹出动画
                    , content: './Gy_WIPBal_Excel.html?OperationType=dao&HSouceBillType='
                })
            }
 
            // 全局辅助函数 Format (如果不存在,简单定义)
            if (typeof Format !== 'function') {
                window.Format = function (date, fmt) {
                    if (!date) return '';
                    var d = new Date(date);
                    var o = {
                        "M+": d.getMonth() + 1,
                        "d+": d.getDate(),
                        "H+": d.getHours(),
                        "m+": d.getMinutes(),
                        "s+": d.getSeconds()
                    };
                    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
                    for (var k in o)
                        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                    return fmt;
                };
            }
 
     
        });
 
        // 下面两个方法供弹窗回调使用 (Gy_EmployeeList.html 和 Gy_Group.html 会调用)
        function GetMouldFileValue(obj)           //器具
        {
            $("#HMouldID").val(obj[0].hmainid);
            $("#HMouldNumber").val(obj[0].模具名称);
        }
        
    </script>
 
</body>
</html>