product.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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: 'product/product/index' + location.search,
  8. add_url: 'product/product/add',
  9. edit_url: 'product/product/edit',
  10. del_url: 'product/product/del',
  11. multi_url: 'product/product/multi',
  12. import_url: 'product/product/import',
  13. table: 'product',
  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. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. {field: 'title', title: __('Title'), operate: 'LIKE'},
  27. {field: 'category_ids', title: __('Category_ids'), operate: 'LIKE'},
  28. {field: 'showswitch', title: __('Showswitch'), searchList: {"1":__('Yes'),"0":__('No')}, table: table, formatter: Table.api.formatter.toggle},
  29. {field: 'loopswitch', title: __('Loopswitch'), table: table, formatter: Table.api.formatter.toggle},
  30. {field: 'recommendswitch', title: __('Recommendswitch'), table: table, formatter: Table.api.formatter.toggle},
  31. {field: 'newswitch', title: __('Newswitch'), table: table, formatter: Table.api.formatter.toggle},
  32. {field: 'coverimage', title: __('Coverimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  33. {field: 'author', title: __('Author'), operate: 'LIKE'},
  34. {field: 'visit', title: __('Visit')},
  35. {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
  36. {field: 'admin_id', title: __('Admin_id')},
  37. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  38. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  39. ]
  40. ]
  41. });
  42. // 为表格绑定事件
  43. Table.api.bindevent(table);
  44. },
  45. recyclebin: function () {
  46. // 初始化表格参数配置
  47. Table.api.init({
  48. extend: {
  49. 'dragsort_url': ''
  50. }
  51. });
  52. var table = $("#table");
  53. // 初始化表格
  54. table.bootstrapTable({
  55. url: 'product/product/recyclebin' + location.search,
  56. pk: 'id',
  57. sortName: 'id',
  58. columns: [
  59. [
  60. {checkbox: true},
  61. {field: 'id', title: __('Id')},
  62. {field: 'title', title: __('Title'), align: 'left'},
  63. {
  64. field: 'deletetime',
  65. title: __('Deletetime'),
  66. operate: 'RANGE',
  67. addclass: 'datetimerange',
  68. formatter: Table.api.formatter.datetime
  69. },
  70. {
  71. field: 'operate',
  72. width: '130px',
  73. title: __('Operate'),
  74. table: table,
  75. events: Table.api.events.operate,
  76. buttons: [
  77. {
  78. name: 'Restore',
  79. text: __('Restore'),
  80. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  81. icon: 'fa fa-rotate-left',
  82. url: 'product/product/restore',
  83. refresh: true
  84. },
  85. {
  86. name: 'Destroy',
  87. text: __('Destroy'),
  88. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  89. icon: 'fa fa-times',
  90. url: 'product/product/destroy',
  91. refresh: true
  92. }
  93. ],
  94. formatter: Table.api.formatter.operate
  95. }
  96. ]
  97. ]
  98. });
  99. // 为表格绑定事件
  100. Table.api.bindevent(table);
  101. },
  102. add: function () {
  103. Controller.api.bindevent();
  104. },
  105. edit: function () {
  106. Controller.api.bindevent();
  107. },
  108. api: {
  109. bindevent: function () {
  110. Form.api.bindevent($("form[role=form]"));
  111. }
  112. }
  113. };
  114. return Controller;
  115. });