Administrator
2022-10-09 23f93897d618a5253a18b65b124196f95891f240
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/**
* 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>&nbsp; 确定",
            //     "class" : "btn btn-danger btn-minier",
            //     click: function() {
            //         $( this ).dialog( "close" );
            //         doDel(item);
            //     }
            // }
            // ,
            {
                html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 取消",
                "class" : "btn btn-minier",
                click: function() {
                    $( this ).dialog( "close" );
                }
            }
        ]
    });
}