fields.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'workorder/fields/index' + location.search,
  8. add_url: 'workorder/fields/add',
  9. edit_url: 'workorder/fields/edit',
  10. del_url: 'workorder/fields/del',
  11. multi_url: 'workorder/fields/multi',
  12. import_url: 'workorder/fields/import',
  13. table: 'workorder_fields',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'weigh',
  22. exportTypes: ['excel'],
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'id', title: __('Id')},
  27. {
  28. field: 'position',
  29. title: __('Position'),
  30. searchList: {
  31. "0": __('Position 0'),
  32. },
  33. formatter: Table.api.formatter.status
  34. },
  35. {field: 'name', title: __('Name')},
  36. {field: 'title', title: __('Title')},
  37. {
  38. field: 'type_list',
  39. title: __('Type_list'),
  40. searchList: {
  41. "string": __('Type_list string'),
  42. "textarea": __('Type_list textarea'),
  43. "text": __('Type_list text'),
  44. "editor": __('Type_list editor'),
  45. "number": __('Type_list number'),
  46. "date": __('Type_list date'),
  47. "time": __('Type_list time'),
  48. "datetime": __('Type_list datetime'),
  49. "select": __('Type_list select'),
  50. "selects": __('Type_list selects'),
  51. "image": __('Type_list image'),
  52. "images": __('Type_list images'),
  53. "file": __('Type_list file'),
  54. "files": __('Type_list files'),
  55. "switch": __('Type_list switch'),
  56. "checkbox": __('Type_list checkbox'),
  57. "radio": __('Type_list radio'),
  58. "city": __('Type_list city')
  59. },
  60. formatter: Table.api.formatter.normal
  61. },
  62. // {field: 'default', title: __('Default')},
  63. // {field: 'rule', title: __('Rule')},
  64. // {field: 'errormsg', title: __('Errormsg')},
  65. {field: 'notice', title: __('Notice')},
  66. {field: 'field_length', title: __('Field_length')},
  67. {
  68. field: 'isfilter',
  69. title: __('Isfilter'),
  70. searchList: {"1": __('Yes'), "0": __('No')},
  71. formatter: Controller.api.formatter.toggle
  72. },
  73. // {field: 'extend', title: __('Extend')},
  74. {
  75. field: 'isbasicinfo',
  76. title: __('Isbasicinfo'),
  77. searchList: {"0": __('Isbasicinfo 0'), "1": __('Isbasicinfo 1')},
  78. formatter: Controller.api.formatter.status
  79. },
  80. {
  81. field: 'status',
  82. title: __('Status'),
  83. searchList: {"0": __('Status 0'), "1": __('Status 1')},
  84. formatter: Table.api.formatter.status
  85. },
  86. {field: 'weigh', title: __('Weigh')},
  87. {
  88. field: 'createtime',
  89. title: __('Createtime'),
  90. operate: 'RANGE',
  91. addclass: 'datetimerange',
  92. formatter: Table.api.formatter.datetime
  93. },
  94. {
  95. field: 'operate',
  96. title: __('Operate'),
  97. table: table,
  98. events: Table.api.events.operate,
  99. formatter: function (value, row, index) {
  100. var ban_del = ['title', 'describe'];
  101. if (ban_del.includes(row.name)) {
  102. var that = $.extend({}, this);
  103. var table = $(that.table).clone(true);
  104. $(table).data("operate-del", null);
  105. that.table = table;
  106. return Table.api.formatter.operate.call(that, value, row, index);
  107. }
  108. return Table.api.formatter.operate.call(this, value, row, index);
  109. }
  110. }
  111. ]
  112. ]
  113. });
  114. // 为表格绑定事件
  115. Table.api.bindevent(table);
  116. },
  117. add: function () {
  118. Controller.api.bindevent();
  119. },
  120. edit: function () {
  121. Controller.api.bindevent();
  122. },
  123. api: {
  124. bindevent: function () {
  125. $("form#add-form").data("validator-options", {ignore: ':hidden'});
  126. $(document).on("change", "#c-type_list", function () {
  127. let typeList = $(this).val();
  128. $(".tf").addClass("hidden");
  129. $(".tf.tf-" + typeList).removeClass("hidden");
  130. if (typeList == 'switch') {
  131. let defaultEl = $('#c-default');
  132. defaultEl.val(defaultEl.val() ? defaultEl.val():'0')
  133. }
  134. });
  135. $(document).on("change", '#c-position', function () {
  136. $(".pp").addClass("hidden");
  137. $(".pp.position-" + $(this).val()).removeClass("hidden");
  138. })
  139. Form.api.bindevent($("form[role=form]"));
  140. $("#c-type_list").trigger("change");
  141. $("#c-position").trigger("change");
  142. },
  143. formatter: {
  144. toggle: function (value, row, index) {
  145. // if (row.position == 0) {
  146. var that = $.extend({}, this);
  147. var table = $(that.table).clone(true);
  148. that.table = table;
  149. return Table.api.formatter.toggle.call(that, value, row, index);
  150. // } else {
  151. // return '-';
  152. // }
  153. },
  154. status: function (value, row, index) {
  155. if (row.position == 0) {
  156. var that = $.extend({}, this);
  157. var table = $(that.table).clone(true);
  158. that.table = table;
  159. return Table.api.formatter.status.call(that, value, row, index);
  160. } else {
  161. return '-';
  162. }
  163. }
  164. }
  165. }
  166. };
  167. return Controller;
  168. });