product.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function ($, undefined, Backend, Table, Form, jstree) {
  2. var Controller = {
  3. index: function () {
  4. $(".btn-detail").data("area", ['90%', '90%']);
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'wwh/product/index',
  9. add_url: 'wwh/product/add',
  10. edit_url: 'wwh/product/edit',
  11. del_url: 'wwh/product/del',
  12. multi_url: 'wwh/product/multi',
  13. table: 'wwh_product',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'product.id',
  22. height: $(window).height() - 97,
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'id', title: __('Id'), },
  27. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  28. {field: 'productcategory.name', title: __('Productcategory')},
  29. {field: 'productname', title: __('Productname')},
  30. {field: 'p_keywords', title: __('P_keywords')},
  31. {field: 'p_description', title: __('P_description')},
  32. {field: 'tjdata', title: __('Tjdata'), searchList: {"0":__('Tjdata 0'),"1":__('Tjdata 1')}, formatter: Table.api.formatter.normal},
  33. {
  34. field: 'model', sortable: false, title: __('Model'), formatter: function (value, row, index) {
  35. var width = this.width != undefined ? this.width : 250;
  36. return "<div style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + "px;'>" + value + "</div>";
  37. }
  38. },
  39. {
  40. field: 'description', sortable: false, title: __('Description'), formatter: function (value, row, index) {
  41. var width = this.width != undefined ? this.width : 250;
  42. return "<div style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + "px;'>" + value + "</div>";
  43. }
  44. },
  45. {field: 'indent_image', title: __('Indent_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
  46. {field: 'banner_images', title: __('Banner_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
  47. {field: 'index_image', title: __('Index_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
  48. {field: 'size_image', title: __('Size_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
  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. queryParams: function (params) {
  54. return params;
  55. },
  56. onPostBody: function () {
  57. $(".btn-detailone").data("area", ['90%', '90%']);
  58. }
  59. });
  60. // 为表格绑定事件
  61. Table.api.bindevent(table);
  62. require(['jstree'], function () {
  63. //全选和展开
  64. $(document).on("click", "#checkall", function () {
  65. $("#channeltree").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  66. });
  67. $(document).on("click", "#expandall", function () {
  68. $("#channeltree").jstree($(this).prop("checked") ? "open_all" : "close_all");
  69. });
  70. $('#channeltree').on("changed.jstree", function (e, data) {
  71. console.log(data);
  72. console.log(data.selected);
  73. var options = table.bootstrapTable('getOptions');
  74. options.pageNumber = 1;
  75. options.queryParams = function (params) {
  76. params.filter = JSON.stringify(data.selected.length > 0 ? {productcategoryid: data.selected.join(",")} : {});
  77. params.op = JSON.stringify(data.selected.length > 0 ? {productcategoryid: 'in'} : {});
  78. return params;
  79. };
  80. table.bootstrapTable('refresh', {});
  81. return false;
  82. });
  83. $('#channeltree').jstree({
  84. "themes": {
  85. "stripes": true
  86. },
  87. "checkbox": {
  88. "keep_selected_style": false,
  89. },
  90. "types": {
  91. "channel": {
  92. "icon": "fa fa-th",
  93. },
  94. "list": {
  95. "icon": "fa fa-list",
  96. },
  97. "link": {
  98. "icon": "fa fa-link",
  99. },
  100. "disabled": {
  101. "check_node": false,
  102. "uncheck_node": false
  103. }
  104. },
  105. 'plugins': ["types", "checkbox"],
  106. "core": {
  107. "multiple": true,
  108. 'check_callback': true,
  109. "themes":{
  110. "icons":false,
  111. },
  112. "data": {
  113. url: "wwh/productcategory/getjsTree",
  114. }
  115. }
  116. });
  117. });
  118. },
  119. add: function () {
  120. Controller.api.bindevent();
  121. },
  122. edit: function () {
  123. Controller.api.bindevent();
  124. },
  125. api: {
  126. bindevent: function () {
  127. Form.api.bindevent($("form[role=form]"));
  128. }
  129. },
  130. };
  131. return Controller;
  132. });