inventory_mv_random.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. //如不使用延迟执行, 有时候会无效
  10. setTimeout(function() {
  11. var $warehouseCode = localStorage.getItem('$warehouseCode');
  12. $("#warehouseCode").val($warehouseCode);
  13. $('#outShelfLocationCode').focus();
  14. }, 1000);
  15. //当失去焦点按回车时,焦点回到之前焦点位置
  16. $(window).keydown(function(event){
  17. if((event.keyCode==13)) {
  18. if(document.activeElement.id == null || document.activeElement.id ==''){
  19. //回到上次焦点地方
  20. //$("#"+focusId).focus();
  21. }
  22. }
  23. });
  24. //提交下架库位
  25. $('#outShelfLocationCode').keyup(function (event) {
  26. if (event.keyCode != "13") {return false;}
  27. $("#outShelfLocationCode").val(trimStr($("#outShelfLocationCode").val()));
  28. if($('#outShelfLocationCode').val()!=''){
  29. //播放扫描声音
  30. playSound('../raw/scan.wav');
  31. submitOutShelfLocationCode();
  32. }
  33. });
  34. //提交商品条码
  35. $('#barcode').keyup(function (event) {
  36. console.log("barcode:"+event.keyCode)
  37. if (event.keyCode != "13") {return false;}
  38. console.log("barcode")
  39. $("#barcode").val(trimStr($("#barcode").val()));
  40. if($("#barcode").val() !='' ){
  41. //播放扫描声音
  42. playSound('../raw/scan.wav');
  43. submitBarcode();
  44. }
  45. });
  46. //输入转移数量
  47. $('#qty').keyup(function (event) {
  48. if (event.keyCode != "13") {return false;}
  49. $("#qty").val(trimStr($("#qty").val()));
  50. if($("#qty").val() =='' || $("#qty").val() == 0){
  51. return;
  52. }
  53. if(isNaN($("#qty").val())){
  54. playSound('../raw/error.wav');
  55. mui.toast($("#qty").val()+'不是一个数字');
  56. return;
  57. }
  58. if(parseInt($("#sysQty").val()) < parseInt($("#qty").val())){
  59. playSound('../raw/error.wav');
  60. mui.toast('转移数量不能大于可用数量');
  61. return;
  62. }
  63. if(parseInt($("#qty").val())<=0){
  64. playSound('../raw/error.wav');
  65. mui.toast('转移数量不能小于等于0');
  66. return;
  67. }
  68. playSound('../raw/scan.wav');
  69. //输入数量回车,光标到上架库位
  70. setFocus('onShelfLocationCode')
  71. });
  72. //提交上架库位
  73. $('#onShelfLocationCode').keyup(function (event) {
  74. if (event.keyCode != "13") {return false;}
  75. $("#onShelfLocationCode").val(trimStr($("#onShelfLocationCode").val()));
  76. if($("#onShelfLocationCode").val() !='' ){
  77. submitInventoryMv();
  78. }
  79. });
  80. });
  81. //提交下架库位
  82. function submitOutShelfLocationCode(){
  83. var outShelfLocationCode=$("#outShelfLocationCode").val();
  84. var msgBody = {};
  85. msgBody.outShelfLocationCode=outShelfLocationCode;
  86. msgBody.warehouseCode=$("#warehouseCode").val();
  87. //序列化成字符串
  88. var msgBodyStr=JSON.stringify(msgBody)
  89. var appRequest = $appRequest;//复制请求封装对象
  90. appRequest.opType = OP_TYPE_MENU.INVENTORY_RANDOM_MV_1;
  91. appRequest.msg = msgBodyStr;//msg是消息内容主体
  92. $.ajax({
  93. type: 'POST',
  94. url: $appRequestUrl,
  95. contentType: "application/json; charset=utf-8",
  96. data: JSON.stringify(appRequest),
  97. success: function (appResponse) {
  98. if(!appResponse.success){
  99. playSound('../raw/error.wav');
  100. mui.toast(appResponse.msg);
  101. return;
  102. }
  103. mui.toast(appResponse.msg);
  104. setFocus('barcode');
  105. },
  106. error: function () {
  107. playSound('../raw/error.wav');
  108. mui.toast('网络断开或服务器发生异常');
  109. }
  110. });
  111. }
  112. //提交商品条码
  113. var inventoryMap = {};
  114. var outShelfInventoryId = -1;
  115. function submitBarcode() {
  116. outShelfInventoryId = -1;
  117. var outShelfLocationCode = $("#outShelfLocationCode").val();
  118. var barcode = $("#barcode").val();
  119. var msgBody = {};
  120. msgBody.outShelfLocationCode = outShelfLocationCode;
  121. msgBody.warehouseCode = $("#warehouseCode").val();
  122. msgBody.barcode = barcode;
  123. //序列化成字符串
  124. var msgBodyStr = JSON.stringify(msgBody)
  125. var appRequest = $appRequest; //复制请求封装对象
  126. appRequest.opType = OP_TYPE_MENU.INVENTORY_RANDOM_MV_2;
  127. appRequest.msg = msgBodyStr; //msg是消息内容主体
  128. console.log("$appRequestUrl:"+$appRequestUrl)
  129. $.ajax({
  130. type: 'POST',
  131. url: $appRequestUrl,
  132. contentType: "application/json; charset=utf-8",
  133. data: JSON.stringify(appRequest),
  134. success: function(appResponse) {
  135. if(!appResponse.success) {
  136. playSound('../raw/error.wav');
  137. mui.toast(appResponse.msg);
  138. return;
  139. }
  140. $("#barcodeShow").val(barcode);
  141. var listInventory = appResponse.extend;
  142. if(listInventory.length > 1) { //出现多条记录时选择
  143. var listLi = [];
  144. for(var i = 0; i < listInventory.length; i++) {
  145. var inventorySingle = listInventory[i];
  146. inventoryMap[inventorySingle.id] = inventorySingle;
  147. listLi.push('<li class="mui-table-view-cell" onclick="selectInventory(\'' + inventorySingle.id + '\')">批次:' + inventorySingle.batchNo + '; 商品品质:' + inventorySingle.qualityName + '; 溯源:' + inventorySingle.inOrderNo1 + '; 可用数量:' + inventorySingle.qtyAvail + ' </li>');
  148. }
  149. var listLiStr = listLi.join('')
  150. $("#inventoryListDetail").html(listLiStr);
  151. mui("#inventoryListShow").popover('show'); //show hide toggle
  152. return
  153. }
  154. var inventorySingle = listInventory[0];
  155. $("#inOrderNo").val(inventorySingle.inOrderNo1);
  156. $("#batchNo").val(inventorySingle.batchNo)
  157. $("#qualityName").val(inventorySingle.qualityName)
  158. $("#sysQty").val(inventorySingle.qtyAvail)
  159. outShelfInventoryId = inventorySingle.id;
  160. console.log("outShelfInventoryId:" + outShelfInventoryId)
  161. setFocus('qty');
  162. },
  163. error: function() {
  164. playSound('../raw/error.wav');
  165. mui.toast('网络断开或服务器发生异常');
  166. }
  167. });
  168. }
  169. //选择一个库存
  170. function selectInventory(inventoryId){
  171. outShelfInventoryId = inventoryId;
  172. var inventorySingle=inventoryMap[outShelfInventoryId]
  173. $("#inOrderNo").val(inventorySingle.inOrderNo1);
  174. $("#batchNo").val(inventorySingle.batchNo)
  175. $("#qualityName").val(inventorySingle.qualityName)
  176. $("#sysQty").val(inventorySingle.qtyAvail)
  177. mui('#inventoryListShow').popover('toggle');
  178. setFocus('qty');
  179. }
  180. //提交完成移位
  181. var isSubmintIng = false;//是否正在提交. 防止按回车太快
  182. function submitInventoryMv() {
  183. if(isSubmintIng){return;}
  184. isSubmintIng = true;
  185. var outShelfLocationCode = $("#outShelfLocationCode").val();
  186. var barcode = $("#barcode").val();
  187. var onShelfLocationCode = $("#onShelfLocationCode").val();
  188. var qty = $("#qty").val();
  189. var msgBody = {};
  190. msgBody.outShelfLocationCode = outShelfLocationCode;
  191. msgBody.warehouseCode = $("#warehouseCode").val();
  192. msgBody.barcode = barcode;
  193. msgBody.onShelfLocationCode = onShelfLocationCode;
  194. msgBody.outShelfInventoryId = outShelfInventoryId;
  195. msgBody.qty = qty;
  196. //序列化成字符串
  197. var msgBodyStr = JSON.stringify(msgBody)
  198. var appRequest = $appRequest; //复制请求封装对象
  199. appRequest.opType = OP_TYPE_MENU.INVENTORY_RANDOM_MV_4;
  200. appRequest.msg = msgBodyStr; //msg是消息内容主体
  201. if(outShelfLocationCode == null || outShelfLocationCode == '') {
  202. playSound('../raw/error.wav');
  203. mui.toast('请输入下架库位');
  204. isSubmintIng = false;
  205. return;
  206. }
  207. if(barcode == null || barcode == '') {
  208. playSound('../raw/error.wav');
  209. mui.toast('请输入商品条码');
  210. isSubmintIng = false;
  211. return;
  212. }
  213. if(outShelfInventoryId == -1) {
  214. playSound('../raw/error.wav');
  215. mui.toast('请先提交下架库位,商品条码');
  216. isSubmintIng = false;
  217. return;
  218. }
  219. if(qty == '' || qty < 0) {
  220. playSound('../raw/error.wav');
  221. mui.toast('转移数量必须大于0');
  222. isSubmintIng = false;
  223. return;
  224. }
  225. if(onShelfLocationCode == null || onShelfLocationCode == '') {
  226. playSound('../raw/error.wav');
  227. mui.toast('请输入上架库位');
  228. isSubmintIng = false;
  229. return;
  230. }
  231. if(onShelfLocationCode == outShelfLocationCode) {
  232. playSound('../raw/error.wav');
  233. mui.toast('下架库位号跟上架库位号不能相同');
  234. isSubmintIng = false;
  235. return;
  236. }
  237. playSound('../raw/scan.wav');
  238. mui(document.getElementById("subButton")).button('loading'); //切换为loading状态
  239. var nwaiting = plus.nativeUI.showWaiting('正在提交中...');
  240. $.ajax({
  241. type: 'POST',
  242. url: $appRequestUrl,
  243. contentType: "application/json; charset=utf-8",
  244. data: JSON.stringify(appRequest),
  245. success: function(appResponse) {
  246. isSubmintIng = false;
  247. nwaiting.close();
  248. mui(document.getElementById("subButton")).button('reset'); //重置button
  249. if(!appResponse.success) {
  250. playSound('../raw/error.wav');
  251. mui.alert(appResponse.msg, '警告', function() {
  252. //移库失败,光标停留在上架库位
  253. setFocus('onShelfLocationCode');
  254. });
  255. return;//return无效的,mui.alert是异步的
  256. } else {
  257. //不写在else里,也会被执行
  258. playSound('../raw/ok.wav');
  259. mui.toast(appResponse.msg);
  260. cleanAll()
  261. }
  262. },
  263. error: function() {
  264. isSubmintIng = false;
  265. playSound('../raw/error.wav');
  266. mui.toast('网络断开或服务器发生异常');
  267. }
  268. });
  269. }
  270. //下一个转移任务
  271. function cleanAll() {
  272. $(".allowClear").each(function() {
  273. $(this).val("")
  274. })
  275. $("#outShelfLocationCode").focus();
  276. }