Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
提交 | 用户 | 时间
58d006 1 /**
A 2 * date: 
3 * author: neeler
4 */
5
6 //test data start
7 // 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})
8 //test data end
9
10 var Obj = {
11     cardno: '', 
12     type: '',
13     fkname: '',
14     stime: '',
15     ptype: '',
16     paperno: '',
17     phone: '',
18     numberplates: '',
19     name: '',
20     vcompany: '',
21     isreturn: '',
22     iswhite: '',
23     position: '',
24     departname: '',
25     sdate: '',
26     edate: '',
27 }
28
29 window.I = {
30     PZ: 50,
31     keyword: $('#keyword'),
32     searchBtn: $('.searchBtn'),
33     moreSearchCondition: $('#moreSearchCondition'),
34     searchBox: $('#searchBox'),
35     sDate: $('#sDate'),
36     eDate: $('#eDate'),
37     cardnoValue: $('#cardno').val(),
38     modal: $('#modal')
39 }
40
41 var ViewModel = function() {
42     var self = this;
43     self.o = ko.observable(ko.mapping.fromJS(Obj));
44     self.keyword = ko.observable(I.cardnoValue);
45     self.list = ko.observableArray();
46
47     self.details = function(item) {
48         showDetails(item);
49     }
50 }
51
52 $(function () {
53     window.vm = new ViewModel();
54     ko.applyBindings(vm);
55     if (I.cardnoValue) {
56         doSearch();
57     }
58     pageInit();
59 });
60
61 function showDetails(item) {
62     vm.o(ko.mapping.fromJS(item));
63     I.modal.modal('show');
64 }
65
66 function pageInit() {
67     I.moreSearchCondition.click(function(event) {
68         if ($(this).hasClass('active')) {
69             I._complexSearch = false;
70             $(this).removeClass('active');
71             $('i', $(this)).addClass('fa-chevron-down').removeClass('fa-chevron-up');
72             I.searchBox.slideUp();
73         } else {
74             I._complexSearch = true;
75             $(this).addClass('active');
76             $('i', $(this)).removeClass('fa-chevron-down').addClass('fa-chevron-up');
77             I.searchBox.slideDown();
78         }
79     });
80     I.searchBtn.click(function(event) {
81         doSearch();
82     });
83     I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) {
84         if (event.keyCode == 13) {
85             doSearch();
86         }
87     });
88 }
89
90 function doSearch() {
91     if (!!I._complexSearch) {
92         getList(vm.keyword(), I.sDate.val(), I.eDate.val(), 0, 1, I.PZ);
93     } else {
94         getList(vm.keyword(), null, null, 0, 1, I.PZ);        
95     }
96 }
97
98 function getList(keyword, sdate, edate, page, pagesize, pages) {
99     $.post('/log/card/getList.htm', {
100         keyword: keyword,
101         sdate: sdate,
102         edate: edate,
103         page: page,
104         pagesize: pagesize,
105         pages: pages
106     }, function(data, textStatus, xhr) {
107         vm.list.removeAll();
108         if (data.code >= 1) {
109            // parent.showErrmsg(data.errmsg);
110             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
111             return;
112         }
113         if (data.code == 0) {
114             if (isList(data.list)) {
115                 $.each(data.list, function(index, val) {
116                     vm.list.push(val);
117                 });
118             }
119             if (!!pages) {
120                 pages = data.pages;
121                 $('#pagdiv').unbind('page').empty();
122                 if (pages > 1) {
123                     $('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){
124                         getList(keyword, sdate, edate, num - 1, pagesize, pages);
125                     });
126                 }
127             }
128             return;
129         }
130     }, 'json');
131 }