receipt.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. $(function() {
  2. var focusId;
  3. $("input").focus(function() {});
  4. setTimeout(function() {
  5. $('#orderNo').focus();
  6. }, 1000);
  7. $('#number').keyup(function(event) {
  8. if(event.keyCode != "13") {
  9. return false;
  10. }
  11. $("#number").val(trimStr($("#number").val()));
  12. if($('#number').val() != '') {
  13. //播放扫描声音
  14. playSound('../raw/scan.wav');
  15. submitNumber();
  16. }
  17. });
  18. $('#barcode').keyup(function(event) {
  19. if(event.keyCode != "13") {
  20. return false;
  21. }
  22. $("#barcode").val(trimStr($("#barcode").val()));
  23. if($("#barcode").val() != '') {
  24. //播放扫描声音
  25. playSound('../raw/scan.wav');
  26. submitBarcode();
  27. }
  28. });
  29. $('#productionDate').keyup(function(event) {
  30. if(event.keyCode != "13") {
  31. return false;
  32. }
  33. if($("#productionDate").val() != '') {
  34. //计算效期/批次
  35. var productionDate = $("#productionDate").val()
  36. if(isNaN(productionDate)) {
  37. //mui.alert("生产日期只能输入数字;现输入值为:" + productionDate, '警告', function() {setFocus('productionDate');});
  38. $("#productionDate").val("");//不合法直接清空
  39. return;
  40. }
  41. //验证是否时间是否合法 时间范围必须小于当前时间 不能小于当前时间10年/ 月份范围必须为:1到12 /该月日期必须合法
  42. var checkResult = checkDate8(productionDate);
  43. if(checkResult != "1") {
  44. mui.alert(checkResult, '警告', function() {setFocus('productionDate');});
  45. return;
  46. }
  47. //不能大于当前时间
  48. var isGt = compareCurrentForDate8(productionDate, true)
  49. if(isGt) {
  50. mui.alert("生产日期不能大于当前时间", '警告', function() {setFocus('productionDate');});
  51. return
  52. }
  53. var inOrderItemEnt = inOrderItemMap[inOrderItemId];
  54. //生成效期
  55. var expDate = getExpDate(productionDate, inOrderItemEnt.shelfLifeDays);
  56. if(expDate != null) {
  57. $("#expiryDate").val(expDate)
  58. //生成批次
  59. var batchNo = genBatchNo(inOrderItemEnt.batchRuleCode, expDate);
  60. if(batchNo != null) {
  61. $("#batchNo").val(batchNo);
  62. setFocus("productQty");
  63. } else {
  64. setFocus("batchNo")
  65. }
  66. return
  67. }
  68. }
  69. setFocus("expiryDate")
  70. });
  71. $('#expiryDate').keyup(function(event) {
  72. if(event.keyCode != "13") {
  73. return false;
  74. }
  75. var inOrderItemEnt = inOrderItemMap[inOrderItemId];
  76. if($("#expiryDate").val() != '') {
  77. //校验效期 并且 生成批次
  78. var expiryDate = $("#expiryDate").val();
  79. if(isNaN(expiryDate)) {
  80. //mui.alert("有效日期只能输入数字;现输入值为:" + expiryDate, '警告', function() {setFocus('expiryDate');});
  81. $("#expiryDate").val("");//不合法直接清空
  82. return
  83. }
  84. //验证是否时间是否合法 时间范围必须小于当前时间 不能小于当前时间10年/ 月份范围必须为:1到12 /该月日期必须合法
  85. var checkResult = checkDate8(expiryDate);
  86. if(checkResult != "1") {
  87. mui.alert(checkResult, '警告', function() {setFocus('expiryDate');});
  88. return
  89. }
  90. }
  91. //生成批次
  92. var batchNo = genBatchNo(inOrderItemEnt.batchRuleCode, expiryDate);
  93. console.log('batchNo:' + batchNo)
  94. if(batchNo != null) {
  95. $("#batchNo").val(batchNo);
  96. setFocus("productQty");
  97. } else {
  98. setFocus("batchNo");
  99. }
  100. });
  101. //batchNo
  102. $('#batchNo').keyup(function(event) {
  103. if(event.keyCode != "13") {
  104. return false;
  105. }
  106. setFocus("productQty");
  107. });
  108. $('#productQty').keyup(function(event) {
  109. if(event.keyCode != "13") {
  110. return false;
  111. }
  112. if($("#productQty").val() != '') {
  113. checkAndSubmit();
  114. }
  115. });
  116. });
  117. var inOrderMap = {};
  118. var inOrderId = -1;
  119. //提交入库单号
  120. function submitNumber() {
  121. var number = $('#number').val();
  122. var numberType = $('#numberType').val();
  123. var formData = {
  124. number: number,
  125. numberType: numberType
  126. };
  127. var appRequest = $appRequest; //复制请求封装对象
  128. appRequest.opType = OP_TYPE_MENU.RECEIPT_1;
  129. appRequest.msg = JSON.stringify(formData); //msg是消息内容主体;//msg是消息内容主体
  130. console.log("$appRequestUrl:" + $appRequestUrl)
  131. $.ajax({
  132. type: 'POST',
  133. url: $appRequestUrl,
  134. contentType: "application/json; charset=utf-8",
  135. data: JSON.stringify(appRequest),
  136. success: function(appResponse) {
  137. console.log(JSON.stringify(appResponse))
  138. if(!appResponse.success) {
  139. playSound('../raw/error.wav');
  140. mui.alert(appResponse.msg, '警告', function() {
  141. setFocus('orderNo');
  142. });
  143. return;
  144. }
  145. //mui.toast(appResponse.msg);
  146. var orderList = appResponse.extend;
  147. if(orderList.length == 1) {
  148. //如果有一条 直接查询预报-收货数据
  149. fillOrderDetail(orderList[0]);
  150. return;
  151. }
  152. //如果有多条 弹框选择
  153. if(orderList.length > 1) { //出现多条记录时选择
  154. var listLi = [];
  155. for(var i = 0; i < orderList.length; i++) {
  156. var orderSingle = orderList[i];
  157. inOrderMap[orderSingle.id] = orderSingle;
  158. listLi.push('<li class="mui-table-view-cell" onclick="selectSingleOrder(\'' + orderSingle.id + '\')">货主:' + orderSingle.customerCode + '; 仓库:' + orderSingle.warehouseCode + '; 创建时间:' + fmtDateTime(orderSingle.createdTime) + ' </li>');
  159. }
  160. var listLiStr = listLi.join('')
  161. $("#inOrderListDetail").html(listLiStr);
  162. mui("#inOrderListShow").popover('show'); //show hide toggle
  163. return
  164. }
  165. },
  166. error: function() {
  167. console.log('网络断开或服务器发生异常')
  168. playSound('../raw/error.wav');
  169. mui.toast('网络断开或服务器发生异常');
  170. }
  171. });
  172. }
  173. var inOrderItemMap = {};
  174. var inOrderItemId = -1;
  175. //提交商品条码
  176. function submitBarcode() {
  177. var orderNo = $("#number").val();
  178. var barcode = $('#barcode').val();
  179. var formData = {
  180. inOrderId: inOrderId,
  181. barcode: barcode,
  182. orderNo: orderNo
  183. };
  184. var appRequest = $appRequest; //复制请求封装对象
  185. appRequest.opType = OP_TYPE_MENU.RECEIPT_2;
  186. appRequest.msg = JSON.stringify(formData); //msg是消息内容主体
  187. $.ajax({
  188. type: 'POST',
  189. url: $appRequestUrl,
  190. contentType: "application/json; charset=utf-8",
  191. data: JSON.stringify(appRequest),
  192. success: function(appResponse) {
  193. console.log("appResponse:" + JSON.stringify(appResponse))
  194. if(!appResponse.success) {
  195. playSound('../raw/error.wav');
  196. mui.alert(appResponse.msg, '警告', function() {setFocus('barcode');});
  197. return;
  198. }
  199. mui.toast(appResponse.msg);
  200. //返回预报收货记录 可能是多条
  201. var list = appResponse.extend;
  202. if(list.length > 1) { //出现多条记录时选择
  203. var listLi = [];
  204. for(var i = 0; i < list.length; i++) {
  205. var singleItem = list[i];
  206. inOrderItemMap[singleItem.id] = singleItem;
  207. if(singleItem.receiptTotal == null) {
  208. singleItem.receiptTotal = 0;
  209. }
  210. listLi.push('<li class="mui-table-view-cell" onclick="selectBarcode(\'' + singleItem.id + '\')">批次:' + singleItem.batchNo + '; 商品品质:' + singleItem.qualityName + '; 预报数量:' + singleItem.quantity + '; 已收数量:' + singleItem.receiptTotal + ' </li>');
  211. }
  212. var listLiStr = listLi.join('')
  213. $("#barcodeListDetail").html(listLiStr);
  214. mui("#barcodeListShow").popover('show'); //show hide toggle
  215. return
  216. }
  217. //只有1条时
  218. inOrderItemMap[list[0].id] = list[0];
  219. fillOrderItem(list[0]);
  220. },
  221. error: function() {
  222. playSound('../raw/error.wav');
  223. mui.toast('网络断开或服务器发生异常');
  224. }
  225. });
  226. }
  227. //下一个条码
  228. function next() {
  229. $("#barcode").val("");
  230. $("#inReceiptId").val("");
  231. $("#batchNo").val(""); //批次号码
  232. $("#receiptQuantity").val(""); //收货数量
  233. $("#toReceivingQty").val("");//待收数量
  234. $("#locationCode").val("");
  235. $("#barcode").focus();
  236. }
  237. /**
  238. * 填充明细
  239. */
  240. function fillOrderDetail(orderSingle) {
  241. $("#warehouseCode").val(orderSingle.warehouseCode);
  242. $("#customerCode").val(orderSingle.customerCode);
  243. //inOrderId
  244. inOrderId = orderSingle.id
  245. setFocus("barcode")
  246. }
  247. /**
  248. * 选择其中一单
  249. * @param {Object} id
  250. */
  251. function selectSingleOrder(inOrderId) {
  252. var orderSingle = inOrderMap[inOrderId]
  253. fillOrderDetail(orderSingle)
  254. mui('#inOrderListShow').popover('toggle');
  255. }
  256. /**
  257. * 选择其中一个条码
  258. * @param {Object} inOrderItemId
  259. */
  260. function selectBarcode(inOrderItemId) {
  261. var orderItemSingle = inOrderItemMap[inOrderItemId]
  262. fillOrderItem(orderItemSingle)
  263. mui('#barcodeListShow').popover('toggle');
  264. setFocus('productionDate')
  265. }
  266. function fillOrderItem(orderItemSingle) {
  267. console.log("orderItemSingle:" + JSON.stringify(orderItemSingle))
  268. inOrderItemId = orderItemSingle.id;
  269. //在条码下显示该inorderitem的部分预报信息
  270. $("#preSku").text(orderItemSingle.sku);
  271. $("#preBatchNo").text(orderItemSingle.batchNo);
  272. $("#preQty").text(orderItemSingle.quantity);
  273. $("#preQuality").text(orderItemSingle.qualityName);
  274. var expiryDateStr = fmtDate8(orderItemSingle.expiryDate);
  275. $("#expiryDate").val(expiryDateStr)
  276. var batchNo = orderItemSingle.batchNo;
  277. $("#batchNo").val(batchNo);
  278. var receiptTotal = orderItemSingle.receiptTotal
  279. if(isNaN(receiptTotal) || receiptTotal == null) {
  280. receiptTotal = 0;
  281. orderItemSingle.receiptTotal = receiptTotal;
  282. }
  283. //待收数量
  284. var toReceivingQty = orderItemSingle.quantity - receiptTotal;
  285. $("#toReceivingQty").val(toReceivingQty)
  286. }
  287. /**
  288. * 提交收货
  289. */
  290. function checkAndSubmit() {
  291. var inOrderItemEntity = inOrderItemMap[inOrderItemId];
  292. var quantity = $('#productQty').val(); //本次收货数量
  293. var qtyTotal = inOrderItemEntity.quantity; // 预报总数
  294. qtyTotal = qtyTotal != null ? qtyTotal : 0;
  295. var receiptTotal = inOrderItemEntity.receiptTotal; // 已收货总数 - 不完全准
  296. receiptTotal = receiptTotal != null ? receiptTotal : 0;
  297. var waitReceipt = qtyTotal - receiptTotal; //待收货数
  298. if(quantity > waitReceipt) {
  299. var btnArray = ['否', '是'];
  300. mui.confirm("收货数量大于预报数量,您确定要执行操作吗?建议检查是否重复收货", '警告', btnArray, function(e) {
  301. if(e.index == 1) {
  302. submitReceipt();
  303. }
  304. })
  305. } else {
  306. submitReceipt();
  307. }
  308. }
  309. var isSubmintIng = false; //是否正在提交. 防止按回车太快
  310. //提交收货明细
  311. function submitReceipt() {
  312. if(isSubmintIng) {
  313. return;
  314. }
  315. isSubmintIng = true;
  316. var inOrderItemEntity = inOrderItemMap[inOrderItemId];
  317. var inOrderEntity = inOrderMap[inOrderId]
  318. var orderId = inOrderId;
  319. var barcode = inOrderItemEntity.barcode; //$("#barcode").val();
  320. var itemId = inOrderItemId; //$("#itemId").val();
  321. var sku = inOrderItemEntity.sku; //$("#itemSku").val();
  322. var batchRuleCode = inOrderItemEntity.batchRuleCode; //$("#batchRuleCode").val();
  323. var batchNo = $("#batchNo").val();
  324. var qualityCode = $('#qualityCode').val();
  325. var quantity = $('#productQty').val(); //本次收货数量
  326. //如果保质期跟有效期不为空 dateType取效期
  327. // var dateType = $("#dateType").val();
  328. var productionDate = $("#productionDate").val();
  329. var expiryDate = $("#expiryDate").val();
  330. var shelfLifeDays = $("#shelfLifeDays").val();
  331. var msgBody = {
  332. orderId: orderId,
  333. barcode: barcode,
  334. itemId: itemId,
  335. sku: sku,
  336. batchRuleCode: batchRuleCode,
  337. batchNo: batchNo,
  338. qualityCode: qualityCode,
  339. quantity: quantity,
  340. productionDateStr: productionDate,
  341. expiryDateStr: expiryDate,
  342. shelfLifeDays: shelfLifeDays
  343. };
  344. //序列化成字符串
  345. var msgBodyStr = JSON.stringify(msgBody)
  346. var appRequest = $appRequest; //复制请求封装对象
  347. appRequest.opType = OP_TYPE_MENU.RECEIPT_3;
  348. appRequest.msg = msgBodyStr; //msg是消息内容主体
  349. var nwaiting = plus.nativeUI.showWaiting('正在提交中...');
  350. $.ajax({
  351. type: 'POST',
  352. url: $appRequestUrl, //标准收货方法
  353. contentType: "application/json; charset=utf-8",
  354. data: JSON.stringify(appRequest),
  355. success: function(result) {
  356. isSubmintIng = false;
  357. nwaiting.close();
  358. if(!result.success) {
  359. mui.alert(result.msg, '警告', function() {});
  360. return;
  361. }
  362. inOrderItemMap = {};
  363. inOrderItemId = -1;
  364. var clearClass = $(".allowClear");
  365. $(".allowClear").each(function() {
  366. $(this).val("")
  367. })
  368. //继续操作. 光标移至条码
  369. setFocus('barcode');
  370. mui.toast(result.msg);
  371. },
  372. error: function() {
  373. isSubmintIng = false;
  374. nwaiting.close();
  375. mui.alert('网络断开或服务器发生异常', '注意', function() {});
  376. }
  377. });
  378. }
  379. var isShowDetails = false;
  380. function showDetails() {
  381. alert(isShowDetails)
  382. if(!isShowDetails) {
  383. $("#showDetails").show();
  384. isShowDetails = true;
  385. $("#showIco").attr("class", "fa fa-angle-double-up");
  386. //显示明细
  387. } else {
  388. $("#showDetails").hide();
  389. isShowDetails = false;
  390. $("#showIco").attr("class", "fa fa-angle-double-down");
  391. }
  392. }
  393. //下一个订单
  394. function cleanAll() {
  395. $("input").each(function() {
  396. $(this).val('')
  397. })
  398. // /number
  399. setFocus('number');
  400. }