/** * date: * author: neeler */ //test data start // 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_pch": "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_cph": "豫C555555", "tdmx_bz": "tdmx_bz", "tdmx_hw": "tdmx_hw"}]}) // 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'}]}) // var data_validVehicle = Mock.mock('/business/validVehicle.htm', {code: 0, errmsg: '车牌号不能使用!'}) // var data_doUnbind = Mock.mock('/business/doUnbind.htm', {code: 0, }) // var data_doBind = Mock.mock('/business/doBind.htm', {code: 0, }) // 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}) // var data_saveItem = Mock.mock('/business/saveItem.htm', {code: 0, }) // var data_doDel = Mock.mock('/transport/yscompany/del.htm', {code: 0, errmsg: 'errmsg'}) // var data_doSave = Mock.mock('/transport/yscompany/save.htm', {code: 0, errmsg: 'errmsg'}) //test data end window.I = { _lastIndex: 0, nowVehicle: null, no: $('#no').val(), allNumBtn: $('#allNumBtn'), bindNumBtn: $('#bindNumBtn'), unbindNumBtn: $('#unbindNumBtn'), vehicleKeyword: $('#vehicleKeyword'), searchVehicleBtn: $('#searchVehicleBtn'), refreshVehicleBtn: $('#refreshVehicleBtn'), tempVehicleModal: $('#tempVehicleModal'), addTempVehicle: $('#addTempVehicle'), tempVehicleSaveBtn: $('#tempVehicleSaveBtn'), selectAllBtn: $('#selectAllBtn'), selectNoBtn: $('#selectNoBtn'), clearSelectBtn: $('#clearSelectBtn'), bindBtn: $('#bindBtn'), unbindBtn: $('#unbindBtn') } var Obj = { vehicleId: '豫A', driver: '', phone: '', IDNum: '', vehicleweight: '', loadweight: '', note: '', feature: '' } var TD = { td_bmbh: '', td_bmmc: '', td_bz: '', td_djrq: '', td_khmc: '', td_tdbh: '', td_tdls: '', td_ywrq: '', td_zdr: '', td_shrq: '', td_shsj: '' } var ViewModel = function() { var self = this; self.o = ko.observable(ko.mapping.fromJS(Obj)); self.td = ko.observable(TD); self.vList = ko.observableArray(); self.list = ko.observableArray(); self.isAdmin = ko.observable(typeof(parent.G) != 'undefined' ? parent.G.isAdmin : false); self.isSelectAll = ko.observable(false); self.allNum = ko.observable(0); self.bindNum = ko.observable(0); self.unbindNum = ko.observable(0); self.selectedNum = ko.observable(0); self.selectedMZ = ko.observable(0); self.selectedJZ = ko.observable(0); self.select = function (item) { I.nowVehicle = {}; for(attr in item) { I.nowVehicle[attr] = item[attr]; } $('#_vhicleId').text(item.vehicleId); $('#_lastweight').text(item.lastweight); $('#_fdweight').text(item.fdweight); $('#_fdnum').text(item.fdnum); $('#_loadweight').text(item.loadweight); $('#vehicleMessage').show(); } self.check = function (item) { self.list.removeAll(); $.each(I._MDB, function (index, value) { if (value.tdmx_cph() === item.vehicleId) { self.list.push(value); } }); setMaterialTableEvent(); computedSelect(); } self.vehicleTasks = function (item) { gotoVehicleDetails(item); } } $(function () { window.vm = new ViewModel(); ko.applyBindings(vm); autoHeight(); getVehicleList(); if (!!I.no) { getList(I.no); } pageInit(); }); function pageInit() { I.unbindBtn.click(function (e) { e.preventDefault(); if ($('.mitem.info').length) { validMessage('确定要取消配车吗?', doUnbind) } else { parent.showErrmsg('请选择一个提单物资!'); } }); I.bindBtn.click(function (e) { e.preventDefault(); if ($('.mitem.info').length) { doBind(); } else { parent.showErrmsg('请选择一个提单物资!'); } }); I.tempVehicleSaveBtn.click(function (e) { e.preventDefault(); if (valid()) { validVehicle(); } }); I.addTempVehicle.click(function (e) { e.preventDefault(); vm.o(ko.mapping.fromJS(Obj)); I.tempVehicleModal.modal('show'); }); I.tempVehicleModal.on('hidden.bs.modal', function (e) { clearError(); }); I.vehicleKeyword.keyup(function (e) { updateVList(); }); I.searchVehicleBtn.click(function (e) { e.preventDefault(); updateVList(); }); I.refreshVehicleBtn.click(function (e) { e.preventDefault(); getVehicleList(); }); I.allNumBtn.click(function (e) { e.preventDefault(); $('.mStatus').removeClass('btn-info'); $(this).addClass('btn-info'); vm.list.removeAll(); $.each(I._MDB, function (index, value) { vm.list.push(value); }); setMaterialTableEvent(); computedSelect(); }); I.bindNumBtn.click(function (e) { e.preventDefault(); $('.mStatus').removeClass('btn-info'); $(this).addClass('btn-info'); vm.list.removeAll(); $.each(I._MDB, function (index, value) { if (value.tdmx_cph() !== '') { vm.list.push(value); } }); setMaterialTableEvent(); computedSelect(); }); I.unbindNumBtn.click(function (e) { e.preventDefault(); $('.mStatus').removeClass('btn-info'); $(this).addClass('btn-info'); vm.list.removeAll(); $.each(I._MDB, function (index, value) { if (value.tdmx_cph() == '') { vm.list.push(value); } }); setMaterialTableEvent(); computedSelect(); }); I.selectAllBtn.click(function (e) { e.preventDefault(); $('.mitem').addClass('info'); computedSelect(); }); I.selectNoBtn.click(function (e) { e.preventDefault(); $('.mitem').removeClass('info'); computedSelect(); }); I.clearSelectBtn.click(function (e) { e.preventDefault(); $('.mitem').removeClass('info'); computedSelect(); }); } function doBind() { if (!!I.AjaxdoBind) { return; } var list = []; var vehicle = I.nowVehicle; if (!vehicle) { parent.showErrmsg('请选择一个车辆!'); return; } var result = true; $.each($('.mitem.info'), function (index, value) { var indx = $(this).attr('data-indx'); $.each(vm.list(), function (index, value) { if (indx === value.indx) { if (value.tdmx_cph() != '') { swal({title:'',text:'选择的配车物资' + value.tdmx_wlmc + '已经配过车!',type:'error',confirmButtonText:'确定'}); result = false; return false; } else { list.push({ tdls: value.tdmx_tdls, tdfl: value.tdmx_tdfl }) } } }); if (!result) { return false; } }); if (!result) { return; } I.AjaxdoBind = true; I.bindBtn.prop('disabled', true); $.post("/business/doBind.htm", {list: $.toJSON(list), vehicle: $.toJSON(vehicle), tdbh: I.no}, function (data, textStatus, jqXHR) { I.AjaxdoBind = false; I.bindBtn.prop('disabled', false); if (data.code >= 1) { swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { showErrmsg('配车成功!'); $.each($('.mitem.info'), function (index, value) { var indx = $(this).attr('data-indx'); $.each(I._MDB, function (index, value) { if (indx === value.indx) { value.tdmx_cph(I.nowVehicle.vehicleId); } }); $.each(vm.list(), function (index, value) { if (indx === value.indx) { value.tdmx_cph(I.nowVehicle.vehicleId); } }); }); updateNum(); getVehicleList(); return; } }, "json" ); } function doUnbind() { if (!!I.AjaxdoUnbind) { return; } var list = []; var arrIndx = []; $.each($('.mitem.info'), function (index, value) { var indx = $(this).attr('data-indx'); $.each(vm.list(), function (index, value) { if (indx === value.indx) { if (value.tdmx_cph() === '') { return true; } else { list.push({ tdls: value.tdmx_tdls, tdfl: value.tdmx_tdfl, vehicleId: value.tdmx_cph() }) arrIndx.push(value.indx); } } }); }); if (!list.length) { return; } I.AjaxdoUnbind = true; I.unbindBtn.prop('disabled', true); $.post("/business/doUnbind.htm", {list: $.toJSON(list), tdbh: I.no}, function (data, textStatus, jqXHR) { I.AjaxdoUnbind = false; I.unbindBtn.prop('disabled', false); if (data.code >= 1) { swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { showErrmsg('取消配车成功!'); $.each(arrIndx, function (index, iv) { $.each(I._MDB, function (index, value) { if (iv === value.indx) { value.tdmx_cph(''); } }); $.each(vm.list(), function (index, value) { if (iv === value.indx) { value.tdmx_cph(''); } }); }); updateNum(); getVehicleList(); return; } }, "json" ); } function getList(keyword) { $.post('/business/getItem.htm', { keyword: keyword }, function(data, textStatus, xhr) { vm.list.removeAll(); if (data.code >= 1) { //parent.showErrmsg(data.errmsg); swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { I._MDB = []; data.item.td_shsj = data.item.td_shsj.slice(0, 19); vm.td(data.item); if (isList(data.list)) { $.each(data.list, function (index, value) { value.tdmx_cph = ko.observable(value.tdmx_cph); value.indx = index + ''; vm.list.push(value); I._MDB.push(value); }); } setMaterialTableEvent(); updateNum(); return; } }, 'json'); } function updateNum() { var allNum = I._MDB.length; var unbindNum = 0; $.each(I._MDB, function (index, value) { value.tdmx_cph() === '' && unbindNum++; }); vm.allNum(allNum); vm.bindNum(allNum - unbindNum); vm.unbindNum(unbindNum); } function setMaterialTableEvent() { $('.mitem').unbind('click').click(function (e) { var index = $('.mitem').index($(this)); e.preventDefault(); if (e.shiftKey) { setMaterialTrSelected(Math.min(index, I._lastIndex), Math.max(index, I._lastIndex)) } else { I._lastIndex = index; $(this).toggleClass('info'); } computedSelect(); }); } function setMaterialTrSelected(start, end) { $.each($('.mitem'), function (index, value) { if (index >= start && index <= end) { $(this).addClass('info'); } }); } function computedSelect() { var selectedNum = $('.mitem.info').length; var selectedMZ = 0; var selectedJZ = 0; $.each($('.mitem.info'), function (index, value) { var indx = $(this).attr('data-indx'); $.each(I._MDB, function (j, jv) { if (jv.indx === indx) { selectedMZ += jv.tdmx_mz; selectedJZ += jv.tdmx_jz; } }); }); vm.selectedNum(selectedNum); vm.selectedMZ(selectedMZ.toFixed(3)); vm.selectedJZ(selectedJZ.toFixed(3)); vm.isSelectAll($('.mitem').length === $('.mitem.info').length); } function getVehicleList() { $.post("/business/getVehicleList.htm", {companyNo: vm.isAdmin() ? '' : (typeof(parent.G) != 'undefined' ? parent.G.loginCompanyNo : 'ABCDEFG')}, 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); } I.VDB.push(value); }); } updateVList(); return; } }, "json" ); } function updateVList() { var str = I.vehicleKeyword.val(); vm.vList.removeAll(); if (!!str) { var reg = new RegExp(str); $.each(I.VDB, function (index, value) { if (reg.test(value.vehicleId)) { vm.vList.push(value); } }); } else { $.each(I.VDB, function (index, value) { vm.vList.push(value); }); } // $('.vitem').click(function (e) { // $('.vitem').removeClass('info'); // $(this).addClass('info'); // }); } function valid(){ var isValid = false; var iF = $('#form'); iF.validate({ rules: { 'vehicleId': { required: true, isPlateNumber: true }, 'driver': { required: true, }, 'phone': { required: true, isPhone: true }, 'IDNum': { required: true, } }, messages: { 'vehicleId': { required: '不能为空!', isPlateNumber: '车牌号不正确!' }, 'driver': { required: '不能为空!', }, 'phone': { required: '不能为空!', isPhone: '手机号不正确!' }, 'IDNum': { required: '不能为空!', } }, errorPlacement: function (err, element) { var p = element.parents('.form-group').eq(0); var d = p.find('.text-error').eq(0); d.css('color', '#D9534F'); err.appendTo(d); } }) isValid = iF.valid(); return isValid; } function validVehicle() { $.post("/business/validVehicle.htm", {vehicleId: ko.mapping.toJS(vm.o()).vehicleId.toUpperCase()}, function (data, textStatus, jqXHR) { if (data.code >= 1) { swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { I.nowVehicle = {}; var obj = ko.mapping.toJS(vm.o()); for(attr in obj) { I.nowVehicle[attr] = obj[attr]; } $('#_vhicleId').text(I.nowVehicle.vehicleId); $('#_lastweight').text(I.nowVehicle.lastweight); $('#_fdweight').text(I.nowVehicle.fdweight); $('#_fdnum').text(I.nowVehicle.fdnum); $('#_loadweight').text(I.nowVehicle.loadweight); $('#vehicleMessage').show(); I.tempVehicleModal.modal('hide'); return; } }, "json" ); } function clearError() { $('#form input').removeClass('error'); $('#form .text-error').html(''); } function autoHeight() { $('.page-content').css('min-height', $(parent.window).height() - 117); $('.table-responsive').css('height', $(parent.window).height() - 275); $('.split').css('left', $('.table-vehicle').width() + 12); } function validMessage(message, cb, cbparams) { $("#modalContent").html(message); $("#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" ); cb(cbparams); } } , { html: "  取消", "class" : "btn btn-minier", click: function() { $( this ).dialog( "close" ); } } ] }); } function gotoVehicleDetails(item) { parent.closableTab.addTab({ 'id': new Date().getTime(), 'name': item.vehicleId + '的配车物资', 'url': '/basic/vehicleBindMaterials.jsf?numberplates=' + encodeURI(encodeURI(item.vehicleId)), 'closable': true }); }