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