product_maintain.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. $(function() {
  2. var focusId;
  3. $('#barcode').focus();
  4. //如不使用延迟执行, 有时候会无效
  5. setTimeout(function() {
  6. $('#barcode').focus();
  7. }, 1000);
  8. $("#length").keyup(function(event){
  9. if(event.keyCode != "13") {
  10. return false;
  11. }
  12. setFocus('width')
  13. })
  14. $("#width").keyup(function(event){
  15. if(event.keyCode != "13") {
  16. return false;
  17. }
  18. setFocus('height')
  19. })
  20. $("#height").keyup(function(event){
  21. if(event.keyCode != "13") {
  22. return false;
  23. }
  24. setFocus('shelfLifeDays')
  25. })
  26. $("#shelfLifeDays").keyup(function(event){
  27. if(event.keyCode != "13") {
  28. return false;
  29. }
  30. setFocus('grossWeight')
  31. })
  32. //提交商品条码
  33. $('#barcode').keyup(function(event) {
  34. if(event.keyCode != "13") {
  35. return false;
  36. }
  37. console.log('submitBarcode')
  38. $("#barcode").val(trimStr($("#barcode").val()));
  39. if($("#barcode").val() != '') {
  40. //播放扫描声音
  41. playSound('../raw/scan.wav');
  42. console.log('submitBarcode:start')
  43. submitBarcode();
  44. }
  45. });
  46. });
  47. var singleBarcodeEntity;
  48. var singleBarcodeId=-1;
  49. var singleBarcodeMap = {};
  50. function submitBarcode() {
  51. $(".allowClear").each(function() {
  52. if($(this).attr('name') != 'barcode'){
  53. $(this).val("")
  54. }
  55. })
  56. $("#customerList").html("")
  57. singleBarcodeId = -1;
  58. var barcode = $("#barcode").val();
  59. var msgBody = {};
  60. msgBody.barcode = barcode;
  61. //序列化成字符串
  62. var msgBodyStr = JSON.stringify(msgBody)
  63. var appRequest = $appRequest; //复制请求封装对象
  64. appRequest.opType = OP_TYPE_MENU.CHECK_PRODUCT2;
  65. appRequest.msg = msgBodyStr; //msg是消息内容主体
  66. console.log("req:"+JSON.stringify(appRequest))
  67. console.log('$appRequestUrl:'+$appRequestUrl)
  68. $.ajax({
  69. type: 'POST',
  70. url: $appRequestUrl,
  71. contentType: "application/json; charset=utf-8",
  72. data: JSON.stringify(appRequest),
  73. success: function(appResponse) {
  74. console.log("appResponse:"+JSON.stringify(appResponse))
  75. if(!appResponse.success || appResponse.extend ==null || appResponse.extend.length == 0) {
  76. playSound('../raw/error.wav');
  77. mui.toast(appResponse.msg);
  78. return;
  79. }
  80. singleBarcodeMap = {};
  81. //
  82. var productBarcodeList = appResponse.extend
  83. if(productBarcodeList.length==1){
  84. singleBarcodeEntity = productBarcodeList[0];
  85. fillBarcodeDetail(singleBarcodeEntity);
  86. setFocus('length')
  87. }
  88. //组装成下拉框
  89. var listCustomer=[];
  90. for (var i =0 ;i < productBarcodeList.length ; i++) {
  91. var productBarcodeSingle = productBarcodeList[i]
  92. singleBarcodeMap[productBarcodeSingle['id']] = productBarcodeSingle;
  93. console.log('this[id]:'+productBarcodeSingle['id'])
  94. console.log('this[customerCode]:'+productBarcodeSingle['customerCode'])
  95. listCustomer.push('<option value="'+productBarcodeSingle['id']+'">'+productBarcodeSingle['customerCode']+'</option>')
  96. }
  97. var listCustomerValue = listCustomer.join('');
  98. if(listCustomer.length>1){
  99. listCustomerValue='<option value="-1">请选择货主</option>'+listCustomerValue;
  100. mui.toast("该条码在系统中存在多条记录,请选择其中一条进行操作");
  101. }
  102. $('#customerList').html(listCustomerValue);
  103. if(listCustomer.length>1){
  104. //customerList
  105. $("#customerList").trigger("click")
  106. }
  107. },
  108. error: function() {
  109. console.log('异常')
  110. playSound('../raw/error.wav');
  111. mui.toast('网络断开或服务器发生异常');
  112. }
  113. });
  114. }
  115. function selectSingleCustomer(obj){
  116. singleBarcodeId = $(obj).val();
  117. if(singleBarcodeId == -1){
  118. $(".allowClear").each(function() {
  119. if($(this).attr('name') != 'barcode'){
  120. $(this).val("")
  121. }
  122. })
  123. return ;
  124. }
  125. singleBarcodeEntity = singleBarcodeMap[singleBarcodeId];
  126. if(singleBarcodeEntity !=null && singleBarcodeEntity){
  127. fillBarcodeDetail(singleBarcodeEntity)
  128. }
  129. setFocus('length')
  130. }
  131. /**
  132. * 填充商品信息
  133. * @param {Object} singleBarcodeEntity
  134. */
  135. function fillBarcodeDetail(singleBarcodeEntity){
  136. singleBarcodeId = singleBarcodeEntity.id;
  137. fillForm(singleBarcodeEntity,['length','width','height','shelfLifeDays','grossWeight','sku'])
  138. }
  139. function fillForm(entity,fileds){
  140. for (var i =0 ; i <fileds.length ; i++) {
  141. var filedSingle = fileds[i];
  142. console.log("filedSingle:"+filedSingle)
  143. var filedValue=entity[filedSingle]
  144. console.log("filedValue:"+filedValue)
  145. if(filedSingle=='grossWeight' && filedValue != null && filedValue != undefined){
  146. filedValue = filedValue*1000.0
  147. }
  148. if(filedValue == null || filedValue == undefined)
  149. filedValue='';
  150. $("[name='"+filedSingle+"']").val(filedValue)
  151. }
  152. }
  153. function getEntity(fileds){
  154. var reqObj = {};
  155. for (var i =0 ; i <fileds.length ; i++) {
  156. var filedSingle = fileds[i];
  157. reqObj[filedSingle] = $("[name='"+filedSingle+"']").val();
  158. }
  159. return reqObj;
  160. }
  161. //提交
  162. function submitMaintain() {
  163. if(singleBarcodeId == -1){
  164. mui.toast("条码在系统中不存在或未选择货主");
  165. return
  166. }
  167. var msgBody = getEntity(['length','width','height','shelfLifeDays','grossWeight','sku','customerCode']);
  168. var grossWeight = msgBody.grossWeight
  169. if(grossWeight != null && grossWeight != undefined && grossWeight!=0){
  170. msgBody.grossWeight = grossWeight/1000.0;
  171. }
  172. msgBody.customerCode = singleBarcodeMap[msgBody.customerCode].customerCode;
  173. //序列化成字符串
  174. var msgBodyStr = JSON.stringify(msgBody)
  175. var appRequest = $appRequest; //复制请求封装对象
  176. appRequest.opType = OP_TYPE_MENU.PRODUCT_MAINTAIN;
  177. appRequest.msg = msgBodyStr; //msg是消息内容主体
  178. plus.nativeUI.showWaiting();
  179. $.ajax({
  180. type: 'POST',
  181. url: $appRequestUrl,
  182. contentType: "application/json; charset=utf-8",
  183. data: JSON.stringify(appRequest),
  184. success: function(appResponse) {
  185. console.log("msgBodyStr:"+msgBodyStr)
  186. console.log("appResponse:"+JSON.stringify(appResponse))
  187. plus.nativeUI.closeWaiting();
  188. if(!appResponse.success) {
  189. playSound('../raw/error.wav');
  190. mui.toast(appResponse.msg);
  191. return;
  192. }
  193. mui.toast(appResponse.msg);
  194. cleanAll();
  195. },
  196. error: function() {
  197. plus.nativeUI.closeWaiting();
  198. playSound('../raw/error.wav');
  199. mui.toast('网络断开或服务器发生异常');
  200. }
  201. });
  202. }
  203. //下一个转移任务
  204. function cleanAll() {
  205. singleBarcodeId = -1;
  206. $(".allowClear").each(function() {
  207. $(this).val("")
  208. })
  209. $("#customerList").html("")
  210. $("#barcode").focus();
  211. }