Administrator
2022-10-09 23f93897d618a5253a18b65b124196f95891f240
提交 | 用户 | 时间
58d006 1 /**
A 2 * date: 
3 * author: neeler 
4 */
5
6 //test data start
7 // var data_getList = Mock.mock('/enterprise/position/getList.htm', {code: 0, list: [
8 //     {id: 1, name: '岗位1', note: '岗位1', lvl: 1},
9 //     {id: 2, name: '岗位2', note: '岗位2', lvl: 2},
10 //     {id: 3, name: '岗位3', note: '岗位3', lvl: 3},
11 //     {id: 4, name: '岗位4', note: '岗位4', lvl: 4},
12 //     {id: 5, name: '岗位5', note: '岗位5', lvl: 5},
13 //     {id: 6, name: '岗位6', note: '岗位6', lvl: 1},
14 //     {id: 7, name: '岗位7', note: '岗位7', lvl: 2},
15 //     {id: 8, name: '岗位8', note: '岗位8', lvl: 3},
16 //     {id: 9, name: '岗位9', note: '岗位9', lvl: 4},
17 //     {id: 10, name: '岗位10', note: '岗位10', lvl: 5},
18 //     {id: 11, name: '岗位11', note: '岗位11', lvl: 1}
19 //     ], pages: 12})
20 // var data_doDel = Mock.mock('/enterprise/position/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
21 // var data_doSave = Mock.mock('/enterprise/position/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
22 //test data end
23
24 window.I = {
25     PZ: 30,
26     keyword: $('#keyword'),
27     searchBtn: $('#searchBtn'),
28     pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0,
29     keywordValue: $('#k').val(),
30     newObj: $('#newObj'),
31     modal: $('#modal'),
32     save: $('#save')
33 }
34
35 var PositionObj = {
36     id: 0,
37     name: '',
38     note: '',
39     lvl: '0',
40 }
41
42 var ViewModel = function() {
43     var self = this;
44     self.o = ko.observable(ko.mapping.fromJS(PositionObj));
45
46     self.keyword = ko.observable(I.keywordValue);
47     self.list = ko.observableArray();
48
49     self.edit = function(item) {
50         doEdit(item);
51     }
52     self.del = function(item) {
53         delConfirm(item);
54     }
55 }
56
57 $(function () {
58     window.vm = new ViewModel();
59     ko.applyBindings(vm);
60     autoHeight();
61     doSearch();
62     pageInit();
63 });
64
65 function pageInit() {
66     $('.table-responsive').scroll(function() {
67         $('.th').css('top', $(this).scrollTop());
68     })
69     I.save.click(function(event) {
70         if (valid()) {
71             doSave();
72         }
73     });
74     I.newObj.click(function(event) {
75         vm.o(ko.mapping.fromJS(PositionObj));
76         I.modal.modal('show');
77     });
78     I.searchBtn.click(function(event) {
79         doOpen();
80     });
81     I.modal.on('hidden.bs.modal', function (e) {
82         clearError();
83     });
84     I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) {
85         if (event.keyCode == 13) {
86             doOpen();
87         }
88     });
89 }
90
91 function doOpen() {
92     doSearch();
93 }
94
95 function doSearch() {
96     getList(vm.keyword(), I.pageValue, I.PZ, 1);
97 }
98
99 function getList(keyword, page, pagesize, pages) {
100     $.post('/basicinfo/vehiclehinfo/getList.htm', {
101         keyword: keyword,
102         page: page,
103         pagesize: pagesize,
104         pages: pages
105     }, function(data, textStatus, xhr) {
106         vm.list.removeAll();
107         if (data.code >= 1) {
108             // parent.showErrmsg(data.errmsg);
109             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
110             return;
111         }
112         if (data.code == 0) {
113             if (isList(data.list)) {
114                 $.each(data.list, function(index, val) {
115                     vm.list.push(val);
116                 });
117             }
118             if (!!pages) {
119                 pages = data.pages;
120                 $('#pagdiv').unbind('page').empty();
121                 if (pages > 1) {
122                     $('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){
123                         getList(keyword, num - 1, pagesize, 0);
124                     });
125                 }
126             }
127             return;
128         }
129     }, 'json');
130 }
131
132 function valid(){
133     var isValid = false;
134     var iF = $('#form');
135     iF.validate({
136         rules: {
137             'name': {
138                 required: true
139             }
140         },
141         messages: {
142             'name': {
143                 required: '不能为空!'
144             }
145         },
146         errorPlacement: function (err, element) {
147             var p = element.parents('.form-group').eq(0);
148             var d = p.find('.text-error').eq(0);
149             d.css('color', '#D9534F');
150             err.appendTo(d);
151         }
152     })
153     isValid = iF.valid();
154     return isValid;
155 }
156
157 function doEdit(item) {
158     vm.o(ko.mapping.fromJS(item));
159     I.modal.modal('show');
160 }
161
162 function delConfirm(item) {
163     $("#modalContent").html('确定要删除【' + item.vehicleID + '】吗?');
164     $("#dialog-confirm").removeClass('hide').dialog({
165         resizable: false,
166         width: '320',
167         modal: true,
168         title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>",
169         title_html: true,
170         position: { my: "center", at: "center", of: window },
171         buttons: [
172             {
173                 html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; 确定",
174                 "class" : "btn btn-danger btn-minier",
175                 click: function() {
176                     $( this ).dialog( "close" );
177                     doDel(item);
178                 }
179             }
180             ,
181             {
182                 html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 取消",
183                 "class" : "btn btn-minier",
184                 click: function() {
185                     $( this ).dialog( "close" );
186                 }
187             }
188         ]
189     });
190 }
191
192 function doDel(item) {
193     if (!!I.AjaxDelItem) return;
194     I.AjaxDelItem = true;
195     $.post('/basicinfo/vehiclehinfo/delItem.htm', item, function(data, textStatus, xhr) {
196         I.AjaxDelItem = false;
197         if (data.code >= 1) {
198             //parent.showErrmsg(data.errmsg);
199             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
200             return;
201         }
202         if (data.code == 0) {
203             vm.list.remove(item);
204             // location.replace(location.href);
205             return;
206         }
207     }, 'json');
208 }
209
210 function doSave() {
211     if (!I.AjaxSaveItem &&valid()) {
212         I.AjaxSaveItem = true;
213         var o = ko.mapping.toJS(vm.o());
214         $.post('/enterprise/position/saveItem.htm', o, function(data, textStatus, xhr) {
215             I.AjaxSaveItem = false;
216             if (data.code >= 1) {
217                 //parent.showErrmsg(data.errmsg);
218                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
219                 return;
220             }
221             if (data.code == 0) {
222                 location.replace(location.href);
223                 return;
224             }
225         }, 'json');
226     }
227 }
228
229 function clearError() {
230     $('#form input').removeClass('error');
231     $('#form .text-error').html('');
232 }
233
234 function autoHeight() {
235     $('.page-content').css('min-height', $(parent.window).height() - 117);
236     $('.table-responsive').css('height', $(parent.window).height() - 217);
237 }
238
239 $(window).resize(function() {autoHeight();})