Administrator
2023-04-19 40ec16bbb7c9d23df625aa31ae42ac36e901749d
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
/**
* date: 
* author: neeler 
*/
 
//test data start
// var data_getList = Mock.mock('/enterprise/position/getList.htm', {code: 0, list: [
//     {id: 1, name: '岗位1', note: '岗位1', lvl: 1},
//     {id: 2, name: '岗位2', note: '岗位2', lvl: 2},
//     {id: 3, name: '岗位3', note: '岗位3', lvl: 3},
//     {id: 4, name: '岗位4', note: '岗位4', lvl: 4},
//     {id: 5, name: '岗位5', note: '岗位5', lvl: 5},
//     {id: 6, name: '岗位6', note: '岗位6', lvl: 1},
//     {id: 7, name: '岗位7', note: '岗位7', lvl: 2},
//     {id: 8, name: '岗位8', note: '岗位8', lvl: 3},
//     {id: 9, name: '岗位9', note: '岗位9', lvl: 4},
//     {id: 10, name: '岗位10', note: '岗位10', lvl: 5},
//     {id: 11, name: '岗位11', note: '岗位11', lvl: 1}
//     ], pages: 12})
// var data_doDel = Mock.mock('/enterprise/position/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
// var data_doSave = Mock.mock('/enterprise/position/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
//test data end
 
window.I = {
    PZ: 30,
    keyword: $('#keyword'),
    searchBtn: $('#searchBtn'),
    pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0,
    keywordValue: $('#k').val(),
    newObj: $('#newObj'),
    modal: $('#modal'),
    save: $('#save')
}
 
var PositionObj = {
    id: 0,
    name: '',
    note: '',
    lvl: '0',
}
 
var ViewModel = function() {
    var self = this;
    self.o = ko.observable(ko.mapping.fromJS(PositionObj));
 
    self.keyword = ko.observable(I.keywordValue);
    self.list = ko.observableArray();
 
    self.edit = function(item) {
        doEdit(item);
    }
    self.del = function(item) {
        delConfirm(item);
    }
}
 
$(function () {
    window.vm = new ViewModel();
    ko.applyBindings(vm);
    autoHeight();
    doSearch();
    pageInit();
});
 
function pageInit() {
    $('.table-responsive').scroll(function() {
        $('.th').css('top', $(this).scrollTop());
    })
    I.save.click(function(event) {
        if (valid()) {
            doSave();
        }
    });
    I.newObj.click(function(event) {
        vm.o(ko.mapping.fromJS(PositionObj));
        I.modal.modal('show');
    });
    I.searchBtn.click(function(event) {
        doOpen();
    });
    I.modal.on('hidden.bs.modal', function (e) {
        clearError();
    });
    I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) {
        if (event.keyCode == 13) {
            doOpen();
        }
    });
}
 
function doOpen() {
    doSearch();
}
 
function doSearch() {
    getList(vm.keyword(), I.pageValue, I.PZ, 1);
}
 
function getList(keyword, page, pagesize, pages) {
    $.post('/basicinfo/vehiclehinfo/getList.htm', {
        keyword: keyword,
        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, num - 1, pagesize, 0);
                    });
                }
            }
            return;
        }
    }, 'json');
}
 
function valid(){
    var isValid = false;
    var iF = $('#form');
    iF.validate({
        rules: {
            'name': {
                required: true
            }
        },
        messages: {
            'name': {
                required: '不能为空!'
            }
        },
        errorPlacement: function (err, element) {
            var p = element.parents('.form-group').eq(0);
            var d = p.find('.text-error').eq(0);
            d.css('color', '#D9534F');
            err.appendTo(d);
        }
    })
    isValid = iF.valid();
    return isValid;
}
 
function doEdit(item) {
    vm.o(ko.mapping.fromJS(item));
    I.modal.modal('show');
}
 
function delConfirm(item) {
    $("#modalContent").html('确定要删除【' + item.vehicleID + '】吗?');
    $("#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" );
                }
            }
        ]
    });
}
 
function doDel(item) {
    if (!!I.AjaxDelItem) return;
    I.AjaxDelItem = true;
    $.post('/basicinfo/vehiclehinfo/delItem.htm', item, function(data, textStatus, xhr) {
        I.AjaxDelItem = false;
        if (data.code >= 1) {
            //parent.showErrmsg(data.errmsg);
            swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
            return;
        }
        if (data.code == 0) {
            vm.list.remove(item);
            // location.replace(location.href);
            return;
        }
    }, 'json');
}
 
function doSave() {
    if (!I.AjaxSaveItem &&valid()) {
        I.AjaxSaveItem = true;
        var o = ko.mapping.toJS(vm.o());
        $.post('/enterprise/position/saveItem.htm', o, function(data, textStatus, xhr) {
            I.AjaxSaveItem = false;
            if (data.code >= 1) {
                //parent.showErrmsg(data.errmsg);
                swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
                return;
            }
            if (data.code == 0) {
                location.replace(location.href);
                return;
            }
        }, 'json');
    }
}
 
function clearError() {
    $('#form input').removeClass('error');
    $('#form .text-error').html('');
}
 
function autoHeight() {
    $('.page-content').css('min-height', $(parent.window).height() - 117);
    $('.table-responsive').css('height', $(parent.window).height() - 217);
}
 
$(window).resize(function() {autoHeight();})