提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* date: |
|
3 |
* author: neeler |
|
4 |
*/ |
|
5 |
|
|
6 |
// test data start |
|
7 |
// var data_getList = Mock.mock('/area/getList.htm', {"rowCount":0,"pagesize":0,"pages":0,"page":0,"items":null, |
|
8 |
// "list":[ |
|
9 |
// {"name":"河南省","bianhao":"01","xsbianhao":"01","mx":false,'jishu':1}, |
|
10 |
// {"name":"河南省郑州市","bianhao":"0101","xsbianhao":"01","mx":true,'jishu':2}, |
|
11 |
// {"name":"河南省洛阳市","bianhao":"0102","xsbianhao":"02","mx":false,'jishu':2}, |
|
12 |
// {"name":"河南省洛阳市偃师市","bianhao":"010201","xsbianhao":"01","mx":true,'jishu':3}, |
|
13 |
// {"name":"山东省","bianhao":"02","xsbianhao":"02","mx":false,'jishu':1} |
|
14 |
// ],"hint":null,"errmsg":null,"code":0}) |
|
15 |
// var data_gecmtList = Mock.mock('/area/getallCMlist.htm', {"rowCount":0,"pagesize":0,"pages":0,"page":0,"items":null, |
|
16 |
// "list":[ |
|
17 |
// {"name":"郑州鑫玉升运输有限公司","companyNo":"001"}, |
|
18 |
// {"name":"河南天海物流有限公司","companyNo":"002"}, |
|
19 |
// {"name":"洛阳市汇宇汽车运输有限公司","companyNo":"003"}, |
|
20 |
// {"name":"河南龙威货运有限公司","companyNo":"004"}, |
|
21 |
// {"name":"王学寨","companyNo":"005"} |
|
22 |
// ],"hint":null,"errmsg":null,"code":0}) |
|
23 |
// var date_getsecmlist = Mock.mock('/area/getcmList.htm', {code: 0, item: '001,003' }) |
|
24 |
// var data_delItem = Mock.mock('/area/delItem.htm', {code: 0, errmsg: '删除失败!'}) |
|
25 |
// var data_saveItem = Mock.mock('/area/saveItem.htm', {code: 0, errmsg: '保存成功!'}) |
|
26 |
|
|
27 |
window.I = { |
|
28 |
PZ: 0, |
|
29 |
addSibling: $('#addSibling'), |
|
30 |
addChild: $('#addChild'), |
|
31 |
search: $('#search'), |
|
32 |
save: $('#save'), |
|
33 |
DB_ep: {}, |
|
34 |
GLXJ:$('#GLXJ') |
|
35 |
} |
|
36 |
|
|
37 |
function EnterpriseObj() { |
|
38 |
return { |
|
39 |
name: '', |
|
40 |
bianhao: '',//编号 |
|
41 |
jishu:'',//级数 |
|
42 |
xsbianhao: '',//显示的编号 |
|
43 |
pbianhao:'',//父节点 |
|
44 |
isadd:false//是否是新增 |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
var ViewModel = function() { |
|
49 |
var self = this; |
|
50 |
//待编辑对象 |
|
51 |
self.o = ko.observable(ko.mapping.fromJS(EnterpriseObj())); |
|
52 |
//是否可以删除 |
|
53 |
self.canDelete = ko.observable(false); |
|
54 |
//是否可以添加子节点 |
|
55 |
self.canAddChild = ko.observable(false); |
|
56 |
//是否修改下级 |
|
57 |
self.canGLXJ=ko.observable(false); |
|
58 |
//删除操作 |
|
59 |
self.del = function() { |
|
60 |
delConfirm(); |
|
61 |
} |
|
62 |
//已选择的物流公司 |
|
63 |
self.selectedList=ko.observableArray(); |
|
64 |
//全部的物流公司 |
|
65 |
self.allCMlist=ko.observableArray(); |
|
66 |
} |
|
67 |
|
|
68 |
$(function () { |
|
69 |
window.vm = new ViewModel(); |
|
70 |
ko.applyBindings(vm); |
|
71 |
getList(); |
|
72 |
pageInit(); |
|
73 |
getallCMlist(); |
|
74 |
}); |
|
75 |
|
|
76 |
function pageInit() { |
|
77 |
I.save.click(function(event) { |
|
78 |
saveItem(); |
|
79 |
}); |
|
80 |
I.addSibling.click(function(event) { |
|
81 |
var o = EnterpriseObj(); |
|
82 |
o.jishu = I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].jishu; |
|
83 |
o.pbianhao=I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].bianhao.substring(0,I.DB_ep[I.selectedId].bianhao.length-2); |
|
84 |
vm.o(ko.mapping.fromJS(o)); |
|
85 |
vm.selectedList([]); |
|
86 |
$('#dp').val('').trigger("chosen:updated"); |
|
87 |
I.GLXJ.attr("checked",false); |
|
88 |
vm.canGLXJ(false); |
|
89 |
}); |
|
90 |
I.addChild.click(function(event) { |
|
91 |
var o = EnterpriseObj(); |
|
92 |
o.jishu = I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].jishu; |
|
93 |
o.jishu+=1; |
|
94 |
o.pbianhao=I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].bianhao; |
|
95 |
vm.o(ko.mapping.fromJS(o)); |
|
96 |
vm.selectedList([]); |
|
97 |
$('#dp').val('').trigger("chosen:updated"); |
|
98 |
I.GLXJ.attr("checked",false); |
|
99 |
vm.canGLXJ(false); |
|
100 |
}); |
|
101 |
I.search.keyup(function(event) { |
|
102 |
var to = false; |
|
103 |
if(to) { |
|
104 |
clearTimeout(to); |
|
105 |
} |
|
106 |
to = setTimeout(function () { |
|
107 |
var v = I.search.val(); |
|
108 |
$('#jstree_Enterprise').jstree(true).search(v); |
|
109 |
}, 250); |
|
110 |
}); |
|
111 |
I.GLXJ.change(function(event){ |
|
112 |
if(I.GLXJ.prop("checked")){ |
|
113 |
I.GLXJ.attr("checked",true); |
|
114 |
}else{ |
|
115 |
I.GLXJ.attr("checked",false); |
|
116 |
} |
|
117 |
}); |
|
118 |
} |
|
119 |
|
|
120 |
function getList(keyword, page, pagesize, pages) { |
|
121 |
$.post('/area/getList.htm', { |
|
122 |
search: keyword, |
|
123 |
page: page, |
|
124 |
pagesize: pagesize, |
|
125 |
pages: pages |
|
126 |
}, function(data, textStatus, xhr) { |
|
127 |
if (data.code >= 1) { |
|
128 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
129 |
return; |
|
130 |
} |
|
131 |
if (data.code == 0) { |
|
132 |
if (!!$('#jstree_Enterprise').jstree(true)) { |
|
133 |
$('#jstree_Enterprise').jstree(true).refresh(); |
|
134 |
} |
|
135 |
if (isList(data.list)) { |
|
136 |
$.jstree.destroy(); |
|
137 |
vm.canAddChild(true); |
|
138 |
var Arr = []; |
|
139 |
var level = 0; |
|
140 |
$.each(data.list, function(index, val) { |
|
141 |
I.DB_ep[val.bianhao] = val; |
|
142 |
//顶级 |
|
143 |
if (val.jishu==1) { |
|
144 |
Arr.push({ |
|
145 |
text: val.xsbianhao + ' ' + val.name, |
|
146 |
id: val.bianhao, |
|
147 |
children: [], |
|
148 |
state: index === 0 ? {selected: true} : '' |
|
149 |
}); |
|
150 |
} else { |
|
151 |
var j = 2; |
|
152 |
var children = Arr[Arr.length - 1].children; |
|
153 |
while (j < val.jishu) { |
|
154 |
children = children[children.length - 1].children; |
|
155 |
j++; |
|
156 |
} |
|
157 |
children.push({ |
|
158 |
text: val.xsbianhao + ' ' + val.name, |
|
159 |
id: val.bianhao, |
|
160 |
children: [] |
|
161 |
}) |
|
162 |
} |
|
163 |
}); |
|
164 |
$('#jstree_Enterprise') |
|
165 |
.jstree({ |
|
166 |
core: { |
|
167 |
check_callback : true, |
|
168 |
data: Arr, |
|
169 |
themes: { |
|
170 |
// stripes: true |
|
171 |
} |
|
172 |
}, |
|
173 |
types: { |
|
174 |
"default" : { |
|
175 |
"icon" : false // 删除默认图标 |
|
176 |
}, |
|
177 |
}, |
|
178 |
plugins : [ |
|
179 |
'search', |
|
180 |
'types', |
|
181 |
'themes' |
|
182 |
] |
|
183 |
}) |
|
184 |
.on("changed.jstree", function (e, data) { |
|
185 |
if(data.selected.length) { |
|
186 |
var selected = data.instance.get_node(data.selected[0]); |
|
187 |
var id = selected.id; |
|
188 |
I.selectedId = id; |
|
189 |
clearValid(); |
|
190 |
vm.o(ko.mapping.fromJS(I.DB_ep[id])); |
|
191 |
vm.canDelete(!selected.children.length); |
|
192 |
vm.canGLXJ(selected.children.length); |
|
193 |
getselectedCMlist(id); |
|
194 |
I.GLXJ.attr("checked",false); |
|
195 |
} |
|
196 |
}) |
|
197 |
.on("ready.jstree", function(e, data) { |
|
198 |
data.instance.open_all(-1); |
|
199 |
$('.page-content').height($('#jstree_Enterprise').height()+50); |
|
200 |
}) |
|
201 |
.on("after_open.jstree",function(e, data){ |
|
202 |
$('.page-content').height($('#jstree_Enterprise').height()+50); |
|
203 |
}) |
|
204 |
.on("after_close.jstree",function(e, data){ |
|
205 |
$('.page-content').height($('#jstree_Enterprise').height()+50); |
|
206 |
}) |
|
207 |
} |
|
208 |
return; |
|
209 |
} |
|
210 |
}, 'json'); |
|
211 |
} |
|
212 |
//获取全部的物流公司 |
|
213 |
function getallCMlist() { |
|
214 |
$.post("/area/getallCMlist.htm", |
|
215 |
function (data, textStatus, jqXHR) { |
|
216 |
vm.allCMlist.removeAll(); |
|
217 |
if (data.code >= 1) { |
|
218 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
219 |
return; |
|
220 |
} |
|
221 |
if (data.code == 0) { |
|
222 |
if (isList(data.list)) { |
|
223 |
$.each(data.list, function(index, val) { |
|
224 |
vm.allCMlist.push(val); |
|
225 |
}); |
|
226 |
$('.chosen-select').chosen({search_contains: true}); |
|
227 |
} |
|
228 |
return; |
|
229 |
} |
|
230 |
}, |
|
231 |
"json" |
|
232 |
); |
|
233 |
} |
|
234 |
//获取已选择的物流公司 |
|
235 |
function getselectedCMlist(bianhao) { |
|
236 |
$.post('/area/getcmList.htm', {bianhao:bianhao}, function(data, textStatus, xhr) { |
|
237 |
vm.selectedList.removeAll(); |
|
238 |
if (data.code >= 1) { |
|
239 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
240 |
return; |
|
241 |
} |
|
242 |
if (data.code == 0) { |
|
243 |
if (data.item) { |
|
244 |
vm.selectedList(data.item.split(',')); |
|
245 |
} else { |
|
246 |
vm.selectedList([]); |
|
247 |
} |
|
248 |
$('#dp').val(vm.selectedList()).trigger("chosen:updated"); |
|
249 |
return; |
|
250 |
} |
|
251 |
}, 'json'); |
|
252 |
} |
|
253 |
|
|
254 |
function delItem() { |
|
255 |
var id = I.selectedId; |
|
256 |
if (!id && !!I.AjaxDelItem) return; |
|
257 |
I.AjaxDelItem = true; |
|
258 |
$.post('/area/delItem.htm', {bianhao: id}, function(data, textStatus, xhr) { |
|
259 |
I.AjaxDelItem = false; |
|
260 |
if (data.code >= 1) { |
|
261 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
262 |
return; |
|
263 |
} |
|
264 |
if (data.code == 0) { |
|
265 |
var ref = $('#jstree_Enterprise').jstree(true), |
|
266 |
sel = ref.get_selected(); |
|
267 |
if(!sel.length) { return false; } |
|
268 |
ref.select_node(ref.get_prev_dom(sel)); |
|
269 |
ref.delete_node(sel); |
|
270 |
} |
|
271 |
}, 'json'); |
|
272 |
} |
|
273 |
|
|
274 |
function saveItem() { |
|
275 |
if (!I.AjaxSaveItem && valid()) { |
|
276 |
I.AjaxSaveItem = true; |
|
277 |
var o = ko.mapping.toJS(vm.o()); |
|
278 |
if(o.bianhao==null||o.bianhao==''){ |
|
279 |
if(o.pbianhao==''&&o.jishu!=1){ |
|
280 |
swal({title:'',text:'数据错误,请刷新页面重新操作!',type:'error',confirmButtonText:'确定'}); |
|
281 |
return |
|
282 |
} |
|
283 |
if(o.pbianhao==''){ |
|
284 |
o.bianhao=o.xsbianhao; |
|
285 |
}else{ |
|
286 |
o.bianhao=o.pbianhao+o.xsbianhao; |
|
287 |
} |
|
288 |
} |
|
289 |
o.companyNos=''; |
|
290 |
if(!!vm.selectedList()){ |
|
291 |
for(var i=0;i<vm.selectedList().length;i++){ |
|
292 |
if(o.companyNos==''){ |
|
293 |
o.companyNos=vm.selectedList()[i]; |
|
294 |
}else{ |
|
295 |
o.companyNos=o.companyNos+','+vm.selectedList()[i]; |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
o.GLXJ=I.GLXJ.prop("checked"); |
|
300 |
$.post('/area/saveItem.htm', o, function(data, textStatus, xhr) { |
|
301 |
I.AjaxSaveItem = false; |
|
302 |
if (data.code >= 1) { |
|
303 |
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); |
|
304 |
return; |
|
305 |
} |
|
306 |
if (data.code == 0) { |
|
307 |
parent.showErrmsg('保存成功!'); |
|
308 |
getList(); |
|
309 |
return; |
|
310 |
} |
|
311 |
}, 'json'); |
|
312 |
} |
|
313 |
} |
|
314 |
|
|
315 |
function valid(){ |
|
316 |
var isValid = false; |
|
317 |
var iF = $('#form'); |
|
318 |
iF.validate({ |
|
319 |
rules: { |
|
320 |
'xsbianhao': { |
|
321 |
required: true, |
|
322 |
rangelength:[2,2], |
|
323 |
}, |
|
324 |
'name': { |
|
325 |
required: true |
|
326 |
} |
|
327 |
}, |
|
328 |
messages: { |
|
329 |
'xsbianhao': { |
|
330 |
required: '编号不能为空!', |
|
331 |
rangelength:'编号必须是两位数字', |
|
332 |
}, |
|
333 |
'name': { |
|
334 |
required: '名称不能为空!' |
|
335 |
} |
|
336 |
}, |
|
337 |
errorPlacement: function (err, element) { |
|
338 |
var p = element.parents('.col-sm-9').eq(0); |
|
339 |
var d = p.children('.text-error').eq(0); |
|
340 |
d.css('color', '#D9534F'); |
|
341 |
err.appendTo(d); |
|
342 |
} |
|
343 |
}) |
|
344 |
isValid = iF.valid(); |
|
345 |
return isValid; |
|
346 |
} |
|
347 |
|
|
348 |
function clearValid() { |
|
349 |
$('input[type="text"]').removeClass('error'); |
|
350 |
$('span.text-error').text(''); |
|
351 |
} |
|
352 |
|
|
353 |
function delConfirm() { |
|
354 |
$("#modalContent").html('确定要删除【' + I.DB_ep[I.selectedId].name + '】吗?'); |
|
355 |
$("#dialog-confirm").removeClass('hide').dialog({ |
|
356 |
resizable: false, |
|
357 |
width: '320', |
|
358 |
modal: true, |
|
359 |
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>", |
|
360 |
title_html: true, |
|
361 |
position: { my: "center", at: "center", of: window }, |
|
362 |
buttons: [ |
|
363 |
{ |
|
364 |
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定", |
|
365 |
"class" : "btn btn-danger btn-minier", |
|
366 |
click: function() { |
|
367 |
$( this ).dialog( "close" ); |
|
368 |
delItem(); |
|
369 |
} |
|
370 |
} |
|
371 |
, |
|
372 |
{ |
|
373 |
html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消", |
|
374 |
"class" : "btn btn-minier", |
|
375 |
click: function() { |
|
376 |
$( this ).dialog( "close" ); |
|
377 |
} |
|
378 |
} |
|
379 |
] |
|
380 |
}); |
|
381 |
} |