/** * date: * author: neeler */ //test data start // var data_getList = Mock.mock('/company/getList.htm', {code: 0, 'list|5-20': [{id: 'id', companyNo: 'companyNo', note: 'note', name: 'name'}], pages: 12}) // var data_doDel = Mock.mock('/company/delItem.htm', {code: 0, errmsg: 'errmsg'}) // var data_doSave = Mock.mock('/company/saveItem.htm', {code: 0, errmsg: 'errmsg'}) //test data end var HOSTNAME = window.location.hostname; window.I = { id: $('#_id').val(), bsNo: $('#_bsNo').val(), printBtn: $('#printBtn') } var ViewModel = function() { var self = this; self.list = ko.observableArray(); self.totalMZ = ko.observable(0); self.totalJZ = ko.observable(0); self.vehicleLoadweight = ko.observable(0); self.overWeight = ko.observable(0); self.isAdmin = ko.observable(typeof(parent.G) != 'undefined' ? parent.G.isAdmin : false); self.del = function(item) { delConfirm(item); } } $(function () { window.vm = new ViewModel(); ko.applyBindings(vm); I.numberplates = $('#_numberplates').val(); getVehicleDetails(I.bsNo); pageInit(); autoHeight(); // getVehicleList(); }); function pageInit() { I.printBtn.click(function (e) { e.preventDefault(); newTab(I.numberplates); }); } function getVehicleDetails(bsNo) { vm.list.removeAll(); var mz = 0; var jz = 0; $.post("/task/getVehicleDetails.htm", {keyword: bsNo}, function (data, textStatus, jqXHR) { if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { if (isList(data.list)) { $.each(data.list, function (index, value) { mz += value.tdmx_mz; jz += value.tdmx_jz; vm.list.push(value); }); } vm.totalMZ(mz.toFixed(3)); vm.totalJZ(jz.toFixed(3)); } }, "json" ); } function getVehicleList() { $.post("/business/getVehicleList.htm", { companyNo: vm.isAdmin() ? '' : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG'), vehicleId:'111111' }, function (data, textStatus, jqXHR) { I.VDB = []; if (data.code >= 1) { swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { if (isList(data.list)) { $.each(data.list, function (index, value) { value.indx = index + ''; value.lastweight = ''; if ($.isNumeric(value.loadweight) && $.isNumeric(value.fdweight)) { value.lastweight = (parseFloat(value.loadweight) - parseFloat(value.fdweight)).toFixed(3); } if (value.vehicleId === I.numberplates) { vm.vehicleLoadweight(value.loadweight); } I.VDB.push(value); }); } // updateVList(); return; } }, "json" ); } function newTab(vehicleId) { parent.closableTab.addTab({ 'id': vehicleId, 'name': '打印', // 'url': encodeURI('http://' + HOSTNAME + ':9088/ReportServer?reportlet=print%2Fprint_fd_xstd.cpt&vehicleId=' + vehicleId), 'url': encodeURI('/task/Printfdxq.htm?bsNo=' + I.bsNo), 'closable': true }); } function autoHeight() { $('.page-content').css('min-height', $(parent.window).height() - 159); $('.table-responsive').css('height', $(parent.window).height() - 159); } function delConfirm(item) { $("#modalContent").html('确定要删除【提单编号:' + item.tdmx_tdbh+'批次号:' +item.tdmx_pch +'】吗?'); $("#dialog-confirm").removeClass('hide').dialog({ resizable: false, width: '320', modal: true, title: "
", title_html: true, position: { my: "center", at: "center", of: window }, buttons: [ { html: " 确定", "class" : "btn btn-danger btn-minier", click: function() { $( this ).dialog( "close" ); doDel(item); } } , { html: " 取消", "class" : "btn btn-minier", click: function() { $( this ).dialog( "close" ); } } ] }); } function doDel(item) { if (!!I.AjaxDelItem) return; I.AjaxDelItem = true; $.post('/task/delbypch.htm', {bsno:I.bsNo,tdno: item.tdmx_tdbh,pch:item.tdmx_pch,cph:$('#_numberplates').val()}, function(data, textStatus, xhr) { I.AjaxDelItem = false; if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { vm.list.remove(item); // getVehicleDetails(item.tdmx_pch); parent.showErrmsg('删除成功!'); I.modal.modal('hide'); return; } }, 'json'); }