旭捷内部项目管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
5.6 KiB

10 months ago
  1. var userId = $("#current_id").val();
  2. var userName = $("#current_username").val();
  3. var site = $("#current_site").val();
  4. var toolDetailList = new Array();
  5. var locationDate;
  6. //页面初始化
  7. $(function(){
  8. // 初始化录入时间
  9. InitStorageTime();
  10. // 初始化光标
  11. $("#tool_detail").focus();
  12. });
  13. // 初始化入库日期
  14. function InitStorageTime(){
  15. var data = getNowFormatDate();
  16. data = data.substring(0, 10);
  17. $("#storage_time").val(data);
  18. }
  19. //为工具实例条码绑定一个失去焦点事件
  20. $("#tool_detail").bind("keydown",function(event){
  21. if (event.keyCode == 13) {
  22. var toolInstanceId = $(this).val();
  23. if(toolInstanceId == null || toolInstanceId == ""){
  24. layer.msg("请输入正确的实例编码!");
  25. $(this).val("");
  26. $(this).focus();
  27. }else {
  28. getToolInstanceData(toolInstanceId);
  29. }
  30. }
  31. });
  32. //为工具实例条码绑定一个失去焦点事件
  33. $("#locationId").bind("keydown",function(event){
  34. if (event.keyCode == 13) {
  35. var locationId = $(this).val();
  36. if(locationId == null || locationId == ""){
  37. layer.msg("请输入正确的库位编码!");
  38. $(this).val("");
  39. $(this).focus();
  40. }else {
  41. getLocation(locationId);
  42. }
  43. }
  44. });
  45. // 获取获取工具实例编码
  46. function getToolInstanceData(toolInstanceId){
  47. $("#tool_detail").val("");
  48. var jsonData = {
  49. site : site,
  50. toolInstanceId : toolInstanceId,
  51. }
  52. $.ajax({
  53. url: "/toolPda/getToolDetail",
  54. contentType: 'application/json',
  55. type:"POST",
  56. data:JSON.stringify(jsonData),//你的formid
  57. dataType:"JSON",
  58. async: false,
  59. beforeSend: function(request) {
  60. request.setRequestHeader("token", $.cookie("token"));
  61. },
  62. success: function (data) {
  63. if(data.code == 401 || data.code == 500){
  64. window.location.href="/login";
  65. }
  66. var row = data.row;
  67. if(row != null || row == ""){
  68. if(row.status != "在库"){
  69. layer.msg("该工具状态错误!");
  70. return false;
  71. }
  72. for (let i = 0; i < toolDetailList.length; i++) {
  73. if(toolDetailList[i].toolInstanceId == row.toolInstanceId){
  74. layer.msg("已有该工具记录!");
  75. $("#tool_detail").focus();
  76. return;
  77. }
  78. }
  79. toolDetailList.push(row);
  80. var str = '<tr id = '+row.toolInstanceId+'>' +
  81. '<th class="" style="text-align:center;background-color: #ffff;">' +
  82. '<span>'+row.toolInstanceId+'</span></th>' +
  83. '<th class="" style="text-align:center;background-color: #ffff;">' +
  84. '<span>'+row.toolDescription+'</span></th>' +
  85. '<th class="" style="text-align:center;background-color: #ffff;">' +
  86. '<span>'+row.locationId+'</span></th>' +
  87. '<th class="" style="text-align:center;background-color: #ffff;">' +
  88. '<button data-toggle="modal" onclick="remove(\''+row.toolInstanceId +'\')" style="padding: 3px 10px;">' +
  89. '删除</button>' +
  90. '</tr>';
  91. $("#dateil_table").append(str);
  92. $("#tool_detail").focus();
  93. }else{
  94. layer.msg("没有该工具记录!");
  95. }
  96. },
  97. error: function(data) {
  98. var responseText = data.responseText;
  99. var json_str = JSON.parse(responseText);
  100. var status = json_str.status;
  101. var message = json_str.message;
  102. //判断是否是session超时
  103. if(403==status){
  104. layer.alert(message,function(){
  105. window.location.href="/login";
  106. });
  107. }
  108. layer.closeAll('loading');
  109. }
  110. })
  111. }
  112. //删除
  113. function remove(toolInstanceId){
  114. for (var i = 0; i < toolDetailList.length; i++) {
  115. if(toolDetailList[i].toolInstanceId == toolInstanceId){
  116. toolDatailRemo(toolDetailList[i].toolInstanceId);
  117. toolDetailList.splice(i,1);
  118. layer.msg("移除成功!");
  119. $("#tool_detail").val("");
  120. $("#tool_detail").focus();
  121. return false;
  122. }
  123. }
  124. layer.msg("没有该工具记录!");
  125. $("#tool_detail").val("");
  126. }
  127. // 移除工具实例编码
  128. function toolDatailRemo(toolInstanceId){
  129. $table=$("#dateil_table tr");
  130. $("tr[id='" + toolInstanceId + "']").remove();
  131. }
  132. //新增库位信息
  133. function updateToolDetail(){
  134. $("#saveDetail").attr('disabled' ,true);
  135. if(toolDetailList.length == 0){
  136. layer.msg("请输入实例编码!");
  137. $("#saveDetail").attr('disabled' ,false);
  138. return;
  139. }
  140. let remark = $('#remark').val()
  141. var alreadyList = new Array;
  142. for(var i = 0; i< toolDetailList.length; i++){
  143. var jsonData = {
  144. toolId:toolDetailList[i].toolId,
  145. site:toolDetailList[i].site,
  146. toolInstanceId:toolDetailList[i].toolInstanceId,
  147. locationId: toolDetailList[i].locationId,
  148. supplierId: toolDetailList[i].supplierId,
  149. transNoHead:'TB',
  150. transType:'工具报废',
  151. transTypeDb:'B',
  152. direction : "-",
  153. userName :userName,
  154. status: "报废",
  155. statusRef: "工具报废",
  156. remark: remark,
  157. };
  158. alreadyList.push(jsonData);
  159. }
  160. $.ajax({
  161. url: "/toolPda/updateToolDetail",
  162. contentType: 'application/json',
  163. type:"POST",
  164. data:JSON.stringify(alreadyList),
  165. dataType:"JSON",
  166. beforeSend: function(request) {
  167. request.setRequestHeader("token", $.cookie("token"));
  168. },
  169. success: function (data) {
  170. if(data.code == 0){
  171. layer.msg(data.msg);
  172. toolDetailList = new Array;
  173. $("#dateil_table").html("");
  174. $("#tool_detail").val("");
  175. $('#remark').val('')
  176. //触发隐藏
  177. $("#location_modal").modal("hide");
  178. }else if(data.code == 401 || data.code == 500){
  179. window.location.href="/login";
  180. }else{
  181. layer.msg(data.msg);
  182. }
  183. },
  184. error: function(data) {
  185. var responseText = data.responseText;
  186. var json_str = JSON.parse(responseText);
  187. var status = json_str.status;
  188. var message = json_str.message;
  189. //判断是否是session超时
  190. if(403==status){
  191. layer.alert(message,function(){
  192. window.location.href="/login";
  193. });
  194. }
  195. layer.closeAll('loading');
  196. }
  197. })
  198. }
  199. //清除前台缓存
  200. function cleanData(){
  201. toolDatail = new Array;
  202. warehouseData = new Array;
  203. $("#dateil_table").html("");
  204. }