monthModule.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. $(document).ready(function () {
  2. let now = new Date();
  3. let year = now.getFullYear();
  4. let month = now.getMonth() + 1;
  5. let day = now.getDate();
  6. if (day >= 20) {
  7. month++
  8. }
  9. $("#selectYear").val(year);
  10. $("#selectMonth").val(month);
  11. initMonthModuleTable();
  12. });
  13. var monthModuleTable;
  14. $("#selectMark").change(function () {
  15. monthModuleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 });
  16. });
  17. $("#selectYear").change(function () {
  18. monthModuleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 });
  19. });
  20. $("#selectMonth").change(function () {
  21. monthModuleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 });
  22. });
  23. function initMonthModuleTable() {
  24. var queryUrl = '/MonthModule/GetMonthModuleTypes';
  25. monthModuleTable = $("#table").bootstrapTable({
  26. url: queryUrl,
  27. showFooter: true,
  28. queryParams: function (params) {
  29. var param = {
  30. mark: $('#selectMark option:selected').val(),
  31. year: $('#selectYear option:selected').val(),
  32. month: $('#selectMonth option:selected').val()
  33. };
  34. return param;
  35. },
  36. columns: [
  37. { field: "id", title: "ID", visible: false },
  38. { field: "mark", title: "Mark", visible: false },
  39. { field: "year", title: "年", visible: false },
  40. { field: "month", title: "月", visible: false },
  41. { field: "moduleType", title: "机种" },
  42. {
  43. field: "planCapacity", title: "计划产能",
  44. footerFormatter: function (value) {
  45. var count = 0;
  46. for (var i in value) {
  47. count += value[i].planCapacity
  48. }
  49. $("#planTotal").text(count);
  50. return count;
  51. }
  52. },
  53. {
  54. field: "lastModuleCapacity", title: "上月差异",
  55. footerFormatter: function (value) {
  56. var count = 0;
  57. for (var i in value) {
  58. count += value[i].lastModuleCapacity
  59. }
  60. $("#lastTotal").text(count);
  61. return count;
  62. } },
  63. { field: "remark", title: "说明" },
  64. {
  65. title: '操作',
  66. field: "id",
  67. formatter: operation,
  68. width: 200
  69. }
  70. ]
  71. });
  72. }
  73. function operation(value, row, index) {
  74. var htm =
  75. "<a class='label' onclick='modelUpdate(\"" + value + "\")'> <i class='fa fa-edit'> 编辑</i></a >" +
  76. "<a class='label' onclick='deleted(\"" + value + "\")'> <i class='fa fa-trash-o'> 删除</i></a >";
  77. return htm;
  78. }
  79. function refreshTable() {
  80. monthModuleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 });
  81. }
  82. function modelCreate() {
  83. $("#Id").val("");
  84. $('#mark').val($('#selectMark option:selected').val());
  85. $('#year').val($('#selectYear option:selected').val());
  86. $('#month').val($('#selectMonth option:selected').val());
  87. $("#modal_month_module_add").modal("show");
  88. }
  89. function saveMonthModule() {
  90. var id = $("#Id").val();
  91. var url;
  92. if (id === null || id === "") {
  93. url = "/MonthModule/CreateMonthModuleType";
  94. } else {
  95. url = "/MonthModule/UpdateMonthModuleType";
  96. }
  97. var ModuleType = $("#ModuleType").val();
  98. var PlanCapacity = $("#PlanCapacity").val();
  99. var LastModuleCapacity = $("#LastModuleCapacity").val();
  100. var mark = $('#mark').val();
  101. var year = $('#year').val();
  102. var month = $('#month').val();
  103. var remark = $('#remark').val();
  104. $.ajax({
  105. url: url,
  106. method: "POST",
  107. headers: {
  108. "Content-Type": "application/json"
  109. },
  110. async: true,
  111. data: JSON.stringify({
  112. "id": id,
  113. "moduleType": ModuleType,
  114. "planCapacity": parseInt(PlanCapacity),
  115. "lastModuleCapacity": parseInt(LastModuleCapacity),
  116. "mark": mark,
  117. "year": parseInt(year),
  118. "month": parseInt(month),
  119. "remark": remark
  120. }),
  121. success: function (result) {
  122. if (result.code === 0) {
  123. $("#modal_month_module_add").modal("hide");
  124. refreshTable();
  125. } else if (result.code === 1) {
  126. alert(result.message);
  127. }
  128. }
  129. });
  130. }
  131. function modelUpdate(id) {
  132. $("#Id").val(id);
  133. $.ajax({
  134. url: "/MonthModule/GetMonthModuleTypes/" + id,
  135. method: "GET",
  136. headers: { "Content-Type": "application/json" },
  137. async: true,
  138. data: {
  139. "year": $('#selectYear').val(),
  140. "month": $('#selectMonth').val()
  141. },
  142. success: function (result) {
  143. if (result.code === 0) {
  144. $("#ModuleType").val(result.data.moduleType);
  145. $("#PlanCapacity").val(result.data.planCapacity);
  146. $("#LastModuleCapacity").val(result.data.lastModuleCapacity);
  147. $('#mark').val(result.data.mark);
  148. $('#year').val(result.data.year);
  149. $('#month').val(result.data.month);
  150. $('#remark').val(result.data.remark);
  151. $("#modal_month_module_add").modal("show");
  152. } else if (result.code === 1) {
  153. alert(result.message);
  154. }
  155. }
  156. });
  157. }
  158. function deleted(id) {
  159. $.ajax({
  160. url: "/MonthModule/DeleteMonthModuleType",
  161. method: "POST",
  162. headers: { "Content-Type": "application/json" },
  163. async: true,
  164. data: JSON.stringify({
  165. "id": id
  166. }),
  167. success: function (result) {
  168. if (result.code === 0) {
  169. refreshTable();
  170. } else if (result.code === 1) {
  171. alert(result.message);
  172. }
  173. }
  174. });
  175. }