/**
|
* date:
|
* author: neeler
|
*/
|
|
//test data start
|
// 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})
|
// var data_doDel = Mock.mock('/gates/cardinuse/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
|
// var data_doSave = Mock.mock('/gates/cardinuse/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
|
// var data_lossRegister = Mock.mock('/gates/cardinuse/lossRegister.htm', {code: 0,})
|
// var data_changeCard = Mock.mock('/gates/cardinuse/changeCard.htm', {code: 0,})
|
// var data_useCard = Mock.mock('/gates/cardinuse/useCard.htm', {code: 0,})
|
// var data_doRecycle = Mock.mock('/gates/cardinuse/doRecycle.htm', {code: 0,})
|
//test data end
|
|
// var TYPE = ['卡号', '车牌号', '姓名']
|
var TYPE = [{key: '卡号', value: '卡号'}, {key: '持卡人', value: '姓名'}]
|
|
var Obj = {
|
dname: '',
|
gonghao: '',
|
phone: '',
|
sex: '',
|
sdate:'',
|
edate:''
|
}
|
|
window.I = {
|
PZ: 30,
|
keyword: $('#keyword'),
|
searchBtn: $('#searchBtn'),
|
modal: $('#modal'),
|
save: $('#save'),
|
addBtn: $('#addBtn'),
|
goveCardModal: $('#goveCardModal'),
|
giveCardBtn: $('#giveCardBtn'),
|
cname: $('#cname')
|
}
|
|
var ViewModel = function() {
|
var self = this;
|
self.o = ko.observable(ko.mapping.fromJS(Obj));
|
self.keyword = ko.observable(I.keywordValue);
|
self.list = ko.observableArray();
|
|
self.type = ko.observable();
|
self.tList = ko.observableArray(TYPE);
|
|
self.oldCardno = ko.observable();
|
self.newCardno = ko.observable();
|
|
self.lossRegister = function(item) {
|
doLossRegister(item);
|
}
|
self.changeCard = function(item) {
|
// doChangeCard(item);
|
self.oldCardno(item.cardno);
|
self.newCardno('');
|
I.modal.modal('show');
|
}
|
self.recycle = function(item) {
|
doRecycle(item);
|
}
|
self.useCard = function(item) {
|
doUseCard(item);
|
}
|
|
self.giveCardno = ko.observable();
|
}
|
|
function doLossRegister(item) {
|
$.post("/gates/cardinuse/lossRegister.htm", {cardno: item.cardno},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
// parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
parent.showErrmsg('挂失成功!');
|
item.lost(true);
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function doRecycle(item) {
|
$.post("/gates/cardinuse/doRecycle.htm", {cardno: item.cardno},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
// parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
parent.showErrmsg('回收成功!');
|
vm.list.remove(item);
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function doUseCard(item) {
|
$.post("/gates/cardinuse/useCard.htm", {cardno: item.cardno},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
// parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
item.lost(false);
|
parent.showErrmsg('启用成功!');
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function doChangeCard() {
|
$.post("/gates/cardinuse/useCard.htm", {oldCardno: vm.oldCardno(), newCardno: vm.newCardno()},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
// parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
jQuery.each(vm.list(), function(index, val) {
|
//iterate through array or object
|
if(val.cardno()==vm.oldCardno()){
|
val.cardno(vm.newCardno());
|
return false;
|
}
|
});
|
parent.showErrmsg('换卡成功!');
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
$(function () {
|
window.vm = new ViewModel();
|
ko.applyBindings(vm);
|
doSearch();
|
typeaheadInit();
|
pageInit();
|
});
|
|
function pageInit() {
|
I.giveCardBtn.click(function (e) {
|
e.preventDefault();
|
if (!!vm.giveCardno() && vm.giveCardno() != '') {
|
if (!!vm.o().gonghao() && vm.o().gonghao() != '') {
|
var sdate=$('#sdate').val();
|
var edate=$('#edate').val();
|
doorkeeperGivecard(vm.o().gonghao(), vm.giveCardno(),sdate,edate);
|
} else {
|
// parent.showErrmsg('没有找到员工!');
|
swal({title:'',text:'没有找到员工',type:'error',confirmButtonText:'确定'});
|
}
|
} else {
|
// parent.showErrmsg('没有卡号!');
|
swal({title:'',text:'没有卡号',type:'error',confirmButtonText:'确定'});
|
}
|
});
|
I.addBtn.click(function (e) {
|
e.preventDefault();
|
vm.o(ko.mapping.fromJS(Obj));
|
I.cname.val('');
|
I.goveCardModal.modal('show');
|
});
|
I.save.click(function (e) {
|
e.preventDefault();
|
if (vm.newCardno() != '') {
|
doChangeCard();
|
} else {
|
parent.showErrmsg('请输入新卡号!');
|
}
|
});
|
I.searchBtn.click(function(event) {
|
doSearch();
|
});
|
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) {
|
if (event.keyCode == 13) {
|
doSearch();
|
}
|
});
|
}
|
|
function doSearch() {
|
getList(vm.keyword(), 0, I.PZ, 1,vm.type());
|
}
|
function doorkeeperGivecard(gonghao, cardno,sdate,edate) {
|
$.post("/gates/cardinuse/doorkeeperGivecard.htm", {gonghao: gonghao, cardno: cardno,sdate:sdate,edate:edate},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
//showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
showErrmsg('发卡成功!');
|
I.goveCardModal.modal('hide');
|
doSearch();
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function getList(keyword, page, pagesize, pages,type) {
|
// $.post('/gates/cardinuse/getList.htm', {
|
$.post('/gates/cardinuse/getDoorkeeperList.htm', {
|
keyword: keyword,
|
page: page,
|
pagesize: pagesize,
|
pages: pages,
|
type:type
|
}, function(data, textStatus, xhr) {
|
vm.list.removeAll();
|
if (data.code >= 1) {
|
//parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
if (isList(data.list)) {
|
$.each(data.list, function(index, val) {
|
val.lost=ko.observable(val.lost);
|
val.cardno=ko.observable(val.cardno);
|
vm.list.push(val);
|
});
|
}
|
if (!!pages) {
|
pages = data.pages;
|
$('#pagdiv').unbind('page').empty();
|
if (pages > 1) {
|
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){
|
getList(keyword, num - 1, pagesize, 0);
|
});
|
}
|
}
|
return;
|
}
|
}, 'json');
|
}
|
|
function typeaheadInit() {
|
var reception = new Bloodhound({
|
datumTokenizer: Bloodhound.tokenizers.whitespace,
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
remote: {
|
url: '/enterprise/enterworker/typeahead.htm?query=%QUERY',
|
wildcard: '%QUERY'
|
}
|
});
|
|
I.cname.typeahead(null, {
|
display: 'name',
|
limit: 20,
|
source: reception
|
});
|
|
I.cname.bind('typeahead:select', function(ev, suggestion) {
|
console.log(suggestion);
|
vm.o().dname(suggestion.dname);
|
vm.o().gonghao(suggestion.gonghao);
|
vm.o().phone(suggestion.phone);
|
vm.o().sex(suggestion.sex);
|
});
|
}
|
|
function validMessage(str) {
|
$("#modalContent").html(str);
|
$("#dialog-confirm").removeClass('hide').dialog({
|
resizable: false,
|
width: '320',
|
modal: true,
|
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>",
|
title_html: true,
|
position: { my: "center", at: "center", of: window },
|
buttons: [
|
// {
|
// html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定",
|
// "class" : "btn btn-danger btn-minier",
|
// click: function() {
|
// $( this ).dialog( "close" );
|
// doDel(item);
|
// }
|
// }
|
// ,
|
{
|
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消",
|
"class" : "btn btn-minier",
|
click: function() {
|
$( this ).dialog( "close" );
|
}
|
}
|
]
|
});
|
}
|