equipment.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.columnDefaults.align = 'left';
  6. Table.api.init({
  7. extend: {
  8. index_url: 'equipment/equipment/index' + location.search,
  9. add_url: 'equipment/equipment/add',
  10. edit_url: 'equipment/equipment/edit',
  11. del_url: 'equipment/equipment/del',
  12. multi_url: 'equipment/equipment/multi',
  13. import_url: 'equipment/equipment/import',
  14. table: 'equipment_equipment',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'id',
  23. columns: [
  24. [
  25. {checkbox: true, align: 'center'},
  26. {field: 'id', title: __('Id'), align: 'center', operate: false},
  27. {field: 'equipment_code', title: __('Equipment_code'), operate: false},
  28. {field: 'archive.model', title: __('Model'), operate: false},
  29. {field: 'archive.name', title: __('Name'), operate: false},
  30. {field: 'archive.load_supplier.name', title: __('Supplier_id')},
  31. {field: 'archive.purchasetime_text', title: __('Purchasetime'), operate: false},
  32. {field: 'archive.region', title: __('Region'), operate: false},
  33. {field: 'archive.load_responsible_user.nickname', title: __('Responsible_uid'), formatter: function(value, row){return value + ',' + row.archive.load_responsible_user.mobile}, operate: false},
  34. {field: 'coding', title: __('Qrcode_tag'), table: table, buttons: [
  35. {
  36. name: 'qrcode',
  37. text: '',
  38. title: __('Qrcode_tag'),
  39. icon: 'fa fa-qrcode',
  40. extend: 'data-area=\'["350px", "380px"]\'',
  41. classname: 'btn btn-xs btn-primary btn-dialog',
  42. url: function(row) {
  43. return 'equipment/equipment/qrcode?coding=' + row.coding + '&equipment_code=' + row.equipment_code;
  44. },
  45. },
  46. ], formatter: Table.api.formatter.buttons, operate: false},
  47. {field: 'work_status_text', title: __('Work_status'), operate: false, custom: {'停机待修': 'info', '正常': 'success', '停机报废': 'danger'}, formatter:Table.api.formatter.label},
  48. {field: 'record', title: __('Record'), table: table, buttons: [
  49. {
  50. name: 'repairs',
  51. title: __('Repair List'),
  52. icon: 'fa fa-wrench',
  53. extend: 'data-area=\'["100%", "100%"]\'',
  54. classname: 'btn btn-xs btn-info btn-dialog',
  55. url: 'equipment/repair/index?equipment_id={id}'
  56. },
  57. {
  58. name: 'inspection',
  59. title: __('Inspection List'),
  60. icon: 'fa fa-recycle',
  61. extend: 'data-area=\'["900px", "600px"]\'',
  62. classname: 'btn btn-xs btn-info btn-dialog',
  63. url: 'equipment/record/list?type=inspection&equipmentId={id}'
  64. },
  65. {
  66. name: 'maintenance',
  67. title: __('Maintenance List'),
  68. icon: 'fa fa-clock-o',
  69. extend: 'data-area=\'["900px", "600px"]\'',
  70. classname: 'btn btn-xs btn-info btn-dialog',
  71. url: 'equipment/record/list?type=maintenance&equipmentId={id}'
  72. }
  73. ], formatter: Table.api.formatter.buttons, operate: false},
  74. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  75. ]
  76. ],
  77. search: false,
  78. commonSearch: false
  79. });
  80. // 为表格绑定事件
  81. Table.api.bindevent(table);
  82. },
  83. recyclebin: function () {
  84. // 初始化表格参数配置
  85. Table.api.init({
  86. extend: {
  87. 'dragsort_url': ''
  88. }
  89. });
  90. var table = $("#table");
  91. // 初始化表格
  92. table.bootstrapTable({
  93. url: 'equipment/equipment/recyclebin' + location.search,
  94. pk: 'id',
  95. sortName: 'id',
  96. columns: [
  97. [
  98. {checkbox: true},
  99. {field: 'id', title: __('Id')},
  100. {field: 'equipment_code', title: __('Equipment_code'), operate: false},
  101. {
  102. field: 'deletetime',
  103. title: __('Deletetime'),
  104. operate: 'RANGE',
  105. addclass: 'datetimerange',
  106. formatter: Table.api.formatter.datetime
  107. },
  108. {
  109. field: 'operate',
  110. width: '130px',
  111. title: __('Operate'),
  112. table: table,
  113. events: Table.api.events.operate,
  114. buttons: [
  115. {
  116. name: 'Restore',
  117. text: __('Restore'),
  118. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  119. icon: 'fa fa-rotate-left',
  120. url: 'equipment/equipment/restore',
  121. refresh: true
  122. }
  123. ],
  124. formatter: Table.api.formatter.operate
  125. }
  126. ]
  127. ],
  128. search: false,
  129. showToggle: false,
  130. showColumns: false,
  131. showExport: false,
  132. commonSearch: false
  133. });
  134. // 为表格绑定事件
  135. Table.api.bindevent(table);
  136. },
  137. add: function () {
  138. Controller.api.bindevent();
  139. },
  140. edit: function () {
  141. Controller.api.bindevent();
  142. },
  143. qrcode: function () {
  144. var dataURLtoBlob = function (dataUrl) {
  145. var arr = dataUrl.split(","),
  146. mime = arr[0].match(/:(.*?);/)[1],
  147. bStr = atob(arr[1]),
  148. n = bStr.length,
  149. u8arr = new Uint8Array(n);
  150. while (n--) {
  151. u8arr[n] = bStr.charCodeAt(n);
  152. }
  153. return new Blob([u8arr], { type: mime });
  154. };
  155. var downloadFile = function (url, name) {
  156. var a = document.createElement("a");
  157. a.setAttribute("href", url);
  158. a.setAttribute("download", name);
  159. a.setAttribute("target", "_blank");
  160. var clickEvent = document.createEvent("MouseEvents");
  161. clickEvent.initEvent("click", true, true);
  162. a.dispatchEvent(clickEvent);
  163. };
  164. var downloadFileByBase64 = function (base64, name) {
  165. var myBlob = dataURLtoBlob(base64);
  166. var myUrl = URL.createObjectURL(myBlob);
  167. downloadFile(myUrl, name);
  168. };
  169. $(document).on("click", ".btn-download", function () {
  170. var base64 = $("#qrcode-url").attr("src");
  171. var name = $(".btn-download").data("name");
  172. downloadFileByBase64(base64, name);
  173. });
  174. },
  175. api: {
  176. bindevent: function () {
  177. Form.api.bindevent($("form[role=form]"));
  178. }
  179. }
  180. };
  181. return Controller;
  182. });