goods.js 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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: 'goods/index',
  8. add_url: 'goods/add',
  9. edit_url: 'goods/edit',
  10. del_url: 'goods/del',
  11. multi_url: 'goods/multi',
  12. table: 'goods',
  13. },
  14. showToggle:false,
  15. showColumns:false,
  16. showExport:false,
  17. searchFormVisible: true,
  18. });
  19. //绑定事件
  20. // $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  21. // var panel = $($(this).attr("href"));
  22. // console.log('goods?category_id='+$(this).attr("href"));
  23. // if (panel.size() > 0) {
  24. // Controller.table[panel.attr("id")].call(this);
  25. // $(this).on('click', function (e) {
  26. // $('goods?category_id='+$(this).attr("href")).trigger("click");
  27. // });
  28. // }
  29. // //移除绑定的事件
  30. // // $(this).unbind('shown.bs.tab');
  31. // });
  32. var table = $("#table");
  33. // 初始化表格
  34. table.bootstrapTable({
  35. url: $.fn.bootstrapTable.defaults.extend.index_url,
  36. pk: 'id',
  37. sortName: 'weigh',
  38. columns: [
  39. [
  40. {checkbox: true},
  41. {field: 'title', title: __('Title'),operate:false},
  42. {field: 'category_id', title: __('Category_name'),searchList: $.getJSON('goods/categorylist'),formatter: Controller.api.formatter.category_name},
  43. {field: 'money', title: __('Money'),operate:false},
  44. {field: 'first_description', title: __('First_description'),operate:false},
  45. {field: 'second_description', title: __('Second_description'),operate:false},
  46. {field: 'type_text', title: __('Type'), operate:false},
  47. {field: 'kandian', title: __('Kandian'),operate:false},
  48. {field: 'free_kandian', title: __('Free_kandian'),operate:false},
  49. {field: 'day', title: __('Day'),operate:false},
  50. {field: 'icon', title: __('Icon'),operate:false},
  51. {field: 'show_type_text', title: __('Show_type'), operate:false},
  52. {field: 'weigh', title: __('Weigh'),operate:false},
  53. {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime,operate:false},
  54. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  55. ]
  56. ]
  57. });
  58. // 为表格绑定事件
  59. Table.api.bindevent(table);
  60. Controller.api.bindevent();
  61. },
  62. add: function () {
  63. Controller.api.bindevent();
  64. },
  65. edit: function () {
  66. Controller.api.bindevent();
  67. },
  68. api: {
  69. bindevent: function () {
  70. Form.api.bindevent($("form[role=form]"));
  71. $(document).on("click", ".resource_type", function () {
  72. var type = $("input[name='row[type]']:checked").val();
  73. if(type==2){
  74. $('.day').removeAttr('style');
  75. $('.kandian').css('display','none');
  76. }
  77. if(type==1){
  78. $('.kandian').removeAttr('style');
  79. $('.day').css('display','none');
  80. }
  81. });
  82. },
  83. formatter: {
  84. category_name:function (value, row, index) {
  85. return row.category.name;
  86. }
  87. }
  88. }
  89. };
  90. return Controller;
  91. });