龙山汽配专用调整MES-UI前端界面
1
yusijie
2023-05-26 d1c9ed51388f9e11a3f837082fdce86b686d378d
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
<!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">
    <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/treeTable.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/layui/lay/modules/util.js"></script>
    <style media="screen">
        .custom-tree-item-clicked {
            color: #FC9003
        }
        .layui-form-item .layui-inline {
            margin-bottom: 5px;
             margin-right: 0px; 
        }
    </style>
</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="component-form-group">
                        <div class="layui-card-header">
                            <div class="layui-btn-group">
                                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="get_Refresh">刷新</button>
                                <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-collapse">
                            <div class="layui-colla-item">
                                <div class="layui-form-item" style="border-top: solid 1px #F6F6F6;">
                                    <div class="layui-row" style="padding:10px 0">
                                        <div class="layui-col-xs3 layui-inline">
                                            <div id="treeUser" lay-filter="treeUser" class="demo-tree demo-tree-box" style="height:650px;overflow: scroll;"></div>
                                        </div>
                                        <div class="layui-col-xs9 layui-inline">
                                            <div>
                                                <table class="" id="mainTable" lay-filter="mainTable"></table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
 
    <script src="../../layuiadmin/layui/zgqlayui.js"></script>
    <script src="../../layuiadmin/zgqCustom/zgqCustom.js"></script>
    <script src="../../layuiadmin/PubCustom.js"></script>
    <script>
        //获取参数
        var params = get_UrlVars();
        if (typeof (params[params[0]]) == "undefined") {
            var OperationType = 1;//操作类型
            var TreeFlag = true;//操作类型
        } else {
            debugger;
            var OperationType = params[params[0]];//操作类型
            var linterid = params[params[1]];//源单id
            var HSouceBillType = params[params[2]];//源单类型
        }
 
        var treeCkData = { id: 0 };
        var TagId = "";
        var TagParentId = "";
 
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index', //主入口模块
        }).use(['tree', 'index', 'form', 'table', 'element', 'laypage', 'laydate'], function () {
            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
            var sGnbm = "";
            if (TreeFlag == "false") {
                //$(".layui-col-xs3").css("display", "none"); //隐藏树型
                //$(".layui-col-xs9").css("width", "100%"); //设置宽度
            }
            else {
                tree.render({
                    elem: '#treeUser',
                    data: getData(),
                    showCheckbox: false,     //是否显示复选框
                    id: 'demoId',
                    isJump: false, //是否允许点击节点时弹出新窗口跳转
                    showLine: true,//是否开启连接线
                    onlyIconControl: true,   //点击后不收缩
                    isopen: false,  //加载完毕后的展开状态,默认值:true
                    accordion: false,
                    click: function (obj) {
                        //点击高光
                        if (obj.data.id !== treeCkData.id) {
                            $('div[data-id="' + obj.data.id + '"] span').eq(1).last().addClass("custom-tree-item-clicked");
                            $('div[data-id="' + treeCkData.id + '"] span').eq(1).last().removeClass('custom-tree-item-clicked');
                            treeCkData = obj.data;
                            TagId = obj.data.id;
                            TagParentId = obj.data.ParentID;
                        }
                        //else {
                        //    $('div[data-id="' + treeCkData.id + '"] span').eq(1).last().removeClass('custom-tree-item-clicked');
                        //    treeCkData = { id: 0 };
                        //    TagId = "";
                        //    TagParentId = "";
                        //}
                        sGnbm = obj.data.id;
                        get_Display(sGnbm);
                    }
                });
            }
 
 
 
            var option = {
                id: 'mainTable'
                ,elem: '#mainTable'
                //, toolbar: '#toolbarDemo'
                , height: '650'
                , limit: Number.MAX_VALUE // 数据表格默认全部显示
                , page: false
                , cellMinWidth: 90
                , cols: [[
                    { type: 'checkbox', fixed: 'left', width: 60 }
                    , { field: 'hid', title: 'hid', sort: true, hide: true }
                    , { field: 'gnbm', title: 'gnbm', sort: true, hide: true }
                    , { field: 'AuthorityHID', title: 'AuthorityHID', edit: 'text', sort: true, hide: true }
                    , {
                        field: 'AuthorityID', title: '是否权限', templet: function (row) {
                            if (row.AuthorityID == 1) {
                                return "<span style='color:green;'>是</span>";
                            }
                            else {
                                return "否";
                            }
                        }
                    }
                    //, {
                    //    field: 'AuthorityHID', title: '是否权限', templet: function (row) {
                    //        var html = "<input type='checkbox' lay-skin='primary' lay-filter='checkboxIsSelected' table-index='" + row.LAY_TABLE_INDEX + "' class='checkboxIsSelected' value='" + row.AuthorityHID + "' ";
                    //        if (row.AuthorityID == 1) {
                    //            html += " checked ";
                    //        }
                    //        html += ">";
                    //        return html;
                    //    }}
                    , { field: 'gnms', title: '功能说明' }
                ]], done: function (res, page, count) {
 
                    //可以自行添加判断的条件是否选中
                    //这句才是真正选中,通过设置关键字LAY_CHECKED为true选中,这里只对第一行选中
                    for (var i = 0; i < res.data.length; i++) {
                        if (res.data[i].AuthorityID == 1) {
                            res.data[i]["LAY_CHECKED"] = 'true';
                            //下面三句是通过更改css来实现选中的效果
                            var index = res.data[i]['LAY_TABLE_INDEX'];
                            $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                            $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                        }
                    }
                   
                }
            };
 
            var index = layer.load(0, { shade: false });
            //进入页面显示的缓存列表
            get_Display(sGnbm);
 
 
            //退出
            form.on('submit(Exit)', function (data) {
                if (OperationType == 1) {
                    //关闭页签
                    Pub_Close(2);
                }
                else {
                    //关闭页签
                    Pub_Close(1);
                }
            });
 
            //刷新按钮
            form.on('submit(get_Refresh)', function () {//提交
                layer.confirm('继续对当前所选用户进行更改权限?', { icon: 3, title: '提示' }, function (index) {
                    location.replace('PowerInformation.html?OperationType=3&linterid=' + linterid + '&HSouceBillType=');
                });
            })
 
            //监听选中数据
            table.on('checkbox(mainTable)', function (obj) {
                //console.log(obj.checked); //当前是否选中状态
                //console.log(obj.data); //选中行的相关数据
                //console.log(obj.type); //如果触发的是全选,则为:all,如果触发的是单选,则为:one
                if (obj.type == 'one') {
                    if (obj.checked) {
                        //同步更新表格和缓存对应的值
                        obj.update({
                            AuthorityHID: 1,
                        });
                    }
                    else {
                        //同步更新表格和缓存对应的值
                        obj.update({
                            AuthorityHID: 0,
                        });
                    }
                }
                else {
                    if (obj.checked) {
                        //同步更新表格和缓存对应的值
                        var tableBak = table.cache["mainTable"]; //获取表格数据
                        buttonArr = [];//清空数组
                        for (var i = 0; i < tableBak.length; i++) {
                            tableBak[i].AuthorityHID = 1;
                            buttonArr.push(tableBak[i]);  //将之前的数据存储
                        }
                        //table.reload("mainTable", {
                        //    data: buttonArr    //将数据重新载入表格
                        //})
                    }
                    else {
                        //同步更新表格和缓存对应的值
                        var tableBak = table.cache["mainTable"]; //获取表格数据
                        buttonArr = [];//清空数组
                        for (var i = 0; i < tableBak.length; i++) {
                            tableBak[i].AuthorityHID = 0;
                            buttonArr.push(tableBak[i]);  //将之前的数据存储
                        }
                        //table.reload("mainTable", {
                        //    data: buttonArr    //将数据重新载入表格
                        //})
                    
                      
                    }
                }
 
            });
 
            //保存
            form.on('submit(Saver)', function (data) {
                if (TagId == "" || TagId == null) {
                    layer.alert("左侧点击树型数据已失效!", { icon: 5 });
                    return false;
                }
                var sSubStr = JSON.stringify(table.cache['mainTable']);
                var sMainSub = TagId + ';' + sSubStr + ';' + linterid;
                //console.log(sMainSub);
                //return false;
                $.ajax(
                    {
                        type: "POST",
                        url: GetWEBURL() + "/Gy_MaintenanceMode/SaverPower", //方法所在页面和方法名
                        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);
                                    get_Display(sGnbm);
                                });
                            }
                            else {
                                layer.alert(data.Message);
                            }
                            layer.closeAll("loading");
                        },
                        error: function (err) {
                            layer.alert("错误:" + err);
                        }
                    });
 
 
 
            });
 
            //加载数据表格
            function get_Display(sGnbm) {
                $.ajax({
                    url: GetWEBURL() + '/PublicPageMethod/PowerList',
                    type: "GET",
                    data: { "czybm": linterid, "sGnbm": sGnbm },
                    success: function (data1) {
                        if (data1.count == 1) {
                            option.data = data1.data;
                            table.render(option);
                            layer.close(index);
                        }
                    }, error: function () {
                        layer.close(index);
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
            }
 
            //以上是layui模块
        });
 
        //查询树状数据
        function getData() {
            var treeData;
 
            $.ajax({
                url: GetWEBURL() + '/Gy_MaintenanceMode/PowerLoadTree',
                type: "GET",
                //data: { "sWhere": sWhere },
                async: false,
                success: function (result) {
                    var data = result.data;
                    //生成数据对象集合
                    treeData = LoadTree(data);
 
                }
            });
            return treeData;
        }
        /**处理树形展示数据,要求有ID和ParentID、title字段**/
        function LoadTree(data) {
            let map = {};
            let treeData = [];
            data.forEach(it => {
                map[it.id.toUpperCase()] = it;    //ID为每个节点的id
            })
            //生成结果集
            data.forEach(it => {
                const parent = map[it.ParentID.toUpperCase()];   //ParentID为父节点的id
                if (parent) {
                    if (!Array.isArray(parent.children)) parent.children = [];
                    parent.children.push(it);
                } else {
                    treeData.push(it)
                }
            })
            return treeData;
        }
 
    </script>
 
</body>
</html>