提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getBizTypeList = Mock.mock('/basicinfo/businesstype/getList.htm', {code: 0, list: [{id: 22, processKey: 'asdfkjasdklfkj123', name: '人员来访短期', businesstypeNo: 'bn123123123', note: 'nnnn', candidateGroups: '12222candidateGroups22', planitem: true, factory: true, direct: 'inout',}, {id: 33, processKey: 'asdfkjasdklfkj123', name: '人员来访长期', businesstypeNo: 'bn222222', note: 'nnnn', candidateGroups: '12222candidateGroups22', planitem: true, factory: true, direct: 'inout',}], pages: 12}) |
|
8 |
// var data_getList = Mock.mock('/weight/gatesQueue/getList.htm', {code: 0, 'list|3-18': [{id: 3, name: 'nnnn1', sdID: 10, sdname: '企管部', countnum: 10, innernum: 7, outernum: 3}], pages: 12}) |
|
9 |
// var data_doDel = Mock.mock('/weight/gatesQueue/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) |
|
10 |
// var data_doSave = Mock.mock('/weight/gatesQueue/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) |
|
11 |
// var data_getList = Mock.mock('/basicconfig/gates/getList.htm', {code: 0, list: [{id: 1, gatesNo: '0001', name: '门禁1', cantruck: true, canperson: false, cancar: true, departname: '部门1', depart: 1}], pages: 12}) |
|
12 |
// var data_getGid = Mock.mock('/weight/gatesQueue/getGid.htm', {code: 0, item: 'bn123123123,bn222222' }) |
|
13 |
// var data_saveGid = Mock.mock('/weight/gatesQueue/saveGid.htm', {code: 0 }) |
|
14 |
//test data end |
|
15 |
|
|
16 |
window.I = { |
|
17 |
PZ: 30, |
|
18 |
keyword: $('#keyword'), |
|
19 |
searchBtn: $('#searchBtn'), |
|
20 |
pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0, |
|
21 |
keywordValue: $('#k').val(), |
|
22 |
newObj: $('#newObj'), |
|
23 |
modal: $('#modal'), |
|
24 |
save: $('#save'), |
|
25 |
gatesModal: $('#gatesModal'), |
|
26 |
saveGid: $('#saveGid') |
|
27 |
} |
|
28 |
|
|
29 |
var Obj = { |
|
30 |
id: 0, |
|
31 |
name: '', |
|
32 |
sdID: '', |
|
33 |
sdname: '', |
|
34 |
countnum: 0, |
|
35 |
innernum: 0, |
|
36 |
outernum: 0, |
|
37 |
gatesNo: '' |
|
38 |
} |
|
39 |
|
|
40 |
var ViewModel = function() { |
|
41 |
var self = this; |
|
42 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
43 |
|
|
44 |
self.keyword = ko.observable(I.keywordValue); |
|
45 |
self.list = ko.observableArray(); |
|
46 |
|
|
47 |
self.edit = function(item) { |
|
48 |
doEdit(item); |
|
49 |
} |
|
50 |
self.del = function(item) { |
|
51 |
delConfirm(item); |
|
52 |
} |
|
53 |
self.used = function (item) { |
|
54 |
doUsed(item); |
|
55 |
} |
|
56 |
self.gates = function(item) { |
|
57 |
setGates(item); |
|
58 |
} |
|
59 |
self.gList = ko.observableArray(); |
|
60 |
self.rList = ko.observableArray(); |
|
61 |
|
|
62 |
self.dList = ko.observableArray(); |
|
63 |
self.gatesList = ko.observableArray(); |
|
64 |
} |
|
65 |
|
|
66 |
$(function () { |
|
67 |
window.vm = new ViewModel(); |
|
68 |
ko.applyBindings(vm); |
|
69 |
getBizTypeList(); |
|
70 |
getDepartList(); |
|
71 |
getGatesList(); |
|
72 |
pageInit(); |
|
73 |
}); |
|
74 |
|
|
75 |
function pageInit() { |
|
76 |
I.saveGid.click(function (e) { |
|
77 |
e.preventDefault(); |
|
78 |
saveGid(); |
|
79 |
}); |
|
80 |
I.save.click(function(event) { |
|
81 |
if (valid()) { |
|
82 |
doSave(); |
|
83 |
} |
|
84 |
}); |
|
85 |
I.newObj.click(function(event) { |
|
86 |
vm.o(ko.mapping.fromJS(Obj)); |
|
87 |
I.modal.modal('show'); |
|
88 |
}); |
|
89 |
I.searchBtn.click(function(event) { |
|
90 |
doOpen(); |
|
91 |
}); |
|
92 |
I.modal.on('hidden.bs.modal', function (e) { |
|
93 |
clearError(); |
|
94 |
}); |
|
95 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
96 |
if (event.keyCode == 13) { |
|
97 |
doOpen(); |
|
98 |
} |
|
99 |
}); |
|
100 |
I.gatesModal.on('hidden.bs.modal', function (e) { |
|
101 |
vm.rList.removeAll(); |
|
102 |
}); |
|
103 |
} |
|
104 |
|
|
105 |
function setGates(item) { |
|
106 |
getGid(item.id); |
|
107 |
$('#dp').val(vm.rList()).trigger("chosen:updated"); |
|
108 |
I.gatesModal.modal('show'); |
|
109 |
} |
|
110 |
|
|
111 |
function getGid(sid) { |
|
112 |
I._sid = sid; |
|
113 |
$.post("/weight/gatesQueue/getGid.htm", {gqID: sid}, |
|
114 |
function (data, textStatus, jqXHR) { |
|
115 |
if (data.code >= 1) { |
|
116 |
// parent.showErrmsg(data.errmsg); |
|
117 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
118 |
return; |
|
119 |
} |
|
120 |
if (data.code == 0) { |
|
121 |
if (data.item) { |
|
122 |
vm.rList(data.item.split(',')); |
|
123 |
} else { |
|
124 |
vm.rList([]); |
|
125 |
} |
|
126 |
$('#dp').val(vm.rList()).trigger("chosen:updated"); |
|
127 |
return; |
|
128 |
} |
|
129 |
}, |
|
130 |
"json" |
|
131 |
); |
|
132 |
} |
|
133 |
|
|
134 |
function saveGid() { |
|
135 |
$.post("/weight/gatesQueue/saveGid.htm", {gqID: I._sid, businesstypeNos: vm.rList().join(',')}, |
|
136 |
function (data, textStatus, jqXHR) { |
|
137 |
if (data.code >= 1) { |
|
138 |
// parent.showErrmsg(data.errmsg); |
|
139 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
140 |
return; |
|
141 |
} |
|
142 |
if (data.code == 0) { |
|
143 |
parent.showErrmsg('保存成功!'); |
|
144 |
return; |
|
145 |
} |
|
146 |
}, |
|
147 |
"json" |
|
148 |
); |
|
149 |
} |
|
150 |
|
|
151 |
function doOpen() { |
|
152 |
var k = $.trim(vm.keyword()); |
|
153 |
k = !!k ? '?keyword=' + k : ''; |
|
154 |
window.open('gatesQueue.jsf' + k, '_self'); |
|
155 |
} |
|
156 |
|
|
157 |
function doSearch() { |
|
158 |
getList(vm.keyword(), I.pageValue, I.PZ, 1); |
|
159 |
} |
|
160 |
|
|
161 |
function getList(keyword, page, pagesize, pages) { |
|
162 |
$.post('/weight/gatesQueue/getList.htm', { |
|
163 |
keyword: keyword, |
|
164 |
page: page, |
|
165 |
pagesize: pagesize, |
|
166 |
pages: pages |
|
167 |
}, function(data, textStatus, xhr) { |
|
168 |
vm.list.removeAll(); |
|
169 |
if (data.code >= 1) { |
|
170 |
//parent.showErrmsg(data.errmsg); |
|
171 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
172 |
return; |
|
173 |
} |
|
174 |
if (data.code == 0) { |
|
175 |
if (isList(data.list)) { |
|
176 |
$.each(data.list, function(index, val) { |
|
177 |
val.used = ko.observable(val.used); |
|
178 |
vm.list.push(val); |
|
179 |
}); |
|
180 |
} |
|
181 |
if (!!pages) { |
|
182 |
pages = data.pages; |
|
183 |
$('#pagdiv').unbind('page').empty(); |
|
184 |
if (pages > 1) { |
|
185 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
186 |
var k = !!I.keywordValue ? '&keyword=' + I.keywordValue : ''; |
|
187 |
window.open('gatesQueue.jsf?page=' + num + k, '_self'); |
|
188 |
}); |
|
189 |
} |
|
190 |
} |
|
191 |
return; |
|
192 |
} |
|
193 |
}, 'json'); |
|
194 |
} |
|
195 |
|
|
196 |
function valid(){ |
|
197 |
var isValid = false; |
|
198 |
var iF = $('#form'); |
|
199 |
iF.validate({ |
|
200 |
rules: { |
|
201 |
'name': { |
|
202 |
required: true |
|
203 |
}, |
|
204 |
'countnum': { |
|
205 |
required: true, |
|
206 |
digits: true |
|
207 |
}, |
|
208 |
'innernum': { |
|
209 |
required: true, |
|
210 |
digits: true |
|
211 |
}, |
|
212 |
'outernum': { |
|
213 |
required: true, |
|
214 |
digits: true |
|
215 |
} |
|
216 |
}, |
|
217 |
messages: { |
|
218 |
'name': { |
|
219 |
required: '不能为空!' |
|
220 |
}, |
|
221 |
'countnum': { |
|
222 |
required: '不能为空!', |
|
223 |
digits: '必须为整数!' |
|
224 |
}, |
|
225 |
'innernum': { |
|
226 |
required: '不能为空!', |
|
227 |
digits: '必须为整数!' |
|
228 |
}, |
|
229 |
'outernum': { |
|
230 |
required: '不能为空!', |
|
231 |
digits: '必须为整数!' |
|
232 |
} |
|
233 |
}, |
|
234 |
errorPlacement: function (err, element) { |
|
235 |
var p = element.parents('.form-group').eq(0); |
|
236 |
var d = p.find('.text-error').eq(0); |
|
237 |
d.css('color', '#D9534F'); |
|
238 |
err.appendTo(d); |
|
239 |
} |
|
240 |
}) |
|
241 |
isValid = iF.valid(); |
|
242 |
return isValid; |
|
243 |
} |
|
244 |
|
|
245 |
function doEdit(item) { |
|
246 |
vm.o(ko.mapping.fromJS(item)); |
|
247 |
I.modal.modal('show'); |
|
248 |
} |
|
249 |
|
|
250 |
function delConfirm(item) { |
|
251 |
$("#modalContent").html('确定要删除【' + item.name + '】吗?'); |
|
252 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
253 |
resizable: false, |
|
254 |
width: '320', |
|
255 |
modal: true, |
|
256 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
257 |
title_html: true, |
|
258 |
position: { my: "center", at: "center", of: window }, |
|
259 |
buttons: [ |
|
260 |
{ |
|
261 |
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
262 |
"class" : "btn btn-danger btn-minier", |
|
263 |
click: function() { |
|
264 |
$( this ).dialog( "close" ); |
|
265 |
doDel(item); |
|
266 |
} |
|
267 |
} |
|
268 |
, |
|
269 |
{ |
|
270 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
271 |
"class" : "btn btn-minier", |
|
272 |
click: function() { |
|
273 |
$( this ).dialog( "close" ); |
|
274 |
} |
|
275 |
} |
|
276 |
] |
|
277 |
}); |
|
278 |
} |
|
279 |
|
|
280 |
function doDel(item) { |
|
281 |
if (!!I.AjaxDelItem) return; |
|
282 |
I.AjaxDelItem = true; |
|
283 |
$.post('/weight/gatesQueue/delItem.htm', {id: item.id}, function(data, textStatus, xhr) { |
|
284 |
I.AjaxDelItem = false; |
|
285 |
if (data.code >= 1) { |
|
286 |
// parent.showErrmsg(data.errmsg); |
|
287 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
288 |
return; |
|
289 |
} |
|
290 |
if (data.code == 0) { |
|
291 |
vm.list.remove(item); |
|
292 |
location.replace(location.href); |
|
293 |
return; |
|
294 |
} |
|
295 |
}, 'json'); |
|
296 |
} |
|
297 |
|
|
298 |
function doSave() { |
|
299 |
if (!I.AjaxSaveItem &&valid()) { |
|
300 |
I.AjaxSaveItem = true; |
|
301 |
var o = ko.mapping.toJS(vm.o()); |
|
302 |
delete o.sdname; |
|
303 |
$.post('/weight/gatesQueue/saveItem.htm', o, function(data, textStatus, xhr) { |
|
304 |
I.AjaxSaveItem = false; |
|
305 |
if (data.code >= 1) { |
|
306 |
//parent.showErrmsg(data.errmsg); |
|
307 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
308 |
return; |
|
309 |
} |
|
310 |
if (data.code == 0) { |
|
311 |
location.replace(location.href); |
|
312 |
return; |
|
313 |
} |
|
314 |
}, 'json'); |
|
315 |
} |
|
316 |
} |
|
317 |
|
|
318 |
function clearError() { |
|
319 |
$('#form input').removeClass('error'); |
|
320 |
$('#form .text-error').html(''); |
|
321 |
} |
|
322 |
|
|
323 |
function doUsed(item) { |
|
324 |
return; |
|
325 |
if (!I.AjaxChangeUsed) { |
|
326 |
var used = !item.used(); |
|
327 |
I.AjaxChangeUsed = true; |
|
328 |
$.post('/basicconfig/company/changeUsed.htm', {id: item.id, used: used}, function(data, textStatus, xhr) { |
|
329 |
I.AjaxChangeUsed = false; |
|
330 |
if (data.code >= 1) { |
|
331 |
//parent.showErrmsg(data.errmsg); |
|
332 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
333 |
return; |
|
334 |
} |
|
335 |
if (data.code == 0) { |
|
336 |
item.used(used); |
|
337 |
return; |
|
338 |
} |
|
339 |
}, 'json'); |
|
340 |
} |
|
341 |
} |
|
342 |
|
|
343 |
function getBizTypeList(keyword, page, pagesize, pages) { |
|
344 |
$.post('/basicinfo/businesstype/getList.htm', { |
|
345 |
keyword: keyword, |
|
346 |
page: page, |
|
347 |
pagesize: pagesize, |
|
348 |
pages: pages |
|
349 |
}, function(data, textStatus, xhr) { |
|
350 |
vm.gList.removeAll(); |
|
351 |
if (data.code >= 1) { |
|
352 |
//parent.showErrmsg(data.errmsg); |
|
353 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
354 |
return; |
|
355 |
} |
|
356 |
if (data.code == 0) { |
|
357 |
if (isList(data.list)) { |
|
358 |
$.each(data.list, function(index, val) { |
|
359 |
vm.gList.push(val); |
|
360 |
}); |
|
361 |
$('.chosen-select').chosen({search_contains: true}); |
|
362 |
} |
|
363 |
return; |
|
364 |
} |
|
365 |
}, 'json'); |
|
366 |
} |
|
367 |
|
|
368 |
function getDepartList(keyword, page, pagesize, pages) { |
|
369 |
$.post('/enterprise/depart/getList.htm', { |
|
370 |
keyword: keyword, |
|
371 |
page: page, |
|
372 |
pagesize: pagesize, |
|
373 |
pages: pages |
|
374 |
}, function(data, textStatus, xhr) { |
|
375 |
vm.dList.removeAll(); |
|
376 |
if (data.code >= 1) { |
|
377 |
//parent.showErrmsg(data.errmsg); |
|
378 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
379 |
return; |
|
380 |
} |
|
381 |
if (data.code == 0) { |
|
382 |
if (isList(data.list)) { |
|
383 |
$.each(data.list, function (indexInArray, valueOfElement) { |
|
384 |
vm.dList.push(valueOfElement); |
|
385 |
}); |
|
386 |
} |
|
387 |
return; |
|
388 |
} |
|
389 |
}, 'json'); |
|
390 |
} |
|
391 |
|
|
392 |
function getGatesList() { |
|
393 |
$.post('/basicconfig/gates/getList.htm', { |
|
394 |
keyword: null, |
|
395 |
depart: null, |
|
396 |
page: 0, |
|
397 |
pagesize: null, |
|
398 |
pages: 0 |
|
399 |
}, function(data, textStatus, xhr) { |
|
400 |
vm.gatesList.removeAll(); |
|
401 |
if (data.code >= 1) { |
|
402 |
//parent.showErrmsg(data.errmsg); |
|
403 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
404 |
return; |
|
405 |
} |
|
406 |
if (data.code == 0) { |
|
407 |
if (isList(data.list)) { |
|
408 |
$.each(data.list, function(index, val) { |
|
409 |
vm.gatesList.push(val); |
|
410 |
}); |
|
411 |
// $('.chosen-select').chosen({search_contains: true}); |
|
412 |
} |
|
413 |
doSearch(); |
|
414 |
return; |
|
415 |
} |
|
416 |
}, 'json'); |
|
417 |
} |