choosemac.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. var layer, eTbl, pId, unbindTbl;
  2. layui.use(['table', 'layer', 'element'], function () {
  3. var table = layui.table;
  4. var element = layui.element;
  5. layer = layui.layer;
  6. pId = QueryString("pId");
  7. // document.querySelector('#macprocess').src = 'processwithmac.html?pId=' + pId;
  8. //第一个实例
  9. eTbl = table.render({
  10. elem: '#tbl',
  11. height: 600,
  12. url: '/mes/api/machine', //数据接口
  13. page: true, //开启分页
  14. toolbar: '#toolbar',
  15. cols: [[ //表头
  16. { checkbox: true },
  17. { field: 'fCode', title: '代码', sort: true },
  18. { field: 'fName', title: '名称', sort: true },
  19. {
  20. field: 'fModel', title: '机型', sort: true, templet: function (d) {
  21. return d.fModelName;
  22. }
  23. },
  24. { field: 'imsIp', title: 'IMS程序所在电脑IP' },
  25. {
  26. field: 'rectime', title: '录入日期', sort: true, templet: function (d) {
  27. return (d.rectime == null || d.rectime == undefined) ? '' : timeFormat(d.rectime);
  28. }
  29. },
  30. { field: 'remark', title: '备注' }
  31. ]],
  32. where: {
  33. filter: " and a.id not in (select macid from MacTProcess) "
  34. }
  35. });
  36. table.on('toolbar(machine)', function (obj) {
  37. layer.confirm('您确定要这样做吗?', function (index) {
  38. var checkStatus = table.checkStatus('tbl');
  39. console.log(checkStatus);
  40. if (checkStatus.data.length === 0) {
  41. layer.msg('请先选中需要操作的机台!', {
  42. icon: 2,
  43. anim: 6
  44. });
  45. return;
  46. }
  47. var ids = '';
  48. for (var i = 0; i < checkStatus.data.length; i++) {
  49. ids += checkStatus.data[i].id + ',';
  50. }
  51. ids = ids.substr(0, ids.length - 1);
  52. if (obj.event == 'add') {
  53. $.ajax({
  54. url: '/mes/api/tprocess/bindmac',
  55. type: 'post',
  56. contentType: 'application/json',
  57. dataType: 'json',
  58. data: JSON.stringify({
  59. pId: pId,
  60. macIds: ids
  61. }),
  62. success: function (res) {
  63. if (res.code == 1) {
  64. layer.msg('操作成功', {
  65. icon: 1,
  66. anim: 0
  67. });
  68. unbindTbl.reload(true);
  69. eTbl.reload(true);
  70. } else {
  71. layer.msg(res.message, {
  72. icon: 2,
  73. anim: 6
  74. });
  75. }
  76. }
  77. })
  78. }
  79. layer.close(index);
  80. });
  81. });
  82. table.on('rowDouble(machine)', function (obj) {
  83. console.log(obj);
  84. layer.open({
  85. type: 2,
  86. content: 'machineAdd.html?id=' + obj.data.id,
  87. area: ['800px', '475px']
  88. });
  89. });
  90. table.on('sort(machine)', function (obj) {
  91. eTbl.reload({
  92. initSort: obj,
  93. where: {
  94. sort: obj.field,
  95. order: obj.type
  96. }
  97. })
  98. });
  99. unbindTbl = table.render({
  100. elem: '#albindtbl',
  101. url: '/mes/api/mactprocess', //数据接口
  102. page: true, //开启分页
  103. toolbar: '#unbindtoolbar',
  104. cols: [[ //表头
  105. { checkbox: true },
  106. // { type: 'numbers' },
  107. { field: 'macCode', title: '机台代码', sort: true },
  108. { field: 'macName', title: '机台名称', sort: true },
  109. {
  110. field: 'macModelName', title: '机型', sort: true, templet: function (d) {
  111. return d.macModelName;
  112. }
  113. },
  114. { field: 'processCode', title: '制程代码', sort: true },
  115. { field: 'processName', title: '制程名称', sort: true },
  116. ]],
  117. where: {
  118. poCode: pId
  119. },
  120. })
  121. table.on('toolbar(albindmachine)', function (obj) {
  122. if (obj.event == "delete") {
  123. layer.confirm('您确定要这样做吗?', function (index) {
  124. var checkStatus = table.checkStatus('albindtbl');
  125. console.log(checkStatus);
  126. if (checkStatus.data.length === 0) {
  127. layer.msg('请先选中需要操作的机台!', {
  128. icon: 2,
  129. anim: 6
  130. });
  131. return;
  132. }
  133. var ids = '';
  134. for (var i = 0; i < checkStatus.data.length; i++) {
  135. ids += checkStatus.data[i].id + ',';
  136. }
  137. ids = ids.substr(0, ids.length - 1);
  138. $.ajax({
  139. url: '/mes/api/mactprocess/delete',
  140. type: 'post',
  141. contentType: 'application/json',
  142. dataType: 'text',
  143. data: JSON.stringify(ids),
  144. success: function (res) {
  145. if (res == '1') {
  146. layer.msg('操作成功', {
  147. icon: 1,
  148. anim: 0
  149. });
  150. eTbl.reload(true);
  151. unbindTbl.reload(true);
  152. } else {
  153. layer.msg('操作失败', {
  154. icon: 2,
  155. anim: 6
  156. });
  157. }
  158. }
  159. });
  160. });
  161. }
  162. });
  163. table.on('sort(albindmachine)', function (obj) {
  164. eTbl.reload({
  165. initSort: obj,
  166. where: {
  167. poCode: pId,
  168. sort: obj.field,
  169. order: obj.type
  170. }
  171. })
  172. });
  173. });
  174. function reloadTable() {
  175. eTbl.reload();
  176. }