智云srmLayUi(安瑞和瑞琪)(通用版本)
111
王 垚
2022-12-16 7f55a1f12d5c4e00d95668a31a542ca848850ea2
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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>隐藏列设置</title>
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <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="../../../../../Scripts/webConfig.js"></script>
    <style>
        /* 防止下拉框的下拉列表被隐藏---必须设置--- */
        .layui-table-cell {
            overflow: visible !important;
        }
        /* 使得下拉框与单元格刚好合适 */
        td .layui-form-select {
            margin-top: -10px;
            margin-left: -15px;
            margin-right: -15px;
        }
    </style>
</head>
<body>
    <div class="layui-fluid" style="padding: 0;">
        <div class="layui-card" style="padding: 2px;background-color: #efefef;">
            <div class="layui-card-body" style="padding: 1px;">
                <form class="layui-form" action="" lay-filter="formData" style="background-color:white;">
                    <div style="padding: 10px; ">
                        <button class="layui-btn layui-btn-normal" type="button" lay-submit="" lay-filter="CheckAll" id="CheckAll">全选</button>
                        <button class="layui-btn layui-btn-normal" type="button" lay-submit="" lay-filter="ClearBill" id="ClearBill">全清</button>
                        <button class="layui-btn layui-btn-normal" type="button" lay-submit="" lay-filter="btnSave" id="btnSave">保存</button>
                        <button class="layui-btn layui-btn-normal" type="button" lay-submit="" lay-filter="Exit" id="Exit">退出</button>
                    </div>
                    <div class="layui-collapse">
                        <div class="layui-colla-item">
                            <div class="layui-form-item" style="padding-top: 10px;">
                                <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab" lay-filter="tab-POStockInBill">
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <div class="layui-form-item" style="padding-top: 10px;">
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">冻结列</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" name="HFixCols" lay-verify="HFixCols" id="HFixCols">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">字体大小</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" name="HFontSize" lay-verify="HFontSize" id="HFontSize">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">列宽</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" lay-verify="HColumnWidth" name="HColumnWidth" id="HColumnWidth">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">点击排序</label>
                                            <div class="layui-input-block" style="margin-left: 120px;width: 184px;">
                                                <select name="HSortFlag" lay-verify="HSortFlag" id="HSortFlag">
                                                    <option value=""></option>
                                                    <option value="是">是</option>
                                                    <option value="否">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">选中行合计</label>
                                            <div class="layui-input-block" style="margin-left: 125px;width: 184px;">
                                                <select name="HSelTotal" lay-verify="HSelTotal" id="HSelTotal">
                                                    <option value=""></option>
                                                    <option value="是">是</option>
                                                    <option value="否">否</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>
<!--行下拉选择(对齐方式)-->
<script type="text/html" id="Alignment">
    <select name="Alignment" lay-filter="Alignment" id="Alignment{{d.LAY_TABLE_INDEX+1}}">
        <option value="L">左对齐</option>
        <option value="M">居中</option>
        <option value="R">右对齐</option>
    </select>
</script>
<!--复选框 是否隐藏-->
<script type="text/html" id="IsHide">
    <div class="layui-input-block" style="margin-left: 20px;">
        <input type="checkbox" name="IsHide" lay-filter="IsHide" id="IsHide{{d.LAY_TABLE_INDEX+1}}" lay-skin="primary">
    </div>
