factory.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var stateList = {};
  3. var Controller = {
  4. index: function () {
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'inspection/factory/index' + location.search,
  9. add_url: 'inspection/factory/add',
  10. edit_url: 'inspection/factory/edit',
  11. del_url: 'inspection/factory/del',
  12. multi_url: 'inspection/factory/multi',
  13. import_url: 'inspection/factory/import',
  14. table: 'factory',
  15. }
  16. });
  17. var table = $("#table");
  18. var statusSearchList = {};
  19. if (Config.statusSearchList) {
  20. try {
  21. if (typeof Config.statusSearchList === 'string') {
  22. statusSearchList = JSON.parse(Config.statusSearchList);
  23. } else {
  24. statusSearchList = Config.statusSearchList;
  25. }
  26. } catch (e) {
  27. console.error('Parse statusSearchList error:', e);
  28. }
  29. }
  30. for (var key in statusSearchList) {
  31. if (statusSearchList.hasOwnProperty(key)) {
  32. stateList[key] = {
  33. text: statusSearchList[key],
  34. class: key == 1 ? 'label-success' : 'label-info',
  35. icon: key == 1 ? 'fa fa-check' : 'fa fa-close'
  36. };
  37. }
  38. }
  39. // 初始化表格
  40. table.bootstrapTable({
  41. url: $.fn.bootstrapTable.defaults.extend.index_url,
  42. pk: 'id',
  43. sortName: 'id',
  44. columns: [
  45. [
  46. {checkbox: true},
  47. {field: 'id', title: __('Id')},
  48. {field: 'name', title: __('Name'), operate: 'LIKE'},
  49. {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  50. {field: 'contact_person', title: __('Contact_person'), operate: 'LIKE'},
  51. {field: 'contact_phone', title: __('Contact_phone'), operate: 'LIKE'},
  52. {field: 'status', title: __('Status'),searchList: statusSearchList, formatter: Controller.api.formatter.status},
  53. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  54. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  55. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  56. ]
  57. ]
  58. });
  59. // 为表格绑定事件
  60. Table.api.bindevent(table);
  61. },
  62. recyclebin: function () {
  63. // 初始化表格参数配置
  64. Table.api.init({
  65. extend: {
  66. 'dragsort_url': ''
  67. }
  68. });
  69. var table = $("#table");
  70. // 初始化表格
  71. table.bootstrapTable({
  72. url: 'inspection/factory/recyclebin' + location.search,
  73. pk: 'id',
  74. sortName: 'id',
  75. columns: [
  76. [
  77. {checkbox: true},
  78. {field: 'id', title: __('Id')},
  79. {field: 'name', title: __('Name'), align: 'left'},
  80. {
  81. field: 'deletetime',
  82. title: __('Deletetime'),
  83. operate: 'RANGE',
  84. addclass: 'datetimerange',
  85. formatter: Table.api.formatter.datetime
  86. },
  87. {
  88. field: 'operate',
  89. width: '140px',
  90. title: __('Operate'),
  91. table: table,
  92. events: Table.api.events.operate,
  93. buttons: [
  94. {
  95. name: 'Restore',
  96. text: __('Restore'),
  97. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  98. icon: 'fa fa-rotate-left',
  99. url: 'inspection/factory/restore',
  100. refresh: true
  101. },
  102. {
  103. name: 'Destroy',
  104. text: __('Destroy'),
  105. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  106. icon: 'fa fa-times',
  107. url: 'inspection/factory/destroy',
  108. refresh: true
  109. }
  110. ],
  111. formatter: Table.api.formatter.operate
  112. }
  113. ]
  114. ]
  115. });
  116. // 为表格绑定事件
  117. Table.api.bindevent(table);
  118. },
  119. add: function () {
  120. Controller.api.bindevent();
  121. },
  122. edit: function () {
  123. Controller.api.bindevent();
  124. },
  125. api: {
  126. bindevent: function () {
  127. Form.api.bindevent($("form[role=form]"));
  128. },
  129. formatter: {
  130. status: function(value, row, index) {
  131. var state = stateList[value] || {};
  132. return '<span class="label ' + (state.class || '') + '"><i class="' + (state.icon || '') + '"></i> ' + (state.text || value) + '</span>';
  133. },
  134. }
  135. }
  136. };
  137. return Controller;
  138. });