1
wtt
2024-09-29 5d232f3b7fea78c77ee63fd7b2c0a733cd8987c0
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
<!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">
    <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>
    <style type="text/css">
 
        /*begin 此样式用于消除行元素中布局宽度不够的问题*/
        .layui-form-item .layui-inline {
            margin-top: 5px;
            margin-bottom: 5px;
            margin-right: 0px;
        }
 
        .layui-form-label {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 31px;
            font-weight: 400;
            line-height: 20px;
            text-align: left;
        }
    </style>
</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="form0" 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>-->
                                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="Exit" onclick='window.frames["系统管理/用户管理/Xt_UserSupliesList.html"] '>退出</button>
                                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="set_Excel">Excel导入</button>
                            </div>
                        </div>
                        <div class="layui-card-body">
                            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                                <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">用户</label>
                                                <div class="layui-input-inline">
                                                    <input type="text" name="UserName" id="UserName" readonly class="layui-input" value="" style="float:left;width:150px;">
                                                    <input type="hidden" name="UserID" id="UserID" class="layui-input" value="" style="float:left;width:150px;">
                                                    <button type="button" lay-submit="" id="button_Edit"  class="layui-btn" lay-filter="UserList" style="width:40px;">
                                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
 
                        <table class="layui-hide" 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-AddLine"><i class="layui-icon layui-icon-form"></i>增加一行</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-CopyLine"><i class="layui-icon layui-icon-form"></i>复制一行</button>
 
                            </div>
                        </script>
                        <script type="text/html" id="xuhao">
                            {{d.LAY_TABLE_INDEX+1}}
                        </script>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        //获取参数
        var params = get_UrlVars();
        if (typeof (params[params[0]]) == "undefined") {
            var OperationType = 1;//操作类型
            var closeType = 2;  //关闭类型
        } else {
            var OperationType = params[params[0]];//操作类型
            var linterid = params[params[1]];//源单id
            var HSouceBillType = params[params[2]];//源单类型
            var closeType = params[params[3]];  //关闭类型
        }
 
        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;
            //查询条件
            var option = [];
            TabRow = { "HSupID": 0, "HSupperNumber": "", "HSupperName": "" };
            //#endregion
 
 
            //#region 进入页面既加载
 
            //初始化表格
            set_InitGrid();
 
            //判断操作类型
            if (OperationType == 1) {//无源新增
                //无源新增
                set_AddFNew();
            }
            else if (OperationType == 3) {//编辑
                set_EditFromGrid(linterid);
                $('#button_Edit').addClass("layui-btn-disabled").attr("disabled", true);
            }
            else {
                layer.alert("未知操作类型!", { icon: 5 });
            }
            //#endregion
 
            //#region 点击事件,包括on和form事件
            //头工具栏
            table.on('toolbar(mainTable)', function (obj) {
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;;
                var AddRow = table.cache['mainTable'];
                var NewRow = { "HSupID": 0, "HSupperNumber": "", "HSupperName": "" };//不能用tabrow代替,layui会自动加上index属性
                switch (obj.event) {
                    //新增一行
                    case 'btn-AddLine': btnAddLine(NewRow);
                        break;
                    //复制一行
                    case 'btn-CopyLine': btnCopyLine(data);
                        break;
                }
            });
 
            //#region 点击行选中高亮
            table.on('row(mainTable)', 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');  //设置复选框选中样式
                    $(obj.tr.selector).attr({ "style": "background:#ceedfa;color:black" });//改变当前tr背景颜色和字体颜色
                } else {
                    obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
                    $(obj.tr.selector).attr({ "style": "background:" });//取消当前tr颜色
                }
                //mainTable 为表格ID   注意此处如果ID不正确将导致你在监听复选框时获取不到你选择的数据,前面的只是添加或删除选中未选中样式以及设置背景色,字体颜色
                layui.each(table.cache.mainTable, function (i, l) {
                    if (obj.tr.index() == l.LAY_TABLE_INDEX) {
                        l.LAY_CHECKED = flag;
                    }
                });
            })
            //#endregion
            //行内事件
            table.on('tool(mainTable)', function (obj) {
                set_GridDelete(obj);   //行内删除
                set_GridCellCheck(obj); //行内快捷键筛选
            });
            //用户信息弹窗
            form.on('submit(UserList)', function () {
                //页面层-自定义
                layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    title: '验收员列表',
                    closeBtn: 1,
                    shift: 2,
                    area: ['80%', '80%'],
                    maxmin: true,
                    content: ['../../PublicPage/PeopleInformation.html', '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('请选择数据');
                        }
                        $("#UserName").val(checkStatus.data[0].HName);
                        $("#UserID").val(checkStatus.data[0].HNumber);
 
                        $.ajax({
                            url: GetWEBURL() + "/Xt_User/SupperPlaylist",
                            type: "GET",
                            data: { "HUserID": checkStatus.data[0].HNumber },
                            success: function (data) {
                                if (data.data != null && data.data != "") {
                                    option.data = data.data;
                                    table.render(option);
                                }
                                else {
                                    table.reload("mainTable", {});
                                    table.reload('mainTable', { data: [] });
                                }
 
                            }
                        });
                        layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                    }
                    , btn2: function (index, layero) {
                        //按钮【按钮二】的回调
                        //return false 开启该代码可禁止点击该按钮关闭
                    },
                    end: function () {
 
                    },
                    success: function (layero, index) {
 
                    }
                });
            });
 
          
            //表格行内事件快捷键筛选
            function set_GridCellCheck(obj) {
                $(document).off('keydown', ".layui-table-edit").on('keydown', '.layui-table-edit', function (e) {
                    if (event.key == "F7") {
                        //供应商代码
                        if (obj.event === 'HSupperNumber')  //模具信息  如果在模具代码列 按F7
                        {
                            //页面层-自定义  //F7选择供应商
                            layer.open({
                                type: 2,
                                skin: 'layui-layer-rim', //加上边框
                                title: '供应商列表',
                                closeBtn: 1,
                                shift: 2,
                                area: ['80%', '80%'],
                                maxmin: true,
                                content: ['../../PublicPage/SupplierInformation.html', '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('请选择数据');
                                    }
                                    var OptionData = checkStatus.data;
                                    if (checkStatus.data.length > 1) {
                                        var rowIndex = $(obj.tr).attr("data-index") * 1;//获取选择列的索引
                                        for (var i = 0; i < OptionData.length; i++) {  //判断选中的数据的长度  用于遍历checkStatus.data数组中的每个元素
                                            if (rowIndex + i >= option.data.length) {           //判断rowIndex + i的索引超出了option.data数组的长度,说明option.data数组需要扩展以包含更多行
                                                var NewRow = { "HSupID": 0, "HSupperNumber": "", "HSupperName": "" };  // 创建一个新的包含数组  
 
                                                table.cache["mainTable"].push(NewRow);    //创建新的包含数组  传入table.cache["mainTable"]数组
                                                option.data = table.cache["mainTable"];  //把传入 table.cache["mainTable"]数组的值赋值给option.data 的属性
 
                                                table.render(option);//渲染界面
                                            }
                                            option.data[rowIndex + i].HSupID = OptionData[i].HItemID;
                                            option.data[rowIndex + i].HSupperNumber = OptionData[i].HNumber;
                                            option.data[rowIndex + i].HSupperName = OptionData[i].HName;
                                        }
                                        table.render(option); //重新渲染表格以显示更新后的数据
                                    } else {
                                        obj.update({
                                            HSupID: checkStatus.data[0].HItemID,
                                            HSupperNumber: checkStatus.data[0].HNumber,
                                            HSupperName: checkStatus.data[0].HName
                                        });
                                    }
                                    //console.log(obj.data);
                                    //同步更新表格和缓存对应的值
                                    
 
                                    layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                                }
                                , btn2: function (index, layero) {
                                    //按钮【按钮二】的回调
                                    //return false 开启该代码可禁止点击该按钮关闭
                                },
                                end: function () {
 
                                }
                            });
                        }
 
                        obj.event = "";
                        return false;
                    }
                })
            }
 
            //保存
            form.on('submit(Saver)', function (data) {
                if ($("#UserName").val() == "") {
                    layer.msg("用户不能为空!");
                    return false;
                }
                var UserID = $("#UserID").val();  //获取选择的用户编码
                //debugger;
                var sSubStr = JSON.stringify(table.cache['mainTable']);
                if (!AllowLoadData(sSubStr))//数据验证
                {
                    return false;
                }
                var list = [];
                for (var i = 0; i < JSON.parse(sSubStr).length; i++) {
                    list.push(JSON.parse(sSubStr)[i].HSupperNumber)
                }
                if (isAllEqual(list)) {
                    layer.msg("有重复的供应商信息!");
                    return false;
                }
 
                var sMainSub = sSubStr + ';' + UserID
                $.ajax(
                    {
                        type: "POST",
                        url: GetWEBURL() + "/Xt_User/SaveUserSupper", //方法所在页面和方法名
                        async: true,
                        data: { "msg": sMainSub },
                        dataType: "json",
                        success: function (data) {
                            if (data.count == 1) { // 说明验证成功了,
                                layer.msg(data.Message, { time: 1 * 1000, icon: 1 }, function () {
                                    $('#add-btn').addClass("layui-btn-disabled").attr("disabled", true);
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    parent.layer.close(index); //再执行关闭                 
                                });
                            }
                            else {
 
                                layer.alert(data.Message);
                                console.log("Reason" + sMainSub + "sub:" + JSON.stringify(layui.table.cache.mainTable));
                            }
                            layer.closeAll("loading");
                        },
                        error: function (err) {
 
                            layer.alert("错误:" + err);
                            console.log("Reason" + sMainStr);
                        }
                    });
            });
 
            //退出
            form.on('submit(Exit)', function (data) {
                if (params[1] != null) {
                    Pub_Close(2);
                } else if (params[1] == null) {
                    var parentWindow = window.parent;
                    Pub_Close(2);
                    parentWindow.openChildPage("系统管理/用户管理/Xt_UserSupliesList.html");
 
                }               
            });
 
            //导入
            form.on('submit(set_Excel)', function () {
                set_Excel();
            });
 
            //#endregion
 
            //#region 此页面所有方法
            //初始化表格
            function set_InitGrid() {
                columns = [
                    { type: 'checkbox', fixed: 'left' }
                    , { templet: '#xuhao', title: '序号', sort: true, fixed: 'left', event: "qwe" }
                    , { field: 'HSupID', title: 'HSupID', edit: 'text', hide: true }
                    , { field: 'HSupperNumber', title: '供应商代码', edit: 'text', event: 'HSupperNumber' }
                    , { field: 'HSupperName', title: '供应商名称', edit: 'text' }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo' }
                ];
                option = {
                    id: 'mainTable'
                    , elem: '#mainTable'
                    , toolbar: '#toolbarDemo'
                    , page: false
                    , cellMinWidth: 120
                    , height: 680
                    , cols: [columns]
                    , limit: 500 //每页默认显示的数量
                    , done: function (res, curr, count) {
                    }
                };
            }
            //无源单新增
            function set_AddFNew() {
                option.data = [{ "HSupID": 0, "HSupperNumber": "", "HSupperName": "" }];
                table.render(option);
            }
 
            //导入
            function set_Excel() {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-rim' //加上边框
                    , area: ['100%', '100%']
                    , title: '用户关联供应商信息列表-导入'
                    , shift: 0//弹出动画
                    , content: '../用户管理/Xt_UserSuplies_Excel.html'
                    , end: function () {
                        //刷新页面,
                        set_InitGrid();
                    }
                })
            }
 
            //编辑
            function set_EditFromGrid(linterid) {
                //编辑加载表头
                $.ajax({
                    url: GetWEBURL() + "GetGy_UserSupplierDetail",
                    type: "GET",
                    data: {
                        "HID": linterid
                    },
                    success: function (result) {
 
                        if (result.code == 1) { // 说明验证成功了,
                            var data = result.data.h_v_Gy_UserSupplierRelationList_Query[0];
                            $("#HItemID").val(data.HItemID);//代码ID
                            $("#UserID").val(data.用户代码);//用户代码
                            $("#UserName ").val(data.用户名称);//用户名称
 
                            layui.form.render();//实时渲染选中和不选中的样式,最好添加这句话
                        } else {
                            layer.alert(result.msg, { icon: 5, btn: ['退出'], time: 100000, offset: 't' });
                        }
                        var arr = [];
                        for (var i = 0; i < result.data.h_v_Gy_UserSupplierRelationList_Query.length; i++) {
                            arr.push({
                                "HSupID": result.data.h_v_Gy_UserSupplierRelationList_Query[i].HSupID,
                                "HSupperNumber": result.data.h_v_Gy_UserSupplierRelationList_Query[i].供应商代码,
                                "HSupperName": result.data.h_v_Gy_UserSupplierRelationList_Query[i].供应商名称,
                            });
 
                        }
                        option.data = arr;
                        table.render(option);
                    }, error: function () {
                        layer.alert("发生错误!", { icon: 5 });
                    }
                });
            }
 
            //增加一行
            function btnAddLine(NewRow) {
                table.cache["mainTable"].push(NewRow);//将NewRow对象添加到table.cache["mainTable"]数组中,  数组存储了表格的所有行数据
                option.data = table.cache["mainTable"];//更新option.data为新的数据数组显示到表格上  //将数据绑定到data上
 
                table.render(option);  //渲染表格
            }
            //复制一行
            function btnCopyLine(data) {
                var copydata = JSON.stringify(data);
                if (data.length <= 0) {
                    layer.msg("请选择需要复制的一行!");
                }
                else if (data.length > 1) {
                    layer.msg("只能选择复制一行!");
                }
                else {
                    var copydata2 = copydata.substring(1, copydata.length);//去除首行字符'['
                    var copyrow = copydata2.substring(0, copydata2.length - 1);//去除末尾字符']'
                    table.cache["mainTable"].push(JSON.parse(copyrow));//将复制的行强转成json追加到表格上
                    option.data = table.cache["mainTable"];//将数据绑定到data上
                    table.render(option);//将数据渲染到表格上
                }
            }
            // 表格行内事件删除
            function set_GridDelete(obj) {
                var data = obj.data;
                var rowIndex = $(obj.tr).attr("data-index");
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        var oldData = table.cache["mainTable"];
                        oldData.splice(obj.tr.data('index'), 1);
                        table.reload('mainTable', { data: oldData });
                        layer.close(index);
                    });
                }
            }
            //#region 判断数据数组中的值是否相同
            function isAllEqual(list) {
                var s = list.join(",") + ",";
                for (var i = 0; i < list.length; i++) {
                    if (s.replace(list[i] + ",", "").indexOf(list[i] + ",") > -1) {
                        return true;
                    }
                }
            }
            //#region 非空验证
            function AllowLoadData(sSubStr) {  //非空验证
                var Result = true;
                if (typeof (sSubStr) == "undefined" || sSubStr == "") {
                    layer.msg("没有物料明细记录", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    return Result = false;
                }
                if (typeof (sSubStr) != "undefined" && typeof (sSubStr) != "") {
                    sSubStr = JSON.parse(sSubStr);
                    for (var i = 0; i < sSubStr.length; i++) {
                        if (sSubStr[i].供应商代码 == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,供应商代码为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return Result = false;
                        }
                    }
                }
                else {
                    return Result = true;
                }
                return Result;
            }
 
        });
    </script>
</body>
</html>