提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getList = Mock.mock('/enterprise/whitecar/getList.htm', {code: 0, 'list|3-19': [{numberplates: '豫A88888', sdate: '2015-07-08', edate: '2030-12-12', departid: '1', departname: '企管部', ctime: '2016-11-11', note: 'nnnnnnnnnote', createid: '1', cname: '顾小白', cdepartid: '1', cdepart: '政务部'}], pages: 12}) |
|
8 |
// var data_getList = Mock.mock('/enterprise/whitecar/getList.htm', {"rowCount":0,"pagesize":0,"pages":1,"page":0,"items":null,"list":[{"numberplates":"豫A6N637","sdate":"2017-02-14 00:00","edate":"2017-02-22 00:00","departid":13,"departname":"信息中心","ctime":"2017-02-20 20:41","note":"试试","createid":null,"cname":null,"cdepartid":null,"cdepart":null,"enState":null, phone: '1333', driver: 'drrrr', valid: true}],"hint":null,"errmsg":null,"code":0}) |
|
9 |
// var data_getDepartList = Mock.mock('/enterprise/depart/getList.htm', {code: 0, list: [ |
|
10 |
// {id: 1,bianhao: '01',name: '河南明泰',note: '',address: '河南省巩义市', level: 1, pid: 0}, |
|
11 |
// {id: 2,bianhao: '0101',name: '企管部',note: '',address: '办公大楼1楼右', level: 2, pid: 1}, |
|
12 |
// {id: 3,bianhao: '010101',name: '铝锭库',note: '',address: '南门挨着磅房', level: 3, pid: 2}, |
|
13 |
// {id: 4,bianhao: '0102',name: '政务部',note: '',address: '办公大楼1楼左', level: 2, pid: 1}, |
|
14 |
// {id: 5,bianhao: '0103',name: '信息中心',note: '',address: '办公大楼4楼最西', level: 2, pid: 1}, |
|
15 |
// {id: 6,bianhao: '02',name: '高精板带',note: '',address: '河南省巩义市', level: 1, pid: 0}, |
|
16 |
// {id: 7,bianhao: '0201',name: '企管部',note: '',address: '办公大楼1楼左', level: 2, pid: 6}, |
|
17 |
// {id: 8,bianhao: '0202',name: '政务部',note: '',address: '办公大楼', level: 2, pid: 6}, |
|
18 |
// {id: 9,bianhao: '03',name: '郑州明泰',note: '',address: '河南省郑州市', level: 1, pid: 0}, |
|
19 |
// {id: 10,bianhao: '0301',name: '企管部',note: '',address: '办公大楼1楼右', level: 2, pid: 9} |
|
20 |
// ]}) |
|
21 |
// var data_doDel = Mock.mock('/enterprise/whitecar/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) |
|
22 |
// var data_doSave = Mock.mock('/enterprise/whitecar/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) |
|
23 |
// var data_getGid = Mock.mock('/enterprise/whitecar/getGid.htm', {code: 0, item: null}) |
|
24 |
// var data_doValid = Mock.mock('/enterprise/whitecar/changeValid.htm', {code: 0, }) |
|
25 |
//test data end |
|
26 |
|
|
27 |
window.I = { |
|
28 |
PZ: 30, |
|
29 |
keyword: $('#keyword'), |
|
30 |
searchBtn: $('#searchBtn'), |
|
31 |
pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0, |
|
32 |
keywordValue: $('#k').val(), |
|
33 |
dValue: parseInt($('#d').val()), |
|
34 |
newObj: $('#newObj'), |
|
35 |
modal: $('#modal'), |
|
36 |
save: $('#save'), |
|
37 |
departName: $('#departName'), |
|
38 |
departModal: $('#departModal'), |
|
39 |
search: $('#search'), |
|
40 |
saveDepart: $('#saveDepart'), |
|
41 |
sdate: $('#sdate'), |
|
42 |
edate: $('#edate'), |
|
43 |
gatesModal: $('#gatesModal'), |
|
44 |
saveGid: $('#saveGid') |
|
45 |
} |
|
46 |
|
|
47 |
var Obj = { |
|
48 |
numberplates: '豫A', |
|
49 |
sdate: '', |
|
50 |
edate: '', |
|
51 |
departid: '', |
|
52 |
departname: '', |
|
53 |
ctime: '', |
|
54 |
note: '', |
|
55 |
createid: '', |
|
56 |
cname: '', |
|
57 |
cdepartid: '', |
|
58 |
cdepart: '', |
|
59 |
driver: '', |
|
60 |
phone: '', |
|
61 |
valid: true |
|
62 |
} |
|
63 |
|
|
64 |
var ViewModel = function() { |
|
65 |
var self = this; |
|
66 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
67 |
|
|
68 |
self.keyword = ko.observable(I.keywordValue); |
|
69 |
self.list = ko.observableArray(); |
|
70 |
|
|
71 |
self.dList = ko.observableArray(); |
|
72 |
|
|
73 |
self.neworedit=ko.observable(true); |
|
74 |
|
|
75 |
self.edit = function(item) { |
|
76 |
self.neworedit(false); |
|
77 |
doEdit(item); |
|
78 |
} |
|
79 |
self.del = function(item) { |
|
80 |
delConfirm(item); |
|
81 |
} |
|
82 |
self.did = ko.observable(I.dValue); |
|
83 |
|
|
84 |
self.change = function() { |
|
85 |
doOpen(); |
|
86 |
} |
|
87 |
self.gates = function(item) { |
|
88 |
setGates(item); |
|
89 |
} |
|
90 |
self.gList = ko.observableArray(); |
|
91 |
self.rList = ko.observableArray(); |
|
92 |
self.valid = function (item) { |
|
93 |
doValid(item); |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
$(function () { |
|
98 |
window.vm = new ViewModel(); |
|
99 |
ko.applyBindings(vm); |
|
100 |
doSearch(); |
|
101 |
getDepartList(); |
|
102 |
getGatesList(); |
|
103 |
pageInit(); |
|
104 |
}); |
|
105 |
|
|
106 |
function pageInit() { |
|
107 |
I.saveGid.click(function (e) { |
|
108 |
e.preventDefault(); |
|
109 |
saveGid(); |
|
110 |
}); |
|
111 |
I.saveDepart.click(function(event) { |
|
112 |
vm.o().departid(I.selected.id); |
|
113 |
vm.o().departname(I.selected.text); |
|
114 |
}); |
|
115 |
I.search.keyup(function(event) { |
|
116 |
var to = false; |
|
117 |
if(to) { |
|
118 |
clearTimeout(to); |
|
119 |
} |
|
120 |
to = setTimeout(function () { |
|
121 |
var v = I.search.val(); |
|
122 |
$('#jstree_Enterprise').jstree(true).search(v); |
|
123 |
}, 250); |
|
124 |
}); |
|
125 |
I.departName.click(function(event) { |
|
126 |
I.departModal.modal('show'); |
|
127 |
}); |
|
128 |
I.save.click(function(event) { |
|
129 |
if (valid()) { |
|
130 |
doSave(); |
|
131 |
} |
|
132 |
}); |
|
133 |
I.newObj.click(function(event) { |
|
134 |
vm.neworedit(true); |
|
135 |
vm.o(ko.mapping.fromJS(Obj)); |
|
136 |
I.modal.modal('show'); |
|
137 |
}); |
|
138 |
I.searchBtn.click(function(event) { |
|
139 |
doOpen(); |
|
140 |
}); |
|
141 |
I.modal.on('hidden.bs.modal', function (e) { |
|
142 |
clearError(); |
|
143 |
}); |
|
144 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
145 |
if (event.keyCode == 13) { |
|
146 |
doOpen(); |
|
147 |
} |
|
148 |
}); |
|
149 |
} |
|
150 |
|
|
151 |
function doOpen() { |
|
152 |
var k = $.trim(vm.keyword()); |
|
153 |
k = !!k ? '?keyword=' + k : ''; |
|
154 |
var d = $.trim(vm.did()); |
|
155 |
d = !!d ? 'd=' + d : ''; |
|
156 |
d = (!!k ? '&' : '?') + d; |
|
157 |
window.open('whitecar.jsf' + k + d, '_self'); |
|
158 |
} |
|
159 |
|
|
160 |
function doSearch() { |
|
161 |
getList(vm.keyword(), !!I.dValue ? I.dValue : null, I.pageValue, I.PZ, 1); |
|
162 |
} |
|
163 |
|
|
164 |
|
|
165 |
function getList(keyword, depart, page, pagesize, pages) { |
|
166 |
$.post('/enterprise/whitecar/getList.htm', { |
|
167 |
keyword: keyword, |
|
168 |
depart: depart, |
|
169 |
page: page, |
|
170 |
pagesize: pagesize, |
|
171 |
pages: pages |
|
172 |
}, function(data, textStatus, xhr) { |
|
173 |
vm.list.removeAll(); |
|
174 |
if (data.code >= 1) { |
|
175 |
//parent.showErrmsg(data.errmsg); |
|
176 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
177 |
return; |
|
178 |
} |
|
179 |
if (data.code == 0) { |
|
180 |
if (isList(data.list)) { |
|
181 |
$.each(data.list, function(index, val) { |
|
182 |
val.valid = ko.observable(val.valid); |
|
183 |
vm.list.push(val); |
|
184 |
}); |
|
185 |
} |
|
186 |
if (!!pages) { |
|
187 |
pages = data.pages; |
|
188 |
$('#pagdiv').unbind('page').empty(); |
|
189 |
if (pages > 1) { |
|
190 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
191 |
var k = !!I.keywordValue ? '&keyword=' + I.keywordValue : ''; |
|
192 |
var d = !!I.dValue ? '&d=' + I.dValue : ''; |
|
193 |
window.open('whitecar.jsf?page=' + num + k + d, '_self'); |
|
194 |
}); |
|
195 |
} |
|
196 |
} |
|
197 |
return; |
|
198 |
} |
|
199 |
}, 'json'); |
|
200 |
} |
|
201 |
|
|
202 |
function valid(){ |
|
203 |
var isValid = false; |
|
204 |
var iF = $('#form'); |
|
205 |
iF.validate({ |
|
206 |
rules: { |
|
207 |
'numberplates': { |
|
208 |
required: true, |
|
209 |
isPlateNumber: true |
|
210 |
// remote: { |
|
211 |
// url: '/enterprise/whitecar/checkPlateNumber.htm', //后台处理程序 |
|
212 |
// type: 'post', //数据发送方式 |
|
213 |
// dataType: 'json', //接受数据格式 |
|
214 |
// data: { //要传递的数据 |
|
215 |
// // numberplates: $('#numberplates').val().toUpperCase() |
|
216 |
// numberplates: function() { |
|
217 |
// return vm.o().numberplates().toUpperCase(); |
|
218 |
// } |
|
219 |
// } |
|
220 |
// } |
|
221 |
}, |
|
222 |
'departName': { |
|
223 |
required: true |
|
224 |
}, |
|
225 |
'sdate': { |
|
226 |
required: true |
|
227 |
}, |
|
228 |
'edate': { |
|
229 |
required: true |
|
230 |
}, |
|
231 |
'driver': { |
|
232 |
required: true |
|
233 |
}, |
|
234 |
'phone': { |
|
235 |
required: true |
|
236 |
} |
|
237 |
}, |
|
238 |
messages: { |
|
239 |
'numberplates': { |
|
240 |
required: '车牌号不能为空!', |
|
241 |
isPlateNumber: '车牌号不正确!' |
|
242 |
//remote: '车牌号已存在!' |
|
243 |
}, |
|
244 |
'departName': { |
|
245 |
required: '部门未选择!' |
|
246 |
}, |
|
247 |
'sdate': { |
|
248 |
required: '起始日期未选择!' |
|
249 |
}, |
|
250 |
'edate': { |
|
251 |
required: '截止日期未选择!' |
|
252 |
}, |
|
253 |
'driver': { |
|
254 |
required: '司机不能为空!' |
|
255 |
}, |
|
256 |
'phone': { |
|
257 |
required: '电话不能为空!' |
|
258 |
} |
|
259 |
}, |
|
260 |
errorPlacement: function (err, element) { |
|
261 |
var p = element.parents('.form-group').eq(0); |
|
262 |
var d = p.find('.text-error').eq(0); |
|
263 |
d.css('color', '#D9534F'); |
|
264 |
err.appendTo(d); |
|
265 |
} |
|
266 |
}) |
|
267 |
isValid = iF.valid(); |
|
268 |
return isValid; |
|
269 |
} |
|
270 |
|
|
271 |
function doEdit(item) { |
|
272 |
vm.o(ko.mapping.fromJS(item)); |
|
273 |
I.modal.modal('show'); |
|
274 |
} |
|
275 |
|
|
276 |
function delConfirm(item) { |
|
277 |
$("#modalContent").html('确定要删除【' + item.numberplates + '】吗?'); |
|
278 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
279 |
resizable: false, |
|
280 |
width: '320', |
|
281 |
modal: true, |
|
282 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
283 |
title_html: true, |
|
284 |
position: { my: "center", at: "center", of: window }, |
|
285 |
buttons: [ |
|
286 |
{ |
|
287 |
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
288 |
"class" : "btn btn-danger btn-minier", |
|
289 |
click: function() { |
|
290 |
$( this ).dialog( "close" ); |
|
291 |
doDel(item); |
|
292 |
} |
|
293 |
} |
|
294 |
, |
|
295 |
{ |
|
296 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
297 |
"class" : "btn btn-minier", |
|
298 |
click: function() { |
|
299 |
$( this ).dialog( "close" ); |
|
300 |
} |
|
301 |
} |
|
302 |
] |
|
303 |
}); |
|
304 |
} |
|
305 |
|
|
306 |
function doDel(item) { |
|
307 |
if (!!I.AjaxDelItem) return; |
|
308 |
I.AjaxDelItem = true; |
|
309 |
$.post('/enterprise/whitecar/delItem.htm', {id: item.numberplates}, function(data, textStatus, xhr) { |
|
310 |
I.AjaxDelItem = false; |
|
311 |
if (data.code >= 1) { |
|
312 |
//parent.showErrmsg(data.errmsg); |
|
313 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
314 |
return; |
|
315 |
} |
|
316 |
if (data.code == 0) { |
|
317 |
vm.list.remove(item); |
|
318 |
location.replace(location.href); |
|
319 |
return; |
|
320 |
} |
|
321 |
}, 'json'); |
|
322 |
} |
|
323 |
|
|
324 |
function doSave() { |
|
325 |
if (!I.AjaxSaveItem &&valid()) { |
|
326 |
I.AjaxSaveItem = true; |
|
327 |
var o = ko.mapping.toJS(vm.o()); |
|
328 |
o.numberplates = o.numberplates.toUpperCase(); |
|
329 |
o.sdate = I.sdate.val(); |
|
330 |
o.edate = I.edate.val(); |
|
331 |
o.valid = $('#objUsed').prop('checked'); |
|
332 |
$.post('/enterprise/whitecar/saveItem.htm', o, function(data, textStatus, xhr) { |
|
333 |
I.AjaxSaveItem = false; |
|
334 |
if (data.code >= 1) { |
|
335 |
//parent.showErrmsg(data.errmsg); |
|
336 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
337 |
return; |
|
338 |
} |
|
339 |
if (data.code == 0) { |
|
340 |
location.replace(location.href); |
|
341 |
return; |
|
342 |
} |
|
343 |
}, 'json'); |
|
344 |
} |
|
345 |
} |
|
346 |
|
|
347 |
function clearError() { |
|
348 |
$('#form input').removeClass('error'); |
|
349 |
$('#form .text-error').html(''); |
|
350 |
} |
|
351 |
|
|
352 |
function getDepartList(keyword, page, pagesize, pages) { |
|
353 |
$.post('/enterprise/depart/getList.htm', { |
|
354 |
keyword: keyword, |
|
355 |
page: page, |
|
356 |
pagesize: pagesize, |
|
357 |
pages: pages |
|
358 |
}, function(data, textStatus, xhr) { |
|
359 |
var allId = []; |
|
360 |
vm.dList.removeAll(); |
|
361 |
if (data.code >= 1) { |
|
362 |
//parent.showErrmsg(data.errmsg); |
|
363 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
364 |
return; |
|
365 |
} |
|
366 |
if (data.code == 0) { |
|
367 |
if (!!$('#jstree_Enterprise').jstree(true)) { |
|
368 |
$('#jstree_Enterprise').jstree(true).refresh(); |
|
369 |
} |
|
370 |
I.DB_ep = {}; |
|
371 |
if (isList(data.list)) { |
|
372 |
var Arr = []; |
|
373 |
var level = 0; |
|
374 |
$.each(data.list, function(index, val) { |
|
375 |
vm.dList.push(val); |
|
376 |
allId.push(val.id); |
|
377 |
I.DB_ep[val.id] = val; |
|
378 |
if (val.level === 2) { |
|
379 |
Arr.push({ |
|
380 |
text: val.name, |
|
381 |
id: val.id, |
|
382 |
children: [], |
|
383 |
state: index === 0 ? {selected: true} : '' |
|
384 |
}); |
|
385 |
} else { |
|
386 |
var j = 3; |
|
387 |
var children = Arr[Arr.length - 1].children; |
|
388 |
while (j < val.level) { |
|
389 |
children = children[children.length - 1].children; |
|
390 |
j++; |
|
391 |
} |
|
392 |
children.push({ |
|
393 |
text: val.name, |
|
394 |
id: val.id, |
|
395 |
children: [] |
|
396 |
}) |
|
397 |
} |
|
398 |
}); |
|
399 |
if (allId.indexOf(I.dValue) != -1) { |
|
400 |
vm.did(I.dValue); |
|
401 |
} |
|
402 |
$('#jstree_Enterprise') |
|
403 |
.jstree({ |
|
404 |
core: { |
|
405 |
check_callback : true, |
|
406 |
data: Arr |
|
407 |
}, |
|
408 |
"plugins" : [ |
|
409 |
'search' |
|
410 |
] |
|
411 |
}) |
|
412 |
.on("changed.jstree", function (e, data) { |
|
413 |
if(data.selected.length) { |
|
414 |
// console.log(data.instance.get_node(data.selected[0])); |
|
415 |
var selected = data.instance.get_node(data.selected[0]); |
|
416 |
I.selected = selected; |
|
417 |
} |
|
418 |
}) |
|
419 |
} |
|
420 |
return; |
|
421 |
} |
|
422 |
}, 'json'); |
|
423 |
} |
|
424 |
|
|
425 |
function getGatesList() { |
|
426 |
$.post('/basicconfig/gates/getList.htm', { |
|
427 |
keyword: null, |
|
428 |
depart: null, |
|
429 |
page: 0, |
|
430 |
pagesize: null, |
|
431 |
pages: 0 |
|
432 |
}, function(data, textStatus, xhr) { |
|
433 |
vm.gList.removeAll(); |
|
434 |
if (data.code >= 1) { |
|
435 |
//parent.showErrmsg(data.errmsg); |
|
436 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
437 |
return; |
|
438 |
} |
|
439 |
if (data.code == 0) { |
|
440 |
if (isList(data.list)) { |
|
441 |
$.each(data.list, function(index, val) { |
|
442 |
vm.gList.push(val); |
|
443 |
}); |
|
444 |
$('.chosen-select').chosen({search_contains: true}); |
|
445 |
} |
|
446 |
return; |
|
447 |
} |
|
448 |
}, 'json'); |
|
449 |
} |
|
450 |
|
|
451 |
function setGates(item) { |
|
452 |
getGid(item.numberplates); |
|
453 |
$('#dp').val(vm.rList()).trigger("chosen:updated"); |
|
454 |
I.gatesModal.modal('show'); |
|
455 |
} |
|
456 |
|
|
457 |
function getGid(sid) { |
|
458 |
I._sid = sid; |
|
459 |
$.post("/enterprise/whitecar/getGid.htm", {sid: sid}, |
|
460 |
function (data, textStatus, jqXHR) { |
|
461 |
if (data.code >= 1) { |
|
462 |
//parent.showErrmsg(data.errmsg); |
|
463 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
464 |
return; |
|
465 |
} |
|
466 |
if (data.code == 0) { |
|
467 |
if (data.item) { |
|
468 |
vm.rList(data.item.split(',')); |
|
469 |
} else { |
|
470 |
vm.rList([]); |
|
471 |
} |
|
472 |
$('#dp').val(vm.rList()).trigger("chosen:updated"); |
|
473 |
return; |
|
474 |
} |
|
475 |
}, |
|
476 |
"json" |
|
477 |
); |
|
478 |
} |
|
479 |
|
|
480 |
function saveGid() { |
|
481 |
$.post("/enterprise/whitecar/saveGid.htm", {sid: I._sid, gid: vm.rList().join(',')}, |
|
482 |
function (data, textStatus, jqXHR) { |
|
483 |
if (data.code >= 1) { |
|
484 |
//parent.showErrmsg(data.errmsg); |
|
485 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
486 |
return; |
|
487 |
} |
|
488 |
if (data.code == 0) { |
|
489 |
parent.showErrmsg('保存成功!'); |
|
490 |
return; |
|
491 |
} |
|
492 |
}, |
|
493 |
"json" |
|
494 |
); |
|
495 |
} |
|
496 |
|
|
497 |
function doValid(item) { |
|
498 |
if (!I.AjaxChangeUsed) { |
|
499 |
var valid = !item.valid(); |
|
500 |
I.AjaxChangeUsed = true; |
|
501 |
$.post('/enterprise/whitecar/valid.htm', {vehicleID: item.numberplates, valid: valid}, function(data, textStatus, xhr) { |
|
502 |
I.AjaxChangeUsed = false; |
|
503 |
if (data.code >= 1) { |
|
504 |
//parent.showErrmsg(data.errmsg); |
|
505 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
506 |
return; |
|
507 |
} |
|
508 |
if (data.code == 0) { |
|
509 |
item.valid(valid); |
|
510 |
return; |
|
511 |
} |
|
512 |
}, 'json'); |
|
513 |
} |
|
514 |
} |