exceptionAdd.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. var detailtbl, datas;
  2. layui.use(['form', 'table'], function () {
  3. var form = layui.form;
  4. var table = layui.table;
  5. console.log(window.location.href);
  6. var id = QueryString('id');
  7. var exCode = QueryString('exCode');
  8. if (id == null || id == undefined || id == '') {
  9. id = '0';
  10. }
  11. if (id != '0') {
  12. $.ajax({
  13. url: '/mes/api/mesexception/' + id,
  14. type: 'get',
  15. dataType: 'json',
  16. success: function (res) {
  17. console.log('查看详情');
  18. console.log(res);
  19. form.val('addForm', {
  20. FCode: res.fcode,
  21. FName: res.fname,
  22. Remark: res.remark
  23. });
  24. }
  25. });
  26. }
  27. loadDetail(id);
  28. form.on('submit(*)', function (data) {
  29. var obj = {
  30. Id: id,
  31. Fcode: data.field.FCode,
  32. Fname: data.field.FName,
  33. Remark: data.field.Remark,
  34. JsonDetail: JSON.stringify(datas)
  35. };
  36. $.ajax({
  37. url: '/mes/api/mesexception/add',
  38. contentType: 'application/json',
  39. type: 'post',
  40. dataType: 'text',
  41. data: JSON.stringify(obj),
  42. success: function (res) {
  43. var result = res == '0' ? '失败' : '成功';
  44. var content = id == '0' ? '添加' : '修改';
  45. var iconId = res == '0' ? 2 : 1;
  46. var animateId = res == '0' ? 6 : 0;
  47. id = res;
  48. if (res != '0') {
  49. layer.msg(content + result, {
  50. icon: iconId,
  51. anim: animateId
  52. });
  53. $.ajax({
  54. url: '/mes/api/mesexception/' + res,
  55. type: 'get',
  56. dataType: 'json',
  57. success: function (res) {
  58. form.val('addForm', {
  59. FCode: res.fcode,
  60. FName: res.fname,
  61. Remark: res.remark
  62. });
  63. loadDetail(res.FCode);
  64. }
  65. });
  66. parent.reloadTable();
  67. } else {
  68. layer.msg('网络错误,请联系管理员', {
  69. icon: 2,
  70. animateId: 6
  71. })
  72. }
  73. }
  74. });
  75. return false;
  76. });
  77. function loadDetail(exCode) {
  78. if (exCode == '0') {
  79. datas = [
  80. ];
  81. loadTable(datas);
  82. } else {
  83. $.ajax({
  84. url: '/mes/api/mesexception/getdetails?exCode=' + exCode,
  85. dataType: 'json',
  86. type: 'get',
  87. success: function (res) {
  88. console.log('=====================');
  89. console.log(res);
  90. datas = res.data;
  91. if (datas) {
  92. loadTable(datas);
  93. }
  94. }
  95. });
  96. }
  97. }
  98. function loadTable() {
  99. detailtbl = table.render({
  100. elem: '#tbl',
  101. data: datas, //数据接口
  102. page: true, //开启分页
  103. toolbar: '#toolbar',
  104. cols: [[ //表头
  105. { checkbox: true },
  106. { field: 'macCode', title: '机型代码', width: 160, sort: true },
  107. { field: 'excCode', title: '异常代码', width: 120, sort: true },
  108. { field: 'reccode', title: '录入人', width: 120, sort: true },
  109. {
  110. field: 'rectime', title: '录入日期', width: 240, sort: true, templet: function (d) {
  111. return (d.rectime == null || d.rectime == undefined) ? '' : timeFormat(d.rectime);
  112. }
  113. },
  114. { field: 'remark', title: '备注', width: 380 }
  115. ]]
  116. });
  117. }
  118. window.refreshTable = function () {
  119. loadTable(datas);
  120. }
  121. table.on('toolbar(exdetail)', function (obj) {
  122. if (obj.event == 'add') {
  123. layer.open({
  124. type: 2,
  125. content: 'exceptionDetailAdd.html',
  126. area: ['600px', '350px']
  127. });
  128. } else if (obj.event == 'delete') {
  129. var checkStatus = table.checkStatus('tbl');
  130. console.log(checkStatus);
  131. if (checkStatus.data.length === 0) {
  132. layer.msg('请先选中需要操作的异常明细!', {
  133. icon: 2,
  134. anim: 6
  135. });
  136. return;
  137. }
  138. for (var i = 0; i < checkStatus.data.length; i++) {
  139. for (var j = 0; j < datas.length; j++) {
  140. if (checkStatus.data[i].id == datas[j].id) {
  141. datas.splice(j, 1);
  142. }
  143. }
  144. }
  145. //重新加载异常明细
  146. refreshTable();
  147. }
  148. });
  149. $('#btnAddContinue').click(function () {
  150. id = '0';
  151. datas = [];
  152. refreshTable();
  153. });
  154. });
  155. function reloadTable() {
  156. detailtbl.reload();
  157. }