You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

135 lines
6.2 KiB

  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. // 合并格式化方法
  3. Table.api.formatter = $.extend(Table.api.formatter,
  4. {
  5. topTimeToggle: function (value, row, index) {
  6. var color = typeof this.color !== 'undefined' ? this.color : 'success';
  7. var yes = typeof this.yes !== 'undefined' ? this.yes : 1;
  8. var no = typeof this.no !== 'undefined' ? this.no : 0;
  9. var url = typeof this.url !== 'undefined' ? this.url : '';
  10. return "<a href='javascript:;' data-toggle='tooltip' title='" + __('Click to toggle') + "' class='btn-change' data-id='"
  11. + row.id + "' " + (url ? "data-url='" + url + "'" : "") + " data-params='" + this.field + "=" + (value == no ? yes : no) + "'><i class='fa fa-toggle-on " + (value == no ? 'fa-flip-horizontal text-gray' : 'text-' + color ) + " fa-2x'></i></a>";
  12. }
  13. }
  14. );
  15. var Controller = {
  16. index: function () {
  17. // 初始化表格参数配置
  18. Table.api.init({
  19. extend: {
  20. index_url: 'unishop/evaluate/index' + location.search,
  21. add_url: 'unishop/evaluate/add',
  22. edit_url: 'unishop/evaluate/edit',
  23. del_url: 'unishop/evaluate/del',
  24. multi_url: 'unishop/evaluate/multi',
  25. table: 'unishop_evaluate',
  26. }
  27. });
  28. var table = $("#table");
  29. // 初始化表格
  30. table.bootstrapTable({
  31. url: $.fn.bootstrapTable.defaults.extend.index_url,
  32. pk: 'id',
  33. sortName: 'id',
  34. columns: [
  35. [
  36. {checkbox: true},
  37. {field: 'id', title: __('Id')},
  38. {field: 'user_id', title: __('User_id')},
  39. {field: 'order_id', title: __('Order_id')},
  40. {field: 'product_id', title: __('Product_id')},
  41. {field: 'product.title', title: __('Product title')},
  42. {field: 'spec', title: __('Spec')},
  43. {field: 'comment', title: __('Comment')},
  44. {field: 'rate', title: __('Rate'), searchList: {"1":__('Rate 1'),"2":__('Rate 2'),"3":__('Rate 3'),"4":__('Rate 4'),"5":__('Rate 5')}, formatter: Table.api.formatter.normal},
  45. {field: 'anonymous', title: __('Anonymous'), searchList: {"0":__('Anonymous 0'),"1":__('Anonymous 1')}, formatter: Table.api.formatter.normal},
  46. {field: 'toptime', title: __('Toptime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.topTimeToggle},
  47. {field: 'toptime', title: __('Top time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  48. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  49. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  50. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  51. ]
  52. ]
  53. });
  54. // 为表格绑定事件
  55. Table.api.bindevent(table);
  56. },
  57. recyclebin: function () {
  58. // 初始化表格参数配置
  59. Table.api.init({
  60. extend: {
  61. 'dragsort_url': ''
  62. }
  63. });
  64. var table = $("#table");
  65. // 初始化表格
  66. table.bootstrapTable({
  67. url: 'unishop/evaluate/recyclebin' + location.search,
  68. pk: 'id',
  69. sortName: 'id',
  70. columns: [
  71. [
  72. {checkbox: true},
  73. {field: 'id', title: __('Id')},
  74. {
  75. field: 'deletetime',
  76. title: __('Deletetime'),
  77. operate: 'RANGE',
  78. addclass: 'datetimerange',
  79. formatter: Table.api.formatter.datetime
  80. },
  81. {
  82. field: 'operate',
  83. width: '130px',
  84. title: __('Operate'),
  85. table: table,
  86. events: Table.api.events.operate,
  87. buttons: [
  88. {
  89. name: 'Restore',
  90. text: __('Restore'),
  91. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  92. icon: 'fa fa-rotate-left',
  93. url: 'unishop/evaluate/restore',
  94. refresh: true
  95. },
  96. {
  97. name: 'Destroy',
  98. text: __('Destroy'),
  99. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  100. icon: 'fa fa-times',
  101. url: 'unishop/evaluate/destroy',
  102. refresh: true
  103. }
  104. ],
  105. formatter: Table.api.formatter.operate
  106. }
  107. ]
  108. ]
  109. });
  110. // 为表格绑定事件
  111. Table.api.bindevent(table);
  112. },
  113. add: function () {
  114. Controller.api.bindevent();
  115. },
  116. edit: function () {
  117. Controller.api.bindevent();
  118. },
  119. api: {
  120. bindevent: function () {
  121. Form.api.bindevent($("form[role=form]"));
  122. }
  123. }
  124. };
  125. return Controller;
  126. });