/** * date: * author: neeler */ //test data start // var data_getList = Mock.mock('/log/card/getList.htm', {code: 0, 'list|1-20': [{cardno: 'cn47877878', type: '门岗用卡', fkname: '发卡人名', stime: '2015-05-05', ptype: '身份证', paperNo: '410103199010287984', phone: '13898927337', numberplates: '豫A12345', name: '万亚伶', vcompany: '光影交错', isreturn: false, iswhite: false, position: false, departname: '高精板带', sdate: '2016-01-01', edate: '2016-12-31',}], pages: 12}) //test data end var Obj = { cardno: '', type: '', fkname: '', stime: '', ptype: '', paperno: '', phone: '', numberplates: '', name: '', vcompany: '', isreturn: '', iswhite: '', position: '', departname: '', sdate: '', edate: '', } window.I = { PZ: 50, keyword: $('#keyword'), searchBtn: $('.searchBtn'), moreSearchCondition: $('#moreSearchCondition'), searchBox: $('#searchBox'), sDate: $('#sDate'), eDate: $('#eDate'), cardnoValue: $('#cardno').val(), modal: $('#modal') } var ViewModel = function() { var self = this; self.o = ko.observable(ko.mapping.fromJS(Obj)); self.keyword = ko.observable(I.cardnoValue); self.list = ko.observableArray(); self.details = function(item) { showDetails(item); } } $(function () { window.vm = new ViewModel(); ko.applyBindings(vm); if (I.cardnoValue) { doSearch(); } pageInit(); }); function showDetails(item) { vm.o(ko.mapping.fromJS(item)); I.modal.modal('show'); } function pageInit() { I.moreSearchCondition.click(function(event) { if ($(this).hasClass('active')) { I._complexSearch = false; $(this).removeClass('active'); $('i', $(this)).addClass('fa-chevron-down').removeClass('fa-chevron-up'); I.searchBox.slideUp(); } else { I._complexSearch = true; $(this).addClass('active'); $('i', $(this)).removeClass('fa-chevron-down').addClass('fa-chevron-up'); I.searchBox.slideDown(); } }); I.searchBtn.click(function(event) { doSearch(); }); I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { if (event.keyCode == 13) { doSearch(); } }); } function doSearch() { if (!!I._complexSearch) { getList(vm.keyword(), I.sDate.val(), I.eDate.val(), 0, 1, I.PZ); } else { getList(vm.keyword(), null, null, 0, 1, I.PZ); } } function getList(keyword, sdate, edate, page, pagesize, pages) { $.post('/log/card/getList.htm', { keyword: keyword, sdate: sdate, edate: edate, page: page, pagesize: pagesize, pages: pages }, 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) { 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, sdate, edate, num - 1, pagesize, pages); }); } } return; } }, 'json'); }