Administrator
2022-12-15 9ce4bb2b6bd1378ba7b0bd6681d22cb37a5e1452
提交 | 用户 | 时间
58d006 1 /**
A 2 * date: 
3 * author: neeler 
4 */
5
6 //test data start
7 // var data_getList = Mock.mock('/business/getItem.htm', { "item": { "td_shrq": "YYYY-MM-DD", "td_bmbh": "0601", "td_bmmc": null, "td_djrq": "20170626", "td_khmc": "巩义市贝思特贸易有限公司", "td_bz": "发上海 不开票 不带清单", "td_ywrq": "20170626", "td_zdr": "王雅", "td_tdbh": "TD-17060001", "td_tdls": "43" }, "code": 0, "list|3-50": [{"tdmx_wlbh": "D8F001","tdmx_wlmc": "8系热轧箔","tdmx_tdfl": "0000000001","tdmx_tdls": "43","tdmx_hjzt": null,"tdmx_dwmx": "吨","tdmx_fdcph": "GFC1706N80075-1","tdmx_bhse": 15372.56,"tdmx_mz": 0.764,"tdmx_pz": 0,"tdmx_jz": 0.679,"tdmx_shdw": "巩义市贝思特贸易有限公司","tdmx_fhdw": "河南眀泰","tdmx_tdlx": "欠款提货","tdmx_sl": 17,"tdmx_ggxh": "0.04*500*C","tdmx_sfzc": "0.0","tdmx_fdcph": "豫C555555", "tdmx_bz": "tdmx_bz", "tdmx_hw": "tdmx_hw"}]})
8 // var data_getVehicleList = Mock.mock('/business/getVehicleList.htm', {code: 0, 'list|5-30': [{vehicleId: 'vehicleId', feature: 'feature', note: 'note', fdnum: 'fdnum', fdweight: '4.551', vehicleweight: 'vehicleweight', loadweight: '51.111', driver: 'driver', phone: 'phone'}]})
9 // var data_validVehicle = Mock.mock('/business/validVehicle.htm', {code: 0, errmsg: '车牌号不能使用!'})
10 // var data_doUnbind = Mock.mock('/business/doUnbind.htm', {code: 0, })
11 // var data_doBind = Mock.mock('/business/doBind.htm', {code: 0, })
12 // var data_getallList = Mock.mock('/vehicle/getallList.htm', {"rowCount":0,"pagesize":0,"pages":0,"page":0,"items":null,"list":[{"note":null,"companyNo":"009","driver":"九阳神功","loadweight":15.0,"phone":"13007607721","companyName":"运输部","rownumber":1,"id|+1": 1,"state":1,"vehicleId":"豫A11111","vehicleweight":10.0}],"hint":null,"errmsg":null,"code":0})
13 // var data_saveItem = Mock.mock('/business/saveItem.htm', {code: 0, })
14 // var data_doDel = Mock.mock('/transport/yscompany/del.htm', {code: 0, errmsg: 'errmsg'})
15 // var data_doSave = Mock.mock('/transport/yscompany/save.htm', {code: 0, errmsg: 'errmsg'})
16 //test data end
17
18 var SORT = [
19     {key: '批次号', value: 'tdmx_fdcph', visible: ko.observable(true)}, 
20     {key: '规格型号', value: 'tdmx_ggxh', visible: ko.observable(true)},
21     {key: '包装', value: 'tdmx_zpbz', visible: ko.observable(true)},
22     {key: '货位', value: 'tdmx_hwbh', visible: ko.observable(true)},
23     {key: '毛重', value: 'tdmx_mz', visible: ko.observable(true)},
24     {key: '净重', value: 'tdmx_jz', visible: ko.observable(true)}
25     ]
26
27 window.I = {
28     _lastIndex: 0,
29     nowVehicle: null,
30     no: $('#no').val(),
31     allNumBtn: $('#allNumBtn'),
32     bindNumBtn: $('#bindNumBtn'),
33     unbindNumBtn: $('#unbindNumBtn'),
34     vehicleKeyword: $('#vehicleKeyword'),
35     searchVehicleBtn: $('#searchVehicleBtn'),
36     refreshVehicleBtn: $('#refreshVehicleBtn'),
37     tempVehicleModal: $('#tempVehicleModal'),
38     addTempVehicle: $('#addTempVehicle'),
39     tempVehicleSaveBtn: $('#tempVehicleSaveBtn'),
40     selectAllBtn: $('#selectAllBtn'),
41     selectNoBtn: $('#selectNoBtn'),
42     clearSelectBtn: $('#clearSelectBtn'),
43     bindBtn: $('#bindBtn'),
44     unbindBtn: $('#unbindBtn'),
45     piciKeyword:$('#piciKeyword'),
46     searchpiciBtn:$('#searchpiciBtn'),
47     SortBtn:$('#SortBtn'),
48     modal: $('#modal'),
49     clearSortBtn: $('#clearSortBtn'),
50     ssortBtn:$('#searchSortBtn'),
51     sxBtn:$('#sxBtn')
52 }
53
54 var Obj = {
55     vehicleId: '豫A',
56     driver: '',
57     phone: '',
58     IDNum: '',
59     vehicleweight: '',
60     loadweight: '',
61     note: '',
62     feature: ''
63 }
64
65 var TD = {
66     td_bmbh: '',
67     td_bmmc: '',
68     td_bz: '',
69     td_djrq: '', 
70     td_khmc: '',
71     td_tdbh: '',
72     td_tdls: '',
73     td_ywrq: '',
74     td_zdr: '',
75     td_shrq: '',
76     td_shsj: '',
77     td_fpbh:''
78 }
79
80 var ViewModel = function() {
81     var self = this;
82     self.o = ko.observable(ko.mapping.fromJS(Obj));
83     self.td = ko.observable(TD);
84     self.vList = ko.observableArray();
85     self.list = ko.observableArray();
86
87     self.isAdmin = ko.observable(typeof(parent.G) != 'undefined' ? parent.G.isAdmin : false);
88
89     self.isSelectAll = ko.observable(false);
90     self.allNum = ko.observable(0);
91     self.bindNum = ko.observable(0);
92     self.unbindNum = ko.observable(0);
93
94     self.selectedNum = ko.observable(0);
95     self.selectedMZ = ko.observable(0);
96     self.selectedJZ = ko.observable(0);
97
98     self.select = function (item) {
99         I.nowVehicle = {};
100         for(attr in item) {
101             I.nowVehicle[attr] = item[attr];
102         }
103         $('#_vhicleId').text(item.vehicleId);
104         $('#_lastweight').text(item.lastweight);
105         $('#_fdweight').text(item.fdweight);
106         $('#_fdnum').text(item.fdnum);
107         $('#_loadweight').text(item.loadweight);
108         $('#vehicleMessage').show();
109     }
110     self.check = function (item) {
111         self.list.removeAll();
112         $.each(I._MDB, function (index, value) { 
113             if (value.tdmx_fdcph() === item.vehicleId) {
114                 self.list.push(value);
115             }
116         });
117         setMaterialTableEvent();
118         computedSelect();
119     }
120     self.vehicleTasks = function (item) {
121         gotoVehicleDetails(item);
122     }
123     self.oList = ko.observableArray(SORT);
124     self.soList = ko.observableArray();
125     self.addSort = function (item) {
126         addSort(item);
127     }
128     self.removeSort = function (item) {
129         removeSort(item);
130     }
131
132 }
133
134 $(function () {
135     window.vm = new ViewModel();
136     ko.applyBindings(vm);
137     autoHeight();
138     getVehicleList();
139     if (!!I.no) {
140         getList(I.no);
141     }
142     pageInit();
143 });
144
145 function pageInit() {
146     I.unbindBtn.click(function (e) { 
147         e.preventDefault();
148         if ($('.mitem.info').length) {
149             validMessage('确定要取消配车吗?', doUnbind)
150         } else {
151             parent.showErrmsg('请选择一个提单物资!');
152         }
153     });
154     I.bindBtn.click(function (e) { 
155         e.preventDefault();
156         if ($('.mitem.info').length) {
157             doBind();
158         } else {
159             parent.showErrmsg('请选择一个提单物资!');
160         }
161     });
162     I.tempVehicleSaveBtn.click(function (e) { 
163         e.preventDefault();
164         if (valid()) {
165             validVehicle();
166         }
167     });
168     I.addTempVehicle.click(function (e) { 
169         e.preventDefault();
170         vm.o(ko.mapping.fromJS(Obj));
171         I.tempVehicleModal.modal('show');
172     });
173     I.tempVehicleModal.on('hidden.bs.modal', function (e) {
174         clearError();
175     });
176     I.vehicleKeyword.keyup(function (e) { 
177         // updateVList();
178          getVehicleList();
179     });
180     I.searchVehicleBtn.click(function (e) { 
181         e.preventDefault();
182         // updateVList();
183          getVehicleList();
184     });
185     I.refreshVehicleBtn.click(function (e) { 
186         e.preventDefault();
187         getVehicleList();
188     });
189     I.allNumBtn.click(function (e) { 
190         e.preventDefault();
191         $('.mStatus').removeClass('btn-info');
192         $(this).addClass('btn-info');
193         vm.list.removeAll();
194         $.each(I._MDB, function (index, value) { 
195              vm.list.push(value);
196              if(value.chooseCli){
197                $('.mitem:last').addClass("info");
198              }
199         });
200         setMaterialTableEvent();
201         computedSelect();
202     });
203     I.bindNumBtn.click(function (e) { 
204         e.preventDefault();
205         $('.mStatus').removeClass('btn-info');
206         $(this).addClass('btn-info');
207         vm.list.removeAll();
208         $.each(I._MDB, function (index, value) { 
209             if (value.tdmx_fdcph() !== '') {
210                  if($('#piciKeyword').val()=='' || value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
211                     vm.list.push(value);
212                     if(value.chooseCli){
213                        $('.mitem:last').addClass("info");
214                     } 
215                  }
216             }
217         });
218         setMaterialTableEvent();
219         computedSelect();
220     });
221     I.unbindNumBtn.click(function (e) { 
222         e.preventDefault();
223         $('.mStatus').removeClass('btn-info');
224         $(this).addClass('btn-info');
225         vm.list.removeAll();
226         $.each(I._MDB, function (index, value) { 
227             if (value.tdmx_fdcph() == '') {
228                  if($('#piciKeyword').val()=='' || value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
229                     vm.list.push(value);
230                     if(value.chooseCli){
231                        $('.mitem:last').addClass("info");
232                     }
233                  }
234             }
235         });
236         setMaterialTableEvent();
237         computedSelect();
238     });
239     I.selectAllBtn.click(function (e) { 
240         e.preventDefault();
241         for(var i=0;i<I._MDB.length;i++){
242             if(I.bindNumBtn.hasClass('btn-info')){
243                 if (I._MDB[i].tdmx_fdcph() !== '') {
244                     if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
245                         I._MDB[i].chooseCli=true; 
246                     }
247                 }
248             }else if(I.unbindNumBtn.hasClass('btn-info')){
249                 if (I._MDB[i].tdmx_fdcph() == '') {
250                     if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
251                         I._MDB[i].chooseCli=true; 
252                     }
253                 }
254             }else{
255                 if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
256                     I._MDB[i].chooseCli=true; 
257                 }
258             }
259         }
260         $('.mitem').addClass('info');
261         computedSelect();
262     });
263     I.selectNoBtn.click(function (e) { 
264         e.preventDefault();
265         for(var i=0;i<I._MDB.length;i++){
266             if(I.bindNumBtn.hasClass('btn-info')){
267                 if (I._MDB[i].tdmx_fdcph() !== '') {
268                      if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
269                         I._MDB[i].chooseCli=false; 
270                      }
271                 }
272             }else if(I.unbindNumBtn.hasClass('btn-info')){
273                 if (I._MDB[i].tdmx_fdcph() == '') {
274                      if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
275                         I._MDB[i].chooseCli=false; 
276                      }
277                 }
278             }else{
279                 if($('#piciKeyword').val()=='' || I._MDB[i].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
280                     I._MDB[i].chooseCli=false; 
281                 }
282             }
283         }
284         $('.mitem').removeClass('info');
285         computedSelect();
286     });
287     I.searchpiciBtn.click(function (e) { 
288         e.preventDefault();
289         if($('#piciKeyword').val()!=''){
290             vm.list.removeAll();
291             $.each(I._MDB, function (index, value) { 
292                 if(value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
293                     if(I.bindNumBtn.hasClass('btn-info')){
294                         if (value.tdmx_fdcph() !== '') {
295                             vm.list.push(value);
296                             if(value.chooseCli){
297                                 $('.mitem:last').addClass("info");
298                             }
299                         }
300                     }else if(I.unbindNumBtn.hasClass('btn-info')){
301                         if (value.tdmx_fdcph() == '') {
302                             vm.list.push(value);
303                             if(value.chooseCli){
304                                 $('.mitem:last').addClass("info");
305                             }
306                         }
307                     }else{
308                        vm.list.push(value);
309                        if(value.chooseCli){
310                             $('.mitem:last').addClass("info");
311                         }
312                     }
313                 }
314             });
315             setMaterialTableEvent();
316             computedSelect();
317         }else{
318              vm.list.removeAll();
319              $('.mStatus').removeClass('btn-info');
320              I.unbindNumBtn.addClass('btn-info');
321             $.each(I._MDB, function (index, value) { 
322                 if (value.tdmx_fdcph()== '') {
323                     vm.list.push(value);
324                     if(value.chooseCli){
325                        $('.mitem:last').addClass("info");
326                     }
327                 }
328             });
329             setMaterialTableEvent();
330             computedSelect();
331         }
332         
333     });
334     I.clearSelectBtn.click(function (e) { 
335         e.preventDefault();
336         for(var i=0;i<I._MDB.length;i++){
337             I._MDB[i].chooseCli=false; 
338         }
339         $('.mitem').removeClass('info');
340         computedSelect();
341     });
342     I.SortBtn.click(function (e) { 
343         e.preventDefault();
344         I.modal.modal('show');
345     });
346      I.clearSortBtn.click(function (e) { 
347         e.preventDefault();
348         vm.soList.removeAll();
349         $.each(vm.oList(), function (index, value) { 
350              value.visible(true);
351         });
352     });
353     I.ssortBtn.click(function(e){
354         e.preventDefault();
355         vm.list.removeAll();
356         I._MDB.sort(SortList);
357         $.each(I._MDB, function (index, value) { 
358             // console.log('排序后:::'+value);
359             if(I.bindNumBtn.hasClass('btn-info')){
360                 if (value.tdmx_fdcph() !== '') {
361                     if($('#piciKeyword').val()=='' || value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
362                             vm.list.push(value);
363                             if(value.chooseCli){
364                                $('.mitem:last').addClass("info");
365                             }
366                     }
367                 }
368             }else if(I.unbindNumBtn.hasClass('btn-info')){
369                 if (value.tdmx_fdcph() == '') {
370                      if($('#piciKeyword').val()=='' || value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
371                         vm.list.push(value);
372                         if(value.chooseCli){
373                            $('.mitem:last').addClass("info");
374                         }
375                      }
376                 }
377             }else{
378                 if($('#piciKeyword').val()=='' || value.tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
379                    vm.list.push(value);  
380                    if(value.chooseCli){
381                        $('.mitem:last').addClass("info");
382                     }
383                 }
384             }
385         });
386         setMaterialTableEvent();
387         computedSelect();
388     });
389     I.sxBtn.click(function(e){
390         e.preventDefault();
391         I.piciKeyword.val('');
392         getList(I.no);
393         $('.mStatus').removeClass('btn-info');
394         I.allNumBtn.addClass('btn-info');
395     });
396
397 }
398
399 function doBind() {
400     if (!!I.AjaxdoBind) {
401         return;
402     }
403     var list = [];
404     var vehicle = I.nowVehicle;
405     if (!vehicle) {
406         parent.showErrmsg('请选择一个车辆!');
407         return;
408     }
409     // var result = true;
410     $.each(I._MDB,function(index,value){
411         if(value.chooseCli){
412              if($.trim(value.tdmx_fdcph())!=''){
413                 swal({title:'',text:'选择的配车物资' + value.tdmx_wlmc + '已经配过车!',type:'error',confirmButtonText:'确定'}); 
414                 // result = false;
415                 return false;
416             }else{
417                 list.push({
418                     tdls: value.tdmx_tdls,
419                     tdfl: value.tdmx_tdfl
420                 })
421             };
422         }
423     });
424     if(!list.length){
425         swal({title:'',text:'请选择配车物资!',type:'error',confirmButtonText:'确定'}); 
426         return ;
427     }
428     // $.each($('.mitem.info'), function (index, value) { 
429     //     var indx = $(this).attr('data-indx');
430     //     $.each(vm.list(), function (index, value) { 
431     //         if (indx === value.indx) {
432     //             if (value.tdmx_fdcph() != '') {
433     //                 swal({title:'',text:'选择的配车物资' + value.tdmx_wlmc + '已经配过车!',type:'error',confirmButtonText:'确定'}); 
434     //                 result = false;
435     //                 return false;
436     //             } else {
437     //                 list.push({
438     //                     tdls: value.tdmx_tdls,
439     //                     tdfl: value.tdmx_tdfl
440     //                 })
441     //             }
442     //         }
443     //     });
444     //     if (!result) {
445     //         return false;
446     //     }
447     // });
448     // if (!result) {
449     //     return;
450     // }
451     I.AjaxdoBind = true;
452     I.bindBtn.prop('disabled', true);
453     $.post("/business/doBind.htm", {list: $.toJSON(list), vehicle: $.toJSON(vehicle), tdbh: I.no},
454         function (data, textStatus, jqXHR) {
455             I.AjaxdoBind = false;
456             I.bindBtn.prop('disabled', false);
457             if (data.code >= 1) {
458                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
459                 return;
460             }
461             if (data.code == 0) {
462                 showErrmsg('配车成功!');
463                 $.each(I._MDB, function (index, value) { 
464                     if(value.chooseCli){
465                         value.tdmx_fdcph(I.nowVehicle.vehicleId);
466                         console.log("::dd::"+value);
467                         $.each(vm.list(), function (index, vv) { 
468                             if (value.tdmx_fdcph === vv.tdmx_fdcph) {
469                                 vv.tdmx_fdcph(I.nowVehicle.vehicleId);
470                             }
471                         });
472                     }
473                 });
474                 // $.each($('.mitem.info'), function (index, value) { 
475                 //     var indx = $(this).attr('data-indx');
476                 //     $.each(I._MDB, function (index, value) { 
477                 //         if (indx === value.indx) {
478                 //             value.tdmx_fdcph(I.nowVehicle.vehicleId);
479                 //         }
480                 //     });
481                 //     $.each(vm.list(), function (index, value) { 
482                 //         if (indx === value.indx) {
483                 //             value.tdmx_fdcph(I.nowVehicle.vehicleId);
484                 //         }
485                 //     });
486                 // });
487                 updateNum();
488                 getVehicleList();
489                 return;
490             }
491         },
492         "json"
493     );
494 }
495
496 function doUnbind() {
497     if (!!I.AjaxdoUnbind) {
498         return;
499     }
500     var list = [];
501     var arrIndx = [];
502     var result = true;
503     $.each(I._MDB, function (index, value){
504         if(value.chooseCli){
505             if($.trim(value.tdmx_fdcph()) === ''){
506                 swal({title:'',text:'选择的配车物资' + value.tdmx_wlmc + '还未配车!',type:'error',confirmButtonText:'确定'}); 
507                 // result = false;
508                 return false;
509                 // return ture;
510             }else{
511                 list.push({
512                     tdls: value.tdmx_tdls,
513                     tdfl: value.tdmx_tdfl,
514                     vehicleId: value.tdmx_fdcph()
515                 })
516                 arrIndx.push(value.tdmx_fdcph);
517             }
518         }
519     });
520     if (!list.length) {
521         swal({title:'',text:'请选择取消配车物资!',type:'error',confirmButtonText:'确定'}); 
522         return;
523     }
524     // $.each($('.mitem.info'), function (index, value) { 
525     //     var indx = $(this).attr('data-indx');
526     //     $.each(vm.list(), function (index, value) { 
527     //         if (indx === value.indx) {
528     //             if (value.tdmx_fdcph() === '') {
529     //                 return true;
530     //             } else {
531     //                 list.push({
532     //                     tdls: value.tdmx_tdls,
533     //                     tdfl: value.tdmx_tdfl,
534     //                     vehicleId: value.tdmx_fdcph()
535     //                 })
536     //                 arrIndx.push(value.indx);
537     //             }
538     //         }
539     //     });
540     // });
541     // if (!list.length) {
542     //     return;
543     // }
544     I.AjaxdoUnbind = true;
545     I.unbindBtn.prop('disabled', true);
546     $.post("/business/doUnbind.htm", {list: $.toJSON(list), tdbh: I.no},
547         function (data, textStatus, jqXHR) {
548             I.AjaxdoUnbind = false;
549             I.unbindBtn.prop('disabled', false);
550             if (data.code >= 1) {
551                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
552                 return;
553             }
554             if (data.code == 0) {
555                 showErrmsg('取消配车成功!');
556                 $.each(arrIndx, function (index, iv) { 
557                     $.each(I._MDB, function (index, value) { 
558                         if (iv === value.tdmx_fdcph) {
559                             value.tdmx_fdcph('');
560                         }
561                     });
562                     $.each(vm.list(), function (index, value) { 
563                         if (iv === value.tdmx_fdcph) {
564                             value.tdmx_fdcph('');
565                         }
566                     });
567                 });
568                 updateNum();
569                 getVehicleList();
570                 return;
571             }
572         },
573         "json"
574     );
575 }
576
577 function getList(keyword) {
578     $.post('/business/getItem.htm', {
579         keyword: keyword
580     }, function(data, textStatus, xhr) {
581         vm.list.removeAll();
582         if (data.code >= 1) {
583             //parent.showErrmsg(data.errmsg);
584             swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
585             return;
586         }
587         if (data.code == 0) {
588             I._MDB = [];
589             data.item.td_shsj = data.item.td_shsj;//.slice(0, 19);
590             vm.td(data.item);
591             if (isList(data.list)) {
592                 $.each(data.list, function (index, value) { 
593                     value.tdmx_fdcph = ko.observable(value.tdmx_fdcph);
594                     value.indx = index + '';
595                     vm.list.push(value);
596                     value.chooseCli=false;
597                     I._MDB.push(value);
598                 });
599             }
600             setMaterialTableEvent();
601             computedSelect();
602             updateNum();
603             return;
604         }
605     }, 'json');
606 }
607
608 function updateNum() {
609     var allNum = I._MDB.length;
610     var unbindNum = 0;
611     $.each(I._MDB, function (index, value) { 
612             value.tdmx_fdcph() === '' && unbindNum++;
613     });
614     vm.allNum(allNum);
615     vm.bindNum(allNum - unbindNum);
616     vm.unbindNum(unbindNum);
617 }
618
619 function setMaterialTableEvent() {
620     $('.mitem').unbind('click').click(function (e) { 
621         var index = $('.mitem').index($(this));
622         e.preventDefault();
623         if (e.shiftKey) {
624             setMaterialTrSelected(Math.min(index, I._lastIndex), Math.max(index, I._lastIndex))
625         } else {
626             I._lastIndex = index;
627             var pchcc=vm.list()[index].tdmx_fdcph;
628             for(var mdblg=0;mdblg<I._MDB.length;mdblg++){
629                 var pchmdb=I._MDB[mdblg].tdmx_fdcph;
630                 if(pchmdb==pchcc){
631                    I._MDB[mdblg].chooseCli=I._MDB[mdblg].chooseCli?false:true;
632                    break;
633                 }
634             }
635             $(this).toggleClass('info');
636         }
637         computedSelect();
638     });
639 }
640
641 function setMaterialTrSelected(start, end) {
642     $.each($('.mitem'), function (index, value) { 
643          if (index >= start && index <= end) {
644             var pchcc=vm.list()[index].tdmx_fdcph;
645             for(var mdblg=0;mdblg<I._MDB.length;mdblg++){
646                 var pchmdb=I._MDB[mdblg].tdmx_fdcph;
647                 if(pchmdb==pchcc){
648                    I._MDB[mdblg].chooseCli=I._MDB[mdblg].chooseCli?false:true;
649                    break;
650                 }
651             }
652             $(this).addClass('info');
653          }
654     });
655 }
656
657 function computedSelect() {
658     var selectedNum = 0;//$('.mitem.info').length;
659     var selectedMZ = 0;
660     var selectedJZ = 0;
661     var serlectBoo=0;
662     for(var vv=0;vv<I._MDB.length;vv++){
663         if(I._MDB[vv].chooseCli){
664             selectedNum +=1;
665             selectedMZ +=I._MDB[vv].tdmx_mz;
666             selectedJZ +=I._MDB[vv].tdmx_jz;
667             if(I.bindNumBtn.hasClass('btn-info')){
668                 if (I._MDB[vv].tdmx_fdcph() !== '') {
669                     if($('#piciKeyword').val()=='' || I._MDB[vv].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
670                            serlectBoo+=1;
671                     }
672                 }
673             }else if(I.unbindNumBtn.hasClass('btn-info')){
674                 if (I._MDB[vv].tdmx_fdcph() == '') {
675                      if($('#piciKeyword').val()=='' || I._MDB[vv].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
676                          serlectBoo+=1;
677                      }
678                 }
679             }else{
680                 if($('#piciKeyword').val()=='' || I._MDB[vv].tdmx_fdcph.indexOf($('#piciKeyword').val())>0){
681                     serlectBoo+=1;
682                 }
683             }
684         }
685     }
686     // $.each($('.mitem.info'), function (index, value) { 
687     //      var indx = $(this).attr('data-indx');
688     //      $.each(I._MDB, function (j, jv) { 
689     //           if (jv.indx === indx) {
690     //             selectedMZ += jv.tdmx_mz;
691     //             selectedJZ += jv.tdmx_jz;
692     //           }
693     //      });
694     // });
695     vm.selectedNum(selectedNum);
696     vm.selectedMZ(selectedMZ.toFixed(3));
697     vm.selectedJZ(selectedJZ.toFixed(3));
698     if(serlectBoo==0){
699          vm.isSelectAll(false);
700     }else{
701         vm.isSelectAll( serlectBoo===vm.list().length);  
702     }
703     // if($('.mitem').length==0){
704     //     vm.isSelectAll(false);
705     // }else{
706     //     vm.isSelectAll($('.mitem').length === $('.mitem.info').length);
707     // }
708 }
709
710 function getVehicleList() {
711     $.post("/business/getVehicleList.htm", {
712         companyNo: vm.isAdmin() ? '' : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG'),
713          vehicleId:I.vehicleKeyword.val()==undefined?'':I.vehicleKeyword.val()
714     },
715         function (data, textStatus, jqXHR) {
716             I.VDB = [];            
717             if (data.code >= 1) {
718                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
719                 return;
720             }
721             if (data.code == 0) {
722                 if (isList(data.list)) {
723                     $.each(data.list, function (index, value) { 
724                         value.indx = index + '';
725                         value.lastweight = '';
726                         if ($.isNumeric(value.loadweight) && $.isNumeric(value.fdweight)) {
727                             value.lastweight = (parseFloat(value.loadweight) - parseFloat(value.fdweight)).toFixed(3);
728                         }
729                         I.VDB.push(value);
730                     });
731                 }
732                 updateVList();
733                 return;
734             }
735         },
736         "json"
737     );
738 }
739
740 function updateVList() {
741     // var str = I.vehicleKeyword.val();
742     vm.vList.removeAll();
743     // if (!!str) {
744     //     var reg = new RegExp(str);
745     //     $.each(I.VDB, function (index, value) { 
746     //          if (reg.test(value.vehicleId)) {
747     //              vm.vList.push(value);
748     //          }
749     //     });
750     // } else {
751     if(I.VDB!=undefined&&I.VDB!=null && I.VDB.length>0){
752         $.each(I.VDB, function (index, value) { 
753             vm.vList.push(value);
754         });
755     }
756     // }
757 }
758
759 function valid(){
760     var isValid = false;
761     var iF = $('#form');
762     iF.validate({
763         rules: {
764             'vehicleId': {
765                 required: true,
766                 isPlateNumber: true
767             },
768             'driver': {
769                 required: true,
770             },
771             'phone': {
772                 required: true,
773                 isPhone: true
774             },
775             'IDNum': {
776                 required: true,
777             }
778         },
779         messages: {
780             'vehicleId': {
781                 required: '不能为空!',
782                 isPlateNumber: '车牌号不正确!'
783             },
784             'driver': {
785                 required: '不能为空!',
786             },
787             'phone': {
788                 required: '不能为空!',
789                 isPhone: '手机号不正确!'
790             },
791             'IDNum': {
792                 required: '不能为空!',
793             }
794         },
795         errorPlacement: function (err, element) {
796             var p = element.parents('.form-group').eq(0);
797             var d = p.find('.text-error').eq(0);
798             d.css('color', '#D9534F');
799             err.appendTo(d);
800         }
801     })
802     isValid = iF.valid();
803     return isValid;
804 }
805
806 function validVehicle() {
807     $.post("/business/validVehicle.htm", {vehicleId: ko.mapping.toJS(vm.o()).vehicleId.toUpperCase()},
808         function (data, textStatus, jqXHR) {
809             if (data.code >= 1) {
810                 swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); 
811                 return;
812             }
813             if (data.code == 0) {
814                 I.nowVehicle = {};
815                 var obj = ko.mapping.toJS(vm.o());
816                 for(attr in obj) {
817                     I.nowVehicle[attr] = obj[attr];
818                 }
819                 $('#_vhicleId').text(I.nowVehicle.vehicleId);
820                 $('#_lastweight').text(I.nowVehicle.lastweight);
821                 $('#_fdweight').text(I.nowVehicle.fdweight);
822                 $('#_fdnum').text(I.nowVehicle.fdnum);
823                 $('#_loadweight').text(I.nowVehicle.loadweight);
824                 $('#vehicleMessage').show();
825                 I.tempVehicleModal.modal('hide');
826                 return;
827             }
828         },
829         "json"
830     );
831 }
832
833 function clearError() {
834     $('#form input').removeClass('error');
835     $('#form .text-error').html('');
836 }
837
838 function autoHeight() {
839     $('.page-content').css('min-height', $(parent.window).height() - 117);
840     $('.table-responsive').css('height', $(parent.window).height() - 275);
841     $('.split').css('left', $('.table-vehicle').width() + 12);
842 }
843
844 function validMessage(message, cb, cbparams) {
845     $("#modalContent").html(message);
846     $("#dialog-confirm").removeClass('hide').dialog({
847         resizable: false,
848         width: '320',
849         modal: true,
850         title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>",
851         title_html: true,
852         position: { my: "center", at: "center", of: window },
853         buttons: [
854             {
855                 html: "<i class='ace-icon fa fa-trash-o bigger-110'></i>&nbsp; 确定",
856                 "class" : "btn btn-danger btn-minier",
857                 click: function() {
858                     $( this ).dialog( "close" );
859                     cb(cbparams);
860                 }
861             }
862             ,
863             {
864                 html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 取消",
865                 "class" : "btn btn-minier",
866                 click: function() {
867                     $( this ).dialog( "close" );
868                 }
869             }
870         ]
871     });
872 }
873
874 function gotoVehicleDetails(item) {
875     parent.closableTab.addTab({
876         'id': new Date().getTime(),
877         'name': item.vehicleId + '的配车物资',
878         'url': '/basic/vehicleBindMaterials.jsf?numberplates=' + encodeURI(encodeURI(item.vehicleId)),
879         'closable': true
880     });
881 }
882
883
884 function SortList(Obj1,Obj2){
885     var reval=0;
886     $.each(vm.soList(), function (index, value) { 
887         var ASCStr=value.result();
888         var fieLd=value.target;
889         if(ASCStr==null||ASCStr==''){
890             ASCStr="asc";
891         }
892         if(fieLd==null||fieLd==''){
893             reval=0;
894         }
895         if("asc"==ASCStr){
896             if(!isNaN(Obj1[fieLd])){
897                 if(Obj1[fieLd]-Obj2[fieLd]>0){
898                     reval=1;
899                     return false;
900                 }else if(Obj1[fieLd]-Obj2[fieLd]<0){
901                     reval=-1;
902                     return false;
903                 }else{
904                     reval=0;
905                 }
906             }else{
907                 if(Obj1[fieLd]> Obj2[fieLd]){
908                    reval=1;
909                    return false;
910                 }else if(Obj1[fieLd]< Obj2[fieLd]){
911                     reval=-1;
912                     return false;
913                 }else{
914                     reval=0;
915                 }
916             }
917         }else{
918             if(!isNaN(Obj1[fieLd])){
919                 if(Obj2[fieLd]-Obj1[fieLd]>0){
920                     reval=1;
921                     return false;
922                 }else if(Obj2[fieLd]-Obj1[fieLd]<0){
923                     reval=-1;
924                     return false;
925                 }else{
926                     reval=0;
927                 }
928             }else{
929                 if(Obj2[fieLd]> Obj1[fieLd]){
930                     reval=1;
931                     return false;
932                 }else if(Obj2[fieLd]< Obj1[fieLd]){
933                     reval=-1;
934                     return false;
935                 }else{
936                     reval=0;
937                 }
938             }
939             
940          }
941     });
942     return reval;
943     
944 }
945 function addSort(item) {
946     item.visible(false);
947     var obj = {
948         key: item.key,
949         target: item.value,
950         result: ko.observable('asc')
951     }
952     vm.soList.push(obj);
953 }
954
955 function removeSort(item) {
956     vm.soList.remove(item);
957     $.each(vm.oList(), function (index, value) { 
958          value.key === item.key && value.visible(true);
959     });
960 }