system-edit.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. var aircraft_type = "";
  2. var aircraft_id = '';
  3. var systemId = 0;
  4. var systemName = '';
  5. $(function() {
  6. var params = window.location.href.split("?");
  7. if (params.length > 1) {
  8. values = params[1].split("&");
  9. if (values.length > 2) {
  10. systemId = values[0].replace("id=", "");
  11. if (systemId !== "0") {
  12. aircraft_type = decodeURI(values[1].replace("aircraft_type=", ""));
  13. systemName = decodeURI(values[2].replace("device_name=", ""));
  14. // funcDes = decodeURI(values[3].replace("device_describe=", ""));
  15. }
  16. }
  17. }
  18. $("#aircraft_name").val(aircraft_type);
  19. $("#device_name").val(systemName);
  20. layui.use(["form", "layer", "laydate"], function() {
  21. $ = layui.jquery;
  22. var form = layui.form,
  23. layer = layui.layer;
  24. var laydate = layui.laydate;
  25. //监听提交
  26. form.on("switch(hide)", function(data) {
  27. isHide = data.elem.checked ? 1 : 0;
  28. });
  29. form.on("select", function(data) {
  30. if (data.elem.id === "aircraft_name") {
  31. aircraft_id = data.elem[data.elem.selectedIndex].value;
  32. aircraft_type = data.elem[data.elem.selectedIndex].text;
  33. }
  34. })
  35. form.on("submit(save)", function(data) {
  36. if ($("#aircraft_name").val().trim() === "") {
  37. showMsg("机型不能为空", 2);
  38. $("#aircraft_type").focus();
  39. return false;
  40. }
  41. if ($("#device_name").val().trim() === "") {
  42. showMsg("系统不能为空", 2);
  43. $("#device_name").focus();
  44. return false;
  45. }
  46. var func = data.field;
  47. func.id = systemId;
  48. func.aircraft_type = aircraft_type;
  49. func.aircraft_id =aircraft_id
  50. let url = "api/device/edit";
  51. fetchJSON(url, func, "post", function(data) {
  52. if (data.status === 0) {
  53. var index = parent.layer.getFrameIndex(window.name);
  54. showMsg("编辑成功", 1, 2000);
  55. parent.layer.close(index);
  56. } else {
  57. showMsg(data.msg, 2);
  58. }
  59. });
  60. return false;
  61. });
  62. function getAirType() {
  63. fetchJSON("api/aircraft/listAll", {}, "get", function(bet) {
  64. if (bet.status === 0) {
  65. $("#aircraft_name").empty();
  66. $("#aircraft_name").append($("<option>", {
  67. value: -1,
  68. text: "请选择机型"
  69. }));
  70. for (var i = 0; i < bet.data.length; i++) {
  71. if (bet.data[i].aircraft_type === aircraft_type) {
  72. $("#aircraft_name").append(
  73. $("<option>", {
  74. value: bet.data[i].id,
  75. text: bet.data[i].aircraft_type,
  76. selected: true
  77. })
  78. );
  79. } else {
  80. $("#aircraft_name").append(
  81. $("<option>", {
  82. value: bet.data[i].id,
  83. text: bet.data[i].aircraft_type
  84. })
  85. );
  86. }
  87. }
  88. layui.use("form", function() {
  89. layui.form.render('select', 'departmentFilter');
  90. });
  91. } else {
  92. showMsg(bet.msg, 2);
  93. }
  94. });
  95. };
  96. getAirType()
  97. });
  98. });