提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getList = Mock.mock('/basicconfig/weighthouse/getList.htm', {code: 0, list: [{id: 22, weighthNo: 'wh0001', name: '磅房1', address: '南门旁边', note: 'nnnnn', status: '正常', departname: '铝锭库', departID: '22'}], pages: 12}) |
|
8 |
// var data_doDel = Mock.mock('/basicconfig/weighthouse/del.htm', {code: 0, }) |
|
9 |
// var data_getGid = Mock.mock('/basicconfig/weighthouse/getGid.htm', {code: 0, item: '1' }) |
|
10 |
//test data end |
|
11 |
|
|
12 |
var STATUS = [ '正常', '维修', '停止']; |
|
13 |
|
|
14 |
var Obj = { |
|
15 |
id: 0, |
|
16 |
weighthNo: '', |
|
17 |
name: '', |
|
18 |
address: '', |
|
19 |
note: '', |
|
20 |
status: '', |
|
21 |
departname: '', |
|
22 |
departID: '', |
|
23 |
} |
|
24 |
|
|
25 |
window.I = { |
|
26 |
PZ: 30, |
|
27 |
keyword: $('#keyword'), |
|
28 |
searchBtn: $('#searchBtn'), |
|
29 |
pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0, |
|
30 |
keywordValue: $('#k').val(), |
|
31 |
dValue: parseInt($('#d').val()) || null, |
|
32 |
newObj: $('#newObj'), |
|
33 |
modal: $('#modal'), |
|
34 |
save: $('#save'), |
|
35 |
departName: $('#departName'), |
|
36 |
departModal: $('#departModal'), |
|
37 |
search: $('#search'), |
|
38 |
saveDepart: $('#saveDepart'), |
|
39 |
gatesModal: $('#gatesModal'), |
|
40 |
saveGid: $('#saveGid') |
|
41 |
} |
|
42 |
|
|
43 |
var ViewModel = function() { |
|
44 |
var self = this; |
|
45 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
46 |
|
|
47 |
self.keyword = ko.observable(I.keywordValue); |
|
48 |
self.sList = ko.observableArray(STATUS); //磅房状态 |
|
49 |
self.dList = ko.observableArray(); //部门列表 |
|
50 |
self.did = ko.observable(I.dValue); //选择的部门的值 |
|
51 |
self.list = ko.observableArray(); |
|
52 |
self.change = function() { |
|
53 |
doOpen(); |
|
54 |
} |
|
55 |
|
|
56 |
self.edit = function(item) { |
|
57 |
doEdit(item); |
|
58 |
} |
|
59 |
self.del = function(item) { |
|
60 |
delConfirm(item); |
|
61 |
} |
|
62 |
|
|
63 |
self.gList = ko.observableArray(); //门禁列表 |
|
64 |
|
|
65 |
self.gates = function(item) { |
|
66 |
setGates(item); |
|
67 |
} |
|
68 |
|
|
69 |
self.rList = ko.observableArray(); |
|
70 |
|
|
71 |
self.mclient = function(item) { |
|
72 |
parent.closableTab.addTab({ |
|
73 |
'id': new Date().getTime(), |
|
74 |
'name': '磅房客户端配置', |
|
75 |
'url': '/basicinfo/weighthouse_mclient.jsf?relationno=' + item.weighthNo + '&name=' + item.name, |
|
76 |
'closable': true |
|
77 |
}); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
$(function () { |
|
82 |
window.vm = new ViewModel(); |
|
83 |
ko.applyBindings(vm); |
|
84 |
getDepartList(); |
|
85 |
getGatesList(); |
|
86 |
doSearch(); |
|
87 |
pageInit(); |
|
88 |
}); |
|
89 |
|
|
90 |
function pageInit() { |
|
91 |
I.saveGid.click(function (e) { |
|
92 |
e.preventDefault(); |
|
93 |
saveGid(); |
|
94 |
}); |
|
95 |
I.save.click(function(event) { |
|
96 |
if (valid()) { |
|
97 |
doSave(); |
|
98 |
} |
|
99 |
}); |
|
100 |
I.searchBtn.click(function(event) { |
|
101 |
doOpen(); |
|
102 |
}); |
|
103 |
I.saveDepart.click(function(event) { |
|
104 |
vm.o().departID(I.selected.id); |
|
105 |
vm.o().departname(I.selected.text); |
|
106 |
}); |
|
107 |
I.search.keyup(function(event) { |
|
108 |
var to = false; |
|
109 |
if(to) { |
|
110 |
clearTimeout(to); |
|
111 |
} |
|
112 |
to = setTimeout(function () { |
|
113 |
var v = I.search.val(); |
|
114 |
$('#jstree_Enterprise').jstree(true).search(v); |
|
115 |
}, 250); |
|
116 |
}); |
|
117 |
I.departName.click(function(event) { |
|
118 |
I.departModal.modal('show'); |
|
119 |
}); |
|
120 |
I.newObj.click(function(event) { |
|
121 |
vm.o(ko.mapping.fromJS(Obj)); |
|
122 |
getNewNo(); |
|
123 |
I.modal.modal('show'); |
|
124 |
}); |
|
125 |
I.modal.on('hidden.bs.modal', function (e) { |
|
126 |
clearError(); |
|
127 |
}); |
|
128 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
129 |
if (event.keyCode == 13) { |
|
130 |
doOpen(); |
|
131 |
} |
|
132 |
}); |
|
133 |
} |
|
134 |
|
|
135 |
function doEdit(item) { |
|
136 |
vm.o(ko.mapping.fromJS(item)); |
|
137 |
I.modal.modal('show'); |
|
138 |
} |
|
139 |
|
|
140 |
function delConfirm(item) { |
|
141 |
$("#modalContent").html('确定要删除【' + item.name + '】吗?'); |
|
142 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
143 |
resizable: false, |
|
144 |
width: '320', |
|
145 |
modal: true, |
|
146 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
147 |
title_html: true, |
|
148 |
position: { my: "center", at: "center", of: window }, |
|
149 |
buttons: [ |
|
150 |
{ |
|
151 |
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
152 |
"class" : "btn btn-danger btn-minier", |
|
153 |
click: function() { |
|
154 |
$( this ).dialog( "close" ); |
|
155 |
doDel(item); |
|
156 |
} |
|
157 |
} |
|
158 |
, |
|
159 |
{ |
|
160 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
161 |
"class" : "btn btn-minier", |
|
162 |
click: function() { |
|
163 |
$( this ).dialog( "close" ); |
|
164 |
} |
|
165 |
} |
|
166 |
] |
|
167 |
}); |
|
168 |
} |
|
169 |
|
|
170 |
function doDel(item) { |
|
171 |
if (!!I.AjaxDelItem) return; |
|
172 |
I.AjaxDelItem = true; |
|
173 |
$.post('/basicconfig/weighthouse/del.htm', {id: item.id}, function(data, textStatus, xhr) { |
|
174 |
I.AjaxDelItem = false; |
|
175 |
if (data.code >= 1) { |
|
176 |
//parent.showErrmsg(data.errmsg); |
|
177 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
178 |
return; |
|
179 |
} |
|
180 |
if (data.code == 0) { |
|
181 |
vm.list.remove(item); |
|
182 |
// location.replace(location.href); |
|
183 |
return; |
|
184 |
} |
|
185 |
}, 'json'); |
|
186 |
} |
|
187 |
|
|
188 |
function valid(){ |
|
189 |
var isValid = false; |
|
190 |
var iF = $('#form'); |
|
191 |
iF.validate({ |
|
192 |
rules: { |
|
193 |
'weighthNo': { |
|
194 |
required: true |
|
195 |
}, |
|
196 |
'name': { |
|
197 |
required: true |
|
198 |
}, |
|
199 |
'departname': { |
|
200 |
required: true |
|
201 |
} |
|
202 |
}, |
|
203 |
messages: { |
|
204 |
'weighthNo': { |
|
205 |
required: '不能为空!' |
|
206 |
}, |
|
207 |
'name': { |
|
208 |
required: '不能为空!' |
|
209 |
}, |
|
210 |
'departname': { |
|
211 |
required: '没有所属部门!' |
|
212 |
} |
|
213 |
}, |
|
214 |
errorPlacement: function (err, element) { |
|
215 |
var p = element.parents('.form-group').eq(0); |
|
216 |
var d = p.find('.text-error').eq(0); |
|
217 |
d.css('color', '#D9534F'); |
|
218 |
err.appendTo(d); |
|
219 |
} |
|
220 |
}) |
|
221 |
isValid = iF.valid(); |
|
222 |
return isValid; |
|
223 |
} |
|
224 |
|
|
225 |
function doSave() { |
|
226 |
if (!I.AjaxSaveItem &&valid()) { |
|
227 |
I.AjaxSaveItem = true; |
|
228 |
var o = ko.mapping.toJS(vm.o()); |
|
229 |
$.post('/basicconfig/weighthouse/save.htm', o, function(data, textStatus, xhr) { |
|
230 |
I.AjaxSaveItem = false; |
|
231 |
if (data.code >= 1) { |
|
232 |
//parent.showErrmsg(data.errmsg); |
|
233 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
234 |
return; |
|
235 |
} |
|
236 |
if (data.code == 0) { |
|
237 |
location.replace(location.href); |
|
238 |
return; |
|
239 |
} |
|
240 |
}, 'json'); |
|
241 |
} |
|
242 |
} |
|
243 |
|
|
244 |
function doSearch() { |
|
245 |
getList(vm.keyword(), vm.did() || I.dValue, I.pageValue, I.PZ, 1); |
|
246 |
} |
|
247 |
|
|
248 |
function getList(keyword, depart, page, pagesize, pages) { |
|
249 |
$.post('/basicconfig/weighthouse/getList.htm', { |
|
250 |
keyword: keyword, |
|
251 |
depart: depart, |
|
252 |
page: page, |
|
253 |
pagesize: pagesize, |
|
254 |
pages: pages |
|
255 |
}, function(data, textStatus, xhr) { |
|
256 |
vm.list.removeAll(); |
|
257 |
if (data.code >= 1) { |
|
258 |
//parent.showErrmsg(data.errmsg); |
|
259 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
260 |
return; |
|
261 |
} |
|
262 |
if (data.code == 0) { |
|
263 |
if (isList(data.list)) { |
|
264 |
$.each(data.list, function(index, val) { |
|
265 |
vm.list.push(val); |
|
266 |
}); |
|
267 |
} |
|
268 |
if (!!pages) { |
|
269 |
pages = data.pages; |
|
270 |
$('#pagdiv').unbind('page').empty(); |
|
271 |
if (pages > 1) { |
|
272 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
273 |
var k = !!I.keywordValue ? '&keyword=' + I.keywordValue : ''; |
|
274 |
var d = !!I.dValue ? '&d=' + I.dValue : ''; |
|
275 |
window.open('gates.jsf?page=' + num + k + d, '_self'); |
|
276 |
}); |
|
277 |
} |
|
278 |
} |
|
279 |
return; |
|
280 |
} |
|
281 |
}, 'json'); |
|
282 |
} |
|
283 |
|
|
284 |
function doOpen() { |
|
285 |
var k = $.trim(vm.keyword()); |
|
286 |
k = !!k ? '?keyword=' + k : ''; |
|
287 |
var d = $.trim(vm.did()); |
|
288 |
d = !!d ? 'd=' + d : ''; |
|
289 |
d = (!!k ? '&' : '?') + d; |
|
290 |
window.open('weighthouse.jsf' + k + d, '_self'); |
|
291 |
} |
|
292 |
|
|
293 |
function clearError() { |
|
294 |
$('#form input').removeClass('error'); |
|
295 |
$('#form .text-error').html(''); |
|
296 |
} |
|
297 |
|
|
298 |
function getDepartList(keyword, page, pagesize, pages) { |
|
299 |
$.post('/enterprise/depart/getList.htm', { |
|
300 |
keyword: keyword, |
|
301 |
page: page, |
|
302 |
pagesize: pagesize, |
|
303 |
pages: pages |
|
304 |
}, function(data, textStatus, xhr) { |
|
305 |
var allId = []; |
|
306 |
vm.dList.removeAll(); |
|
307 |
if (data.code >= 1) { |
|
308 |
//parent.showErrmsg(data.errmsg); |
|
309 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
310 |
return; |
|
311 |
} |
|
312 |
if (data.code == 0) { |
|
313 |
if (!!$('#jstree_Enterprise').jstree(true)) { |
|
314 |
$('#jstree_Enterprise').jstree(true).refresh(); |
|
315 |
} |
|
316 |
I.DB_ep = {}; |
|
317 |
if (isList(data.list)) { |
|
318 |
var Arr = []; |
|
319 |
var level = 0; |
|
320 |
$.each(data.list, function(index, val) { |
|
321 |
vm.dList.push(val); |
|
322 |
allId.push(val.id); |
|
323 |
I.DB_ep[val.id] = val; |
|
324 |
if (val.level === 2) { |
|
325 |
Arr.push({ |
|
326 |
text: val.name, |
|
327 |
id: val.id, |
|
328 |
children: [], |
|
329 |
state: index === 0 ? {selected: true} : '' |
|
330 |
}); |
|
331 |
} else { |
|
332 |
var j = 3; |
|
333 |
var children = Arr[Arr.length - 1].children; |
|
334 |
while (j < val.level) { |
|
335 |
children = children[children.length - 1].children; |
|
336 |
j++; |
|
337 |
} |
|
338 |
children.push({ |
|
339 |
text: val.name, |
|
340 |
id: val.id, |
|
341 |
children: [] |
|
342 |
}) |
|
343 |
} |
|
344 |
}); |
|
345 |
// console.log(allId); |
|
346 |
if (allId.indexOf(I.dValue) != -1) { |
|
347 |
vm.did(I.dValue); |
|
348 |
} |
|
349 |
$('#jstree_Enterprise') |
|
350 |
.jstree({ |
|
351 |
core: { |
|
352 |
check_callback : true, |
|
353 |
data: Arr |
|
354 |
}, |
|
355 |
"plugins" : [ |
|
356 |
'search' |
|
357 |
] |
|
358 |
}) |
|
359 |
.on("changed.jstree", function (e, data) { |
|
360 |
if(data.selected.length) { |
|
361 |
// console.log(data.instance.get_node(data.selected[0])); |
|
362 |
var selected = data.instance.get_node(data.selected[0]); |
|
363 |
I.selected = selected; |
|
364 |
} |
|
365 |
}) |
|
366 |
} |
|
367 |
return; |
|
368 |
} |
|
369 |
}, 'json'); |
|
370 |
} |
|
371 |
|
|
372 |
function setGates(item) { |
|
373 |
getGid(item.id); |
|
374 |
$('#dp').val(vm.rList()).trigger("chosen:updated"); |
|
375 |
I.gatesModal.modal('show'); |
|
376 |
} |
|
377 |
|
|
378 |
function getGid(sid) { |
|
379 |
I._sid = sid; |
|
380 |
$.post("/basicconfig/weighthouse/getGid.htm", {sid: sid}, |
|
381 |
function (data, textStatus, jqXHR) { |
|
382 |
if (data.code >= 1) { |
|
383 |
//parent.showErrmsg(data.errmsg); |
|
384 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
385 |
return; |
|
386 |
} |
|
387 |
if (data.code == 0) { |
|
388 |
if (data.item) { |
|
389 |
vm.rList(data.item.split(',')); |
|
390 |
} else { |
|
391 |
vm.rList([]); |
|
392 |
} |
|
393 |
$('#dp').val(vm.rList()).trigger("chosen:updated"); |
|
394 |
return; |
|
395 |
} |
|
396 |
}, |
|
397 |
"json" |
|
398 |
); |
|
399 |
} |
|
400 |
|
|
401 |
function saveGid() { |
|
402 |
$.post("/basicconfig/weighthouse/saveGid.htm", {sid: I._sid, gid: vm.rList().join(',')}, |
|
403 |
function (data, textStatus, jqXHR) { |
|
404 |
if (data.code >= 1) { |
|
405 |
//parent.showErrmsg(data.errmsg); |
|
406 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
407 |
return; |
|
408 |
} |
|
409 |
if (data.code == 0) { |
|
410 |
parent.showErrmsg('保存成功!'); |
|
411 |
return; |
|
412 |
} |
|
413 |
}, |
|
414 |
"json" |
|
415 |
); |
|
416 |
} |
|
417 |
|
|
418 |
function getGatesList() { |
|
419 |
$.post('/basicconfig/gates/getList.htm', { |
|
420 |
keyword: null, |
|
421 |
depart: null, |
|
422 |
page: 0, |
|
423 |
pagesize: null, |
|
424 |
pages: 0 |
|
425 |
}, function(data, textStatus, xhr) { |
|
426 |
vm.gList.removeAll(); |
|
427 |
if (data.code >= 1) { |
|
428 |
//parent.showErrmsg(data.errmsg); |
|
429 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
430 |
return; |
|
431 |
} |
|
432 |
if (data.code == 0) { |
|
433 |
if (isList(data.list)) { |
|
434 |
$.each(data.list, function(index, val) { |
|
435 |
vm.gList.push(val); |
|
436 |
}); |
|
437 |
$('.chosen-select').chosen({search_contains: true}); |
|
438 |
} |
|
439 |
return; |
|
440 |
} |
|
441 |
}, 'json'); |
|
442 |
} |
|
443 |
|
|
444 |
function getNewNo() { |
|
445 |
$.post("/basicconfig/prefix/getNewNo.htm", {type: 'weighthouse'}, |
|
446 |
function (data, textStatus, jqXHR) { |
|
447 |
if (data.code >= 1) { |
|
448 |
// parent.showErrmsg(data.errmsg); |
|
449 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
450 |
return; |
|
451 |
} |
|
452 |
if (data.code == 0) { |
|
453 |
// vm.o().visitNo(data.number); |
|
454 |
$('#weighthNo').val(data.number); |
|
455 |
return; |
|
456 |
} |
|
457 |
}, |
|
458 |
"json" |
|
459 |
); |
|
460 |
} |