$(function() { var focusId; $('#barcode').focus(); //如不使用延迟执行, 有时候会无效 setTimeout(function() { $('#barcode').focus(); }, 1000); $("#length").keyup(function(event){ if(event.keyCode != "13") { return false; } setFocus('width') }) $("#width").keyup(function(event){ if(event.keyCode != "13") { return false; } setFocus('height') }) $("#height").keyup(function(event){ if(event.keyCode != "13") { return false; } setFocus('shelfLifeDays') }) $("#shelfLifeDays").keyup(function(event){ if(event.keyCode != "13") { return false; } setFocus('grossWeight') }) //提交商品条码 $('#barcode').keyup(function(event) { if(event.keyCode != "13") { return false; } console.log('submitBarcode') $("#barcode").val(trimStr($("#barcode").val())); if($("#barcode").val() != '') { //播放扫描声音 playSound('../raw/scan.wav'); console.log('submitBarcode:start') submitBarcode(); } }); }); var singleBarcodeEntity; var singleBarcodeId=-1; var singleBarcodeMap = {}; function submitBarcode() { $(".allowClear").each(function() { if($(this).attr('name') != 'barcode'){ $(this).val("") } }) $("#customerList").html("") singleBarcodeId = -1; var barcode = $("#barcode").val(); var msgBody = {}; msgBody.barcode = barcode; //序列化成字符串 var msgBodyStr = JSON.stringify(msgBody) var appRequest = $appRequest; //复制请求封装对象 appRequest.opType = OP_TYPE_MENU.CHECK_PRODUCT2; appRequest.msg = msgBodyStr; //msg是消息内容主体 console.log("req:"+JSON.stringify(appRequest)) console.log('$appRequestUrl:'+$appRequestUrl) $.ajax({ type: 'POST', url: $appRequestUrl, contentType: "application/json; charset=utf-8", data: JSON.stringify(appRequest), success: function(appResponse) { console.log("appResponse:"+JSON.stringify(appResponse)) if(!appResponse.success || appResponse.extend ==null || appResponse.extend.length == 0) { playSound('../raw/error.wav'); mui.toast(appResponse.msg); return; } singleBarcodeMap = {}; // var productBarcodeList = appResponse.extend if(productBarcodeList.length==1){ singleBarcodeEntity = productBarcodeList[0]; fillBarcodeDetail(singleBarcodeEntity); setFocus('length') } //组装成下拉框 var listCustomer=[]; for (var i =0 ;i < productBarcodeList.length ; i++) { var productBarcodeSingle = productBarcodeList[i] singleBarcodeMap[productBarcodeSingle['id']] = productBarcodeSingle; console.log('this[id]:'+productBarcodeSingle['id']) console.log('this[customerCode]:'+productBarcodeSingle['customerCode']) listCustomer.push('') } var listCustomerValue = listCustomer.join(''); if(listCustomer.length>1){ listCustomerValue=''+listCustomerValue; mui.toast("该条码在系统中存在多条记录,请选择其中一条进行操作"); } $('#customerList').html(listCustomerValue); if(listCustomer.length>1){ //customerList $("#customerList").trigger("click") } }, error: function() { console.log('异常') playSound('../raw/error.wav'); mui.toast('网络断开或服务器发生异常'); } }); } function selectSingleCustomer(obj){ singleBarcodeId = $(obj).val(); if(singleBarcodeId == -1){ $(".allowClear").each(function() { if($(this).attr('name') != 'barcode'){ $(this).val("") } }) return ; } singleBarcodeEntity = singleBarcodeMap[singleBarcodeId]; if(singleBarcodeEntity !=null && singleBarcodeEntity){ fillBarcodeDetail(singleBarcodeEntity) } setFocus('length') } /** * 填充商品信息 * @param {Object} singleBarcodeEntity */ function fillBarcodeDetail(singleBarcodeEntity){ singleBarcodeId = singleBarcodeEntity.id; fillForm(singleBarcodeEntity,['length','width','height','shelfLifeDays','grossWeight','sku']) } function fillForm(entity,fileds){ for (var i =0 ; i