channelfufen.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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: 'channelfufen/index',
  8. multi_url: 'channelfufen/show',
  9. table: 'admin',
  10. },
  11. search:false
  12. });
  13. var table = $("#table");
  14. // 初始化表格
  15. table.bootstrapTable({
  16. url: $.fn.bootstrapTable.defaults.extend.index_url + '?ids='+Config.data.fufenid,
  17. pk: 'id',
  18. sortName: 'admin.id',
  19. sortOrder: 'desc',
  20. columns: [
  21. [
  22. {checkbox: true},
  23. {field: 'id', title: __('Id')},
  24. {field: 'username', title: '账号', operate: 'LIKE'},
  25. {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
  26. {field: 'appid', title: __('Appid'), operate: false},
  27. {field: 'c_nickname', title: '开户人', operate: false},
  28. {field: 'operate', title: __('Operate'), formatter: function (value, row) {
  29. return "<a href='javascript:;' class='batch_relation' data-channel_id='"+row.id+"'>关联</a>";
  30. }}
  31. ]
  32. ]
  33. });
  34. $(document).delegate('.batch_relation', 'click', function () {
  35. var ids = [];
  36. if ($(this).data('channel_id')) {
  37. ids.push($(this).data('channel_id'));
  38. } else {
  39. ids = Table.api.selectedids(table);
  40. }
  41. Controller.api.batchrelation(ids, 'add', table)
  42. });
  43. // 为表格绑定事件
  44. Table.api.bindevent(table);
  45. },
  46. show: function () {
  47. // 初始化表格参数配置
  48. Table.api.init({
  49. extend: {
  50. index_url: 'channelfufen/show',
  51. multi_url: 'channelfufen/del',
  52. table: 'admin',
  53. },
  54. search:false
  55. });
  56. var table = $("#table");
  57. // 初始化表格
  58. table.bootstrapTable({
  59. url: $.fn.bootstrapTable.defaults.extend.index_url + '?ids='+Config.data.fufenid,
  60. pk: 'id',
  61. sortName: 'admin.id',
  62. sortOrder: 'desc',
  63. columns: [
  64. [
  65. {checkbox: true},
  66. {field: 'id', title: __('Id')},
  67. {field: 'username', title: '账号', operate: 'LIKE'},
  68. {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
  69. {field: 'appid', title: __('Appid'), operate: false},
  70. {field: 'c_nickname', title: '开户人', operate: false},
  71. {field: 'operate', title: __('Operate'), formatter: function (value, row) {
  72. return "<a href='javascript:;' class='batch_relation' data-channel_id='"+row.id+"'>删除</a>";
  73. }}
  74. ]
  75. ]
  76. });
  77. $(document).delegate('.batch_relation', 'click', function () {
  78. var ids = [];
  79. if ($(this).data('channel_id')) {
  80. ids.push($(this).data('channel_id'));
  81. } else {
  82. ids = Table.api.selectedids(table);
  83. }
  84. Controller.api.batchrelation(ids, 'remove', table)
  85. });
  86. // 为表格绑定事件
  87. Table.api.bindevent(table);
  88. },
  89. api: {
  90. bindevent: function () {
  91. Form.api.bindevent($("form[role=form]"));
  92. },
  93. batchrelation: function (ids, action, table) {
  94. Layer.confirm(
  95. __('已选中条数:%s', ids.length),
  96. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  97. function (index) {
  98. var url = 'channelfufen/batch_relation';
  99. var options = {url: url, data: { channel_ids: ids.join(","), fufen_id: Config.data.fufenid, action: action}};
  100. Fast.api.ajax(options, function (data, ret) {
  101. Layer.msg('处理成功!');
  102. table.bootstrapTable('refresh');
  103. parent.layer.close(this);
  104. }, function (data, ret) {
  105. });
  106. Layer.close(index);
  107. }
  108. );
  109. }
  110. }
  111. };
  112. return Controller;
  113. });