提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getList = Mock.mock('/enterprise/vehicletype/getList.htm', {code: 0, list: [ |
|
8 |
// {id: 1, name: '货车类型1', note: '货车类型1',}, |
|
9 |
// {id: 2, name: '货车类型2', note: '货车类型2',}, |
|
10 |
// {id: 3, name: '货车类型3', note: '货车类型3',}, |
|
11 |
// {id: 4, name: '货车类型4', note: '货车类型4',}, |
|
12 |
// {id: 5, name: '货车类型5', note: '货车类型5',}, |
|
13 |
// {id: 6, name: '货车类型6', note: '货车类型6',}, |
|
14 |
// {id: 7, name: '货车类型7', note: '货车类型7',}, |
|
15 |
// {id: 8, name: '货车类型8', note: '货车类型8',}, |
|
16 |
// {id: 9, name: '货车类型9', note: '货车类型9',}, |
|
17 |
// {id: 10, name: '货车类型10', note: '货车类型10',}, |
|
18 |
// {id: 11, name: '货车类型11', note: '货车类型11',} |
|
19 |
// ], pages: 12}) |
|
20 |
// var data_doDel = Mock.mock('/enterprise/vehicletype/delItem.htm', {code: 0, errmsg: '此货车类型正在使用中不能删除!'}) |
|
21 |
// var data_doSave = Mock.mock('/enterprise/vehicletype/saveItem.htm', {code: 0, errmsg: '此货车类型正在使用中不能删除!'}) |
|
22 |
//test data end |
|
23 |
|
|
24 |
window.I = { |
|
25 |
PZ: 30, |
|
26 |
keyword: $('#keyword'), |
|
27 |
searchBtn: $('#searchBtn'), |
|
28 |
pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0, |
|
29 |
keywordValue: $('#k').val(), |
|
30 |
newObj: $('#newObj'), |
|
31 |
modal: $('#modal'), |
|
32 |
save: $('#save') |
|
33 |
} |
|
34 |
|
|
35 |
var PositionObj = { |
|
36 |
id: 0, |
|
37 |
name: '', |
|
38 |
note: '', |
|
39 |
} |
|
40 |
|
|
41 |
var ViewModel = function() { |
|
42 |
var self = this; |
|
43 |
self.o = ko.observable(ko.mapping.fromJS(PositionObj)); |
|
44 |
|
|
45 |
self.keyword = ko.observable(I.keywordValue); |
|
46 |
self.list = ko.observableArray(); |
|
47 |
|
|
48 |
self.edit = function(item) { |
|
49 |
doEdit(item); |
|
50 |
} |
|
51 |
self.del = function(item) { |
|
52 |
delConfirm(item); |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
$(function () { |
|
57 |
window.vm = new ViewModel(); |
|
58 |
ko.applyBindings(vm); |
|
59 |
doSearch(); |
|
60 |
pageInit(); |
|
61 |
}); |
|
62 |
|
|
63 |
function pageInit() { |
|
64 |
I.save.click(function(event) { |
|
65 |
if (valid()) { |
|
66 |
doSave(); |
|
67 |
} |
|
68 |
}); |
|
69 |
I.newObj.click(function(event) { |
|
70 |
vm.o(ko.mapping.fromJS(PositionObj)); |
|
71 |
I.modal.modal('show'); |
|
72 |
}); |
|
73 |
I.searchBtn.click(function(event) { |
|
74 |
doOpen(); |
|
75 |
}); |
|
76 |
I.modal.on('hidden.bs.modal', function (e) { |
|
77 |
clearError(); |
|
78 |
}); |
|
79 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
80 |
if (event.keyCode == 13) { |
|
81 |
doOpen(); |
|
82 |
} |
|
83 |
}); |
|
84 |
} |
|
85 |
|
|
86 |
function doOpen() { |
|
87 |
var k = $.trim(vm.keyword()); |
|
88 |
k = !!k ? '?keyword=' + k : ''; |
|
89 |
window.open('vehicletype.jsf' + k, '_self'); |
|
90 |
} |
|
91 |
|
|
92 |
function doSearch() { |
|
93 |
getList(vm.keyword(), I.pageValue, I.PZ, 1); |
|
94 |
} |
|
95 |
|
|
96 |
function getList(keyword, page, pagesize, pages) { |
|
97 |
$.post('/enterprise/vehicletype/getList.htm', { |
|
98 |
keyword: keyword, |
|
99 |
page: page, |
|
100 |
pagesize: pagesize, |
|
101 |
pages: pages |
|
102 |
}, function(data, textStatus, xhr) { |
|
103 |
vm.list.removeAll(); |
|
104 |
if (data.code >= 1) { |
|
105 |
//parent.showErrmsg(data.errmsg); |
|
106 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
107 |
return; |
|
108 |
} |
|
109 |
if (data.code == 0) { |
|
110 |
if (isList(data.list)) { |
|
111 |
$.each(data.list, function(index, val) { |
|
112 |
vm.list.push(val); |
|
113 |
}); |
|
114 |
} |
|
115 |
if (!!pages) { |
|
116 |
pages = data.pages; |
|
117 |
$('#pagdiv').unbind('page').empty(); |
|
118 |
if (pages > 1) { |
|
119 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
120 |
var k = !!I.keywordValue ? '&keyword=' + I.keywordValue : ''; |
|
121 |
window.open('vehicletype.jsf?page=' + num + k, '_self'); |
|
122 |
}); |
|
123 |
} |
|
124 |
} |
|
125 |
return; |
|
126 |
} |
|
127 |
}, 'json'); |
|
128 |
} |
|
129 |
|
|
130 |
function valid(){ |
|
131 |
var isValid = false; |
|
132 |
var iF = $('#form'); |
|
133 |
iF.validate({ |
|
134 |
rules: { |
|
135 |
'name': { |
|
136 |
required: true |
|
137 |
} |
|
138 |
}, |
|
139 |
messages: { |
|
140 |
'name': { |
|
141 |
required: '不能为空!' |
|
142 |
} |
|
143 |
}, |
|
144 |
errorPlacement: function (err, element) { |
|
145 |
var p = element.parents('.form-group').eq(0); |
|
146 |
var d = p.find('.text-error').eq(0); |
|
147 |
d.css('color', '#D9534F'); |
|
148 |
err.appendTo(d); |
|
149 |
} |
|
150 |
}) |
|
151 |
isValid = iF.valid(); |
|
152 |
return isValid; |
|
153 |
} |
|
154 |
|
|
155 |
function doEdit(item) { |
|
156 |
vm.o(ko.mapping.fromJS(item)); |
|
157 |
I.modal.modal('show'); |
|
158 |
} |
|
159 |
|
|
160 |
function delConfirm(item) { |
|
161 |
$("#modalContent").html('确定要删除【' + item.name + '】吗?'); |
|
162 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
163 |
resizable: false, |
|
164 |
width: '320', |
|
165 |
modal: true, |
|
166 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
167 |
title_html: true, |
|
168 |
position: { my: "center", at: "center", of: window }, |
|
169 |
buttons: [ |
|
170 |
{ |
|
171 |
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
172 |
"class" : "btn btn-danger btn-minier", |
|
173 |
click: function() { |
|
174 |
$( this ).dialog( "close" ); |
|
175 |
doDel(item); |
|
176 |
} |
|
177 |
} |
|
178 |
, |
|
179 |
{ |
|
180 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
181 |
"class" : "btn btn-minier", |
|
182 |
click: function() { |
|
183 |
$( this ).dialog( "close" ); |
|
184 |
} |
|
185 |
} |
|
186 |
] |
|
187 |
}); |
|
188 |
} |
|
189 |
|
|
190 |
function doDel(item) { |
|
191 |
if (!!I.AjaxDelItem) return; |
|
192 |
I.AjaxDelItem = true; |
|
193 |
$.post('/enterprise/vehicletype/delItem.htm', {id: item.id}, function(data, textStatus, xhr) { |
|
194 |
I.AjaxDelItem = false; |
|
195 |
if (data.code >= 1) { |
|
196 |
//parent.showErrmsg(data.errmsg); |
|
197 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
198 |
return; |
|
199 |
} |
|
200 |
if (data.code == 0) { |
|
201 |
vm.list.remove(item); |
|
202 |
location.replace(location.href); |
|
203 |
return; |
|
204 |
} |
|
205 |
}, 'json'); |
|
206 |
} |
|
207 |
|
|
208 |
function doSave() { |
|
209 |
if (!I.AjaxSaveItem &&valid()) { |
|
210 |
I.AjaxSaveItem = true; |
|
211 |
var o = ko.mapping.toJS(vm.o()); |
|
212 |
$.post('/enterprise/vehicletype/saveItem.htm', o, function(data, textStatus, xhr) { |
|
213 |
I.AjaxSaveItem = false; |
|
214 |
if (data.code >= 1) { |
|
215 |
//parent.showErrmsg(data.errmsg); |
|
216 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
217 |
return; |
|
218 |
} |
|
219 |
if (data.code == 0) { |
|
220 |
location.replace(location.href); |
|
221 |
return; |
|
222 |
} |
|
223 |
}, 'json'); |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
function clearError() { |
|
228 |
$('#form input').removeClass('error'); |
|
229 |
$('#form .text-error').html(''); |
|
230 |
} |