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
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
 
var CustomerManager = {
    CustomerGrid: undefined,
    Server: function () {
        var config = (function () {
            var URL_GetList = "/CustomerAjax/GetCustomerList";
            var URL_Add= "/CustomerAjax/AddCustomer";
            var URL_Delete = "/CustomerAjax/DelCustomer";
            var URL_Start = "/CustomerAjax/StartCustomer";
            var URL_Stop = "/CustomerAjax/StopCustomer";
            return {
                URL_GetList: URL_GetList,
                URL_Add: URL_Add,
                URL_Delete: URL_Delete,
                URL_Start: URL_Start,
                URL_Stop: URL_Stop,
            };
        })();
 
        //数据操作服务
        var dataServer = (function ($, config) {
 
            //查询分页列表
            var GetList = function (data, callback) {
                $.gitAjax({
                    url: config.URL_GetList,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Add = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Add,
                    data: { ajaxdata: JSON.stringify(data) },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
 
            var Delete = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Delete,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            var Start = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Start,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            var Stop = function (data, callback) {
                $.gitAjax({
                    url: config.URL_Stop,
                    data: data,
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (callback != undefined && typeof callback == "function") {
                            callback(result);
                        }
                    }
                });
            }
            return {
                GetList: GetList,
                Add: Add,
                Delete: Delete,
                Start: Start,
                Stop:Stop,
            }
 
        })($, config);
        return dataServer;0
    },
    Dialog: function (CusNum, Command) {
        var submit = function (v, h, f) {
            if (v) {
                var CusNum = h.find('input[name="CusNum"]').val();
                var CusName = h.find('input[name="CusName"]').val();
                var Contacts = h.find('input[name="Contacts"]').val();
                var Mobile = h.find('input[name="Mobile"]').val();
                var Phone = h.find('input[name="Phone"]').val();
                var Fax = h.find('input[name="Fax"]').val();
                var Address = h.find('input[name="Address"]').val();
                var CusType = h.find('select[name="CusType"]').val();
                var Demo = h.find('input[name="Demo"]').val();
                var Email = h.find('input[name="Email"]').val();
 
                if (git.IsEmpty(CusNum)) {
                    $.jBox.tip("请输入客户编码", "warn");
                    return false;
                }
 
                if (git.IsEmpty(CusName)) {
                    $.jBox.tip("请输入客户名称", "warn");
                    return false;
                }
 
                var param = {};
                param["Operation"] = Command;
                param["CusNum"] = CusNum;
                param["CusName"] = CusName;
                param["Contacts"] = Contacts;
                param["Mobile"] = Mobile;
                param["Phone"] = Phone;
                param["Fax"] = Fax;
                param["CusType"] = CusType;
                param["Address"] = Address;
                param["Demo"] = Demo;
                param["Email"] = Email;
                var Server = CustomerManager.Server();
                Server.Add(param, function (result) {
                    if (result.Code == 1) {
                        $.jBox.tip(result.Message, "info");
                        var pageSize = $("#mypager").pager("GetPageSize");
                        var pageIndex = $("#mypager").pager("GetCurrent");
                        CustomerManager.PageClick(pageIndex, pageSize);
                    } else {
                        $.jBox.tip(result.Message, "warn");
                    }
                });
            }
        }
       
        //窗体加载完成回调事件
        var loaded = function (h) {
            h.find('input[name="CusNum"]').attr("disabled", false);
        }
        if (Command == "Add") {
            $.jBox.open("get:/BasicInfo/Customer/Add", "添加客户信息", 650, 400, { buttons: { "确定": true, "取消": false }, submit: submit });
        }
        if (Command == "Edit") {
            $.jBox.open("get:/BasicInfo/Customer/Add?CusNum=" + CusNum, "编辑客户信息", 650, 400, { buttons: { "确定": true, "取消": false }, submit: submit, loaded: loaded });
        } 
    },
 
 
    PageClick: function (PageIndex, PageSize) {
        $.jBox.tip("正在努力加载数据...", "loading");
        var Server = CustomerManager.Server();
        var search = CustomerManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
        console.log(JSON.stringify(search));
        Server.GetList(search, function (result) {
            CustomerManager.SetTable(result);
            $.jBox.closeTip();
        });
    },
    Refresh: function () {
        var PageSize = $("#mypager").pager("GetPageSize");
        var PageIndex = $("#mypager").pager("GetCurrent");
        $.jBox.tip("正在努力加载数据...", "loading");
        var Server = CustomerManager.Server();
        var search = CustomerManager.GetSearch();
        search["PageIndex"] = PageIndex;
        search["PageSize"] = PageSize;
        Server.GetList(search, function (result) {
            CustomerManager.SetTable(result);
            $.jBox.closeTip();
        });
    },
 
    SetTable: function (result) {
        var cols = [
            {
                title: '客户编码', name: 'CusNum', width: 110, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '客户名称', name: 'CusName', width: 90, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
 
            {
                title: '联系人', name: 'Contacts', width: 70, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '手机', name: 'Mobile', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
 
            {
                title: '固话', name: 'Phone', width: 90, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '传真', name: 'Fax', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '邮箱', name: 'Email', width: 90, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '类别', name: 'CusType', width: 100, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
 
            {
                title: '地址', name: 'Address', width: 120, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },    
            {
                title: '描述', name: 'Demo', width: 120, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },
            {
                title: '启用/停用', name: 'Enable', width: 80, align: 'center', lockWidth: false, sortable: true, renderer: function (data, item, rowIndex) {
                    return data;
                }
            },  
        ];
 
        if (this.CustomerGrid == undefined) {
            var ht = masterUI.MMGridHeight();
            this.CustomerGrid = $("#tabList").mmGrid({
                cols: cols,
                items: result.Result.List,
                checkCol: true,
                nowrap: true,
                remoteSort: true,
                multiSelect: true,
                height: ht
            });
            //绑定事件
            //CustomerManager.BindEvent();
        } else {
            this.CustomerGrid.load(result.Result.List);
        }
        var pageInfo = result.PageInfo;
        if (pageInfo != undefined) {
            $("#mypager").pager({ pagenumber: pageInfo.PageIndex, recordCount: pageInfo.RowCount, pageSize: pageInfo.PageSize, buttonClickCallback: CustomerManager.PageClick });
        }
    },
 
    GetSelect: function () {
        var list = [];
        if (this.CustomerGrid != undefined) {
            var rows = this.CustomerGrid.selectedRows();
            if (rows != undefined && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {
                    list.push(rows[i].CusNum);
                }
            }
        }
        return list;
    },
    GetSearch: function () {
        var searchBar = $("div[data-condition='search']");
        var CusNum = searchBar.find("input[name='CusNum']").val();
        var CusName = searchBar.find("input[name='CusName']").val();
        var CusType = searchBar.find("select[name='CusType']").val();
        var Enable = searchBar.find("select[name='Enable']").val();
       
 
        var search = {};
        search["CusNum"] = CusNum;
        search["CusName"] = CusName;
        search["CusType"] = CusType;
        search["Enable"] = Enable;
       
 
        return search;
    },
    ToolBar: function () {
 
        //工具栏按钮点击事件
        $("div.toolbar").find("a.btn").click(function () {
            var command = $(this).attr("data-command");
 
            if (command == "Add") {
                var list = CustomerManager.Dialog("", "Add");
            }
            else if (command == "Edit") {
                var list = CustomerManager.GetSelect();
                if (list.length == 0) {
                    $.jBox.tip("请选择要编辑项", "warn");
                    return false;
                }
 
                var CusNum = list[0];
                CustomerManager.Dialog(CusNum, "Edit");
 
            }
            else if (command == "Delete") {
                var submit = function (v, h, f) {
                    if (v == "ok") {
                        var list = CustomerManager.GetSelect();
                        if (list.length == 0) {
                            $.jBox.tip("请选择要删除的项", "warn");
                            return false;
                        }
                        var param = {};
                        param["list"] = JSON.stringify(list);
                        var Server = CustomerManager.Server();
                        Server.Delete(param, function (result) {
                            $.jBox.tip(result.Message, "success");
                            var pageSize = $("#mypager").pager("GetPageSize");
                            CustomerManager.PageClick(1, pageSize);
                        });
                    }
                }
                $.jBox.confirm("确定要删除吗?", "提示", submit);
            }
            else if (command == "Start") {
                var submit = function (v, h, f) {
                    if (v == "ok") {
                        var list = CustomerManager.GetSelect();
                        if (list.length == 0) {
                            $.jBox.tip("请选择启用的客户项", "warn");
                            return false;
                        }
                        var param = {};
                        param["list"] = JSON.stringify(list);
                        var Server = CustomerManager.Server();
                        Server.Start(param, function (result) {
                            $.jBox.tip(result.Message, "success");
                            var pageSize = $("#mypager").pager("GetPageSize");
                            CustomerManager.PageClick(1, pageSize);
                        });
                    }
                }
                $.jBox.confirm("确定要启用选中客户吗?", "提示", submit);
            }
            else if (command == "Stop") {
                var submit = function (v, h, f) {
                    if (v == "ok") {
                        var list = CustomerManager.GetSelect();
                        if (list.length == 0) {
                            $.jBox.tip("请选择停用的客户项", "warn");
                            return false;
                        }
                        var param = {};
                        param["list"] = JSON.stringify(list);
                        var Server = CustomerManager.Server();
                        Server.Stop(param, function (result) {
                            $.jBox.tip(result.Message, "success");
                            var pageSize = $("#mypager").pager("GetPageSize");
                            CustomerManager.PageClick(1, pageSize);
                        });
                    }
                }
                $.jBox.confirm("确定要启用选中客户吗?", "提示", submit);
            }
        });
 
        //搜索
        var searchBar = $("div[data-condition='search']");
        searchBar.find("a[data-command='search']").click(function () {
            CustomerManager.PageClick(1, 10);
        });
 
        //监听回车事件,用于扫描
        $("input[name='CusNum']").keydown(function (event) {
            if (event.keyCode == 13) {
                var value = $(this).val();
                if (!git.IsEmpty(value)) {
                    CustomerManager.PageClick(1, 10);
                    setTimeout(function () {
                        $("input[name='CusNum']").val("");
                        $("input[name='CusNum']").focus();
                    }, 300);
                }
            }
        });
 
        $("input[name='CusNum']").focus();
        //加载默认数据
        CustomerManager.PageClick(1, 10);
    }
};