macmodel.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. var layer, eTbl;
  2. layui.use(['table', 'layer', 'form'], function () {
  3. var table = layui.table;
  4. layer = layui.layer;
  5. var form = layui.form;
  6. //第一个实例
  7. eTbl = table.render({
  8. elem: '#tbl',
  9. url: '/mes/api/macmodel', //数据接口
  10. page: true, //开启分页
  11. toolbar: '#toolbar',
  12. cols: [[ //表头
  13. { checkbox: true },
  14. { field: 'fCode', title: '代码', width: 160, sort: true },
  15. { field: 'fName', title: '名称', width: 120, sort: true },
  16. { field: 'tpCode', title: '制程代码', width: 160, sort: true },
  17. {
  18. field: 'rectime', title: '录入日期', width: 240, sort: true, templet: function (d) {
  19. return (d.rectime == null || d.rectime == undefined) ? '' : timeFormat(d.rectime);
  20. }
  21. },
  22. { field: 'remark', title: '备注', width: 380 }
  23. ]]
  24. });
  25. table.on('toolbar(macmodel)', function (obj) {
  26. if (obj.event == 'add') {
  27. layer.open({
  28. type: 2,
  29. title: '新增机器型号',
  30. content: 'macmodelAdd.html',
  31. area: ['800px', '400px']
  32. });
  33. } else if (obj.event == 'delete') {
  34. var checkStatus = table.checkStatus('tbl');
  35. console.log(checkStatus);
  36. if (checkStatus.data.length === 0) {
  37. layer.msg('请先选中需要操作的型号!', {
  38. icon: 2,
  39. anim: 6
  40. });
  41. return;
  42. }
  43. var ids = '';
  44. for (var i = 0; i < checkStatus.data.length; i++) {
  45. ids += checkStatus.data[i].id + ',';
  46. }
  47. ids = ids.substr(0, ids.length - 1);
  48. $.ajax({
  49. url: '/mes/api/macmodel/delete',
  50. type: 'post',
  51. contentType: 'application/json',
  52. dataType: 'text',
  53. data: JSON.stringify(ids),
  54. success: function (res) {
  55. if (res) {
  56. layer.msg('操作成功', {
  57. icon: 1,
  58. anim: 0
  59. });
  60. eTbl.reload(true);
  61. } else {
  62. layer.msg('操作失败', {
  63. icon: 2,
  64. anim: 6
  65. });
  66. }
  67. }
  68. });
  69. } else if (obj.event == 'search') {
  70. showToast();
  71. var fcode = $('input[name=fCode]').val();
  72. var name = $('input[name=name]').val();
  73. eTbl.reload({
  74. where: {
  75. fcode: fcode,
  76. name: name
  77. },
  78. done: () => {
  79. form.val('searchForm', {
  80. fCode: fcode,
  81. name: name
  82. })
  83. layer.closeAll('loading');
  84. }
  85. });
  86. }
  87. else if (obj.event == 'all') {
  88. showToast();
  89. $('input[name=fCode]').val('');
  90. $('input[name=name]').val('');
  91. eTbl.reload({
  92. where: {
  93. fcode: fcode,
  94. name: name
  95. },
  96. done: () => {
  97. layer.closeAll('loading');
  98. }
  99. });
  100. }
  101. });
  102. table.on('rowDouble(macmodel)', function (obj) {
  103. console.log(obj);
  104. layer.open({
  105. type: 2,
  106. content: 'macmodelAdd.html?id=' + obj.data.id,
  107. area: ['800px', '400px']
  108. });
  109. });
  110. table.on('sort(macmodel)', function (obj) {
  111. eTbl.reload({
  112. initSort: obj,
  113. where: {
  114. sort: obj.field,
  115. order: obj.type
  116. }
  117. })
  118. });
  119. });
  120. function reloadTable() {
  121. eTbl.reload();
  122. }