keyword.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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: 'search/keyword/index',
  8. add_url: 'book/book/select',
  9. del_url: 'search/keyword/del',
  10. multi_url: 'search/keyword/multi',
  11. table: 'search_keyword',
  12. },
  13. showToggle:false,
  14. showColumns:false,
  15. showExport:false,
  16. commonSearch:false,
  17. });
  18. var table = $("#table");
  19. // 初始化表格
  20. table.bootstrapTable({
  21. url: $.fn.bootstrapTable.defaults.extend.index_url,
  22. pk: 'id',
  23. sortName: 'weigh',
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'keyword', title: __('Keyword')},
  29. {field: 'book_id', title: __('书籍id')},
  30. {field: 'weigh', title: __('Weigh')},
  31. {field: 'book.cansee_text', title: '代理商/渠道商是否可见', operate: false},
  32. {field: 'book.state_text', title: '上架状态', operate: false},
  33. {field: 'sex_text', title: __('频道'), operate:false},
  34. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  35. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. Controller.api.bindevent();
  42. },
  43. add: function () {
  44. Controller.api.bindevent();
  45. },
  46. edit: function () {
  47. Controller.api.bindevent();
  48. },
  49. api: {
  50. bindevent: function () {
  51. Form.api.bindevent($("form[role=form]"));
  52. //搜索关键词 选择书籍后回调
  53. var refreshkey = function (data) {
  54. var ids = [];
  55. for ( var i = data.length - 1; i >= 0 ; i-- ) {
  56. ids.push(data[i].id);
  57. }
  58. Fast.api.ajax({
  59. url: "search/keyword/add",
  60. type: "get",
  61. data: {ids: ids.join(',')},
  62. },function () {
  63. $('.btn-refresh').trigger('click');
  64. });
  65. };
  66. $(document).on('click', "#select-resources", function () {
  67. var block_id = Config.block_id;
  68. parent.Backend.api.open($(this).attr("href") + "?action=searchkeyword&state=1" , __('Select'), {callback: refreshkey});
  69. return false;
  70. });
  71. }
  72. }
  73. };
  74. return Controller;
  75. });