提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
//test data start |
|
7 |
// var data_getList = Mock.mock('/basicconfig/prefix/getList.htm', {code: 0, 'list|3-20': [ |
|
8 |
// {id: 1,title: '名称',prefix: 'OP',surfix: 'ED',bitnum: 10,leveling: 2,currents: 'OP012345ED', note: 'nnnnnote'} |
|
9 |
// ], pages: 12}) |
|
10 |
// var data_doDel = Mock.mock('/basicconfig/prefix/delItem.htm', {code: 0, errmsg: '删除失败!'}) |
|
11 |
// var data_doSave = Mock.mock('/basicconfig/prefix/saveItem.htm', {code: 0, errmsg: '保存失败!'}) |
|
12 |
//test data end |
|
13 |
|
|
14 |
var TITLE = [{name: '往来单位', value: 'company'}, {name: '人员来访', value: 'persionvisit'}, {name: '门禁编号', value: 'gates'}, {name: '发卡点', value: 'cardplace'}, {name: '卡编号', value: 'card'}, {name: '物资', value: 'materiel'}, {name: '设备', value: 'cequipment'}, {name: '客户端', value: 'mclient'}, {name: '员工', value: 'ewer'}, {name: '部门', value: 'depart'}, {name: '长期卡', value: 'longvisit'}, {name: '携带物资', value: 'peoplematetialsheet'}, {name: '铝锭采购', value: 'albuy'}, {name: '铝锭退货', value: 'alback'}, {name: '装卸点', value: 'shipmentarea'}, {name: '现场记录', value: 'shipment'}, {name: '业务类型', value: 'businesstype'}, {name: '排队配置', value: 'gatesqueue'}, {name: '供应采购', value: 'materialbuy'}, {name: '供应退货', value: 'materialback'}, {name: '产品销售', value: 'productsale'}, {name: '产品退货', value: 'productback'}, {name: '外出维修出厂', value: 'fixout'}, {name: '外出维修入场', value: 'fixin'}, {name: '半成品内转出', value: 'inturnSemiOut'}, {name: '半成品内转人', value: 'inturnSemiIn'}, {name: '铝内转入', value: 'inturnAlIn'}, {name: '铝内转出', value: 'inturnAlOut'}, {name: '普通物资内转出', value: 'inturnMaterilOut'}, {name: '普通物资内转入', value: 'inturnMaterialIn'}, {name: '废旧物资处理', value: 'wasteProcess'}, {name: '其他运输出厂', value: 'materielOut'}, {name: '其他运输进厂', value: 'materielIn'}, {name: '来料加工', value: 'Machining'},{name: '废料采购', value: 'scrapPurchase'},{name: 'vehicleOMsheet', value: 'vehicleOMsheet'}]; |
|
15 |
|
|
16 |
window.I = { |
|
17 |
PZ: 30, |
|
18 |
keyword: $('#keyword'), |
|
19 |
searchBtn: $('#searchBtn'), |
|
20 |
pageValue: !!$('#p').val() ? $('#p').val() - 1 : 0, |
|
21 |
keywordValue: $('#k').val(), |
|
22 |
newObj: $('#newObj'), |
|
23 |
modal: $('#modal'), |
|
24 |
save: $('#save') |
|
25 |
} |
|
26 |
|
|
27 |
var Obj = { |
|
28 |
id: 0, |
|
29 |
title: '', |
|
30 |
prefix: '', |
|
31 |
surfix: '', |
|
32 |
bitnum: '', |
|
33 |
leveling: 1, |
|
34 |
currents: '', |
|
35 |
note: '', |
|
36 |
} |
|
37 |
|
|
38 |
var Obj = { |
|
39 |
id: 0, |
|
40 |
name: '', |
|
41 |
title: '', |
|
42 |
prefix: '', |
|
43 |
surfix: '', |
|
44 |
datestr: true, |
|
45 |
lvl: true, |
|
46 |
concatupper: true, |
|
47 |
bitnum: '', |
|
48 |
leveling: '', |
|
49 |
currents: '', |
|
50 |
note: '', |
|
51 |
tablename: '', |
|
52 |
fieldname: '', |
|
53 |
} |
|
54 |
|
|
55 |
var ViewModel = function() { |
|
56 |
var self = this; |
|
57 |
self.keyword = ko.observable(I.keywordValue); |
|
58 |
self.list = ko.observableArray(); |
|
59 |
self.o = ko.observable(ko.mapping.fromJS(Obj)); |
|
60 |
self.edit = function(item) { |
|
61 |
doEdit(item); |
|
62 |
} |
|
63 |
self.del = function(item) { |
|
64 |
delConfirm(item); |
|
65 |
} |
|
66 |
self.tList = ko.observableArray(TITLE); |
|
67 |
} |
|
68 |
|
|
69 |
$(function () { |
|
70 |
window.vm = new ViewModel(); |
|
71 |
ko.applyBindings(vm); |
|
72 |
doSearch(); |
|
73 |
pageInit(); |
|
74 |
}); |
|
75 |
|
|
76 |
function pageInit() { |
|
77 |
I.save.click(function(event) { |
|
78 |
if (valid()) { |
|
79 |
doSave(); |
|
80 |
} |
|
81 |
}); |
|
82 |
I.searchBtn.click(function(event) { |
|
83 |
doOpen(); |
|
84 |
}); |
|
85 |
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) { |
|
86 |
if (event.keyCode == 13) { |
|
87 |
doOpen(); |
|
88 |
} |
|
89 |
}); |
|
90 |
I.newObj.click(function(event) { |
|
91 |
vm.o(ko.mapping.fromJS(Obj)); |
|
92 |
I.modal.modal('show'); |
|
93 |
}); |
|
94 |
I.modal.on('hidden.bs.modal', function (e) { |
|
95 |
clearError(); |
|
96 |
}); |
|
97 |
} |
|
98 |
|
|
99 |
function doOpen() { |
|
100 |
var k = $.trim(vm.keyword()); |
|
101 |
k = !!k ? '?keyword=' + k : ''; |
|
102 |
window.open('prefix.jsf' + k, '_self'); |
|
103 |
} |
|
104 |
|
|
105 |
function doSearch() { |
|
106 |
getList(vm.keyword(), I.pageValue, I.PZ, 1); |
|
107 |
} |
|
108 |
|
|
109 |
function getList(keyword, page, pagesize, pages) { |
|
110 |
$.post("/basicconfig/prefix/getList.htm", { |
|
111 |
keyword: keyword, |
|
112 |
page: page, |
|
113 |
pagesize: pagesize, |
|
114 |
pages: pages |
|
115 |
}, |
|
116 |
function (data, textStatus, jqXHR) { |
|
117 |
if (data.code >= 1) { |
|
118 |
//parent.showErrmsg(data.errmsg); |
|
119 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
120 |
return; |
|
121 |
} |
|
122 |
if (data.code == 0) { |
|
123 |
if (isList(data.list)) { |
|
124 |
$.each(data.list, function (indexInArray, valueOfElement) { |
|
125 |
// valueOfElement.title += indexInArray; |
|
126 |
valueOfElement.title ; |
|
127 |
vm.list.push(valueOfElement); |
|
128 |
}); |
|
129 |
} |
|
130 |
if (!!pages) { |
|
131 |
pages = data.pages; |
|
132 |
$('#pagdiv').unbind('page').empty(); |
|
133 |
if (pages > 1) { |
|
134 |
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){ |
|
135 |
var k = !!I.keywordValue ? '&keyword=' + I.keywordValue : ''; |
|
136 |
window.open('prefix.jsf?page=' + num + k, '_self'); |
|
137 |
}); |
|
138 |
} |
|
139 |
} |
|
140 |
return; |
|
141 |
} |
|
142 |
}, |
|
143 |
"json" |
|
144 |
); |
|
145 |
} |
|
146 |
|
|
147 |
function doEdit(item) { |
|
148 |
vm.o(ko.mapping.fromJS(item)); |
|
149 |
I.modal.modal('show'); |
|
150 |
} |
|
151 |
|
|
152 |
function delConfirm(item) { |
|
153 |
$("#modalContent").html('确定要删除【' + item.title + '】吗?'); |
|
154 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
155 |
resizable: false, |
|
156 |
width: '320', |
|
157 |
modal: true, |
|
158 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
159 |
title_html: true, |
|
160 |
position: { my: "center", at: "center", of: window }, |
|
161 |
buttons: [ |
|
162 |
{ |
|
163 |
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
164 |
"class" : "btn btn-danger btn-minier", |
|
165 |
click: function() { |
|
166 |
$( this ).dialog( "close" ); |
|
167 |
doDel(item); |
|
168 |
} |
|
169 |
} |
|
170 |
, |
|
171 |
{ |
|
172 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
173 |
"class" : "btn btn-minier", |
|
174 |
click: function() { |
|
175 |
$( this ).dialog( "close" ); |
|
176 |
} |
|
177 |
} |
|
178 |
] |
|
179 |
}); |
|
180 |
} |
|
181 |
|
|
182 |
function doDel(item) { |
|
183 |
if (!!I.AjaxDelItem) return; |
|
184 |
I.AjaxDelItem = true; |
|
185 |
$.post('/basicconfig/prefix/delItem.htm', {id: item.id}, function(data, textStatus, xhr) { |
|
186 |
I.AjaxDelItem = false; |
|
187 |
if (data.code >= 1) { |
|
188 |
//parent.showErrmsg(data.errmsg); |
|
189 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
190 |
return; |
|
191 |
} |
|
192 |
if (data.code == 0) { |
|
193 |
vm.list.remove(item); |
|
194 |
location.replace(location.href); |
|
195 |
return; |
|
196 |
} |
|
197 |
}, 'json'); |
|
198 |
} |
|
199 |
|
|
200 |
function doSave() { |
|
201 |
if (!I.AjaxSaveItem &&valid()) { |
|
202 |
I.AjaxSaveItem = true; |
|
203 |
var o = ko.mapping.toJS(vm.o()); |
|
204 |
o.datestr = $('#objDatestr').prop('checked'); |
|
205 |
o.lvl = $('#objLvl').prop('checked'); |
|
206 |
o.concatupper = $('#objConcatupper').prop('checked'); |
|
207 |
$.post('/basicconfig/prefix/saveItem.htm', o, function(data, textStatus, xhr) { |
|
208 |
I.AjaxSaveItem = false; |
|
209 |
if (data.code >= 1) { |
|
210 |
//parent.showErrmsg(data.errmsg); |
|
211 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
212 |
return; |
|
213 |
} |
|
214 |
if (data.code == 0) { |
|
215 |
location.replace(location.href); |
|
216 |
return; |
|
217 |
} |
|
218 |
}, 'json'); |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
function valid(){ |
|
223 |
var isValid = false; |
|
224 |
var iF = $('#form'); |
|
225 |
iF.validate({ |
|
226 |
rules: { |
|
227 |
'name': { |
|
228 |
required: true |
|
229 |
}, |
|
230 |
// 'prefix': { |
|
231 |
// required: true |
|
232 |
// }, |
|
233 |
// 'surfix': { |
|
234 |
// required: true |
|
235 |
// }, |
|
236 |
'bitnum': { |
|
237 |
required: true, |
|
238 |
digits: true, |
|
239 |
min: 1 |
|
240 |
} |
|
241 |
}, |
|
242 |
messages: { |
|
243 |
'name': { |
|
244 |
required: '名称不能为空!' |
|
245 |
}, |
|
246 |
// 'prefix': { |
|
247 |
// required: '前缀不能为空!' |
|
248 |
// }, |
|
249 |
// 'surfix': { |
|
250 |
// required: '后缀不能为空!' |
|
251 |
// }, |
|
252 |
'bitnum': { |
|
253 |
required: '位数不能为空!', |
|
254 |
digits: '必须为整数!', |
|
255 |
min: '必须大于0', |
|
256 |
} |
|
257 |
}, |
|
258 |
errorPlacement: function (err, element) { |
|
259 |
var p = element.parents('.form-group').eq(0); |
|
260 |
var d = p.find('.text-error').eq(0); |
|
261 |
d.css('color', '#D9534F'); |
|
262 |
err.appendTo(d); |
|
263 |
} |
|
264 |
}) |
|
265 |
isValid = iF.valid(); |
|
266 |
return isValid; |
|
267 |
} |
|
268 |
|
|
269 |
function clearError() { |
|
270 |
$('#form input').removeClass('error'); |
|
271 |
$('#form .text-error').html(''); |
|
272 |
} |