inventory_check_plan.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. $('#inventoryCheckCode').focus();
  11. }, 1000);
  12. //当失去焦点按回车时,焦点回到之前焦点位置
  13. $(window).keydown(function(event){
  14. if((event.keyCode==13)) {
  15. if(document.activeElement.id == null || document.activeElement.id ==''){
  16. //回到上次焦点地方
  17. //$("#"+focusId).focus();
  18. }
  19. }
  20. });
  21. $('#inventoryCheckCode').keyup(function (event) {
  22. if (event.keyCode != "13") {return false;}
  23. $("#inventoryCheckCode").val(trimStr($("#inventoryCheckCode").val()));
  24. if($('#inventoryCheckCode').val()!=''){
  25. //播放扫描声音
  26. playSound('../raw/scan.wav');
  27. submitCheckCode();
  28. }
  29. });
  30. $('#locationCode').keyup(function (event) {
  31. if (event.keyCode != "13") {return false;}
  32. $("#locationCode").val(trimStr($("#locationCode").val()));
  33. if($("#locationCode").val() !='' ){
  34. //播放扫描声音
  35. playSound('../raw/scan.wav');
  36. submitLocationCode();
  37. }
  38. });
  39. $('#barcode').keyup(function (event) {
  40. if (event.keyCode != "13") {return false;}
  41. $("#barcode").val(trimStr($("#barcode").val()));
  42. if($("#barcode").val() !='' ){
  43. //播放扫描声音
  44. playSound('../raw/scan.wav');
  45. submitBarcode();
  46. }
  47. });
  48. $('#batchNo').keyup(function (event) {
  49. if (event.keyCode != "13") {return false;}
  50. $("#batchNo").val(trimStr($("#batchNo").val()));
  51. if($("#batchNo").val() !='' ){
  52. var a = $("#batchNo").val();
  53. var b = a.toUpperCase();
  54. $("#batchNo").val(b);
  55. //播放扫描声音
  56. playSound('../raw/scan.wav');
  57. submitBatchNo();
  58. }
  59. });
  60. $('#checkQty').keyup(function (event) {
  61. if (event.keyCode != "13") {return false;}
  62. if($("#checkQty").val() !='' ){
  63. //提交上架
  64. submitInventoryCheck();
  65. }
  66. });
  67. });
  68. //提交入库单号
  69. function submitCheckCode(){
  70. var inventoryCheckCode = $('#inventoryCheckCode').val();
  71. var appRequest = $appRequest;//复制请求封装对象
  72. appRequest.opType = OP_TYPE_MENU.INVENTORY_PLAN_CHECK_1;
  73. appRequest.msg = inventoryCheckCode;//msg是消息内容主体
  74. $.ajax({
  75. type: 'POST',
  76. url: $appRequestUrl,
  77. contentType: "application/json; charset=utf-8",
  78. data: JSON.stringify(appRequest),
  79. success: function (appResponse) {
  80. if(!appResponse.success){
  81. playSound('../raw/error.wav');
  82. mui.alert(appResponse.msg, '警告', function() { setFocus('inventoryCheckCode'); });
  83. return;
  84. }
  85. mui.toast(appResponse.msg);
  86. var check = appResponse.extend;
  87. $("#inventoryCheckId").val(check.id);
  88. $("#warehouseCode").val(check.warehouseCode);
  89. $("#customerCode").val(check.customerCode);
  90. $("#customerId").val(check.customerId);
  91. nextLocation();
  92. getNextLocationCode();
  93. },
  94. error: function () {
  95. playSound('../raw/error.wav');
  96. mui.toast('网络断开或服务器发生异常');
  97. }
  98. });
  99. }
  100. function submitLocationCode(){
  101. var inventoryCheckId = $("#inventoryCheckId").val();
  102. var warehouseCode = $("#warehouseCode").val();
  103. var customerCode = $("#customerCode").val();
  104. var customerId = $("#customerId").val();
  105. var locationCode = $("#locationCode").val();
  106. var formData = {
  107. inventoryCheckId:inventoryCheckId,
  108. warehouseCode:warehouseCode,
  109. customerCode:customerCode,
  110. customerId:customerId,
  111. locationCode:locationCode
  112. };
  113. var appRequest = $appRequest;//复制请求封装对象
  114. appRequest.opType = OP_TYPE_MENU.INVENTORY_PLAN_CHECK_2;
  115. appRequest.msg = JSON.stringify(formData);//msg是消息内容主体
  116. $.ajax({
  117. type: 'POST',
  118. url: $appRequestUrl,
  119. contentType: "application/json; charset=utf-8",
  120. data: JSON.stringify(appRequest),
  121. success: function (appResponse) {
  122. if(!appResponse.success){
  123. playSound('../raw/error.wav');
  124. mui.alert(appResponse.msg, '警告', function() { setSelect('locationCode'); });
  125. return;
  126. }
  127. //mui.toast(appResponse.msg);
  128. //返回收货记录 可能是多条
  129. var list = appResponse.extend;
  130. if(list.length == 0 ){
  131. //2019-05-10改为库位只要存在就行
  132. $('#barcode').val("");
  133. $('#barcode').focus();
  134. //playSound('../raw/error.wav');
  135. //mui.alert('后台返回list长度为0', '警告', function() { setSelect('locationCode'); });
  136. return;
  137. }
  138. refreshItems();
  139. //默认显示第一个商品条码
  140. //var checkDetail = list[0];
  141. //$("#barcode").val(checkDetail.barcode);//条码
  142. $('#barcode').val("");
  143. $('#barcode').focus();
  144. //跳到条码并选中
  145. //setSelect('barcode');
  146. },
  147. error: function () {
  148. playSound('../raw/error.wav');
  149. mui.toast('网络断开或服务器发生异常');
  150. }
  151. });
  152. }
  153. //提交商品条码
  154. function submitBarcode(){
  155. var inventoryId = $("#inventoryId").val();//库存记录id
  156. var barcodeShow = $("#barcodeShow").val();
  157. var barcode = $('#barcode').val();
  158. if(barcodeShow != barcode){
  159. //展示条码和当前扫描的条码不一样,说明换商品了.要不要提交展示条码的盘点数量submitInventoryCheck?
  160. //若自动提交,适合拿一件扫一件的情况,需考虑叠加的问题
  161. exeSubmitBarcode();
  162. return;
  163. }
  164. var checkQty = $("#checkQty").val();
  165. if(checkQty == null || checkQty == ''){checkQty = 0;}
  166. $("#checkQty").val((parseInt(checkQty)+1));
  167. //回到条码输入框,用户应当继续扫描条码
  168. $("#barcode").val('');//清空条码,用户只需要看展示条码,最后手工点击提交
  169. setSelect('barcode');
  170. }
  171. function exeSubmitBarcode(){
  172. var inventoryCheckId = $("#inventoryCheckId").val();
  173. var warehouseCode = $("#warehouseCode").val();
  174. var customerCode = $("#customerCode").val();
  175. var customerId = $("#customerId").val();
  176. var locationCode = $("#locationCode").val();
  177. var barcode = $("#barcode").val();
  178. if(barcode == ''){
  179. return;
  180. }
  181. var formData = {
  182. inventoryCheckId:inventoryCheckId,
  183. warehouseCode:warehouseCode,
  184. customerCode:customerCode,
  185. customerId:customerId,
  186. locationCode:locationCode,
  187. barcode:barcode
  188. };
  189. var appRequest = $appRequest;//复制请求封装对象
  190. appRequest.opType = OP_TYPE_MENU.INVENTORY_PLAN_CHECK_3;
  191. appRequest.msg = JSON.stringify(formData);//msg是消息内容主体
  192. $.ajax({
  193. type: 'POST',
  194. url: $appRequestUrl,
  195. contentType: "application/json; charset=utf-8",
  196. data: JSON.stringify(appRequest),
  197. success: function (appResponse) {
  198. if(!appResponse.success){
  199. playSound('../raw/error.wav');
  200. mui.alert(appResponse.msg, '警告', function() { setFocus('barcode'); });
  201. return;
  202. }
  203. $("#barcodeShow").val(barcode);
  204. $("#barcode").val("");
  205. $('#checkQty').val(1);//盘点数量
  206. //mui.toast(appResponse.msg);
  207. //返回收货记录 可能是多条
  208. var list = appResponse.extend;
  209. //2019-05-09改为可以输入该库位原本没有的商品条码
  210. if(list.length == 0 ){
  211. //去输入批次号码
  212. mui.toast("该库位,商品条码未找到现有库存,请手工输入批次号码");
  213. $('#sysQty').val("0");//系统数量
  214. $("#batchNo").val("");
  215. $("#batchNo").removeAttr("readonly");
  216. $("#batchNo").focus();
  217. //系统自动输入批次?
  218. $("#qualityName").val("");
  219. $("#qualityCode").val("0");
  220. $('#qualityName').hide();//隐藏原品质
  221. $('#qualityCode').show();//显示可选批次
  222. //playSound('../raw/error.wav');
  223. //mui.alert('后台返回list长度为0', '警告', function() { setFocus('barcode'); });
  224. return;
  225. }
  226. //暂先只处理第一条.. 后续可改为界面选择一条
  227. //提醒客户这个条码有几个批次
  228. mui.toast("该库位,条码下有"+list.length+"个批次待盘点,请注意分批次盘点");
  229. var checkDetail = list[0];
  230. $("#inventoryCheckDetailId").val(checkDetail.id);//
  231. $("#inventoryId").val(checkDetail.inventoryId);//库存记录id
  232. $("#inOrderNo").val(checkDetail.inOrderNo);
  233. $("#batchNo").val(checkDetail.batchNo);//批次号码
  234. $('#qualityName').val(checkDetail.qualityName);//品质
  235. $('#qualityCode').val(checkDetail.qualityCode);//品质
  236. $('#qualityCode').hide();//隐藏可选批次
  237. $('#qualityName').show();//显示原品质
  238. $("#batchNo").attr("readonly","readonly");
  239. $('#sysQty').val(checkDetail.sysQty);//系统数量
  240. },
  241. error: function () {
  242. playSound('../raw/error.wav');
  243. mui.toast('网络断开或服务器发生异常');
  244. }
  245. });
  246. }
  247. //提交批次号码
  248. function submitBatchNo(){
  249. var barcodeShow = $("#barcodeShow").val();
  250. if(barcodeShow == ''){
  251. return;
  252. }
  253. //提示选择库存品质
  254. //setSelect('qualityCode');
  255. $("#qualityCode").focus();
  256. //去条码输入框
  257. //setSelect('barcode');
  258. }
  259. var isSubmintIng = false;//是否正在提交. 防止按回车太快
  260. function submitInventoryCheck(){
  261. if(isSubmintIng){return;}
  262. isSubmintIng = true;
  263. var inventoryCheckCode = $("#inventoryCheckCode").val();
  264. var inventoryCheckId = $("#inventoryCheckId").val();
  265. var warehouseCode = $("#warehouseCode").val();
  266. var customerCode = $("#customerCode").val();
  267. var customerId = $("#customerId").val();
  268. var inventoryCheckDetailId = $("#inventoryCheckDetailId").val();
  269. var inventoryId = $("#inventoryId").val();
  270. var locationCode = $("#locationCode").val();
  271. var barcode = $("#barcode").val();
  272. var barcodeShow = $("#barcodeShow").val();
  273. barcode = barcodeShow;
  274. var inOrderNo = $("#inOrderNo").val();
  275. var batchNo = $("#batchNo").val();//批次号码
  276. var qualityName = $("#qualityName").val();
  277. var qualityCode = $("#qualityCode").val();
  278. var sysQty = $("#sysQty").val();
  279. var checkQty = $("#checkQty").val();
  280. if(inventoryCheckId == ''){
  281. mui.toast('请先提交盘点单号');
  282. isSubmintIng = false;
  283. return;
  284. }
  285. if(locationCode == ''){
  286. mui.toast('库位不能为空');
  287. isSubmintIng = false;
  288. return;
  289. }
  290. if(checkQty == '' || checkQty < 0){
  291. mui.toast('盘点数量不能小于0');
  292. isSubmintIng = false;
  293. return;
  294. }
  295. if(barcodeShow == ''){
  296. mui.toast('请先在商品条码输入框按回车');
  297. isSubmintIng = false;
  298. return;
  299. }
  300. var formData = {
  301. inventoryCheckCode:inventoryCheckCode,
  302. inventoryCheckId:inventoryCheckId,
  303. barcode:barcode,
  304. inventoryCheckDetailId:inventoryCheckDetailId,
  305. inventoryId:inventoryId,
  306. locationCode:locationCode,
  307. sysQty:sysQty,
  308. checkQty:checkQty,
  309. inOrderNo:inOrderNo,
  310. batchNo:batchNo,
  311. qualityName:qualityName,
  312. qualityCode:qualityCode
  313. };
  314. var appRequest = $appRequest;//复制请求封装对象
  315. appRequest.opType = OP_TYPE_MENU.INVENTORY_PLAN_CHECK_4;
  316. appRequest.msg = JSON.stringify(formData);//msg是消息内容主体
  317. var nwaiting = plus.nativeUI.showWaiting('正在提交中...');
  318. $.ajax({
  319. type: 'POST',
  320. url: $appRequestUrl,
  321. contentType: "application/json; charset=utf-8",
  322. data: JSON.stringify(appRequest),
  323. success: function (appResponse) {
  324. isSubmintIng = false;
  325. nwaiting.close();
  326. if(!appResponse.success){
  327. playSound('../raw/error.wav');
  328. mui.alert(appResponse.msg, '警告', function() { setFocus('locationCode'); });
  329. return;
  330. }
  331. mui.toast(appResponse.msg);
  332. //播放成功声音
  333. playSound('../raw/ok.wav');
  334. //下一个库位
  335. nextLocation();
  336. //获取下一个库位
  337. getNextLocationCode();
  338. //整单完成. 下一个盘点单
  339. if(appResponse.extend){cleanAll();}
  340. },
  341. error: function () {
  342. isSubmintIng = false;
  343. nwaiting.close();
  344. playSound('../raw/error.wav');
  345. mui.toast('网络断开或服务器发生异常');
  346. }
  347. });
  348. }
  349. function getNextLocationCode(){
  350. var inventoryCheckId = $("#inventoryCheckId").val();
  351. var appRequest = $appRequest;//复制请求封装对象
  352. appRequest.opType = OP_TYPE_MENU.INVENTORY_PLAN_CHECK_NEXT_LOCATION;
  353. appRequest.msg = inventoryCheckId;//msg是消息内容主体
  354. var locationCode = "";
  355. $.ajax({
  356. type: 'POST',
  357. url: $appRequestUrl,
  358. contentType: "application/json; charset=utf-8",
  359. data: JSON.stringify(appRequest),
  360. async:false,
  361. success: function (appResponse) {
  362. if(!appResponse.success){
  363. return;
  364. }
  365. locationCode = appResponse.msg;
  366. $("#prosess").html(appResponse.extend);
  367. //$("#nextLocation").val(locationCode);//推荐库位
  368. $("#nextLocation").html(locationCode);
  369. }
  370. });
  371. return locationCode;
  372. }
  373. //下一个条码
  374. function nextLocation(){
  375. $("#inventoryCheckDetailId").val("");
  376. $("#inventoryId").val("");
  377. $("#locationCode").val("");
  378. $("#barcode").val("");
  379. $("#barcodeShow").val("");
  380. $("#inOrderNo").val("");
  381. $("#barcode").val("");
  382. $("#batchNo").val("");//批次号码
  383. $("#qualityName").val("");
  384. $("#qualityCode").val("0");
  385. $('#qualityCode').hide();//隐藏可选批次
  386. $('#qualityName').show();//显示原品质
  387. $("#batchNo").attr("readonly","readonly");
  388. $("#sysQty").val("");
  389. $("#checkQty").val("");
  390. $("#locationCode").focus();
  391. }
  392. //下一个订单
  393. function cleanAll(){
  394. $("#inventoryCheckCode").val("");
  395. $("#inventoryCheckId").val("");
  396. $("#warehouseCode").val("");
  397. $("#customerCode").val("");
  398. $("#customerId").val("");
  399. $("#inventoryCheckDetailId").val("");
  400. $("#inventoryId").val("");
  401. $("#locationCode").val("");
  402. $("#barcode").val("");
  403. $("#barcodeShow").val("");
  404. $("#inOrderNo").val("");
  405. $("#barcode").val("");
  406. $("#batchNo").val("");//批次号码
  407. $("#qualityName").val("");
  408. $("#qualityCode").val("0");
  409. $('#qualityCode').hide();//隐藏可选批次
  410. $('#qualityName').show();//显示原品质
  411. $("#batchNo").attr("readonly","readonly");
  412. $("#sysQty").val("");
  413. $("#checkQty").val("0");
  414. $("#prosess").html("");
  415. //$("#nextLocation").val("");//推荐库位
  416. $("#nextLocation").html("");//推荐库位
  417. $("#inventoryCheckCode").focus();
  418. }
  419. //打开和关闭待盘点明细展示
  420. var isShowDetails = false;
  421. function showDetails(){
  422. if(!isShowDetails){
  423. $("#showDetails").show();
  424. isShowDetails = true;
  425. $("#showIco").attr("class", "fa fa-angle-double-up");
  426. //刷新明细
  427. refreshItems();
  428. }else{
  429. $("#showDetails").hide();
  430. isShowDetails = false;
  431. $("#showIco").attr("class", "fa fa-angle-double-down");
  432. }
  433. //回到上次焦点地方
  434. if(focusId!=null && focusId != ''){
  435. $("#"+focusId).focus();
  436. }
  437. }
  438. function refreshItems(){
  439. var inventoryCheckId = $("#inventoryCheckId").val();
  440. var warehouseCode = $("#warehouseCode").val();
  441. var customerCode = $("#customerCode").val();
  442. var customerId = $("#customerId").val();
  443. var locationCode = $("#locationCode").val();
  444. if(inventoryCheckId == '' || locationCode == ''){return;}
  445. $("#itemList").empty();
  446. var formData = {
  447. inventoryCheckId:inventoryCheckId,
  448. warehouseCode:warehouseCode,
  449. customerCode:customerCode,
  450. customerId:customerId,
  451. locationCode:locationCode
  452. };
  453. var appRequest = $appRequest;//复制请求封装对象
  454. appRequest.opType = OP_TYPE_MENU.INVENTORY_PLAN_CHECK_2;
  455. appRequest.msg = JSON.stringify(formData);//msg是消息内容主体
  456. $.ajax({
  457. type: 'POST',
  458. url: $appRequestUrl,
  459. contentType: "application/json; charset=utf-8",
  460. data: JSON.stringify(appRequest),
  461. success: function (appResponse) {
  462. if(!appResponse.success){
  463. playSound('../raw/error.wav');
  464. return;
  465. }
  466. var list = appResponse.extend;
  467. if(list.length == 0 ){
  468. playSound('../raw/error.wav');
  469. return;
  470. }
  471. for(var index = 0; index < list.length; index ++){
  472. var item = list[index];
  473. handleNullFiled(item);
  474. var tr = "<tr id='item_"+item.id+"'>";
  475. tr += "<th><div style='width:100%;overflow: hidden;font-size: 9pt;text-align: left;'>"+item.barcode+"</div></th>";
  476. tr += "<th><div style='width:100%;overflow: hidden;font-size: 9pt;text-align: left;'>"+item.batchNo+"</div></th>";
  477. tr += "<th><div style='width:100%;overflow: hidden;font-size: 9pt;text-align: left;'>"+item.sysQty+"</div></th>";
  478. tr += "</tr>";
  479. $("#itemList").append(tr);
  480. }
  481. },
  482. error: function () {
  483. playSound('../raw/error.wav');
  484. mui.toast('网络断开或服务器发生异常');
  485. }
  486. });
  487. }
  488. function selectQuality(){
  489. var qualityCode = $("#qualityCode").val();
  490. if(qualityCode != '0'){
  491. //去条码输入框
  492. setSelect('barcode');
  493. }
  494. }