postbackreferral.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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: 'postbackreferral/index?&type=' + Config.type + '&rule_id=' + Config.rule_id + '&action=' + Config.action,
  8. table: 'referral',
  9. },
  10. search: false
  11. });
  12. var table = $("#table");
  13. // 初始化表格
  14. table.bootstrapTable({
  15. url: $.fn.bootstrapTable.defaults.extend.index_url,
  16. pk: 'id',
  17. sortName: 'id',
  18. columns: [
  19. [
  20. {checkbox: true},
  21. {field: 'id', title: __('Id')},
  22. {field: 'name', title: __('Name')},
  23. {
  24. field: 'operate',
  25. title: __('Operate'),
  26. operate: false,
  27. formatter: function (value, row, table) {
  28. if (Config.action == 'relation') {
  29. return "<a href='javascript:;' class='batch_relation' data-action='add' data-referral_id='" + row.id + "'>关联</a>";
  30. } else {
  31. return "<a href='javascript:;' class='batch_relation' data-action='delete' data-referral_id='" + row.id + "'>删除</a>";
  32. }
  33. }
  34. }
  35. ]
  36. ]
  37. });
  38. // 为表格绑定事件
  39. Table.api.bindevent(table);
  40. $(document).delegate('.batch_relation', 'click', function () {
  41. var ids = [];
  42. var action = $(this).data('action');
  43. if ($(this).data('referral_id')) {
  44. ids.push($(this).data('referral_id'));
  45. } else {
  46. ids = Table.api.selectedids(table);
  47. }
  48. Controller.api.batchrelation(ids, action, table)
  49. });
  50. },
  51. add: function () {
  52. Controller.api.bindevent();
  53. },
  54. edit: function () {
  55. Controller.api.bindevent();
  56. },
  57. api: {
  58. bindevent: function () {
  59. Form.api.bindevent($("form[role=form]"));
  60. },
  61. batchrelation: function (ids, action, table) {
  62. if (ids.length) {
  63. debugger
  64. var msg = '';
  65. if (ids[0] == '-1') {
  66. if (!$(table).find('.no-records-found').length) {
  67. if (action == 'add') {
  68. msg = '关联全部推广链接?';
  69. } else {
  70. msg = '删除全部推广链接?';
  71. }
  72. } else {
  73. Layer.alert('推广链接为空,操作取消');
  74. return;
  75. }
  76. } else {
  77. msg = __('已选中推广链接个数:%s', ids.length);
  78. }
  79. Layer.confirm(
  80. msg,
  81. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  82. function (index) {
  83. var url = 'postbackreferral/batch_relation';
  84. var options = {
  85. url: url,
  86. data: {referral_ids: ids.join(","), rule_id: Config.rule_id, action: action, type: Config.type}
  87. };
  88. Fast.api.ajax(options, function (data, ret) {
  89. Layer.msg('处理成功!');
  90. table.bootstrapTable('refresh');
  91. parent.layer.close(this);
  92. }, function (data, ret) {
  93. });
  94. Layer.close(index);
  95. }
  96. );
  97. }
  98. }
  99. }
  100. };
  101. return Controller;
  102. });