var selectItemNum = -1; var selectmore = -1; var domTitle; var selectValue = ''; jQuery().ready(function() { var elementCarNo = document.getElementById("licenceNo"); jQuery("#licenceNo").bind("keyup", function() { webChangelicenceNo(this); }); // js.event.add(elementCarNo, "focus", function() { // eme = elementCarNo; // }); //检查输入中的非法字符 function checkChar(InString) { for (Count = 0; Count < InString.length; Count++) { TempChar = InString.substring(Count, Count + 1); if (!checkshuzi(TempChar) && !checkzimu(TempChar) && !checkhanzi(TempChar)) { return (true); } } return (false); } //判断数字 function checkshuzi(shuziString) { var shuzi = shuziString.match(/\d/g); if (shuzi == null) return (false); else return (true); } //判断字母 function checkzimu(zimuString) { var zimu = zimuString.match(/[a-z]/ig); if (zimu == null) return (false); else return (true); } //判断汉字 function checkhanzi(hanziString) { var hanzi = hanziString.match(/[^ -~]/g); if (hanzi == null) return (false); else return (true); } //enter key event for licenceNo jQuery("#licenceNo").keydown(function(e) { // var e = e || event; // var eventKeyCode = e.witch || e.keyCode; // if (eventKeyCode == 13) { // var reg = /^([\u4e00-\u9fa5]|[A-Z]){1,2}[A-Za-z0-9]{1,2}[-\s]?[0-9A-Za-z]{5}$/; // // if ($("vehicleNumber").value) { // // if (!reg.test($('vehicleNumber').value)) { // alert("输入的车牌号码不符合规范,请检查!"); // this. // // (); // this.select() // return; // } // if (jQuery('#vehicleNumber').val() != jQuery('#vehicleNumber').defaultValue) { // window.location.assign('txn.do?method=getRepairOrderByVehicleNumber&vehicleNumber=' + (jQuery('#vehicleNumber').val() == jQuery('#vehicleNumber').defaultValue ? '' : jQuery('#vehicleNumber').val())); // } // else { // window.location.assign('customer.do?method=carindex'); // } // } // else { // window.location.assign('customer.do?method=carindex'); // } // } var e = e || event; var eventKeyCode = e.witch || e.keyCode; if (eventKeyCode == 13) { // var reg = /^([\u4e00-\u9fa5]|[A-Z]){1,2}[A-Za-z0-9]{1,2}[-\s]?[0-9A-Za-z]{5}$/; if ($("licenceNo").value) { var nameValue = jQuery('#licenceNo').val(); var ResultStr = ""; var ResultStr1 = ""; //去除空格 Temp = nameValue.split(" "); for (i = 0; i < Temp.length; i++) ResultStr1 += Temp[i]; //去除横杠 "-" Temp1 = ResultStr1.split("-"); for (i = 0; i < Temp1.length; i++) ResultStr += Temp1[i]; //if (!reg.test(jQuery('#m_text_id').val())) { if (checkChar(ResultStr)) { alert("输入的车牌号码不符合规范,请检查!"); // this.focus(); // this.select() // return; } else if (jQuery('#licenceNo').val() != jQuery('#licenceNo').defaultValue) { var nameValue = ResultStr; //如果首字符是汉字 if (checkhanzi(nameValue.substring(0, 1))) { if (checkzimu(nameValue.substring(1, 2)) && (nameValue.substring(2).length == 5 || nameValue.substring(2).length == 6) && !checkhanzi(nameValue.substring(2))) { window.location.assign('txn.do?method=getRepairOrderByVehicleNumber&vehicleNumber=' + (nameValue == jQuery('#licenceNo').defaultValue ? '' : nameValue)); } else { alert("输入的车牌号码不符合规范,请检查!"); // this.focus(); // this.select() // return; } } //如果首字符是字母 else if (checkzimu(nameValue.substring(0, 1))) { if (checkzimu(nameValue.substring(1, 2)) && nameValue.length >= 7 && !checkhanzi(nameValue.substring(2))) { window.location.assign('txn.do?method=getRepairOrderByVehicleNumber&vehicleNumber=' + (nameValue == jQuery('#licenceNo').defaultValue ? '' : nameValue)); } else if (!checkhanzi(nameValue) && (nameValue.length == 5 || nameValue.length == 6)) { //前缀 var r = bcgogo.get("product.do?method=userLicenseNo"); if (r === null) { return; } else { var locaono = r[0].localCarNo; jQuery("#licenceNo").val((locaono + jQuery("#licenceNo").val()).toUpperCase()); locaono = ''; } } else { alert("输入的车牌号码不符合规范,请检查!"); // this.focus(); // this.select() // return; } } //如果既不是汉字也不是字母 else { if (nameValue.length <= 4 || nameValue.length >= 7) { alert("输入的车牌号码不符合规范,请检查!"); // this.focus(); // this.select() // return; } else { //5,6为数字的判断是否有汉字 if (!checkhanzi(nameValue)) { //添加前缀 var r = bcgogo.get("product.do?method=userLicenseNo"); if (r === null) { return; } else { var locaono = r[0].localCarNo; jQuery("#licenceNo").val((locaono + jQuery("#licenceNo").val()).toUpperCase()); locaono = ''; } } else { alert("输入的车牌号码不符合规范,请检查!"); // this.focus(); // this.select() // return; } } } // // window.location.assign('txn.do?method=getRepairOrderByVehicleNumber&vehicleNumber=' + (jQuery('#vehicleNumber').val() == jQuery('#vehicleNumber').defaultValue ? '' : jQuery('#vehicleNumber').val())); } else { window.location.assign('customer.do?method=carindex'); } } else { window.location.assign('customer.do?method=carindex'); } } }); js.event.add(elementCarNo, "blur", function() { if (selectValue != '') { elementCarNo.value = selectValue; var nameValue = selectValue; var ResultStr = ""; var ResultStr1 = ""; //去除空格 Temp = nameValue.split(" "); for (i = 0; i < Temp.length; i++) ResultStr1 += Temp[i]; //去除横杠 "-" Temp1 = ResultStr1.split("-"); for (i = 0; i < Temp1.length; i++) ResultStr += Temp1[i]; if (jQuery("#licenceNo") != null) { if (checkChar(ResultStr)) { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } else if (checkhanzi(ResultStr.substring(0, 1))) { if (checkzimu(ResultStr.substring(1, 2)) && (ResultStr.substring(2).length == 5 || ResultStr.substring(2).length == 6) && !checkhanzi(ResultStr.substring(2))) { // window.location.assign('txn.do?method=getRepairOrderByVehicleNumber&vehicleNumber=' + (ResultStr == $('vehicleNumber').defaultValue ? '' : ResultStr)); jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + ResultStr, async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); } else { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } } //如果首字符是字母 else if (checkzimu(ResultStr.substring(0, 1))) { if (checkzimu(ResultStr.substring(1, 2)) && (ResultStr.length == 7||ResultStr.length == 8) && !checkhanzi(ResultStr.substring(2))) { // window.location.assign('txn.do?method=getRepairOrderByVehicleNumber&vehicleNumber=' + (ResultStr == '车牌号' ? '' : ResultStr)); var r = bcgogo.post("product.do?method=sevenOrEightLicenseNo&plateValue="+ResultStr); if (r === null) { return; } else { locaono = r[0].carno; jQuery("#vehicleNumber").val(locaono); locaono = ''; } jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + jQuery("#vehicleNumber").val(), async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); } else if(checkzimu(ResultStr.substring(1, 2)) && ResultStr.length>9 && !checkhanzi(ResultStr.substring(2))) { jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + ResultStr, async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); } else if (!checkhanzi(ResultStr) && (ResultStr.length == 5 || ResultStr.length == 6)) { //前缀 var r = bcgogo.get("product.do?method=userLicenseNo"); if (r === null) { return; } else { var locaono = r[0].localCarNo; jQuery("#licenceNo").val(locaono + jQuery("#licenceNo").val()); jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + jQuery("#licenceNo").val(), async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); locaono = ''; } } else { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } } //如果既不是汉字也不是字母 else { if (nameValue.length <= 4) { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } else { //5,6为数字的判断是否有汉字 if (!checkhanzi(nameValue)) { //添加前缀 var r = bcgogo.get("product.do?method=userLicenseNo"); if (r === null) { return; } else { var locaono = r[0].localCarNo; jQuery("#licenceNo").val((locaono + jQuery("#licenceNo").val()).toString().toUpperCase()); jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + jQuery("#licenceNo").val(), async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); locaono = ''; } } else { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } } } } // } else { var nameValue = jQuery("#licenceNo").val(); var ResultStr = ""; var ResultStr1 = ""; //去除空格 Temp = nameValue.split(" "); for (i = 0; i < Temp.length; i++) ResultStr1 += Temp[i]; //去除横杠 "-" Temp1 = ResultStr1.split("-"); for (i = 0; i < Temp1.length; i++) ResultStr += Temp1[i]; if (jQuery("#licenceNo") != null) { if (checkChar(ResultStr)) { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } else if (checkhanzi(ResultStr.substring(0, 1))) { if (checkzimu(ResultStr.substring(1, 2)) && (ResultStr.substring(2).length == 5 || ResultStr.substring(2).length == 6) && !checkhanzi(ResultStr.substring(2))) { // window.location.assign('txn.do?method=getRepairOrderByVehicleNumber&vehicleNumber=' + (ResultStr == $('vehicleNumber').defaultValue ? '' : ResultStr)); jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + ResultStr, async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); } else { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } } //如果首字符是字母 else if (checkzimu(ResultStr.substring(0, 1))) { if (checkzimu(ResultStr.substring(1, 2)) && ResultStr.length >= 7 && !checkhanzi(ResultStr.substring(2))) { // window.location.assign('txn.do?method=getRepairOrderByVehicleNumber&vehicleNumber=' + (ResultStr == '车牌号' ? '' : ResultStr)); jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + ResultStr, async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); } else if (!checkhanzi(ResultStr) && (ResultStr.length == 5 || ResultStr.length == 6)) { //前缀 var r = bcgogo.get("product.do?method=userLicenseNo"); if (r === null) { return; } else { var locaono = r[0].localCarNo; jQuery("#licenceNo").val((locaono + jQuery("#licenceNo").val()).toUpperCase()); jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + jQuery("#licenceNo").val(), async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); locaono = ''; } } else { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } } //如果既不是汉字也不是字母 else { if (nameValue.length <= 4 || nameValue.length >= 7) { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } else { //5,6为数字的判断是否有汉字 if (!checkhanzi(nameValue)) { //添加前缀 var r = bcgogo.get("product.do?method=userLicenseNo"); if (r === null) { return; } else { var locaono = r[0].localCarNo; jQuery("#licenceNo").val((locaono + jQuery("#licenceNo").val()).toUpperCase()); jQuery.ajax({ type:"POST", url:"txn.do?method=getRepairOrderByVehicleNumber&type=ajax&btnType=" + jQuery("#pageType").val() + "&vehicleNumber=" + jQuery("#licenceNo").val(), async:true, cache:false, dataType:"json", error:function(XMLHttpRequest, error, errorThrown) { }, success:function(jsonStr) { initCustomerAndVehicle(jsonStr); } } ); locaono = ''; } } else { alert("输入的车牌号码不符合规范,请检查!"); this.focus(); this.select() // return; } } } } // } $("div_brandvehiclelicenceNo").style.display = "none"; selectItemNum = -1; // eme = null; selectValue = ""; // elementCarNo.value=""; }); function webChangelicenceNo(thisObj) { if(elementCarNo.value==''||elementCarNo.value==null) { jQuery("#div_brandvehiclelicenceNo").css({'display':'none'}); } else { elementCarNo.value = elementCarNo.value.replace(/[\ |\\]/g, ""); searchSuggestionlicenceNo(thisObj, elementCarNo.value, "notclick"); } } jQuery(window).keydown(function(e) { // var eventCode = event.keyCode || e.which; var e = e || event; var eventKeyCode = e.witch || e.keyCode; if (jQuery("#div_brandvehiclelicenceNo").css("display") == "block") { if (eventKeyCode == 38 && (selectItemNum - 1 >= 0 || selectItemNum == 0 || selectItemNum == -1)) { if (domTitle == 'brand' || domTitle == 'model' || domTitle == 'product_name') { selectItemNum = selectItemNum == 0 || selectItemNum == -1 ? (selectmore + 1) : selectItemNum; } else { selectItemNum = selectItemNum == 0 || selectItemNum == -1 ? (selectmore) : selectItemNum; } jQuery("#Scroller-Container_idlicenceNo > a").removeAttr("class"); jQuery("#selectItem" + (selectItemNum - 1)).mouseover(); } else if (eventKeyCode == 40) { if (domTitle == 'brand' || domTitle == 'model' || domTitle == 'product_name') { selectItemNum = selectItemNum == selectmore ? -1 : selectItemNum; } else { selectItemNum = selectItemNum == selectmore - 1 ? -1 : selectItemNum; } jQuery("#Scroller-Container_idlicenceNo > a").removeAttr("class"); jQuery("#selectItem" + (selectItemNum + 1)).mouseover(); } else if (selectItemNum != -1 && eventKeyCode == 13) { jQuery("#selectItem" + (selectItemNum)).click(); } } }); }); function ajaxStylelicenceNo(domObject, jsonStr) { var offset = jQuery(domObject).offset(); var offsetHeight = jQuery(domObject).height(); var offsetWidth = jQuery(domObject).width(); //var offsetWidth = jQuery("#m_text").width(); domTitle = domObject.name; var x = getX(domObject); var y = getY(domObject); //alert(offset.left + "\n\n" + offset.top); selectmore = jsonStr.length; if(selectmore<=0) { jQuery("#div_brandvehiclelicenceNo").css({'display':'none'}); } else { jQuery("#div_brandvehiclelicenceNo").css({ 'display':'block','position':'absolute', 'left':x + 'px', 'top':y + offsetHeight + 8 + 'px' }); jQuery("#Scroller-Container_idlicenceNo").html(""); for (var i = 0; i < jsonStr.length; i++) { var a = jQuery("<a id='selectItem" + i + "'></a>"); a.html(jsonStr[i].carno); a.mouseover(function() { jQuery("#Scroller-Container_idlicenceNo > a").removeAttr("class"); jQuery(this).attr("class", "hover"); selectValue = jQuery(this).html(); var selectValueOther = jQuery(this).html(); if (typeof(selectValueOther) != "undefined") { selectValue = selectValueOther; } else { selectValue = ""; } selectItemNum = parseInt(this.id.substring(10)); }); a.click(function() { jQuery(domObject).val(jQuery(this).html()); jQuery(domObject).blur(); jQuery("#div_brandvehiclelicenceNo").css({'display':'none'}); selectItemNum = -1; // if (jQuery("#brand").val() != "" && jQuery("#model").val() != "" && jQuery("#year").val() != "" && jQuery("#engine").val() != "") { // searchVehicleIds(jQuery("#brand").val(), jQuery("#model").val(), jQuery("#year").val(), jQuery("#engine").val()) // } }); jQuery("#Scroller-Container_idlicenceNo").append(a); } } //弹出复选框的最后一项 if ((domTitle == 'brand' || domTitle == 'model') && jsonStr.length == 9) { var a = jQuery("<a id='selectItem" + (selectmore) + "'></a>"); a.html("更多"); a.mouseover(function() { jQuery("#Scroller-Container_idlicenceNo > a").removeAttr("class"); jQuery(this).attr("class", "hover"); selectItemNum = parseInt(this.id.substring(10)); }); a.click(function() { jQuery("#div_brandvehiclelicenceNo").css({'display':'none'}); jQuery("#iframe_PopupBox").attr("src", "product.do?method=createsearchvehicleinfo&domtitle=" + domTitle + "&brandvalue=" + jQuery("#brand").val()); jQuery("#iframe_PopupBox").css({'display':'block'}); Mask.Login(); }); jQuery("#Scroller-Container_idheader").append(a); } } function getX(elem) { var x = 0; while (elem) { x = x + elem.offsetLeft; elem = elem.offsetParent; } return x; } function getY(elem) { var y = 0; while (elem) { y = y + elem.offsetTop; elem = elem.offsetParent; } return y; } function searchSuggestionlicenceNo(domObject, elementCarNo, eventStr) { //车辆信息查询 var searchWord; if (eventStr == "click") { searchWord = ""; } else { searchWord = domObject.value; } jQuery.ajax({ type:"POST", url:"product.do?method=searchlicenseplate", async:true, data:{ plateValue:searchWord }, cache:false, dataType:"json", success:function(jsonStr) { ajaxStylelicenceNo(domObject, jsonStr); } } ); } // jQuery("#vehicleNumber").blur(function(){ //// $("div_brandvehicleheader").style.display = "none"; //// selectItemNum = -1; // eme=null; // alert('aaaa'); // }); // // jQuery("#vehicleNumber").focus(function(){ // alert('bbb'); // eme=this; // });