shelf.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. $(function(){
  2. var focusId;
  3. $("input").focus(function(){
  4. //记住焦点位置
  5. focusId = this.id;
  6. //this.scrollIntoView(true);//回到顶部
  7. //window.setTimeout("myScrollIntoView()",100);
  8. });
  9. setTimeout(function() {
  10. $('#orderNo').focus();
  11. }, 1000);
  12. //同步手工改数量
  13. var last_qty = $("#_quantity").val();
  14. function setQuantity(){
  15. var _qty = $("#_quantity").val();
  16. if(_qty < 0){
  17. $("#_quantity").val(0);
  18. return;
  19. }
  20. if(_qty == last_qty){
  21. return;
  22. }
  23. last_qty = _qty;
  24. $("#quantity").val(_qty);
  25. }
  26. window.setInterval(setQuantity,500);
  27. //当失去焦点按回车时,焦点回到之前焦点位置
  28. $(window).keydown(function(event){
  29. if((event.keyCode==13)) {
  30. if(document.activeElement.id == null || document.activeElement.id ==''){
  31. //回到上次焦点地方
  32. //$("#"+focusId).focus();
  33. }
  34. }
  35. });
  36. $('#orderNo').keyup(function (event) {
  37. if (event.keyCode != "13") {return false;}
  38. $("#orderNo").val(trimStr($("#orderNo").val()));
  39. if($('#orderNo').val()!=''){
  40. //播放扫描声音
  41. playSound('../raw/scan.wav');
  42. //player('../raw/scan.wav');
  43. submitOrderNo();
  44. }
  45. });
  46. $('#barcode').keyup(function (event) {
  47. if (event.keyCode != "13") {return false;}
  48. $("#barcode").val(trimStr($("#barcode").val()));
  49. if($("#barcode").val() !='' ){
  50. //播放扫描声音
  51. playSound('../raw/scan.wav');
  52. submitBarcode();
  53. }
  54. });
  55. $('#locationCode').keyup(function (event) {
  56. if (event.keyCode != "13") {return false;}
  57. $("#locationCode").val(trimStr($("#locationCode").val()));
  58. if($("#locationCode").val() !='' ){
  59. //播放扫描声音
  60. playSound('../raw/scan.wav');
  61. setFocus('quantity');
  62. }
  63. });
  64. $('#quantity').keyup(function (event) {
  65. if (event.keyCode != "13") {return false;}
  66. if($("#quantity").val() !='' ){
  67. //提交上架
  68. submitInShelf();
  69. }
  70. });
  71. });
  72. //提交入库单号
  73. function submitOrderNo(){
  74. var orderNo = $('#orderNo').val();
  75. var appRequest = $appRequest;//复制请求封装对象
  76. appRequest.opType = OP_TYPE_MENU.IN_SHELF_1;
  77. appRequest.msg = orderNo;//msg是消息内容主体
  78. $.ajax({
  79. type: 'POST',
  80. url: $appRequestUrl,
  81. contentType: "application/json; charset=utf-8",
  82. data: JSON.stringify(appRequest),
  83. success: function (appResponse) {
  84. if(!appResponse.success){
  85. playSound('../raw/error.wav');
  86. mui.alert(appResponse.msg, '警告', function() { setFocus('orderNo'); });
  87. return;
  88. }
  89. mui.toast(appResponse.msg);
  90. var order = appResponse.extend;
  91. $("#inOrderId").val(order.id);
  92. $("#inOrderType").val(order.typeCode);
  93. $("#warehouseCode").val(order.warehouseCode);
  94. $("#customerCode").val(order.customerCode);
  95. $("#customerId").val(order.customerId);
  96. next();
  97. },
  98. error: function () {
  99. playSound('../raw/error.wav');
  100. mui.toast('网络断开或服务器发生异常');
  101. }
  102. });
  103. }
  104. //提交商品条码
  105. function submitBarcode(){
  106. var inOrderId = $('#inOrderId').val();
  107. var orderNo = $('#orderNo').val();
  108. var barcode = $('#barcode').val();
  109. var formData = {inOrderId:inOrderId,orderNo:orderNo,barcode:barcode};
  110. var appRequest = $appRequest;//复制请求封装对象
  111. appRequest.opType = OP_TYPE_MENU.IN_SHELF_2;
  112. appRequest.msg = JSON.stringify(formData);//msg是消息内容主体
  113. $.ajax({
  114. type: 'POST',
  115. url: $appRequestUrl,
  116. contentType: "application/json; charset=utf-8",
  117. data: JSON.stringify(appRequest),
  118. success: function (appResponse) {
  119. if(!appResponse.success){
  120. playSound('../raw/error.wav');
  121. mui.alert(appResponse.msg, '警告', function() { setFocus('barcode'); });
  122. return;
  123. }
  124. mui.toast(appResponse.msg);
  125. //返回收货记录 可能是多条
  126. var list = appResponse.extend;
  127. if(list.length == 0 ){
  128. playSound('../raw/error.wav');
  129. mui.alert('后台返回list长度为0', '警告', function() { setFocus('barcode'); });
  130. return;
  131. }
  132. //暂先只处理第一条.. 后续可改为界面选择一条
  133. var inReceipt = list[0];
  134. $("#inReceiptId").val(inReceipt.id);//收货记录id
  135. $("#batchNo").val(inReceipt.batchNo);//批次号码
  136. $("#receiptQuantity").val(inReceipt.quantity);//收货数量
  137. $('#receiptQualityCode').val(inReceipt.qualityName);//选中收货品质
  138. $('#shelfQualityCode').val(inReceipt.qualityCode);
  139. //获取推荐库位
  140. getRecommendLocationCode();
  141. //跳到库位
  142. $('#locationCode').focus();
  143. },
  144. error: function () {
  145. playSound('../raw/error.wav');
  146. mui.toast('网络断开或服务器发生异常');
  147. }
  148. });
  149. }
  150. //获取推荐库位
  151. function getRecommendLocationCode(){
  152. var recommendRuleCode = $("#recommendRuleCode").val();
  153. var warehouseCode = $("#warehouseCode").val();
  154. var barcode = $("#barcode").val();
  155. var qualityCode = $("#shelfQualityCode").val();
  156. var customerId = $("#customerId").val();
  157. var inOrderId = $("#inOrderId").val();
  158. var inOrderType = $("#inOrderType").val();
  159. var _inReceipt ={};//只取部分参数
  160. _inReceipt.recommendRuleCode = recommendRuleCode;
  161. _inReceipt.warehouseCode = warehouseCode;
  162. _inReceipt.barcode = barcode;
  163. _inReceipt.qualityCode = qualityCode;
  164. _inReceipt.customerId = customerId;
  165. _inReceipt.inOrderId = inOrderId;
  166. _inReceipt.inOrderType = inOrderType;
  167. var appRequest = $appRequest;//复制请求封装对象
  168. appRequest.opType = OP_TYPE_MENU.GetRecommendLocationCode;
  169. appRequest.msg = JSON.stringify(_inReceipt);//msg是消息内容主体
  170. var locationCode = "";
  171. $.ajax({
  172. type: 'POST',
  173. url: $appRequestUrl,
  174. contentType: "application/json; charset=utf-8",
  175. data: JSON.stringify(appRequest),
  176. async:false,
  177. success: function (appResponse) {
  178. if(!appResponse.success){
  179. return;
  180. }
  181. locationCode = appResponse.msg;
  182. $("#recommendLocationCode").val(locationCode);//推荐库位
  183. }
  184. });
  185. return locationCode;
  186. }
  187. //提交上架
  188. var isSubmintIng = false;//是否正在提交. 防止按回车太快
  189. function submitInShelf(){
  190. if(isSubmintIng){return;}
  191. isSubmintIng = true;
  192. var inOrderId = $("#inOrderId").val()+'';
  193. var orderNo = $("#orderNo").val();
  194. var barcode = $("#barcode").val();
  195. var inReceiptId = $("#inReceiptId").val();
  196. var qualityCode = $("#shelfQualityCode").val();//上架品质 -- 已控制跟收货品质相同
  197. var quantity = $("#quantity").val();
  198. var locationCode = $("#locationCode").val();//实际上架库位
  199. var customerCode = $("#customerCode").val();
  200. var warehouseCode = $("#warehouseCode").val();
  201. if(inReceiptId == ''){
  202. mui.toast('请先提交商品条码');
  203. isSubmintIng = false;
  204. return;
  205. }
  206. if(inOrderId == '' || locationCode == '' || barcode == ''){
  207. isSubmintIng = false;
  208. return;
  209. }
  210. var formData = {
  211. inOrderId:inOrderId,
  212. orderNo:orderNo,
  213. barcode:barcode,
  214. inReceiptId:inReceiptId,
  215. locationCode:locationCode,
  216. qualityCode:qualityCode,
  217. quantity:quantity
  218. };
  219. var appRequest = $appRequest;//复制请求封装对象
  220. appRequest.opType = OP_TYPE_MENU.IN_SHELF_3;
  221. appRequest.msg = JSON.stringify(formData);//msg是消息内容主体
  222. var nwaiting = plus.nativeUI.showWaiting('正在提交中...');
  223. $.ajax({
  224. type: 'POST',
  225. url: $appRequestUrl,
  226. contentType: "application/json; charset=utf-8",
  227. data: JSON.stringify(appRequest),
  228. success: function (appResponse) {
  229. isSubmintIng = false;
  230. nwaiting.close();
  231. if(!appResponse.success){
  232. playSound('../raw/error.wav');
  233. mui.alert(appResponse.msg, '警告', function() { setFocus('locationCode'); });
  234. return;
  235. }
  236. mui.toast(appResponse.msg);
  237. //播放成功声音
  238. playSound('../raw/ok.wav');
  239. //下一个条码
  240. next();
  241. //整单完成. 下一个入库单
  242. if(appResponse.extend){cleanAll();}
  243. },
  244. error: function () {
  245. isSubmintIng = false;
  246. nwaiting.close();
  247. playSound('../raw/error.wav');
  248. mui.toast('网络断开或服务器发生异常');
  249. }
  250. });
  251. }
  252. //下一个条码
  253. function next(){
  254. $("#barcode").val("");
  255. $("#inReceiptId").val("");
  256. $("#batchNo").val("");//批次号码
  257. $("#receiptQuantity").val("");//收货数量
  258. $("#quantity").val("");
  259. $("#_quantity").val("0");
  260. $("#recommendLocationCode").val("");
  261. $("#locationCode").val("");
  262. $("#receiptQualityCode").val('');
  263. $("#shelfQualityCode").val("");
  264. $("#barcode").focus();
  265. }
  266. //下一个订单
  267. function cleanAll(){
  268. $("#inOrderId").val("");
  269. $("#inOrderType").val("");
  270. $("#orderNo").val("");
  271. $("#warehouseCode").val("");
  272. $("#customerCode").val("");
  273. $("#barcode").val("");
  274. $("#inReceiptId").val("");
  275. $("#batchNo").val("");//批次号码
  276. $("#receiptQuantity").val("");//收货数量
  277. $("#quantity").val("");
  278. $("#_quantity").val("0");
  279. $("#recommendLocationCode").val("");
  280. $("#locationCode").val("");
  281. $("#receiptQualityCode").val('');
  282. $("#shelfQualityCode").val("");
  283. $("#orderNo").focus();
  284. playSound('../raw/ok.wav');
  285. mui.toast('入库单上架成功,请录入下一单。');
  286. }