</script>
<script>
    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
            , element = layui.element;
        //查询条件
        var sWhere = "";
        var option = [];
        //#endregion
 
        //#region 进入页面即加载
 
        var params = getUrlVars();
        var HModName = params[params[0]]; //模块名称
        var colName = params[params[1]]; //列名
        colName = decodeURI(colName);//对URI 进行解码
        //初始化界面
        set_ClearBill();
 
        //#endregion
 
        //#region 触发事件:包括form.on(){}格式的所有点击事件、选择事件等
 
        //行选择处理(对齐方式)
        form.on('select(Alignment)', function (data) {
            //获取下拉框选中的值
            var elem = data.othis.parents('tr');
            var dataindex = elem.attr("data-index");
            $.each(option.data, function (index, value) {
                if (value.LAY_TABLE_INDEX == dataindex) {
                    value.Alignment = data.value;//把选中下拉框id值赋值给表格缓存
                }
            });
        });
 
        //是否隐藏
        form.on('checkbox(IsHide)', function (data) {
            //获取下拉框选中的值
            var elem = data.othis.parents('tr');
            var dataindex = elem.attr("data-index");
            $.each(option.data, function (index, value) {
                if (value.LAY_TABLE_INDEX == dataindex) {
                    value.IsHide = data.elem.checked;//把选中下拉框id值赋值给表格缓存
                }
            });
        });
 
        //保存
        form.on('submit(btnSave)', function (data) {
            set_AddNew(data);
        });
 
        //全选
        form.on('submit(CheckAll)', function (data) {
            for (var i = 0; i < table.cache["mainTable"].length; i++) {
                table.cache["mainTable"][i].IsHide = true;
                $('#IsHide' + (i + 1)).prop("checked", true);
            }
            form.render('checkbox');
        });
 
        //全清
        form.on('submit(ClearBill)', function (data) {
            for (var i = 0; i < table.cache["mainTable"].length; i++) {
                table.cache["mainTable"][i].IsHide = false;
                $('#IsHide' + (i + 1)).attr("checked", false);
            }
            form.render('checkbox');
        });
 
        //退出
        form.on('submit(Exit)', function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        })
 
        //#endregion
 
        //#region 此页面所有的方法
 
        //初始化界面
        function set_ClearBill() {
            set_InitGrid();
            get_Display();
        }
 
        function get_Display() {
            var ajaxLoad = layer.load();
            $.ajax({
                url: GetWEBURL() + '/Xt_grdAlignment_WMES/grdAlignmentWMESList',
                type: "GET",
                data: { "HModName": HModName, "user": sessionStorage["HUserName"] },
                success: function (data1) {
                    var colNames = [];//相对单据传过来的列名
                    var cols = [];//要传进表格的数据
                    var dataCol = [];
 
                    if (data1.data.length != 0) {
                        //数据库查询出的列数据
                        dataCol = data1.data[0].HGridString.split(',');
                    }
 
                    colNames = colName.split(',');
 
                    if (data1.data.length != 0 && dataCol.length == colNames.length) {
                        //冻结列
                        $("#HFixCols").val(data1.data[0].HFixCols);
                        //字体大小
                        $("#HFontSize").val(data1.data[0].HFontSize);
                        //列宽
                        $("#HColumnWidth").val(data1.data[0].HColumnWidth);
 
                        //表格的数据填充
                        for (var i = 0; i < colNames.length; i++) {
                            var dataCols = dataCol[i].split('|');
                            cols.push({ "ColumnName": colNames[i], "IsHide": dataCols[1] == 1 ? true : false, "Alignment": dataCols[2], "ColumnWidth": dataCols[3] })
                        }
                        option.data = cols;
                        table.render(option);
 
                        //页面多选框 下拉框 重新渲染
                        for (var i = 0; i < colNames.length; i++) {
                            var dataCols = dataCol[i].split('|');
                            if (dataCols[1] == 1) {
                                $("#IsHide" + (i + 1)).attr("checked", true);
                            }
                            $('#Alignment' + (i + 1)).find("option[value='" + dataCols[2] + "']").attr("selected", true);
                        }
                        form.render('checkbox');
                        form.render('select');
                        layer.close(ajaxLoad);
                    } else {
                        //默认不选中 显示字体居左  表格的数据填充
                        for (var i = 0; i < colNames.length; i++) {
                            cols.push({ "ColumnName": colNames[i], "IsHide": false, "Alignment": "L", "ColumnWidth": 100 })
                        }
                        option.data = cols;
                        table.render(option);
 
                        //默认不选中 显示字体居左 页面多选框 下拉框 重新渲染
                        for (var i = 0; i < colNames.length; i++) {
                            $('#IsHide' + (i + 1)).prop("checked", false);
                            $('#Alignment' + (i + 1)).find("option[value='L']").attr("selected", true);
                        }
                        form.render('checkbox');
                        form.render('select');
                        layer.close(ajaxLoad);
                    }
                }, error: function () {
                    layer.close(ajaxLoad);
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
        }
 
        //表格数据
        function set_InitGrid() {
            option = {
                elem: '#mainTable'
                //, toolbar: '#toolbarDemo'
                , height: 420
                , cellMinWidth: 90
                , limit: 500
                , cols: [[
                    { field: 'ColumnName', title: '列名', width: 100 }
                    , { file: 'IsHide', title: '是否隐藏', width: 100, templet: '#IsHide' }
                    , { field: 'Alignment', title: '对齐方式', width: 100, templet: '#Alignment' }
                    , { field: 'ColumnWidth', title: '列宽', width: 100, edit: 'text' }
                ]]
            };
        }
 
        //保存HMaker
        function set_AddNew(data) {
            var num = [];
            for (var i = 0; i < table.cache["mainTable"].length; i++) {
                if (table.cache["mainTable"][i] != "") {
                    table.cache["mainTable"][i].LAY_TABLE_INDEX = i;
                    num.push(table.cache["mainTable"][i])
                }
            }
 
            var sMainStr = JSON.stringify(data.field);
            var sSubStr = JSON.stringify(num);
            var OperationType = "1";
            var sMainSub = sMainStr + ';' + sSubStr + ';' + HModName + ';' + OperationType + ";" + sessionStorage["HUserName"];//sessionStorage["HUserName"]
 
            var index = layer.load();
            $.ajax({
                type: "POST",
                url: GetWEBURL() + "/Xt_grdAlignment_WMES/AddgrdAlignmentWMES",
                async: true,
                data: { "sMainSub": sMainSub },
                dataType: "json",
                success: function (data) {
                    if (data.count == 1) {
                        layer.close(index);
                        layer.msg("提交成功");
                    }
                    else {
                        layer.close(index);
                        layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    }
                },
                error: function (err) {
                    layer.close(index);
                    layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                }
            });
        }
 
        //获取参数
        function getUrlVars() {
            var vars = [], hash;
            var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        }
 
 
 
        //#endregion
 
    });
 
 
</script>