提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getList = Mock.mock('/gates/cardinuse/getList.htm', {code: 0, 'list|5-10': [{cardno: 'cardno', type: 'type', fkname: 'fkname', stime: 'stime', ptype: 'ptype', paperNo: 'paperNo', phone: 'phone', numberplates: 'numberplates', name: 'name', vcompany: 'vcompany', lost: 'lost', isreturn: 'isreturn', iswhite: 'iswhite', position: 'position', departname: 'departname', sdate: 'sdate', edate: 'edate'}], pages: 12}) |
|
8 |
// var data_doDel = Mock.mock('/gates/cardinuse/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) |
|
9 |
// var data_doSave = Mock.mock('/gates/cardinuse/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'}) |
|
10 |
// var data_lossRegister = Mock.mock('/gates/cardinuse/lossRegister.htm', {code: 0,}) |
|
11 |
// var data_changeCard = Mock.mock('/gates/cardinuse/changeCard.htm', {code: 0,}) |
|
12 |
// var data_useCard = Mock.mock('/gates/cardinuse/useCard.htm', {code: 0,}) |
|
13 |
//var data_doRecycle = Mock.mock('/gates/cardinuse/delay.htm', {code: 0,}) |
|
14 |
//test data end |
|
15 |
|
|
16 |
// var TYPE = ['卡号', '车牌号', '姓名'] |
|
17 |
var TYPE = [{key: '卡号', value: '卡号'}, {key: '车牌号', value: '车牌号'}, {key: '持卡人', value: '姓名'}] |
|
18 |
|
|
19 |
window.I = { |
|
20 |
PZ: 30, |
|
21 |
keyword: $('#keyword'), |
|
22 |
searchBtn: $('#searchBtn'), |
|
23 |
modal: $('#modal'), |
|
24 |
save: $('#changcardbtn'), |
|
25 |
addBtn: $('#addBtn'), |
|
26 |
goveCardModal: $('#goveCardModal'), |
|
27 |
giveCardBtn: $('#giveCardBtn') |
|
28 |
} |
|
29 |
|
|
30 |
var ViewModel = function() { |
|
31 |
var self = this; |
|
32 |
self.keyword = ko.observable(I.keywordValue); |
|
33 |
self.list = ko.observableArray(); |
|
34 |
|
|
35 |
self.type = ko.observable(); |
|
36 |
self.tList = ko.observableArray(TYPE); |
|
37 |
|
|
38 |
self.oldCardno = ko.observable(); |
|
39 |
self.newCardno = ko.observable(); |
|
40 |
|
|
41 |
self.lossRegister = function(item) { |
|
42 |
doLossRegister(item); |
|
43 |
} |
|
44 |
self.changeCard = function(item) { |
|
45 |
// doChangeCard(item); |
|
46 |
self.oldCardno(item.cardno); |
|
47 |
self.newCardno(''); |
|
48 |
I.modal.modal('show'); |
|
49 |
} |
|
50 |
self.recycle = function(item) { |
|
51 |
doRecycle(item); |
|
52 |
} |
|
53 |
self.useCard = function(item) { |
|
54 |
doUseCard(item); |
|
55 |
} |
|
56 |
self.item=null; |
|
57 |
self.delayCard=function(item){ |
|
58 |
self.item=item; |
|
59 |
self.oldCardno(item.cardno()); |
|
60 |
$('#newenddate').val(item.edate); |
|
61 |
$('#carddelaymodal').modal('show'); |
|
62 |
|
|
63 |
} |
|
64 |
self.giveCardno = ko.observable(); |
|
65 |
} |
|
66 |
|
|
67 |
function doLossRegister(item) { |
|
68 |
$.post("/gates/cardinuse/lossRegister.htm", {cardno: item.cardno}, |
|
69 |
function (data, textStatus, jqXHR) { |
|
70 |
if (data.code >= 1) { |
|
71 |
//parent.showErrmsg(data.errmsg); |
|
72 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
73 |
return; |
|
74 |
} |
|
75 |
if (data.code == 0) { |
|
76 |
parent.showErrmsg('挂失成功!'); |
|
77 |
item.lost(true); |
|
78 |
return; |
|
79 |
} |
|
80 |
}, |
|
81 |
"json" |
|
82 |
); |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
function doDelayCard(cardno,edate) { |
|
87 |
$.post("/gates/cardinuse/delay.htm", {cardno: cardno,edate:edate}, |
|
88 |
function (data, textStatus, jqXHR) { |
|
89 |
if (data.code >= 1) { |
|
90 |
//parent.showErrmsg(data.errmsg); |
|
91 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
92 |
return; |
|
93 |
} |
|
94 |
if (data.code == 0) { |
|
95 |
parent.showErrmsg('延期成功!'); |
|
96 |
if(vm.item!=null){ |
|
97 |
vm.item.edate=data.item; |
|
98 |
vm.item.vdate(vm.item.sdate+'--'+vm.item.edate); |
|
99 |
} |
|
100 |
$('#carddelaymodal').modal('hide'); |
|
101 |
return; |
|
102 |
} |
|
103 |
} |
|
104 |
,"json"); |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
function doRecycle(item) { |
|
109 |
$.post("/gates/cardinuse/doRecycle.htm", {cardno: item.cardno}, |
|
110 |
function (data, textStatus, jqXHR) { |
|
111 |
if (data.code >= 1) { |
|
112 |
//parent.showErrmsg(data.errmsg); |
|
113 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
114 |
return; |
|
115 |
} |
|
116 |
if (data.code == 0) { |
|
117 |
parent.showErrmsg('回收成功!'); |
|
118 |
vm.list.remove(item); |
|
119 |
return; |
|
120 |
} |
|
121 |
}, |
|
122 |
"json" |
|
123 |
); |
|
124 |
} |
|
125 |
|
|
126 |
function doUseCard(item) { |
|
127 |
$.post("/gates/cardinuse/useCard.htm", {cardno: item.cardno}, |
|
128 |
function (data, textStatus, jqXHR) { |
|
129 |
if (data.code >= 1) { |
|
130 |
// parent.showErrmsg(data.errmsg); |
|
131 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
132 |
return; |
|
133 |
} |
|
134 |
if (data.code == 0) { |
|
135 |
item.lost(false); |
|
136 |
parent.showErrmsg('启用成功!'); |
|
137 |
return; |
|
138 |
} |
|
139 |
}, |
|
140 |
"json" |
|
141 |
); |
|
142 |
} |
|
143 |
|
|
144 |
function doChangeCard() { |
|
145 |
$.post("/gates/cardinuse/changeCard.htm", {oldCardno: vm.oldCardno(), newCardno: vm.newCardno()}, |
|
146 |
function (data, textStatus, jqXHR) { |
|
147 |
if (data.code >= 1) { |
|
148 |
//parent.showErrmsg(data.errmsg); |
|
149 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
150 |
return; |
|
151 |
} |
|
152 |
if (data.code == 0) { |
|
153 |
jQuery.each(vm.list(), function(index, val) { |
|
154 |
//iterate through array or object |
|
155 |
if(val.cardno()==vm.oldCardno()){ |
|
156 |
val.cardno(vm.newCardno()); |
|
157 |
return false; |
|
158 |
} |
|
159 |
}); |
|
160 |
parent.showErrmsg('换卡成功!'); |
|
161 |
return; |
|
162 |
} |
|
163 |
}, |
|
164 |
"json" |
|
165 |
); |
|
166 |
} |
|
167 |
|
|
168 |
$(function () { |
|
169 |
window.vm = new ViewModel(); |
|
170 |
ko.applyBindings(vm); |
|
171 |
doSearch(); |
|
172 |
pageInit(); |
|
173 |
}); |
|
174 |
|
|
175 |
function pageInit() { |
|
176 |
I.giveCardBtn.click(function (e) { |
|
177 |
e.preventDefault(); |
|
178 |
if (vm.giveCardno() != '') { |
|
179 |
; |
|
180 |
} else { |
|
181 |
//parent.showErrmsg('没有卡号!'); |
|
182 |
swal({title:'',text:'没有找到卡号!',type:'error',confirmButtonText:'确定'}); |
|
183 |
} |
|
184 |
}); |
|
185 |
I.addBtn.click(function (e) { |
|
186 |
e.preventDefault(); |
|
187 |
I.goveCardModal.modal('show'); |
|
188 |
}); |
|
189 |
I.save.click(function (e) { |
|
190 |
e.preventDefault(); |
|
191 |
if (vm.newCardno() != '') { |
|
192 |
doChangeCard(); |
|
193 |
} else { |
|
194 |
parent.showErrmsg('请输入新卡号!'); |
|
195 |
} |
|
196 |
}); |
|
197 |
I.searchBtn.click(function(event) { |
|
198 |
doSearch(); |
|
199 |
}); |
|
200 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
201 |
if (event.keyCode == 13) { |
|
202 |
doSearch(); |
|
203 |
} |
|
204 |
}); |
|
205 |
|
|
206 |
|
|
207 |
$('#changecdnewcard').on(ISIE ? 'keypress' : 'keydown', function (event) { |
|
208 |
if (event.keyCode == 13) { |
|
209 |
event.preventDefault(); |
|
210 |
return false; |
|
211 |
} |
|
212 |
}); |
|
213 |
|
|
214 |
$('#carddelaybtn').click(function(){ |
|
215 |
var cardno=vm.oldCardno(); |
|
216 |
var edate=$('#newenddate').val(); |
|
217 |
if(edate==''||cardno==''){ |
|
218 |
swal({title:'',text:'卡延期请输入有效的日期!',type:'error',confirmButtonText:'确定'}); |
|
219 |
} |
|
220 |
doDelayCard(cardno,edate); |
|
221 |
}); |
|
222 |
} |
|
223 |
|
|
224 |
function doSearch() { |
|
225 |
getList(vm.keyword(), 0, I.PZ, 1,vm.type()); |
|
226 |
} |
|
227 |
|
|
228 |
function getList(keyword, page, pagesize, pages,type) { |
|
229 |
$.post('/gates/cardinuse/getList.htm', { |
|
230 |
keyword: keyword, |
|
231 |
page: page, |
|
232 |
pagesize: pagesize, |
|
233 |
pages: pages, |
|
234 |
type:type |
|
235 |
}, function(data, textStatus, xhr) { |
|
236 |
vm.list.removeAll(); |
|
237 |
if (data.code >= 1) { |
|
238 |
//parent.showErrmsg(data.errmsg); |
|
239 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
240 |
return; |
|
241 |
} |
|
242 |
if (data.code == 0) { |
|
243 |
if (isList(data.list)) { |
|
244 |
$.each(data.list, function(index, val) { |
|
245 |
val.lost=ko.observable(val.lost); |
|
246 |
val.cardno=ko.observable(val.cardno); |
|
247 |
val.vdate=ko.observable(val.sdate+'--'+val.edate); |
|
248 |
vm.list.push(val); |
|
249 |
}); |
|
250 |
} |
|
251 |
if (!!pages) { |
|
252 |
pages = data.pages; |
|
253 |
$('#pagdiv').unbind('page').empty(); |
|
254 |
if (pages > 1) { |
|
255 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
256 |
getList(keyword, num - 1, pagesize, 0); |
|
257 |
}); |
|
258 |
} |
|
259 |
} |
|
260 |
return; |
|
261 |
} |
|
262 |
}, 'json'); |
|
263 |
} |
|
264 |
|
|
265 |
function validMessage(str) { |
|
266 |
$("#modalContent").html(str); |
|
267 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
268 |
resizable: false, |
|
269 |
width: '320', |
|
270 |
modal: true, |
|
271 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
272 |
title_html: true, |
|
273 |
position: { my: "center", at: "center", of: window }, |
|
274 |
buttons: [ |
|
275 |
// { |
|
276 |
// html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
277 |
// "class" : "btn btn-danger btn-minier", |
|
278 |
// click: function() { |
|
279 |
// $( this ).dialog( "close" ); |
|
280 |
// doDel(item); |
|
281 |
// } |
|
282 |
// } |
|
283 |
// , |
|
284 |
{ |
|
285 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
286 |
"class" : "btn btn-minier", |
|
287 |
click: function() { |
|
288 |
$( this ).dialog( "close" ); |
|
289 |
} |
|
290 |
} |
|
291 |
] |
|
292 |
}); |
|
293 |
} |