1
0

product_picture.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. $(function() {
  2. var focusId;
  3. $('#barcode').focus();
  4. //如不使用延迟执行, 有时候会无效
  5. setTimeout(function() {
  6. $('#barcode').focus();
  7. }, 1000);
  8. //提交商品条码
  9. $('#barcode').keyup(function(event) {
  10. if(event.keyCode != "13") {
  11. return false;
  12. }
  13. $("#barcode").val(trimStr($("#barcode").val()));
  14. if($("#barcode").val() != '') {
  15. //播放扫描声音
  16. playSound('../raw/scan.wav');
  17. submitBarcode();
  18. }
  19. });
  20. });
  21. function submitBarcode() {
  22. var barcode = $("#barcode").val();
  23. var customerCode = $("#customerCode").val();
  24. var msgBody = {};
  25. msgBody.barcode = barcode;
  26. msgBody.customerCode = customerCode;
  27. //序列化成字符串
  28. var msgBodyStr = JSON.stringify(msgBody)
  29. var appRequest = $appRequest; //复制请求封装对象
  30. appRequest.opType = OP_TYPE_MENU.CHECK_PRODUCT;
  31. appRequest.msg = msgBodyStr; //msg是消息内容主体
  32. $.ajax({
  33. type: 'POST',
  34. url: $appRequestUrl,
  35. contentType: "application/json; charset=utf-8",
  36. data: JSON.stringify(appRequest),
  37. success: function(appResponse) {
  38. if(!appResponse.success) {
  39. playSound('../raw/error.wav');
  40. mui.toast(appResponse.msg);
  41. return;
  42. }
  43. var list = appResponse.extend; //ProductBarcodelist
  44. if(list.length == 0){
  45. playSound('../raw/error.wav');
  46. mui.toast('该条码未查到商品信息');
  47. return;
  48. }
  49. //先判断是否已经选择了货主,如果选择了并且该货主也存在结果中,不能清空,不然每次扫描条码都要选货主
  50. var oldCustomerCode = $("#customerCode").val();
  51. $("#customerCode").empty();
  52. //重新设置select
  53. for(var i = 0; i < list.length; i++) {
  54. var pb = list[i];
  55. $("#customerCode").append("<option value='" + pb.customerCode + "'>" + pb.customerCode + "</option>"); //添加option
  56. }
  57. $("#customerCode").val(oldCustomerCode);
  58. countPicture();
  59. return;
  60. },
  61. error: function() {
  62. playSound('../raw/error.wav');
  63. mui.toast('网络断开或服务器发生异常');
  64. }
  65. });
  66. }
  67. //看条码+货主是否已经有图片,避免重复拍照
  68. function countPicture() {
  69. var barcode = $("#barcode").val();
  70. var customerCode = $("#customerCode").val();
  71. var msgBody = {};
  72. msgBody.barcode = barcode;
  73. msgBody.customerCode = customerCode;
  74. //序列化成字符串
  75. var msgBodyStr = JSON.stringify(msgBody)
  76. var appRequest = $appRequest; //复制请求封装对象
  77. appRequest.opType = OP_TYPE_MENU.COUNT_PRODUCT_PICTURE;
  78. appRequest.msg = msgBodyStr; //msg是消息内容主体
  79. $.ajax({
  80. type: 'POST',
  81. url: $appRequestUrl,
  82. contentType: "application/json; charset=utf-8",
  83. data: JSON.stringify(appRequest),
  84. success: function(appResponse) {
  85. if(!appResponse.success || appResponse.extend.length == 0) {
  86. return;
  87. }
  88. var msg = appResponse.msg;
  89. $("#tips").text(msg);
  90. },
  91. error: function() {
  92. mui.toast('网络断开或服务器发生异常');
  93. }
  94. });
  95. }
  96. //提交拍照
  97. function submitUpload() {
  98. var barcode = $("#barcode").val();
  99. var customerCode = $("#customerCode").val();
  100. var msgBody = {};
  101. msgBody.barcode = barcode;
  102. msgBody.customerCode = customerCode;
  103. msgBody.imgArray = imgArray; //图片base64数据
  104. if(barcode == null || barcode == ''){
  105. mui.toast('商品条码不能为空');
  106. return false;
  107. }
  108. if(customerCode == null || customerCode == ''){
  109. mui.toast('货主代码不能为空');
  110. return false;
  111. }
  112. if(imgArray == null){
  113. mui.toast('图片不能为空');
  114. return false;
  115. }
  116. //序列化成字符串
  117. var msgBodyStr = JSON.stringify(msgBody)
  118. var appRequest = $appRequest; //复制请求封装对象
  119. appRequest.opType = OP_TYPE_MENU.PRODUCT_PICTURE;
  120. appRequest.msg = msgBodyStr; //msg是消息内容主体
  121. mui.toast('开始上传图片');
  122. plus.nativeUI.showWaiting();
  123. $.ajax({
  124. type: 'POST',
  125. url: $appRequestUrl,
  126. contentType: "application/json; charset=utf-8",
  127. data: JSON.stringify(appRequest),
  128. success: function(appResponse) {
  129. plus.nativeUI.closeWaiting();
  130. if(!appResponse.success) {
  131. playSound('../raw/error.wav');
  132. mui.toast(appResponse.msg);
  133. return;
  134. }
  135. mui.toast(appResponse.msg);
  136. cleanAll();
  137. },
  138. error: function() {
  139. plus.nativeUI.closeWaiting();
  140. playSound('../raw/error.wav');
  141. mui.toast('网络断开或服务器发生异常');
  142. }
  143. });
  144. }
  145. //下一个转移任务
  146. function cleanAll() {
  147. $(".allowClear").each(function() {
  148. $(this).val("")
  149. })
  150. imgArray.splice(0, imgArray.length);
  151. document.getElementsByClassName("showimg")[0].innerHTML = null;
  152. $("#barcode").focus();
  153. }