提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getList = Mock.mock('/company/getList.htm', {code: 0, 'list|5-20': [{id: 'id', companyNo: 'companyNo', note: 'note', name: 'name'}], pages: 12}) |
|
8 |
// var data_doDel = Mock.mock('/company/delItem.htm', {code: 0, errmsg: 'errmsg'}) |
|
9 |
// var data_doSave = Mock.mock('/company/saveItem.htm', {code: 0, errmsg: 'errmsg'}) |
|
10 |
//test data end |
|
11 |
var YWDY = [{'name': '河南明泰铝业股份有限公司', 'code': '101'}, |
|
12 |
{'name': '河南明泰科技发展有限公司', 'code': '103'}, |
|
13 |
{'name': '郑州明泰实业有限公司', 'code': '102'}, |
|
14 |
{'name': '河南泰鸿新材料有限公司', 'code': '113'}, |
|
15 |
{'name': '河南明晟新材料科技有限公司', 'code': '111'}, |
|
16 |
{'name': '河南义瑞新材料科技有限公司', 'code': '114'}, |
|
17 |
]; |
|
18 |
|
|
19 |
window.I = { |
|
20 |
PZ: 30, |
|
21 |
keyword: $('#keyword'), |
|
22 |
searchBtn: $('#searchBtn'), |
|
23 |
pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0, |
|
24 |
keywordValue: $('#k').val(), |
|
25 |
newObj: $('#newObj'), |
|
26 |
modal: $('#modal'), |
|
27 |
save: $('#save') |
|
28 |
} |
|
29 |
|
|
30 |
var Obj = { |
|
31 |
id: 0, |
|
32 |
companyNo: '', |
|
33 |
name: '', |
|
34 |
note: '', |
|
35 |
hasSPR: false //has self pickup right |
|
36 |
} |
|
37 |
|
|
38 |
var ViewModel = function() { |
|
39 |
var self = this; |
|
40 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
41 |
|
|
42 |
self.keyword = ko.observable(I.keywordValue); |
|
43 |
self.list = ko.observableArray(); |
|
44 |
|
|
45 |
//业务单元value |
|
46 |
self.yvList = ko.observableArray(); |
|
47 |
//业务单元 |
|
48 |
self.ywdyList=ko.observableArray(YWDY); |
|
49 |
|
|
50 |
self.edit = function(item) { |
|
51 |
doEdit(item); |
|
52 |
} |
|
53 |
self.del = function(item) { |
|
54 |
delConfirm(item); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
$(function () { |
|
59 |
window.vm = new ViewModel(); |
|
60 |
ko.applyBindings(vm); |
|
61 |
$(".chosen-select").chosen(); |
|
62 |
$("#dp_chosen").width(270); |
|
63 |
autoHeight(); |
|
64 |
doSearch(); |
|
65 |
pageInit(); |
|
66 |
}); |
|
67 |
|
|
68 |
function pageInit() { |
|
69 |
$('.table-responsive').scroll(function() { |
|
70 |
$('.th').css('top', $(this).scrollTop()); |
|
71 |
}) |
|
72 |
I.save.click(function(event) { |
|
73 |
if (valid()) { |
|
74 |
doSave(); |
|
75 |
} |
|
76 |
}); |
|
77 |
I.newObj.click(function(event) { |
|
78 |
vm.o(ko.mapping.fromJS(Obj)); |
|
79 |
vm.yvList.removeAll(); |
|
80 |
I.modal.modal('show'); |
|
81 |
}); |
|
82 |
I.searchBtn.click(function(event) { |
|
83 |
doOpen(); |
|
84 |
}); |
|
85 |
I.modal.on('hidden.bs.modal', function (e) { |
|
86 |
clearError(); |
|
87 |
}); |
|
88 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
89 |
if (event.keyCode == 13) { |
|
90 |
doOpen(); |
|
91 |
} |
|
92 |
}); |
|
93 |
} |
|
94 |
|
|
95 |
function doOpen() { |
|
96 |
var k = $.trim(vm.keyword()); |
|
97 |
getList(k, 0, I.PZ, 1); |
|
98 |
} |
|
99 |
|
|
100 |
function doSearch() { |
|
101 |
doOpen(); |
|
102 |
} |
|
103 |
|
|
104 |
function getList(keyword, page, pagesize, pages) { |
|
105 |
I._page = page; |
|
106 |
$.post('/company/getList.htm', { |
|
107 |
searchword: keyword, |
|
108 |
page: page, |
|
109 |
pagesize: pagesize, |
|
110 |
pages: pages |
|
111 |
}, function(data, textStatus, xhr) { |
|
112 |
vm.list.removeAll(); |
|
113 |
if (data.code >= 1) { |
|
114 |
//parent.showErrmsg(data.errmsg); |
|
115 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
116 |
return; |
|
117 |
} |
|
118 |
if (data.code == 0) { |
|
119 |
if (isList(data.list)) { |
|
120 |
$.each(data.list, function(index, val) { |
|
121 |
val.hasSPR=ko.observable(val.hasSPR=='true'?true:false); |
|
122 |
val.ywdyNames =''; |
|
123 |
if(isList(val.ywList)){ |
|
124 |
for(var k=0;k<val.ywList.length;k++){ |
|
125 |
if(val.ywdyNames==''){ |
|
126 |
val.ywdyNames=val.ywList[k].name; |
|
127 |
}else{ |
|
128 |
val.ywdyNames+=(','+val.ywList[k].name); |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
vm.list.push(val); |
|
133 |
}); |
|
134 |
$('tbody tr').click(function (e) { |
|
135 |
$('tbody tr').removeClass('info'); |
|
136 |
$(this).addClass('info'); |
|
137 |
}); |
|
138 |
} |
|
139 |
if (!!pages) { |
|
140 |
pages = data.pages; |
|
141 |
$('#pagdiv').unbind('page').empty(); |
|
142 |
if (pages > 1) { |
|
143 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
144 |
getList(keyword, num - 1, pagesize, 0); |
|
145 |
}); |
|
146 |
} |
|
147 |
} |
|
148 |
return; |
|
149 |
} |
|
150 |
}, 'json'); |
|
151 |
} |
|
152 |
|
|
153 |
function valid(){ |
|
154 |
var isValid = false; |
|
155 |
var iF = $('#form'); |
|
156 |
iF.validate({ |
|
157 |
rules: { |
|
158 |
'companyNo': { |
|
159 |
required: true |
|
160 |
}, |
|
161 |
'name': { |
|
162 |
required: true |
|
163 |
} |
|
164 |
}, |
|
165 |
messages: { |
|
166 |
'companyNo': { |
|
167 |
required: '不能为空!' |
|
168 |
}, |
|
169 |
'name': { |
|
170 |
required: '不能为空!' |
|
171 |
} |
|
172 |
}, |
|
173 |
errorPlacement: function (err, element) { |
|
174 |
var p = element.parents('.form-group').eq(0); |
|
175 |
var d = p.find('.text-error').eq(0); |
|
176 |
d.css('color', '#D9534F'); |
|
177 |
err.appendTo(d); |
|
178 |
} |
|
179 |
}) |
|
180 |
isValid = iF.valid(); |
|
181 |
return isValid; |
|
182 |
} |
|
183 |
|
|
184 |
function doEdit(item) { |
|
185 |
vm.o(ko.mapping.fromJS(item)); |
|
186 |
vm.yvList.removeAll(); |
|
187 |
if(isList(item.ywList)){ |
|
188 |
$.each(item.ywList, function(index, val) { |
|
189 |
vm.yvList.push(val.code); |
|
190 |
}); |
|
191 |
} |
|
192 |
$('#dp').val(vm.yvList()).trigger("chosen:updated"); |
|
193 |
I.modal.modal('show'); |
|
194 |
} |
|
195 |
|
|
196 |
function delConfirm(item) { |
|
197 |
$("#modalContent").html('确定要删除【' + item.name + '】吗?'); |
|
198 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
199 |
resizable: false, |
|
200 |
width: '320', |
|
201 |
modal: true, |
|
202 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
203 |
title_html: true, |
|
204 |
position: { my: "center", at: "center", of: window }, |
|
205 |
buttons: [ |
|
206 |
{ |
|
207 |
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
208 |
"class" : "btn btn-danger btn-minier", |
|
209 |
click: function() { |
|
210 |
$( this ).dialog( "close" ); |
|
211 |
doDel(item); |
|
212 |
} |
|
213 |
} |
|
214 |
, |
|
215 |
{ |
|
216 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
217 |
"class" : "btn btn-minier", |
|
218 |
click: function() { |
|
219 |
$( this ).dialog( "close" ); |
|
220 |
} |
|
221 |
} |
|
222 |
] |
|
223 |
}); |
|
224 |
} |
|
225 |
|
|
226 |
function doDel(item) { |
|
227 |
if (!!I.AjaxDelItem) return; |
|
228 |
I.AjaxDelItem = true; |
|
229 |
$.post('/company/delItem.htm', {companyNo: item.companyNo}, function(data, textStatus, xhr) { |
|
230 |
I.AjaxDelItem = false; |
|
231 |
if (data.code >= 1) { |
|
232 |
//parent.showErrmsg(data.errmsg); |
|
233 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
234 |
return; |
|
235 |
} |
|
236 |
if (data.code == 0) { |
|
237 |
vm.list.remove(item); |
|
238 |
parent.showErrmsg('删除成功!'); |
|
239 |
return; |
|
240 |
} |
|
241 |
}, 'json'); |
|
242 |
} |
|
243 |
|
|
244 |
function doSave() { |
|
245 |
if (!I.AjaxSaveItem &&valid()) { |
|
246 |
I.AjaxSaveItem = true; |
|
247 |
I.save.prop('disabled', true); |
|
248 |
var o = ko.mapping.toJS(vm.o()); |
|
249 |
o.ywdyNos=vm.yvList().join(','); |
|
250 |
o.hasSPR = $('#hasSPR').prop('checked'); |
|
251 |
$.post('/company/saveItem.htm', o, function(data, textStatus, xhr) { |
|
252 |
I.AjaxSaveItem = false; |
|
253 |
I.save.prop('disabled', false); |
|
254 |
if (data.code >= 1) { |
|
255 |
//parent.showErrmsg(data.errmsg); |
|
256 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
257 |
return; |
|
258 |
} |
|
259 |
if (data.code == 0) { |
|
260 |
parent.showErrmsg('保存成功!'); |
|
261 |
I.modal.modal('hide'); |
|
262 |
getList($.trim(vm.keyword()), I._page, I.PZ, 1); |
|
263 |
return; |
|
264 |
} |
|
265 |
}, 'json'); |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
269 |
function clearError() { |
|
270 |
$('#form input').removeClass('error'); |
|
271 |
$('#form .text-error').html(''); |
|
272 |
} |
|
273 |
|
|
274 |
function autoHeight() { |
|
275 |
$('.page-content').css('min-height', $(parent.window).height() - 117); |
|
276 |
$('.table-responsive').css('height', $(parent.window).height() - 217); |
|
277 |
} |