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