vip.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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: 'vip/vip/index' + location.search,
  8. add_url: 'vip/vip/add',
  9. edit_url: 'vip/vip/edit',
  10. del_url: 'vip/vip/del',
  11. multi_url: 'vip/vip/multi',
  12. import_url: 'vip/vip/import',
  13. table: 'vip',
  14. },
  15. });
  16. Table.button.edit.extend = Table.button.edit.extend + ` data-area='["90%","90%"]'`
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'level',
  23. sortOrder: 'asc',
  24. columns: [
  25. [{
  26. checkbox: true
  27. },
  28. {
  29. field: 'id',
  30. title: __('Id')
  31. },
  32. {
  33. field: 'level',
  34. title: __('Level')
  35. },
  36. // {field: 'group_id', title: __('Group_id')},
  37. {
  38. field: 'name',
  39. title: __('Name'),
  40. operate: 'LIKE'
  41. },
  42. {
  43. field: 'label',
  44. title: __('Label'),
  45. operate: 'LIKE'
  46. },
  47. {
  48. field: 'intro',
  49. title: __('Intro'),
  50. operate: 'LIKE'
  51. },
  52. {
  53. field: 'image',
  54. title: __('Image'),
  55. operate: false,
  56. events: Table.api.events.image,
  57. formatter: Table.api.formatter.image
  58. },
  59. // {field: 'price', title: __('Price'), operate: 'BETWEEN'},
  60. {
  61. field: 'sales',
  62. title: __('Sales')
  63. },
  64. {
  65. field: 'createtime',
  66. title: __('Createtime'),
  67. operate: 'RANGE',
  68. addclass: 'datetimerange',
  69. autocomplete: false,
  70. formatter: Table.api.formatter.datetime
  71. },
  72. {
  73. field: 'status',
  74. title: __('Status'),
  75. searchList: {
  76. "normal": __('Normal'),
  77. "hidden": __('Hidden'),
  78. "pulloff": __('Pulloff')
  79. },
  80. formatter: Table.api.formatter.status
  81. },
  82. {
  83. field: 'operate',
  84. title: __('Operate'),
  85. table: table,
  86. events: Table.api.events.operate,
  87. formatter: Table.api.formatter.operate
  88. }
  89. ]
  90. ]
  91. });
  92. // 为表格绑定事件
  93. Table.api.bindevent(table);
  94. },
  95. diyFieldList(type) {
  96. var container = $("#pricetable");
  97. var refresh = function () {
  98. setTimeout(function () {
  99. if ($("select option[value=1]:selected", container).length == 0) {
  100. $("select option[value=1]:first", container).prop("selected", true);
  101. }
  102. }, 1);
  103. };
  104. container.on('change', "select", function () {
  105. if ($(this).val() == 1) {
  106. $(this).closest(".fieldlist").find("select").not(this).find("option[value=0]").prop("selected", true);
  107. $("option[value=1]", this).prop("selected", true);
  108. } else {
  109. refresh();
  110. }
  111. });
  112. container.on("click", ".btn-remove", function () {
  113. refresh();
  114. });
  115. container.on("fa.event.appendfieldlist", ".btn-append", function (e, obj) {
  116. refresh();
  117. });
  118. $("#righttable").on("fa.event.appendfieldlist", ".btn-append", function (e, obj) {
  119. Form.events.plupload(obj);
  120. Form.events.faselect(obj);
  121. });
  122. },
  123. add: function () {
  124. this.diyFieldList('add');
  125. Controller.api.bindevent();
  126. },
  127. edit: function () {
  128. this.diyFieldList('edit');
  129. Controller.api.bindevent();
  130. },
  131. api: {
  132. bindevent: function () {
  133. Form.api.bindevent($("form[role=form]"));
  134. }
  135. }
  136. };
  137. return Controller;
  138. });