recipe.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. $(document).ready(function () {
  2. initLineSelect();
  3. initRecipeTable();
  4. });
  5. var recipeTable;
  6. var size;
  7. var number;
  8. function initRecipeTable() {
  9. var queryUrl = '/Recipe/GetRecipes';
  10. recipeTable = $("#recipe_table").bootstrapTable({
  11. url: queryUrl,
  12. columns: [
  13. { field: "id", title: "ID", visible: false },
  14. { field: "productionLineId", title: "线别ID", visible: false },
  15. { field: "productionLineName", title: "线别" },
  16. { field: "moduleType", title: "机种" },
  17. { field: "theoryCapacity", title: "理论产能(pcs)" },
  18. { field: "theoryTT", title: "理论节拍(s)" },
  19. { field: "theoryRefueledTime", title: "换料标准(min)" },
  20. { field: "createTime", title: "创建时间" },
  21. {
  22. title: '操作',
  23. field: "id",
  24. formatter: operation,
  25. width: 200
  26. }
  27. ],
  28. pagination: true,
  29. pageNumber: 1,
  30. pageSize: size,
  31. pageList: [10, 25, 50, 100],
  32. smartDisplay: false,
  33. sidePagination: "server",
  34. queryParams: function (params) {
  35. var temp = {
  36. pageNumber: (params.offset / params.limit) + 1,
  37. pageSize: params.limit,
  38. keyword: $("#keyword").val()
  39. };
  40. number = temp.pageNumber;
  41. return temp;
  42. }
  43. });
  44. }
  45. function initLineSelect() {
  46. $.ajax({
  47. url: "/ProductionLine/GetProductionLines",
  48. method: "GET",
  49. headers: { "Content-Type": "application/json" },
  50. async: true,
  51. success: function (result) {
  52. if (result.code === 0) {
  53. for (var i = 0; i < result.data.length; i++) {
  54. var id = result.data[i].id;
  55. var value = result.data[i].name;
  56. $("#Line").append("<option value=" + id + ">" + value + "</option>");
  57. }
  58. } else if (result.code === 1) {
  59. alert(result.message);
  60. }
  61. }
  62. });
  63. }
  64. function operation(value, row, index) {
  65. var htm =
  66. "<a class='label' onclick='modelUpdateRecipe(\"" + value + "\")'> <i class='fa fa-edit'> 编辑</i></a >" +
  67. "<a class='label' onclick='deleteRecipe(\"" + value + "\")'> <i class='fa fa-trash-o'> 删除</i></a >";
  68. return htm;
  69. }
  70. function refreshRecipeTable() {
  71. recipeTable.bootstrapTable("refreshOptions", { pageNubmer: 1 });
  72. }
  73. function selectPageRecipeTable() {
  74. recipeTable.bootstrapTable("selectPage", number);
  75. }
  76. function modelCreateRecipe() {
  77. $("#Id").val("");
  78. $("#modal_recipe_add").modal("show");
  79. }
  80. function saveRecipe() {
  81. var id = $("#Id").val();
  82. var url;
  83. if (id === null || id === "") {
  84. url = "/Recipe/CreateRecipe";
  85. } else {
  86. url = "/Recipe/UpdateRecipe/" + id;
  87. }
  88. var ModuleType = $("#ModuleType").val();
  89. var TheoryCapacity = $("#TheoryCapacity").val();
  90. var TheoryTT = $("#TheoryTT").val();
  91. var ProductionLineId = $("#Line").val();
  92. var TheoryRefueledTime = $("#TheoryRefueledTime").val();
  93. $.ajax({
  94. url: url,
  95. method: "POST",
  96. headers: {
  97. "Content-Type": "application/json"
  98. },
  99. async: true,
  100. data: JSON.stringify({
  101. "moduleType": ModuleType,
  102. "productionLineId": ProductionLineId,
  103. "theoryCapacity": parseInt(TheoryCapacity),
  104. "theoryTT": parseFloat(TheoryTT),
  105. "theoryRefueledTime": parseFloat(TheoryRefueledTime)
  106. }),
  107. success: function (result) {
  108. if (result.code === 0) {
  109. $("#modal_recipe_add").modal("hide");
  110. if (id === null || id === "") {
  111. refreshRecipeTable();
  112. } else {
  113. selectPageRecipeTable();
  114. }
  115. } else if (result.code === 1) {
  116. alert(result.message);
  117. }
  118. }
  119. });
  120. }
  121. function modelUpdateRecipe(id) {
  122. $("#Id").val(id);
  123. $.ajax({
  124. url: "/Recipe/" + id,
  125. method: "GET",
  126. headers: { "Content-Type": "application/json" },
  127. async: true,
  128. success: function (result) {
  129. if (result.code === 0) {
  130. $("#ModuleType").val(result.data.moduleType);
  131. $("#TheoryCapacity").val(result.data.theoryCapacity);
  132. $("#TheoryTT").val(result.data.theoryTT);
  133. $("#Line").val(result.data.productionLineId);
  134. $("#TheoryRefueledTime").val(result.data.theoryRefueledTime)
  135. } else if (result.code === 1) {
  136. alert(result.message);
  137. }
  138. }
  139. });
  140. $("#modal_recipe_add").modal("show");
  141. }
  142. function deleteRecipe(id) {
  143. $.ajax({
  144. url: "/Recipe/DeleteRecipe/" + id,
  145. method: "POST",
  146. headers: { "Content-Type": "application/json" },
  147. async: true,
  148. success: function (result) {
  149. if (result.code === 0) {
  150. if (id === null || id === "") {
  151. refreshRecipeTable();
  152. } else {
  153. selectPageRecipeTable();
  154. }
  155. } else if (result.code === 1) {
  156. alert(result.message);
  157. }
  158. }
  159. });
  160. }