bklLiudl
2024-07-23 277bbae216debe7e6c04e8cc6ee6e1ba9763e14b
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
var Dictionary = {
    InTable: undefined,
    // 查询
    PageClick: function (PageIndex, PageSize) {
        $.jBox.tip("正在努力加载数据...", "loading");
        var search = Dictionary.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
 
        $.gitAjax({
            async: false,
            url: "/DictionaryAjax/GetDictionaryItems",
            data: { ajaxdata: JSON.stringify(search) },
            type: "post",
            dataType: "json",
            success: function (result) {
                $.jBox.closeTip();
                if (result != null) {
                    if (result.Code == 1) {
                        // 查询成功,绑定Table
                        Dictionary.SetTable(result);
                    }
                    else {
                        // 查询失败,提示操作员
                        $.jBox.tip(result.Message, "warn");
                    }
                }
            }
        });
    },
 
    // 加载Table表格
    SetTable: function (result) {
        // 定义Table列
        var cols = [
            {
                title: '数据类别', name: 'TopName', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '属性名称', name: 'TypeName', width: 100, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '创建日期', name: 'CreatTime', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
 
                    return git.JsonToDateTimeto(data);
                }
            },
            {
                title: '创建人', name: 'CreatUser', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '修改日期', name: 'UpdateTime', width: 120, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return git.JsonToDateTimeto(data);
                }
            },
            {
                title: '修改人', name: 'UpdateUser', width: 80, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '操作', name: 'Guid', width: 70, align: 'center', lockWidth: false, renderer: function (data, item, rowIndex) {
                    var html = "";
                    html += '<a class="edit dis" href="javascript:void(0)">编辑</a>&nbsp;&nbsp;';
                    return html;
                }
            },
        ];
 
        // 设置Table
        if (this.InTable == undefined) {
            var ht = masterUI.MMGridHeight();
            this.InTable = $("#tabList").mmGrid({
                cols: cols,
                sortName: 'CreateTime',
                sortStatus: 'desc',
                fullWidthRows: true,
                multiSelect: true,
                //indexCol: true,
                items: result.Result.List,
                checkCol: true,
                nowrap: true,
                height: ht
            });
 
            //绑定事件
            Dictionary.BindEvent();
        }
        else {
            this.InTable.load(result.Result.List);
        }
 
        // 绑定分页信息,切换分页调用查询方法
        var pageInfo = result.PageInfo;
        if (pageInfo != undefined) {
            $("#mypager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: Dictionary.PageClick });
        }
    },
 
    // 绑定行事件
    BindEvent: function () {
        this.InTable.on('loadSuccess', function (e, data) {     //loadSuccess
            LoadBtn.SetBtn();
        });
 
        this.InTable.off("cellSelected").on("cellSelected", function (e, item, rowIndex, colIndex) {
            // 绑定编辑库区事件
            if ($(e.target).is("a.edit")) {
                var Guid = item.Guid;
                Dictionary.Dialog(Guid, "Edit");
            }
        });
    },
 
    // 获取查询条件
    GetSearch: function () {
        var searchBar = $("div[data-condition='search']");
        var TypeName = searchBar.find("input[name='TypeName']").val();
        var TopCode = searchBar.find("select[name='TopCode']").val();
 
        var search = {};
        search["TopCode"] = TopCode;
        search["TypeName"] = TypeName;
        return search;
    },
 
    // 获取Table选中行
    GetSelect: function () {
        var list = [];
        if (this.InTable != undefined) {
            var rows = this.InTable.selectedRows();
            if (rows != undefined && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    list.push(rows[i].Guid);
                }
            }
        }
        return list;
    },
 
    // Add Edit 窗体赋值
    Dialog: function (Guid, Command) {
 
        var submit = function (v, h, f) {
            if (v) {
                var TypeName = h.find('input[name="TypeName"]').val();
                var TopCode = h.find('select[name="TopCode"]').val();
 
                if (git.IsEmpty(TypeName)) {
                    $.jBox.tip("请输入属性名称!", "warn");
                    return false;
                }
 
                if (git.IsEmpty(TopCode))
                {
                    $.jBox.tip("请选择所属区域!", "warn");
                    return false;
                }
 
                var param = {};
                param["Guid"] = Guid;
                param["TopCode"] = TopCode;
                param["TypeName"] = TypeName;
 
                // 判断是否重复
                var bl = "Fales";
                $.gitAjax({
                    async: false,
                    url: "/DictionaryAjax/IsExist",
                    data: { ajaxdata: JSON.stringify(param) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (result.Result == "True") {
                            $.jBox.tip("属性名称重复,请修改!", "warn");
                            bl = "True";
                        }
                    }
                });
 
                if (bl == "True") {
                    return false;
                }
 
                $.gitAjax({
                    url: "/DictionaryAjax/SetDictionarys",
                    data: { ajaxdata: JSON.stringify(param) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (result.Code == 1) {
                            $.jBox.tip(result.Message, "info");
                            var pageSize = $("#mypager").pager("GetPageSize");
                            var pageIndex = $("#mypager").pager("GetCurrent");
                            Dictionary.PageClick(pageIndex, pageSize);
                        }
                        else {
                            $.jBox.tip(result.Message, "warn");
                        }
                    }
                });
            }
        }
 
        //窗体加载完成回调事件 
        var loaded = function (h) {
            // 设置禁止更改列
            h.find('select[name="TopCode"]').attr("disabled", "disabled");
        }
 
        switch (Command) {
            case "Add":
                $.jBox.open("get:/BasicInfo/Dictionary/AddEdit", "新增属性", 370, 180, { buttons: { "确定": true, "关闭": false }, submit: submit });
                break;
            case "Edit":
                $.jBox.open("get:/BasicInfo/Dictionary/AddEdit?Guid=" + Guid, "编辑属性", 370, 180, { buttons: { "确定": true, "关闭": false }, submit: submit, loaded: loaded });
                break;
            default: break;
        }
    },
 
    // view页操作响应
    ToolBar: function () {
 
        var btnClick = $("div.toolbar");
        btnClick.find("a.btn").click(function () {
            var command = $(this).attr("data-command");
            switch (command) {
                case "Add":
                    var list = Dictionary.Dialog("", "Add");
                    break;
                case "Delete":
                    var submit = function (v, h, f) {
                        if (v == "ok") {
                            var list = Dictionary.GetSelect();
                            if (list.length == 0) {
                                $.jBox.tip("请选择要删除的项", "warn");
                                return false;
                            }
                            var param = {};
                            param["list"] = JSON.stringify(list);
 
                            $.gitAjax({
                                url: "/DictionaryAjax/DelDictionarys",
                                data: param,
                                type: "post",
                                dataType: "json",
                                success: function (result) {
                                    // 提示操作信息
                                    $.jBox.tip(result.Message, "success");
                                    var pageSize = $("#mypager").pager("GetPageSize");
                                    Dictionary.PageClick(1, pageSize);
                                }
                            });
                        }
                    }
                    $.jBox.confirm("确定要删除吗?", "提示", submit);
                default: break;
            }
 
        })
 
 
        // 搜索按钮绑定查询事件  获取div => div.find事件搜寻按钮 => click事件
        var searchBar = $("div[data-condition='search']");
        searchBar.find("a[data-command='search']").click(function () {
            // 调用查询方法,绑定分页信息
            Dictionary.PageClick(1, 50);
        });
 
        //监听回车事件,用于扫描
        searchBar.find("input[name='TypeName']").keydown(function (event) {
            if (event.keyCode == 13) {
                var value = $(this).val();
                if (!git.IsEmpty(value)) {
                    Dictionary.PageClick(1, 50);
 
                    setTimeout(function () {
                        //searchBar.find("input[name='TypeName']").val("");
                        searchBar.find("input[name='TypeName']").focus();
                    }, 300);
                }
            }
        });
 
        //窗体加载获得焦点
        searchBar.find("input[name='TypeName']").focus();
 
        //加载默认数据
        Dictionary.PageClick(1, 50);
    }
}