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