1
pzy
2024-08-11 db08b0f3239df006eadea02d004451ab6a90eb5f
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
<!DOCTYPE html>
<html>
<head>
    <meta 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.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>
 
    <div id="layout1" class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <form id="form" class="layui-form" lay-filter="component-form-group" action="">
                        <div class="layui-card-header">
                            <div class="layui-btn-group">
 
                                <button type="button" id="add-btn" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Saver">保存</button>
                                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Exit">退出</button>
 
                            </div>
 
                        </div>
                        <div class="layui-card-body">
                            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                                <h1 style="text-align:center;"><b>休息日</b></h1>
                                <div class="layui-tab-content">
                                    <div class="layui-tab-item layui-show">
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label" style="width: 120px">代码:</label>
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" name="HNumber" lay-verify="HNumber" id="HNumber" autocomplete="off">
                                                    <input name="HItemID" id="HItemID" autocomplete="off" type="hidden">
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label" style="width: 120px">名称:</label>
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" name="HName" id="HName" autocomplete="off">
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label" style="width: 120px">助记码:</label>
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" name="HHelpCode" id="HHelpCode" autocomplete="off">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label">车间</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="HDeptName" id="HDeptName" class="layui-input" value="" style="float:left;width:150px;">
                                                    <input type="hidden" name="HDeptID" id="HDeptID" value="0">
                                                    <button type="button" lay-submit="" class="layui-btn" lay-filter="HDept-BT" 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" style="width: 120px">休息日期:</label>
                                                <div class="layui-input-inline">
                                                    <input type="date" class="layui-input" lay-verify="HRestDay" name="HRestDay" id="HRestDay">
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label" style="width: 120px">生产组织:</label>
                                                <div class="layui-input-inline">
                                                    <select name="HOrgID" id="HOrgID" lay-verify="HOrgID">
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <label class="layui-form-label" style="width: 120px">使用组织:</label>
                                                <div class="layui-input-inline">
                                                    <select name="HUSEORGID" id="HUSEORGID" lay-verify="HUSEORGID">
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label" style="width: 120px">使用状态:</label>
                                                <div class="layui-input-inline">
                                                    <select name="HUseFlag" id="HUseFlag" lay-verify="HUseFlag">
                                                        <option value="未检测" selected>未检测</option>
                                                        <option value="未使用">未使用</option>
                                                        <option value="已使用">已使用</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="layui-inline">
                                                <label class="layui-form-label" style="width: 120px"> 禁用标志:</label>
                                                <div class="layui-input-inline">
                                                    <input type="checkbox" name="HStopflag" id="HStopflag" lay-skin="primary" title="" value="">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-col-xs11">
                                                <label class="layui-form-label"> 备注:</label>
                                                <div class="layui-input-block">
                                                    <input class="layui-input" name="HRemark" id="HRemark" autocomplete="off">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
 
    <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/zgqCustom/zgqCustom.js"></script>
    <script>
        //获取参数
        var params = get_UrlVars();
        if (typeof (params[params[0]]) == "undefined") {
            var OperationType = 1;//操作类型
        } else {
            var OperationType = params[params[0]];//操作类型
            var linterid = params[params[1]];//源单id
            var HSouceBillType = params[params[2]];//源单类型
        }
        HRestDay
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate', 'table', 'element'], function () {
            //#region 公共变量
            var $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , table = layui.table
                , form = layui.form
                , laydate = layui.laydate
                , element = layui.element;
            //#endregion
            //#region 进入页面即加载
            var HOrgIDBar = "";
            var HOrgIDBar1 = "";
          
            //判断操作类型
            if (OperationType == 1) {//无源单
                //初始化界面
                set_ClearBill();
                set_AddFNew();
                //初始化日期
                $("#HRestDay").val(Format(new Date(), "yyyy-MM-dd"));
 
            }
            else if (OperationType == 3) {//编辑
                set_EditFromGrid();
               
            }
            else {
                layer.alert("未知操作类型!", { icon: 5 });
            }
            //#endregion
 
            //#region 触发事件:包括form.on(){}格式的所有点击事件、选择事件等
 
            //反关闭
            form.on('submit(HDept-BT)', function (data) {
                get_Department( );
            });
 
 
            //保存
            form.on('submit(Saver)', function (data) {//保存
                var isWeekendCheck = isWeekend(data.field.HRestDay);
                if (isWeekendCheck == true) {
                    var isEndCheck = document.getElementById("HStopflag").checked;
                    isEndCheck == true ? data.field.HStopflag = 'true' : data.field.HStopflag = 'false';//将数组合并成字符串
                    var sMainStr = JSON.stringify(data.field) + ";" + sessionStorage["HUserName"];
                    $.ajax(
                        {
                            type: "POST",
                            url: GetWEBURL() + "SaveGy_RestDayList", //方法所在页面和方法名
                            async: true,
                            data: { "msg": sMainStr },
                            dataType: "json",
                            success: function (data) {
                                if (data.count == 1) { // 说明验证成功了,
                                    layer.msg(data.Message, { icon: 1 });
                                    $('#add-btn').addClass("layui-btn-disabled").attr("disabled", true);
                                }
                                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);
                                console.log("Reason" + sMainStr);
                            }
                        });
                } else {
                    f_alert("休息日期不是星期六或星期日,请重现选择!");
                }
              
            });
            //退出
            form.on('submit(Exit)', function (data) {//
                if (linterid == undefined) {
                    //关闭页签
                    Pub_Close(2);
                }
                else {
                    //关闭页签
                    Pub_Close(1);
                }
            });
 
            //监听提交
            form.verify({
                numberOrEmpty: function (value, item) {
                    // if (value != '') {
                    if (!/^\d+$/.test(value)) {
                        return '不能为空或数字或者0';
                    }
                    //}
                }
            });
            //#endregion
 
 
            //#region 当前页面面所有的方法
 
            //初始化界面
            function set_ClearBill() {
                Organ();
                Organ1();
            }
            //无源单新增
            function set_AddFNew() {
                $("#HItemID").val("0");
                $("#HNumber").val("");
                var HName = sessionStorage["HUserName"]
                set_HDeptOrgId(HName);
            }
            //编辑
            function set_EditFromGrid() {
                $("#HItemID").val(linterid);
                set_EditForm(linterid);  //编辑获取表头
                //初始化界面
                set_ClearBill();
            }
            //编辑加载表头
            function set_EditForm(linterid) {
                //查询检验方案单是否存在
                $.ajax({
                    url: GetWEBURL() + "GetGy_RestDayDetailEdit",
                    type: "GET",
                    async: false,
                    data: {
                        "HID": linterid
                    },
                    success: function (result) {
                        if (result.code == 1) { // 说明验证成功了,
                            var data = result.data.h_v_Gy_RestDay[0];
                            $("#HItemID").val(data.HItemID);//代码ID
                            $("#HNumber").val(data.休息日代码);//代码
                            $("#HName").val(data.休息日名称);//名称
                            $("#HHelpCode").val(data.助记码);//助记码
                            $("#HUSEORGID").val(data.HUSEORGID);//使用组织
                            $("#HUseFlag ").val(data.使用状态);//使用状态
                            $("#HDeptID").val(data.HDeptID);//代码ID
                            $("#HDeptName").val(data.车间名称);//代码
                            $("#HRestDay").val(formatDate(data.休息日期));//代码
                            $("#HOrgID").val(data.生产组织);//使用组织
                            $("#HRemark").val(data.备注);//备注
                            $("input[name='HStopflag']").attr("checked", data.禁用标志 == "是" ? true : false);//true:选中 false:不选中
                            layui.form.render();//实时渲染选中和不选中的样式,最好添加这句话
                            //组织的值HOrgID变化,重新渲染
                            HOrgIDBar = data.HUSEORGID;
                            HOrgIDBar1 = data.HOrgID;
                        } else {
                            layer.alert(result.msg, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                        }
                    }, error: function () {
                        layer.alert("发生错误!", { icon: 5 });
                    }
                });
            }
 
            //#region 部门选择页面
            function get_Department() {
 
                layer.open({ 
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    title: '部门列表',
                    closeBtn: 1,
                    shift: 2,
                    area: ['90%', '90%'],
                    maxmin: true,
                    content: ['../../../views/基础资料/公用基础资料/Gy_DepartmentList.html', '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('请选择数据');
                        }
 
                        $("#HDeptID").val(checkStatus.data[0].HItemID);//部门id
                        $("#HDeptName").val(checkStatus.data[0].部门名称);//部门名称
 
                        layer.close(layer.index);
                    }
                    , btn2: function (index, layero) {
                    },
                    end: function () {
 
                    }
                });
            }
            //#endregion
 
            //根据当前人获取部门,组织
            function set_HDeptOrgId(HName) {
                $.ajax({
                    url: GetWEBURL() + "GetGy_RestDayDetail",
                    type: "GET",
                    data: {
                        "HName": HName
                    },
                    success: function (result) {
                        if (result.code == 1) { // 说明验证成功了,
                            var data = result.data.Gy_Czygl[0];
                            $("#HDeptID").val(data.HDeptID);//代码ID
                            $("#HDeptName").val(data.部门名称);//代码
                            $("#HNumber").val(generateString(data.部门编码, data.组织编码));//代码
                            $("#HName").val(generateString1(data.部门名称, data.组织名称));//名称
 
                        } else {
                            layer.alert(result.msg, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                        }
                    }, error: function () {
                        layer.alert("发生错误!", { icon: 5 });
                    }
                });
            }
            //自动生成代码
            function generateString(HDeptNumber, HOrgNumber) {
                var currentDate = new Date();
                var year = currentDate.getFullYear();
                var month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 获取月份时需加1,且补齐两位数
                var day = currentDate.getDate().toString().padStart(2, '0'); // 获取日期,且补齐两位数
                // 拼接字符串
                var result = HDeptNumber + '-' + HOrgNumber + '-' + year + month + day;
                return result;
            }
            //自动生成名称
            function generateString1(HDeptName, HOrgName) {
                var currentDate = new Date();
                var year = currentDate.getFullYear();
                var month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // 获取月份时需加1,且补齐两位数
                var day = currentDate.getDate().toString().padStart(2, '0'); // 获取日期,且补齐两位数
                // 拼接字符串
                var result = HDeptName + '-' + HOrgName + '-' + year + month + day;
                return result;
            }
            //判断是否是周六周日
            function isWeekend(dateString) {
                var date = new Date(dateString);
                var dayOfWeek = date.getDay();
                return (dayOfWeek === 0 || dayOfWeek === 6);
            }
            //返回页面提示信息
            function f_alert(sMsg) {
                layer.alert(sMsg, { icon: 5 });
 
            }
            //#region  时间转换
            function formatDate(date) {
                var d = new Date(date),
                    month = '' + (d.getMonth() + 1),
                    day = '' + d.getDate(),
                    year = d.getFullYear();
 
                if (month.length < 2) {
                    month = '0' + month;
                }
                if (day.length < 2) {
                    day = '0' + day;
                }
 
                return [year, month, day].join('-');
            }
            //获取登录页组织列
            function Organ() {
                var Organization = '';
                $.ajax({
                    type: "get",
                    async: false,
                    url: GetWEBURL() + "/Web/GetOrganizations",
                    success: function (result) {
                        if (result.count == 1) { // 说明验证成功了,
                            var data = result.data;
                            for (var i = 0; i < data.length; i++) {
                                Organization += '<option  style="color:blue;" value="' + data[i].ID + '">' + data[i].Name + '</option>';
                            }
                            $("#HUSEORGID").append(Organization);
                            if (OperationType == 1 || OperationType == 4) {
                                HOrgIDBar = sessionStorage["OrganizationID"];
                            }
                            $("#HUSEORGID").val(HOrgIDBar);
                            form.render('select');
                        }
                        layer.closeAll("loading");
                    }
                })
            }
            function Organ1() {
                var Organization1 = '';
                $.ajax({
                    type: "get",
                    async: false,
                    url: GetWEBURL() + "/Web/GetOrganizations",
                    success: function (result) {
                        if (result.count == 1) { // 说明验证成功了,
                            var data = result.data;
                            for (var i = 0; i < data.length; i++) {
                                Organization1 += '<option  style="color:blue;" value="' + data[i].ID + '">' + data[i].Name + '</option>';
                            }
                            $("#HOrgID").append(Organization1);
                            if (OperationType == 1 || OperationType == 4) {
                                HOrgIDBar1 = sessionStorage["OrganizationID"];
                            }
                            $("#HOrgID").val(HOrgIDBar1);
                            form.render('select');
                        }
                        layer.closeAll("loading");
                    }
                })
            }
            //#endregion
        });
 
    </script>
</body>
</html>