pzy
2024-09-12 704d753a742434f29e74077bf8c02338e59a8264
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
<!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/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 src="../../../layuiadmin/HideButton.js"></script>
 
    <style>
        /* 当鼠标悬浮在表格的奇数行上时改变背景色 */
        .layui-table tbody tr:nth-child(odd):hover {
            background-color: #ffff00; /* 更改为你想要的颜色 */
        }
 
        /* 当鼠标悬浮在表格的偶数行上时改变背景色 */
        .layui-table tbody tr:nth-child(even):hover {
            background-color: #ffff00; /* 更改为你想要的颜色 */
        }
    </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-collapse">
                            <div class="layui-colla-item">-->
                        <!--<div class="layui-colla-title layui-inline">
                        </div>-->
                        <!--</div>
                        </div>-->
                        <table class="" id="mainTable" lay-filter="mainTable"></table>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script>
 
 
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index', //主入口模块
        }).use(['index', 'form', 'table', 'element', 'laypage', 'laydate'], function () {
            //#region 公用变量
            var $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , table = layui.table
                , form = layui.form
                , element = layui.element
                , laypage = layui.laypage
                , laydate = layui.laydate
 
            var option = [];
            var sWhere = "";
            //#endregion
 
            //#region 触发事件
            //#region 点击返回行的数据
            table.on('row(mainTable)', function (obj) {
                parent.childData = obj.data;
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            })
            //#endregion
            //#endregion
 
            //#region 本页面所有被调用的方法
            //#region 初始化界面
            function set_ClearBill(sql,tableView) {
                //初始化表格
                set_InitGrid();
                //查询
                get_Display(sql, tableView);
            }
            //#endregion
 
            //#region 初始化表格方法
            function set_InitGrid() {
                option = {
                    elem: '#mainTable'
                    //, toolbar: '#toolbarDemo'
                    , height: 'full-50'
                    , cellMinWidth: 90
                    , page: true
                    , limit: 5
                    , limits: [5, 10, 15, 20]
                    , totalRow: true
                    , cols: [[
                        { field: '代码', title: '代码', width: 150, sort: true }
                        , { field: '名称', title: '名称', width: 150, sort: true }
                    ]]
                    , data: []
                    , done: function (res, curr, count) {
                        // 设置行样式
                        var style = 'background-color: #ffff00;'; // 指定的背景色
                        // 假设我们要设置第三行的背景色
                        var targetIndex = rowIndex; // 行号索引,从0开始计数
                        $('tr[data-index=' + targetIndex + ']').attr('style', style);
                    }
                };
            }
            //#endregion
 
            //#region 查询
            function get_Display(sql, tableView) {
                $.ajax({
                    url: GetWEBURL() + '/Gy_GetBaseData/Gy_GetBaseData',
                    type: "GET",
                    data: { "sql": sql, "tableView": tableView, "user": sessionStorage["HUserName"] },
                    success: function (data1) {
                        if (data1.count == 1) {
                            var data = [];
                            var col = [];
                            //给空的数组赋值
                            for (var key in data1.list) {
                                data.push({ "id": data1.list[key].ColmCols, "name": data1.list[key].ColmCols, "Type": data1.list[key].ColmType });
                            }
                            //判断是否是纯英文
                            var patrn = new RegExp("[\u4E00-\u9FA5]+");
                            //在列表左边添加勾选框
                            for (var i = 0; i < data.length; i++) {
                                if (!patrn.test(data[i].name)) {
                                    col.push({ field: data[i].name, title: data[i].name, hide: true }); //隐藏列
                                }
                                else {
                                    switch (data[i].Type) {
                                        case 'DateTime':
                                            col.push({ field: data[i].id, title: data[i].name, align: 'center', sort: true, templet: "<div>{{d." + data[i].name + " ==null ?'':layui.util.toDateString(d." + data[i].name + ", 'yyyy-MM-dd')}}</div>", width: 120 });
                                            break;
                                        default:
                                            col.push({ field: data[i].id, title: data[i].name, align: 'center', sort: true, width: 120 });
                                    }
                                }
                            }
 
 
                            option.cols = [col];
                            option.data = data1.data;
                            table.render(option);
                        } else {
                            layer.alert(data1.code + data1.Message, { icon: 5 });
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
            }
            //#endregion
            //#endregion
 
 
            //#region 为window对象声明并定义getData方法,用于通过window对象调用layui.use内部定义的方法
            //#region 根据父页面传递的参数,查询数据并渲染表格
            window.getData = function (sql,tableView) {
                set_ClearBill(sql, tableView);
            }
            //#endregion
 
            //#region 根据父页面传递的索引,渲染行背景,实现选中功能
            window.setSelectedRow = function (currRowIndex) {
                rowIndex += currRowIndex;
                if (rowIndex >= option.data.length) {
                    rowIndex = option.data.length - 1;
                    parent.currRowIndex = rowIndex + 1;
                } else if (rowIndex < -1) {
                    rowIndex = -1;
                    parent.currRowIndex = rowIndex + 1;
                }
                table.render(option);
                rowIndex = -1;
            }
            //#endregion
 
            //#region 根据父页面传递的索引,返回选中行数据到父页面
            window.getSelectedData = function (currRowIndex) {
                parent.childData = option.data[currRowIndex - 1];
 
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
            //#endregion
 
            //#endregion
        });
 
            //#endregion
            //以上是layui模块
 
 
 
 
        //#region 文本框输入搜索相关数据-变量
        parent.childPage = window;                                                      //子窗口对象 赋给 父窗口
        var rowIndex = -1;                                                               //用于定位 当前选中的数据的位置
        //#endregion
    </script>
 
</body>
</html>