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