/** * 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/delay.htm', {code: 0,}) //test data end // var TYPE = ['卡号', '车牌号', '姓名'] var TYPE = [{key: '卡号', value: '卡号'}, {key: '车牌号', value: '车牌号'}, {key: '持卡人', value: '姓名'}] window.I = { PZ: 30, keyword: $('#keyword'), searchBtn: $('#searchBtn'), modal: $('#modal'), save: $('#changcardbtn'), addBtn: $('#addBtn'), goveCardModal: $('#goveCardModal'), giveCardBtn: $('#giveCardBtn') } var ViewModel = function() { var self = this; 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.item=null; self.delayCard=function(item){ self.item=item; self.oldCardno(item.cardno()); $('#newenddate').val(item.edate); $('#carddelaymodal').modal('show'); } 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 doDelayCard(cardno,edate) { $.post("/gates/cardinuse/delay.htm", {cardno: cardno,edate:edate}, 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('延期成功!'); if(vm.item!=null){ vm.item.edate=data.item; vm.item.vdate(vm.item.sdate+'--'+vm.item.edate); } $('#carddelaymodal').modal('hide'); 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/changeCard.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(); pageInit(); }); function pageInit() { I.giveCardBtn.click(function (e) { e.preventDefault(); if (vm.giveCardno() != '') { ; } else { //parent.showErrmsg('没有卡号!'); swal({title:'',text:'没有找到卡号!',type:'error',confirmButtonText:'确定'}); } }); I.addBtn.click(function (e) { e.preventDefault(); 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(); } }); $('#changecdnewcard').on(ISIE ? 'keypress' : 'keydown', function (event) { if (event.keyCode == 13) { event.preventDefault(); return false; } }); $('#carddelaybtn').click(function(){ var cardno=vm.oldCardno(); var edate=$('#newenddate').val(); if(edate==''||cardno==''){ swal({title:'',text:'卡延期请输入有效的日期!',type:'error',confirmButtonText:'确定'}); } doDelayCard(cardno,edate); }); } function doSearch() { getList(vm.keyword(), 0, I.PZ, 1,vm.type()); } function getList(keyword, page, pagesize, pages,type) { $.post('/gates/cardinuse/getList.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); val.vdate=ko.observable(val.sdate+'--'+val.edate); 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 validMessage(str) { $("#modalContent").html(str); $("#dialog-confirm").removeClass('hide').dialog({ resizable: false, width: '320', modal: true, title: "
", title_html: true, position: { my: "center", at: "center", of: window }, buttons: [ // { // html: " 确定", // "class" : "btn btn-danger btn-minier", // click: function() { // $( this ).dialog( "close" ); // doDel(item); // } // } // , { html: " 取消", "class" : "btn btn-minier", click: function() { $( this ).dialog( "close" ); } } ] }); }