提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getNewNo = Mock.mock('/basicconfig/prefix/getNewNo.htm', {code: 0, number: 'V8912374891327S'}) |
|
8 |
// var data_getList = Mock.mock('/vehicle/getallList.htm', {code: 0, 'list|5-20': [{companyName: 'companyName', id: 'id', vehicleId: 'vehicleId', vehicleweight: 'vehicleweight', unitname: 'unitname', driver: 'driver', phone: 'phone', loadweight: 'loadweight', state: false, note: 'note', companyNo: 'companyNo'}], pages: 12}) |
|
9 |
// var data_getCompanyList = Mock.mock('/company/getList.htm', {code: 0, 'list|5-20': [{id: 'id', companyNo: 'companyNo', note: 'note', name: 'name'}], pages: 12}) |
|
10 |
// var data_doDel = Mock.mock('/vehicle/delItem.htm', {code: 0, errmsg: '不能删除!'}) |
|
11 |
// var data_doSave = Mock.mock('/vehicle/saveItem.htm', {code: 0, errmsg: '不能删除!'}) |
|
12 |
// var data_doValid = Mock.mock('/vehicle/changeState.htm', {code: 0, item: true}) |
|
13 |
//test data end |
|
14 |
|
|
15 |
var TYPE = ['千克' ,'吨' ] |
|
16 |
|
|
17 |
window.I = { |
|
18 |
PZ: 30, |
|
19 |
keyword: $('#keyword'), |
|
20 |
searchBtn: $('#searchBtn'), |
|
21 |
_page: !!$('#p').val() ? $('#p').val() - 1 : 0, |
|
22 |
keywordValue: $('#k').val(), |
|
23 |
newObj: $('#newObj'), |
|
24 |
modal: $('#modal'), |
|
25 |
save: $('#save') |
|
26 |
} |
|
27 |
|
|
28 |
var Obj = { |
|
29 |
id: 0, |
|
30 |
vehicleId: '豫A', |
|
31 |
driver: '', |
|
32 |
phone: '', |
|
33 |
IDNum:'', |
|
34 |
vehicleweight: '', |
|
35 |
loadweight: '', |
|
36 |
state: true, |
|
37 |
note: '', |
|
38 |
companyNo: '', |
|
39 |
feature: '' |
|
40 |
} |
|
41 |
|
|
42 |
var ViewModel = function() { |
|
43 |
var self = this; |
|
44 |
self.isAdmin = ko.observable(typeof(parent.G) != 'undefined' ? parent.G.isAdmin : false); |
|
45 |
self.tList = ko.observableArray(); |
|
46 |
self.mtid = ko.observable(); |
|
47 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
48 |
|
|
49 |
self.keyword = ko.observable(I.keywordValue); |
|
50 |
self.list = ko.observableArray(); |
|
51 |
|
|
52 |
self.edit = function(item) { |
|
53 |
doEdit(item); |
|
54 |
} |
|
55 |
self.del = function(item) { |
|
56 |
delConfirm(item); |
|
57 |
} |
|
58 |
|
|
59 |
self.change = function() { |
|
60 |
doOpen(); |
|
61 |
} |
|
62 |
self.mtvalid=function(item){ |
|
63 |
doValid(item); |
|
64 |
} |
|
65 |
|
|
66 |
self.tyList = ko.observableArray(TYPE); |
|
67 |
} |
|
68 |
|
|
69 |
$(function () { |
|
70 |
window.vm = new ViewModel(); |
|
71 |
ko.applyBindings(vm); |
|
72 |
doSearch(); |
|
73 |
autoHeight(); |
|
74 |
if (vm.isAdmin()) { |
|
75 |
getCompanyList(); |
|
76 |
} |
|
77 |
pageInit(); |
|
78 |
}); |
|
79 |
|
|
80 |
function pageInit() { |
|
81 |
$('.table-responsive').scroll(function() { |
|
82 |
$('.th').css('top', $(this).scrollTop()); |
|
83 |
}) |
|
84 |
I.save.click(function(event) { |
|
85 |
if (valid()) { |
|
86 |
doSave(); |
|
87 |
} |
|
88 |
}); |
|
89 |
I.newObj.click(function(event) { |
|
90 |
vm.o(ko.mapping.fromJS(Obj)); |
|
91 |
// getNewNo(); |
|
92 |
I.modal.modal('show'); |
|
93 |
}); |
|
94 |
I.searchBtn.click(function(event) { |
|
95 |
doOpen(); |
|
96 |
}); |
|
97 |
I.modal.on('hidden.bs.modal', function (e) { |
|
98 |
clearError(); |
|
99 |
}); |
|
100 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
101 |
if (event.keyCode == 13) { |
|
102 |
doOpen(); |
|
103 |
} |
|
104 |
}); |
|
105 |
} |
|
106 |
|
|
107 |
function doOpen() { |
|
108 |
doSearch(); |
|
109 |
} |
|
110 |
|
|
111 |
function doSearch() { |
|
112 |
getList(vm.keyword(), vm.mtid(), I._page, I.PZ, 1); |
|
113 |
} |
|
114 |
|
|
115 |
function getList(keyword, companyNo, page, pagesize, pages) { |
|
116 |
I._page = page; |
|
117 |
$.post('/vehicle/getallList.htm', { |
|
118 |
searchword: keyword, |
|
119 |
companyNo: vm.isAdmin() ? companyNo : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG'), |
|
120 |
page: page, |
|
121 |
pagesize: pagesize, |
|
122 |
pages: pages |
|
123 |
}, function(data, textStatus, xhr) { |
|
124 |
vm.list.removeAll(); |
|
125 |
if (data.code >= 1) { |
|
126 |
//parent.showErrmsg(data.errmsg); |
|
127 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
128 |
return; |
|
129 |
} |
|
130 |
if (data.code == 0) { |
|
131 |
if (isList(data.list)) { |
|
132 |
$.each(data.list, function(index, val) { |
|
133 |
val.state=ko.observable(val.state); |
|
134 |
vm.list.push(val); |
|
135 |
}); |
|
136 |
$('tbody tr').click(function (e) { |
|
137 |
$('tbody tr').removeClass('info'); |
|
138 |
$(this).addClass('info'); |
|
139 |
}); |
|
140 |
} |
|
141 |
if (!!pages) { |
|
142 |
pages = data.pages; |
|
143 |
$('#pagdiv').unbind('page').empty(); |
|
144 |
if (pages > 1) { |
|
145 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
146 |
getList(keyword, companyNo, num - 1, pagesize, 0); |
|
147 |
}); |
|
148 |
} |
|
149 |
} |
|
150 |
return; |
|
151 |
} |
|
152 |
}, 'json'); |
|
153 |
} |
|
154 |
|
|
155 |
function valid(){ |
|
156 |
var isValid = false; |
|
157 |
var iF = $('#form'); |
|
158 |
iF.validate({ |
|
159 |
rules: { |
|
160 |
'vehicleId': { |
|
161 |
required: true, |
|
162 |
isPlateNumber: true |
|
163 |
}, |
|
164 |
'driver': { |
|
165 |
required: true, |
|
166 |
}, |
|
167 |
'phone': { |
|
168 |
required: true, |
|
169 |
isPhone: true |
|
170 |
}, |
|
171 |
'IDNum':{ |
|
172 |
required:true, |
|
173 |
|
|
174 |
} |
|
175 |
}, |
|
176 |
messages: { |
|
177 |
'vehicleId': { |
|
178 |
required: '不能为空!', |
|
179 |
isPlateNumber: '车牌号不正确!' |
|
180 |
}, |
|
181 |
'driver': { |
|
182 |
required: '不能为空!', |
|
183 |
}, |
|
184 |
'phone': { |
|
185 |
required: '不能为空!', |
|
186 |
isPhone: '手机号不正确!' |
|
187 |
}, |
|
188 |
'IDNum': { |
|
189 |
required: '不能为空!', |
|
190 |
} |
|
191 |
}, |
|
192 |
errorPlacement: function (err, element) { |
|
193 |
var p = element.parents('.form-group').eq(0); |
|
194 |
var d = p.find('.text-error').eq(0); |
|
195 |
d.css('color', '#D9534F'); |
|
196 |
err.appendTo(d); |
|
197 |
} |
|
198 |
}) |
|
199 |
isValid = iF.valid(); |
|
200 |
return isValid; |
|
201 |
} |
|
202 |
|
|
203 |
function doEdit(item) { |
|
204 |
if(isFunction(item.valid)){ |
|
205 |
item.valid=item.valid(); |
|
206 |
} |
|
207 |
vm.o(ko.mapping.fromJS(item)); |
|
208 |
I.modal.modal('show'); |
|
209 |
} |
|
210 |
|
|
211 |
function delConfirm(item) { |
|
212 |
$("#modalContent").html('确定要删除【' + item.vehicleId + '】吗?'); |
|
213 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
214 |
resizable: false, |
|
215 |
width: '320', |
|
216 |
modal: true, |
|
217 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
218 |
title_html: true, |
|
219 |
position: { my: "center", at: "center", of: window }, |
|
220 |
buttons: [ |
|
221 |
{ |
|
222 |
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
223 |
"class" : "btn btn-danger btn-minier", |
|
224 |
click: function() { |
|
225 |
$( this ).dialog( "close" ); |
|
226 |
doDel(item); |
|
227 |
} |
|
228 |
} |
|
229 |
, |
|
230 |
{ |
|
231 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
232 |
"class" : "btn btn-minier", |
|
233 |
click: function() { |
|
234 |
$( this ).dialog( "close" ); |
|
235 |
} |
|
236 |
} |
|
237 |
] |
|
238 |
}); |
|
239 |
} |
|
240 |
|
|
241 |
function doDel(item) { |
|
242 |
if (!!I.AjaxDelItem) return; |
|
243 |
I.AjaxDelItem = true; |
|
244 |
$.post('/vehicle/delItem.htm', {vehicleId: item.vehicleId}, function(data, textStatus, xhr) { |
|
245 |
I.AjaxDelItem = false; |
|
246 |
if (data.code >= 1) { |
|
247 |
//parent.showErrmsg(data.errmsg); |
|
248 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
249 |
return; |
|
250 |
} |
|
251 |
if (data.code == 0) { |
|
252 |
vm.list.remove(item); |
|
253 |
parent.showErrmsg('删除成功!'); |
|
254 |
I.modal.modal('hide'); |
|
255 |
return; |
|
256 |
} |
|
257 |
}, 'json'); |
|
258 |
} |
|
259 |
|
|
260 |
function doSave() { |
|
261 |
if (!I.AjaxSaveItem &&valid()) { |
|
262 |
I.AjaxSaveItem = true; |
|
263 |
I.save.prop('disabled', true); |
|
264 |
var o = ko.mapping.toJS(vm.o()); |
|
265 |
o.vehicleId = o.vehicleId.toUpperCase(); |
|
266 |
o.state = $('#state').prop('checked'); |
|
267 |
o.companyNo = vm.isAdmin() ? o.companyNo : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG') |
|
268 |
$.post('/vehicle/saveItem.htm', o, function(data, textStatus, xhr) { |
|
269 |
I.AjaxSaveItem = false; |
|
270 |
I.save.prop('disabled', false); |
|
271 |
if (data.code >= 1) { |
|
272 |
//parent.showErrmsg(data.errmsg); |
|
273 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
274 |
return; |
|
275 |
} |
|
276 |
if (data.code == 0) { |
|
277 |
parent.showErrmsg('保存成功!'); |
|
278 |
I.modal.modal('hide'); |
|
279 |
getList(vm.keyword(), vm.mtid(), I._page, I.PZ, 1); |
|
280 |
return; |
|
281 |
} |
|
282 |
}, 'json'); |
|
283 |
} |
|
284 |
} |
|
285 |
|
|
286 |
function clearError() { |
|
287 |
$('#form input').removeClass('error'); |
|
288 |
$('#form .text-error').html(''); |
|
289 |
} |
|
290 |
|
|
291 |
function getCompanyList() { |
|
292 |
$.post('/company/getList.htm', null, function(data, textStatus, xhr) { |
|
293 |
vm.tList.removeAll(); |
|
294 |
if (data.code >= 1) { |
|
295 |
//parent.showErrmsg(data.errmsg); |
|
296 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
297 |
return; |
|
298 |
} |
|
299 |
if (data.code == 0) { |
|
300 |
if (isList(data.list)) { |
|
301 |
$.each(data.list, function(index, val) { |
|
302 |
vm.tList.push(val); |
|
303 |
}); |
|
304 |
} |
|
305 |
} |
|
306 |
}, 'json'); |
|
307 |
} |
|
308 |
|
|
309 |
|
|
310 |
function doValid(item){ |
|
311 |
var state=true; |
|
312 |
if(isFunction(item.state)){ |
|
313 |
state=item.state(); |
|
314 |
}else{ |
|
315 |
state=item.state; |
|
316 |
} |
|
317 |
jQuery.post('/vehicle/changeState.htm', {vehicleId: item.vehicleId, state: !state}, function(data, textStatus, xhr) { |
|
318 |
//optional stuff to do after success |
|
319 |
if(data.code==0){ |
|
320 |
item.state(data.item); |
|
321 |
}else{ |
|
322 |
//parent.showErrmsg(data.errmsg); |
|
323 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
324 |
} |
|
325 |
},'json'); |
|
326 |
} |
|
327 |
|
|
328 |
function getNewNo() { |
|
329 |
$.post("/basicconfig/prefix/getNewNo.htm", {type: 'materiel'}, |
|
330 |
function (data, textStatus, jqXHR) { |
|
331 |
if (data.code >= 1) { |
|
332 |
//parent.showErrmsg(data.errmsg); |
|
333 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
334 |
return; |
|
335 |
} |
|
336 |
if (data.code == 0) { |
|
337 |
// vm.o().visitNo(data.number); |
|
338 |
$('#materielNo').val(data.number); |
|
339 |
return; |
|
340 |
} |
|
341 |
}, |
|
342 |
"json" |
|
343 |
); |
|
344 |
} |
|
345 |
|
|
346 |
function autoHeight() { |
|
347 |
$('.page-content').css('min-height', $(parent.window).height() - 117); |
|
348 |
$('.table-responsive').css('height', $(parent.window).height() - 217); |
|
349 |
} |