123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- $(function() {
- var focusId;
- $('#barcode').focus();
- //如不使用延迟执行, 有时候会无效
- setTimeout(function() {
- $('#barcode').focus();
- }, 1000);
- //提交商品条码
- $('#barcode').keyup(function(event) {
- if(event.keyCode != "13") {
- return false;
- }
- $("#barcode").val(trimStr($("#barcode").val()));
- if($("#barcode").val() != '') {
- //播放扫描声音
- playSound('../raw/scan.wav');
- submitBarcode();
- }
- });
- });
- function submitBarcode() {
- var barcode = $("#barcode").val();
- var customerCode = $("#customerCode").val();
- var msgBody = {};
- msgBody.barcode = barcode;
- msgBody.customerCode = customerCode;
- //序列化成字符串
- var msgBodyStr = JSON.stringify(msgBody)
- var appRequest = $appRequest; //复制请求封装对象
- appRequest.opType = OP_TYPE_MENU.CHECK_PRODUCT;
- appRequest.msg = msgBodyStr; //msg是消息内容主体
- $.ajax({
- type: 'POST',
- url: $appRequestUrl,
- contentType: "application/json; charset=utf-8",
- data: JSON.stringify(appRequest),
- success: function(appResponse) {
- if(!appResponse.success) {
- playSound('../raw/error.wav');
- mui.toast(appResponse.msg);
- return;
- }
- var list = appResponse.extend; //ProductBarcodelist
- if(list.length == 0){
- playSound('../raw/error.wav');
- mui.toast('该条码未查到商品信息');
- return;
- }
-
- //先判断是否已经选择了货主,如果选择了并且该货主也存在结果中,不能清空,不然每次扫描条码都要选货主
- var oldCustomerCode = $("#customerCode").val();
-
- $("#customerCode").empty();
-
- //重新设置select
- for(var i = 0; i < list.length; i++) {
- var pb = list[i];
- $("#customerCode").append("<option value='" + pb.customerCode + "'>" + pb.customerCode + "</option>"); //添加option
- }
- $("#customerCode").val(oldCustomerCode);
-
- countPicture();
- return;
- },
- error: function() {
- playSound('../raw/error.wav');
- mui.toast('网络断开或服务器发生异常');
- }
- });
- }
- //看条码+货主是否已经有图片,避免重复拍照
- function countPicture() {
- var barcode = $("#barcode").val();
- var customerCode = $("#customerCode").val();
- var msgBody = {};
- msgBody.barcode = barcode;
- msgBody.customerCode = customerCode;
- //序列化成字符串
- var msgBodyStr = JSON.stringify(msgBody)
- var appRequest = $appRequest; //复制请求封装对象
- appRequest.opType = OP_TYPE_MENU.COUNT_PRODUCT_PICTURE;
- appRequest.msg = msgBodyStr; //msg是消息内容主体
- $.ajax({
- type: 'POST',
- url: $appRequestUrl,
- contentType: "application/json; charset=utf-8",
- data: JSON.stringify(appRequest),
- success: function(appResponse) {
- if(!appResponse.success || appResponse.extend.length == 0) {
- return;
- }
-
- var msg = appResponse.msg;
- $("#tips").text(msg);
- },
- error: function() {
- mui.toast('网络断开或服务器发生异常');
- }
- });
- }
- //提交拍照
- function submitUpload() {
- var barcode = $("#barcode").val();
- var customerCode = $("#customerCode").val();
-
- var msgBody = {};
- msgBody.barcode = barcode;
- msgBody.customerCode = customerCode;
- msgBody.imgArray = imgArray; //图片base64数据
-
- if(barcode == null || barcode == ''){
- mui.toast('商品条码不能为空');
- return false;
- }
- if(customerCode == null || customerCode == ''){
- mui.toast('货主代码不能为空');
- return false;
- }
- if(imgArray == null){
- mui.toast('图片不能为空');
- return false;
- }
-
- //序列化成字符串
- var msgBodyStr = JSON.stringify(msgBody)
- var appRequest = $appRequest; //复制请求封装对象
- appRequest.opType = OP_TYPE_MENU.PRODUCT_PICTURE;
- appRequest.msg = msgBodyStr; //msg是消息内容主体
- mui.toast('开始上传图片');
- plus.nativeUI.showWaiting();
- $.ajax({
- type: 'POST',
- url: $appRequestUrl,
- contentType: "application/json; charset=utf-8",
- data: JSON.stringify(appRequest),
- success: function(appResponse) {
- plus.nativeUI.closeWaiting();
- if(!appResponse.success) {
- playSound('../raw/error.wav');
- mui.toast(appResponse.msg);
- return;
- }
- mui.toast(appResponse.msg);
- cleanAll();
- },
- error: function() {
- plus.nativeUI.closeWaiting();
- playSound('../raw/error.wav');
- mui.toast('网络断开或服务器发生异常');
- }
- });
- }
- //下一个转移任务
- function cleanAll() {
- $(".allowClear").each(function() {
- $(this).val("")
- })
-
- imgArray.splice(0, imgArray.length);
- document.getElementsByClassName("showimg")[0].innerHTML = null;
- $("#barcode").focus();
- }
|