channelfunctionmanage.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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: 'auth/channelfunctionmanage/index',
  8. add_url: 'auth/channelfunctionmanage/add',
  9. edit_url: 'auth/channelfunctionmanage/edit',
  10. del_url: 'auth/channelfunctionmanage/del',
  11. multi_url: 'auth/channelfunctionmanage/multi',
  12. do_choose: 'auth/channelfunctionmanage/operate',
  13. select_url: 'referral/vipreferral/selectchannel',
  14. },
  15. showToggle: false,
  16. showColumns: false,
  17. visible: false,
  18. commonSearch: false,
  19. showExport: false
  20. });
  21. var table = $("#table");
  22. table.bootstrapTable({
  23. url: $.fn.bootstrapTable.defaults.extend.index_url,
  24. columns: [
  25. [
  26. {field: 'id', title: '功能ID'},
  27. {field: 'name', title: __('功能名称')},
  28. {field: 'rule_name', title: __('方法名称')},
  29. {
  30. field: 'id',
  31. operate:false,
  32. title: __('关联渠道'),
  33. formatter: Controller.api.formatter.fm_associate_channels
  34. },
  35. {
  36. field: 'id',
  37. operate:false,
  38. title: __('一键清除'),
  39. formatter: function (index, row, value) {
  40. return "<a href='javascript:;' class='qd-associate-all' data-rule_id='" + index + "' data-channel_id='"+ row.channel_id+"'>清除所有渠道</a>";
  41. }
  42. },
  43. {
  44. field: 'operate',
  45. title: '操作',
  46. table: table,
  47. events: Table.api.events.operate,
  48. formatter: Table.api.formatter.operate
  49. }
  50. ]
  51. ]
  52. });
  53. //一键清除
  54. $(document).on('click', '.qd-associate-all', function () {
  55. var rule_id = $(this).data("rule_id");
  56. Layer.confirm(
  57. '确定要清理所有渠道吗',
  58. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  59. function (index) {
  60. $.post('/admin/auth/frontlimit/operate',
  61. {
  62. 'id': rule_id,
  63. 'channel_ids': "*",
  64. 'method': 'remove'
  65. },
  66. function (result) {
  67. Toastr.success('操作成功');
  68. //刷新页面
  69. table.bootstrapTable('refresh');
  70. });
  71. Layer.close(index);
  72. }
  73. );
  74. });
  75. // 列表关联
  76. $(document).on('click', '.qd-associate', function () {
  77. var rule_id = $(this).data("rule_id");
  78. var channel_ids = $(this).data("channel_id");
  79. if (channel_ids == 'undefined') {
  80. channel_ids = '';
  81. }
  82. Fast.api.open('/admin/auth/channel?operate=add&channel_ids=' + channel_ids, "关联渠道", {callback: function (data) {
  83. $.post('/admin/auth/frontlimit/operate',
  84. {
  85. 'id': rule_id,
  86. 'channel_ids': data,
  87. 'method': 'add'
  88. },
  89. function (result) {
  90. Toastr.success('操作成功');
  91. //刷新页面
  92. table.bootstrapTable('refresh');
  93. });
  94. }
  95. });
  96. });
  97. // 列表 查看
  98. $(document).on('click', '.qd-view', function () {
  99. var rule_id = $(this).data("rule_id");
  100. var channel_ids = $(this).data("channel_id");
  101. if (channel_ids == 'undefined') {
  102. channel_ids = '';
  103. }
  104. Fast.api.open('/admin/auth/channel?operate=remove&channel_ids=' + channel_ids, "关联渠道", {callback: function (data) {
  105. $.post('/admin/auth/frontlimit/operate',
  106. {
  107. 'id': rule_id,
  108. 'channel_ids': data,
  109. 'method': 'remove'
  110. },
  111. function (result) {
  112. Toastr.success('操作成功');
  113. //刷新页面
  114. table.bootstrapTable('refresh');
  115. });
  116. }
  117. });
  118. });
  119. $(document).on("click", ".qd-edit", function () {
  120. var rule_id = $(this).data("rule_id");
  121. var channel_ids = $(this).data("channel_id");
  122. if (channel_ids == 'undefined') {
  123. channel_ids = '';
  124. }
  125. layer.open({
  126. type: 1,
  127. title: '批量关联',
  128. maxmin: true,
  129. area: ['60%', '80%'],
  130. btn: ['确定', '取消'],
  131. shadeClose: true, //点击遮罩关闭层
  132. content: $("#qd_multi_edit"),
  133. yes: function (data) {
  134. var channel_ids = $("#c-channel_id").val();
  135. $("#c-channel_id").val("");
  136. $.post('/admin/auth/frontlimit/operate',
  137. {
  138. 'id': rule_id,
  139. 'channel_ids': channel_ids,
  140. 'method': 'add'
  141. },
  142. function (result) {
  143. Toastr.success('操作成功');
  144. //刷新页面
  145. table.bootstrapTable('refresh');
  146. });
  147. layer.closeAll();
  148. }
  149. });
  150. });
  151. // 为表格绑定事件
  152. Table.api.bindevent(table);
  153. },
  154. add: function () {
  155. Form.api.bindevent($("form[role=form]"));
  156. },
  157. edit: function () {
  158. Form.api.bindevent($("form[role=form]"));
  159. },
  160. api: {
  161. formatter: {
  162. fm_associate_channels:function (value, row, index) {
  163. html = '';
  164. if(row.channel_id == '*'){
  165. html += "已关联所有渠道";
  166. }else{
  167. html += "<a href='javascript:;' class='qd-associate' data-rule_id='" + value + "' data-channel_id='"+ row.channel_id+"'>关联</a>&nbsp;&nbsp;";
  168. html += "<a href='javascript:;' class='qd-view' data-rule_id='" + value + "' data-channel_id='"+ row.channel_id+"'>查看</a>&nbsp;&nbsp;";
  169. html += "<a href='javascript:;' class='qd-edit' data-rule_id='" + value + "' data-channel_id='"+ row.channel_id+"'>批量关联</a>";
  170. }
  171. return html;
  172. }
  173. }
  174. }
  175. };
  176. return Controller;
  177. });