hjg
2024-02-05 301115d5e96b56cd093eee3fcff2d60a15184162
提交 | 用户 | 时间
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: 25,
29     Page:0,
30     Pages:1,
31     addSibling: $('#addSibling'),
32     addChild: $('#addChild'),
33     search: $('#search'),
34     save: $('#save'),
35     DB_ep: {},
36     GLXJ:$('#GLXJ'),
37     CC_ep:{} 
38 }
39
40 function EnterpriseObj() {
41     return {
42         name: '',
43         bianhao: '',//编号
44         jishu:'',//级数
45         code: '',//显示的编号
46         pbianhao:'',//父节点
47         isadd:false//是否是新增
48     }
49 }
50
51 var ViewModel = function() {
52     var self = this;
53     //待编辑对象
54     self.o = ko.observable(ko.mapping.fromJS(EnterpriseObj()));
55     //是否可以删除
56     // self.canDelete = ko.observable(false);
57     //是否可以添加子节点
58     // self.canAddChild = ko.observable(false);
59     // 是否修改下级
60     self.canGLXJ=ko.observable(false);
61     //删除操作
62     // self.del = function() {
63     //     delConfirm();
64     // }
65     //已选择的物流公司
66     self.selectedList=ko.observableArray();
67     //全部的物流公司
68     self.allCMlist=ko.observableArray();
69     //业务单元编号
70     self.ywdyNoVal=ko.observable('103');
71     self.ywdychange=function(){
72         getselectedCMlist(I.selectedId);
73     }
74 }
75
76 $(function () {
77     window.vm = new ViewModel();
78     ko.applyBindings(vm);
79     getList(I.search.val(),I.Page,I.PZ,I.Pages);
80     pageInit();
81     getallCMlist();
82 });
83
84 function pageInit() {
85     I.save.click(function(event) {
86         saveItem();
87     });
88     // I.addSibling.click(function(event) {
89     //     var o = EnterpriseObj();
90     //     o.jishu = I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].jishu;
91     //     o.pbianhao=I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].bianhao.substring(0,I.DB_ep[I.selectedId].bianhao.length-2);
92     //     vm.o(ko.mapping.fromJS(o));
93     //     vm.selectedList([]);
94     //     $('#dp').val('').trigger("chosen:updated");
95     //     I.GLXJ.attr("checked",false);
96     //     vm.canGLXJ(false);
97     // });
98     // I.addChild.click(function(event) {
99     //     var o = EnterpriseObj();
100     //      o.jishu = I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].jishu;
101     //      o.jishu+=1;
102     //      o.pbianhao=I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].bianhao;
103     //     vm.o(ko.mapping.fromJS(o));
104     //     vm.selectedList([]);
105     //     $('#dp').val('').trigger("chosen:updated");
106     //     I.GLXJ.attr("checked",false);
107     //     vm.canGLXJ(false);
108     // });
109     I.search.keyup(function(event) {
110         // var to = false;
111         // if(to) {
112         //     clearTimeout(to);
113         // }
114         // to = setTimeout(function () {
115         //     var v = I.search.val();
116         //     $('#jstree_Enterprise').jstree(true).search(v);
117         // }, 250);
118          if(event.keyCode ==13){
119             getList(I.search.val(),0,I.PZ,1);
120          }
121     });
122     I.GLXJ.change(function(event){
123         if(I.GLXJ.prop("checked")){
124             I.GLXJ.attr("checked",true);
125         }else{
126             I.GLXJ.attr("checked",false);
127         }
128     });
129 }
130
131 function getList(keyword, page, pagesize, pages) {
132     $.post('/area/getList.htm', {
133         search: keyword,
134         page: page,
135         pagesize: 0,
136         pages: 0
137     }, function(data, textStatus, xhr) {
138         if (data.code >= 1) {
139             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
140             return;
141         }
142         if (data.code == 0) {
143             I.CC_ep={};
144             if (!!$('#jstree_Enterprise').jstree(true)) {
145                 $('#jstree_Enterprise').jstree(true).refresh();
146             }
147             if (isList(data.list)) {
148                 $.jstree.destroy();
149                 // vm.canAddChild(true);
150                 var Arr = [];
151                 var level = 0;
152                 $.each(data.list, function(index, val) {
153                     //顶级
154                     val.jishu=1;
155                     if(I.CC_ep[val.code.substring(0,2)]!=null && I.CC_ep[val.code.substring(0,2)]!=''){
156                         jishu=2;
157                     }else{
158                         I.CC_ep[val.code.substring(0,2)]=val.code;
159                         jishu=1;
160                     }
161                     val.jishu=jishu;
162                     I.DB_ep[val.code] = val;
163                     if(val.fd_companyS==null){
164                         val.fd_companyS=[];
165                     }
166                     if (jishu==1) {
167                         Arr.push({
168                             text: val.code + ' ' + val.name,
169                             id: val.code,
170                             companyS:val.fd_companyS,
171                             children: [],
172                             state: index === 0 ? {selected: true} : ''
173                         });
174                     } else {
175                         var j = 2;
176                         var children = Arr[Arr.length - 1].children;
177                        while (j < val.jishu) {
178                             children = children[children.length - 1].children;
179                             j++;
180                         }
181                         children.push({
182                             text: val.code + ' ' + val.name,
183                             id: val.code,
184                             companyS:val.fd_companyS,
185                             children: []
186                         })
187                     }
188                 });
189                 $('#jstree_Enterprise')
190                 .jstree({
191                     core: {
192                         check_callback : true,
193                         data: Arr,
194                         themes: {
195                             //  stripes: true 
196                         }
197                     },
198                     types: {
199                         "default" : {
200                             "icon" : false  // 删除默认图标
201                         },
202                     },
203                     plugins : [
204                       'search',
205                       'types',
206                       'themes'
207                     ]
208                 })
209                 .on("changed.jstree", function (e, data) {
210                     if(data.selected.length) {
211                         var selected = data.instance.get_node(data.selected[0]);
212                         var id = selected.id;
213                         I.selectedId = id;
214                         clearValid();
215                         vm.selectedList.removeAll();
216                         if(isList(selected.original.companyS)){
217                             $.each(selected.original.companyS, function(index, val) {
218                                 vm.selectedList.push(val.companyNo);
219                             });
220                         }else{
221                             vm.selectedList([]);
222                         }
223                         $('#dp').val(vm.selectedList()).trigger("chosen:updated");
224                         vm.o(ko.mapping.fromJS(I.DB_ep[id]));
225                         // vm.canDelete(!selected.children.length);
226                         if(vm.o().jishu()==1){
227                              vm.canGLXJ(true);
228                         }else{
229                              vm.canGLXJ(false);
230                          }
231                         getselectedCMlist(id);
232                         I.GLXJ.attr("checked",false);
233                     }
234                 })
235                 .on("ready.jstree", function(e, data) {
236                     data.instance.open_all(-1);
237                      $('.page-content').height($('#jstree_Enterprise').height()+50);
238                 })
239                 .on("after_open.jstree",function(e, data){
240                      $('.page-content').height($('#jstree_Enterprise').height()+50);
241                 })
242                 .on("after_close.jstree",function(e, data){
243                      $('.page-content').height($('#jstree_Enterprise').height()+50);
244                 })
245             }
246
247             if (!!pages) {
248                 pages = data.pages;
249                 $('#pagdiv').unbind('page').empty();
250                 if (pages > 1) {
251                     $('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){
252                         I.Page=num-1;
253                         I.Pages=0;
254                         getList(keyword,num - 1, pagesize, 0);
255                     });
256                 }
257             }
258             return;
259         }
260     }, 'json');
261 }
262 //获取全部的物流公司
263 function getallCMlist() {
264     $.post("/area/getallCMlist.htm",
265         function (data, textStatus, jqXHR) {
266             vm.allCMlist.removeAll();
267             if (data.code >= 1) {
268                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
269                 return;
270             }
271             if (data.code == 0) { 
272                 if (isList(data.list)) {
273                     $.each(data.list, function(index, val) {
274                         vm.allCMlist.push(val);
275                     });
276                     $('.chosen-select').chosen({search_contains: true});
277                 }
278                 return;
279             }
280         },
281         "json"
282     );
283 }
284 //获取已选择的物流公司
285 function getselectedCMlist(bianhao) {
286     $.post('/area/getcmList.htm', {bianhao:bianhao,ywdyNo:vm.ywdyNoVal()}, function(data, textStatus, xhr) {
287         vm.selectedList.removeAll();
288        if (data.code >= 1) {
289             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
290             return;
291         }
292         if (data.code == 0) {
293            if (data.item) {
294                 vm.selectedList(data.item.split(','));
295             } else {
296                 vm.selectedList([]);
297             }
298             $('#dp').val(vm.selectedList()).trigger("chosen:updated");
299             return;
300         }
301     }, 'json');
302 }
303
304 // function delItem() {
305 //     var id = I.selectedId;
306 //     if (!id && !!I.AjaxDelItem) return;
307 //     I.AjaxDelItem = true;
308 //     $.post('/area/delItem.htm', {bianhao: id}, function(data, textStatus, xhr) {
309 //         I.AjaxDelItem = false;
310 //         if (data.code >= 1) {
311 //             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
312 //             return;
313 //         }
314 //         if (data.code == 0) {
315 //             var ref = $('#jstree_Enterprise').jstree(true),
316 //                 sel = ref.get_selected();
317 //             if(!sel.length) { return false; }
318 //             ref.select_node(ref.get_prev_dom(sel));
319 //             ref.delete_node(sel);
320 //         }
321 //     }, 'json');
322 // }
323
324 function saveItem() {
325     if (!I.AjaxSaveItem && valid()) {
326         I.AjaxSaveItem = true;
327         var o = ko.mapping.toJS(vm.o());
328         // if(o.bianhao==null||o.bianhao==''){
329         //     if(o.pbianhao==''&&o.jishu!=1){
330         //         swal({title:'',text:'数据错误,请刷新页面重新操作!',type:'error',confirmButtonText:'确定'}); 
331         //         return
332         //     }
333         //     if(o.pbianhao==''){
334         //         o.bianhao=o.xsbianhao;
335         //     }else{
336         //          o.bianhao=o.pbianhao+o.xsbianhao;
337         //     }
338         // }
339         o.companyNos='';
340         if(!!vm.selectedList()){
341             for(var i=0;i<vm.selectedList().length;i++){
342                 if(o.companyNos==''){
343                     o.companyNos=vm.selectedList()[i];
344                 }else{
345                      o.companyNos=o.companyNos+','+vm.selectedList()[i];
346                 }
347             }
348         }
349         o.GLXJ=I.GLXJ.prop("checked");
350         o.ywdyNo=vm.ywdyNoVal();
351         $.post('/area/saveItem.htm', o, function(data, textStatus, xhr) {
352             I.AjaxSaveItem = false;
353             if (data.code >= 1) {
354                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
355                 return;
356             }
357             if (data.code == 0) {
358                 parent.showErrmsg('保存成功!');
359                 getList(I.search.val(),I.Page,I.PZ,I.Pages);
360                 return;
361             }
362         }, 'json');
363     }
364 }
365
366 function valid(){
367     var isValid = false;
368     var iF = $('#form');
369     iF.validate({
370         rules: {
371             'xsbianhao': {
372                 required: true,
373                 rangelength:[2,2],
374             },
375             'name': {
376                 required: true
377             }
378         },
379         messages: {
380             'xsbianhao': {
381                 required: '编号不能为空!',
382                 rangelength:'编号必须是两位数字',
383             },
384             'name': {
385                 required: '名称不能为空!'
386             }
387         },
388         errorPlacement: function (err, element) {
389             var p = element.parents('.col-sm-9').eq(0);
390             var d = p.children('.text-error').eq(0);
391             d.css('color', '#D9534F');
392             err.appendTo(d);
393         }
394     })
395     isValid = iF.valid();
396     return isValid;
397 }
398
399 function clearValid() {
400     $('input[type="text"]').removeClass('error');
401     $('span.text-error').text('');
402 }
403
404 // function delConfirm() {
405 //     $("#modalContent").html('确定要删除【' + I.DB_ep[I.selectedId].name + '】吗?');
406 //     $("#dialog-confirm").removeClass('hide').dialog({
407 //         resizable: false,
408 //         width: '320',
409 //         modal: true,
410 //         title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>",
411 //         title_html: true,
412 //         position: { my: "center", at: "center", of: window },
413 //         buttons: [
414 //             {
415 //                 html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; 确定",
416 //                 "class" : "btn btn-danger btn-minier",
417 //                 click: function() {
418 //                     $( this ).dialog( "close" );
419 //                     delItem();
420 //                 }
421 //             }
422 //             ,
423 //             {
424 //                 html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 取消",
425 //                 "class" : "btn btn-minier",
426 //                 click: function() {
427 //                     $( this ).dialog( "close" );
428 //                 }
429 //             }
430 //         ]
431 //     });
432 // }
433
434
435 // function getChooseWLGS( ){
436
437 // }